[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
src/klfbackend/klfbackend.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  *   file klfbackend.h
00003  *   This file is part of the KLatexFormula Project.
00004  *   Copyright (C) 2011 by Philippe Faist
00005  *   philippe.faist@bluewin.ch
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /* $Id$ */
00023 
00024 #ifndef KLFBACKEND_H
00025 #define KLFBACKEND_H
00026 
00027 #include <QString>
00028 #include <QStringList>
00029 #include <QByteArray>
00030 #include <QImage>
00031 #include <QMutex>
00032 #include <QMap>
00033 #include <QVariant>
00034 
00035 #include <klfdefs.h>
00036 #include <klfpobj.h>
00037 #include <klfutil.h> // KLFRefPtr
00038 
00040 
00045 
00046 #define KLFERR_NOERROR 0
00047 
00049 #define KLFERR_TEMPDIR_FAIL -48
00050 
00051 #define KLFERR_MISSINGLATEXFORMULA -1
00052 
00053 #define KLFERR_MISSINGMATHMODETHREEDOTS -2
00054 
00055 #define KLFERR_TEXWRITEFAIL -3
00056 
00057 #define KLFERR_LATEX_NORUN -4
00058 
00059 #define KLFERR_NOLATEXPROG KLFERR_LATEX_NORUN
00060 
00061 #define KLFERR_LATEX_NONORMALEXIT -5
00062 
00063 #define KLFERR_LATEXNONORMALEXIT KLFERR_LATEX_NONORMALEXIT
00064 
00065 #define KLFERR_LATEX_NOOUTPUT -6
00066 
00067 #define KLFERR_NODVIFILE KLFERR_LATEX_NOOUTPUT
00068 
00069 #define KLFERR_LATEX_OUTPUTREADFAIL -24
00070 
00071 #define KLFERR_DVIREADFAIL KLFERR_LATEX_OUTPUTREADFAIL
00072 
00073 #define KLFERR_DVIPS_NORUN -7
00074 
00075 #define KLFERR_NODVIPSPROG KLFERR_DVIPS_NORUN
00076 
00077 #define KLFERR_DVIPS_NONORMALEXIT -8
00078 
00079 #define KLFERR_DVIPSNONORMALEXIT KLFERR_DVIPS_NONORMALEXIT
00080 
00081 #define KLFERR_DVIPS_NOOUTPUT -9
00082 
00083 #define KLFERR_NOEPSFILE KLFERR_DVIPS_NOOUTPUT
00084 
00085 #define KLFERR_DVIPS_OUTPUTREADFAIL -10
00086 
00087 #define KLFERR_EPSREADFAIL KLFERR_DVIPS_OUTPUTREADFAIL
00088 
00089 #define KLFERR_DVIPS_OUTPUTNOBBOX -11
00090 
00091 #define KLFERR_NOEPSBBOX KLFERR_DVIPS_OUTPUTNOBBOX
00092 
00093 #define KLFERR_GSBBOX_NORUN -25
00094 
00095 #define KLFERR_GSBBOX_NONORMALEXIT -26
00096 
00097 #define KLFERR_GSBBOX_NOOUTPUT -27
00098 
00099 #define KLFERR_GSBBOX_NOBBOX -28
00100 
00101 #define KLFERR_GSPOSTPROC_NORUN -29
00102 
00103 #define KLFERR_GSPOSTPROC_NONORMALEXIT -30
00104 
00105 #define KLFERR_GSPOSTPROC_NOOUTPUT -22
00106 
00107 #define KLFERR_GSPOSTPROC_NOOUTLINEFONTS -49
00108 
00109 #define KLFERR_NOEPSFILE_OF KLFERR_GSPOSTPROC_NOOUTPUT
00110 
00111 #define KLFERR_GSPOSTPROC_OUTPUTREADFAIL -23
00112 
00113 #define KLFERR_EPSREADFAIL_OF KLFERR_GSPOSTPROC_OUTPUTREADFAIL
00114 
00115 #define KLFERR_GSPNG_NORUN -14
00116 
00117 #define KLFERR_NOGSPROG KLFERR_GSPNG_NORUN
00118 
00119 #define KLFERR_GSPNG_NONORMALEXIT -15
00120 
00121 #define KLFERR_GSNONORMALEXIT KLFERR_GSPNG_NONORMALEXIT
00122 
00123 #define KLFERR_GSPNG_NOOUTPUT -16
00124 
00125 #define KLFERR_NOPNGFILE KLFERR_GSPNG_NOOUTPUT
00126 
00127 #define KLFERR_GSPNG_OUTPUTREADFAIL -17
00128 
00129 #define KLFERR_PNGREADFAIL KLFERR_GSPNG_OUTPUTREADFAIL
00130 
00131 #define KLFERR_PDFMARKSWRITEFAIL -47
00132 
00133 #define KLFERR_GSPDF_NORUN -31
00134 
00135 #define KLFERR_GSPDF_NONORMALEXIT -19
00136 
00137 #define KLFERR_EPSTOPDFNONORMALEXIT KLFERR_GSPDF_NONORMALEXIT
00138 
00139 #define KLFERR_GSPDF_NOOUTPUT -20
00140 
00141 #define KLFERR_NOPDFFILE KLFERR_GSPDF_NOOUTPUT
00142 
00143 #define KLFERR_GSPDF_OUTPUTREADFAIL -21
00144 
00145 #define KLFERR_PDFREADFAIL KLFERR_GSPDF_OUTPUTREADFAIL
00146 
00147 #define KLFERR_NOGSVERSION -32
00148 
00149 #define KLFERR_GSSVG_NOSVG -33
00150 
00151 #define KLFERR_GSSVG_NORUN -34
00152 
00153 #define KLFERR_GSSVG_NONORMALEXIT -35
00154 
00155 #define KLFERR_GSSVG_NOOUTPUT -36
00156 
00157 #define KLFERR_GSSVG_OUTPUTREADFAIL -37
00158 
00159 #define KLFERR_USERSCRIPT_NORUN -38
00160 #define KLFERR_USERSCRIPT_NONORMALEXIT -39
00161 #define KLFERR_USERSCRIPT_NOSCRIPTINFO -40
00162 #define KLFERR_USERSCRIPT_INVALIDSCRIPTINFO -41
00163 #define KLFERR_USERSCRIPT_NOOUTPUT -42
00164 #define KLFERR_USERSCRIPT_OUTPUTREADFAIL -43
00165 #define KLFERR_USERSCRIPT_BADKLFVERSION -44
00166 #define KLFERR_USERSCRIPT_BADSKIPFORMATS -45
00167 #define KLFERR_USERSCRIPT_BADCATEGORY -46
00168 // last error defined: -49
00169 
00170 
00171 
00173 #define KLFERR_PROGERR_LATEX 1
00174 
00175 #define KLFERR_PROGERR_DVIPS 2
00176 
00177 #define KLFERR_PROGERR_GSBBOX 6
00178 
00179 #define KLFERR_PROGERR_GSPOSTPROC 5
00180 
00181 #define KLFERR_PROGERR_GS_OF KLFERR_PROGERR_GSPOSTPROC
00182 
00183 #define KLFERR_PROGERR_GSPNG 3
00184 
00185 #define KLFERR_PROGERR_GS KLFERR_PROGERR_GSPNG
00186 
00187 #define KLFERR_PROGERR_GSPDF 4
00188 
00189 #define KLFERR_PROGERR_EPSTOPDF KLFERR_PROGERR_GSPDF
00190 
00191 #define KLFERR_PROGERR_GSSVG 7
00192 
00193 #define KLFERR_PROGERR_USERSCRIPT 8
00194 // last error defined: 8
00195 
00196 
00198 
00206 class KLF_EXPORT KLFBackend
00207 {
00208 public:
00209 
00210   class TemplateGenerator;
00211 
00213 
00218   struct klfSettings
00219   {
00221     klfSettings() : tborderoffset(0), rborderoffset(0), bborderoffset(0), lborderoffset(0),
00222                     calcEpsBoundingBox(true), outlineFonts(true),
00223                     wantRaw(false), wantPDF(true), wantSVG(true), execenv(),
00224                     templateGenerator(NULL) { }
00225 
00227     QString tempdir;
00229     QString latexexec;
00231     QString dvipsexec;
00233     QString gsexec;
00243     QString epstopdfexec;
00244 
00248     double tborderoffset;
00252     double rborderoffset;
00256     double bborderoffset;
00260     double lborderoffset;
00261 
00264     bool calcEpsBoundingBox;
00265 
00273     bool outlineFonts;
00274 
00277     bool wantRaw;
00278 
00281     bool wantPDF;
00282 
00285     bool wantSVG;
00286 
00289     QStringList execenv;
00290 
00294     TemplateGenerator *templateGenerator;
00295 
00300     QMap<QString,QString> userScriptInterpreters;
00301   };
00302 
00304 
00306   struct klfInput
00307   {
00309     klfInput() : fontsize(-1), fg_color(0x00), bg_color(0xffffffff), dpi(600), vectorscale(1.0),
00310                  bypassTemplate(false) { }
00312     QString latex;
00318     QString mathmode;
00321     QString preamble;
00326     double fontsize;
00327 
00328     unsigned long fg_color;
00334     unsigned long bg_color;
00337     int dpi;
00338 
00340     double vectorscale;
00341 
00348     bool bypassTemplate;
00349 
00356     QString userScript;
00357 
00364     QMap<QString,QString> userScriptParam;
00365   };
00366 
00368 
00370   struct klfOutput
00371   {
00381     int status;
00382 
00390     QString errorstr;
00391 
00393     QImage result;
00394 
00396     klfInput input;
00398     klfSettings settings;
00399 
00401     QByteArray dvidata;
00408     QByteArray pngdata_raw;
00428     QByteArray pngdata;
00434     QByteArray epsdata_raw;
00441     QByteArray epsdata_bbox;
00445     QByteArray epsdata;
00447     QByteArray pdfdata;
00449     QByteArray svgdata;
00451     double width_pt;
00453     double height_pt;
00454   };
00455 
00517   static klfOutput getLatexFormula(const klfInput& in, const klfSettings& settings,
00518                                    bool isMainThread = true);
00519 
00534   static QStringList availableSaveFormats(const klfOutput * output = NULL) ;
00535 
00540   static QStringList availableSaveFormats(const klfOutput& output) ;
00541 
00568   static bool saveOutputToFile(const klfOutput& output, const QString& fileName,
00569                                const QString& format = QString(), QString* errorString = NULL);
00570 
00576   static bool saveOutputToDevice(const klfOutput& output, QIODevice *device,
00577                                  const QString& format = QString("PNG"), QString* errorString = NULL);
00578 
00593   static bool detectSettings(klfSettings *settings, const QString& extraPath = QString(),
00594                              bool isMainThread = true);
00595 
00618   static bool detectOptionSettings(klfSettings *settings, bool isMainThread = true);
00619 
00621   static QStringList userScriptSettingsToEnvironment(const QMap<QString,QString>& userScriptSettings);
00622 
00623 
00624   class TemplateGenerator {
00625   public:
00626     TemplateGenerator();
00627     virtual ~TemplateGenerator();
00628 
00629     virtual QString generateTemplate(const klfInput& input, const klfSettings& settings) = 0;
00630   };
00631 
00632   class DefaultTemplateGenerator : public TemplateGenerator {
00633   public:
00634     DefaultTemplateGenerator();
00635     virtual ~DefaultTemplateGenerator();
00636 
00637     virtual QString generateTemplate(const klfInput& input, const klfSettings& settings);
00638   };
00639 
00640 
00641 
00642 private:
00643   KLFBackend();
00644 };
00645 
00646 
00647 
00649 KLF_EXPORT bool operator==(const KLFBackend::klfInput& a, const KLFBackend::klfInput& b);
00650 KLF_EXPORT bool operator==(const KLFBackend::klfSettings& a, const KLFBackend::klfSettings& b);
00651 
00671 KLF_EXPORT bool klf_detect_execenv(KLFBackend::klfSettings *settings);
00672 
00673 
00674 
00675 
00676 
00677 KLF_EXPORT QStringList klfSettingsToEnvironmentForUserScript(const KLFBackend::klfSettings& settings);
00678 KLF_EXPORT QStringList klfInputToEnvironmentForUserScript(const KLFBackend::klfInput& in);
00679 
00680 
00681 
00687 class KLF_EXPORT KLFAbstractLatexMetaInfo
00688 {
00689 public:
00690   KLFAbstractLatexMetaInfo();
00691   virtual ~KLFAbstractLatexMetaInfo();
00692 
00693   virtual QString loadField(const QString& key) = 0;
00694   virtual void saveField(const QString& key, const QString& value) = 0;
00695 
00696   virtual void saveMetaInfo(const KLFBackend::klfInput& in, const KLFBackend::klfSettings& settings) ;
00697 };
00698 
00699 class KLF_EXPORT KLFImageLatexMetaInfo : public KLFAbstractLatexMetaInfo
00700 {
00701 public:
00702   KLFImageLatexMetaInfo(QImage *img);
00703 
00704   QString loadField(const QString &k);
00705   void saveField(const QString& k, const QString& v);
00706 
00707 private:
00708   QImage *_w;
00709 };
00710 
00711 
00728 class KLFPdfmarksWriteLatexMetaInfo : public KLFAbstractLatexMetaInfo
00729 {
00730 public:
00731   KLFPdfmarksWriteLatexMetaInfo(QByteArray * string);
00732 
00733   void saveField(const QString& k, const QString& v);
00734   void finish();
00735 
00737   void savePDFField(const QString& k, const QString& v);
00738 
00740   QString loadField(const QString& );
00741 
00742 private:
00743   QByteArray * _s;
00744 };
00745 
00746 
00747 
00748 
00749 
00750 #endif

Generated by doxygen 1.7.6.1. The KLatexFormula website is hosted on sourceforge.net