[KLF Application][KLF Tools][KLF Backend][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) 2007 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: klfbackend.h 540 2010-10-04 00:19:05Z philippe $ */
00023 
00024 #ifndef KLFBACKEND_H
00025 #define KLFBACKEND_H
00026 
00027 #include <klfdefs.h>
00028 
00029 #include <qstring.h>
00030 #include <qstringlist.h>
00031 #ifdef KLFBACKEND_QT4
00032 #include <QByteArray>
00033 #else
00034 #include <qmemarray.h>
00035 #endif
00036 #include <qimage.h>
00037 #include <qmutex.h>
00038 
00039 
00040 
00042 
00047 
00048 #define KLFERR_NOERROR 0
00049 
00051 #define KLFERR_MISSINGLATEXFORMULA -1
00052 
00053 #define KLFERR_MISSINGMATHMODETHREEDOTS -2
00054 
00055 #define KLFERR_TEXWRITEFAIL -3
00056 
00057 #define KLFERR_NOLATEXPROG -4
00058 
00059 #define KLFERR_LATEXNONORMALEXIT -5
00060 
00061 #define KLFERR_NODVIFILE -6
00062 
00063 #define KLFERR_NODVIPSPROG -7
00064 
00065 #define KLFERR_DVIPSNONORMALEXIT -8
00066 
00067 #define KLFERR_NOEPSFILE -9
00068 
00069 #define KLFERR_EPSREADFAIL -10
00070 
00071 #define KLFERR_NOEPSBBOX -11
00072 
00073 #define KLFERR_BADEPSBBOX -12
00074 
00075 #define KLFERR_EPSWRITEFAIL -13
00076 
00077 #define KLFERR_NOEPSFILE_OF -22
00078 
00079 #define KLFERR_EPSREADFAIL_OF -23
00080 
00081 #define KLFERR_NOGSPROG -14
00082 
00083 #define KLFERR_GSNONORMALEXIT -15
00084 
00085 #define KLFERR_NOPNGFILE -16
00086 
00087 #define KLFERR_PNGREADFAIL -17
00088 
00089 #define KLFERR_NOEPSTOPDFPROG -18
00090 
00091 #define KLFERR_EPSTOPDFNONORMALEXIT -19
00092 
00093 #define KLFERR_NOPDFFILE -20
00094 
00095 #define KLFERR_PDFREADFAIL -21
00096 // last error defined: -23
00097 
00099 #define KLFERR_PROGERR_LATEX 1
00100 
00101 #define KLFERR_PROGERR_DVIPS 2
00102 
00103 #define KLFERR_PROGERR_GS 3
00104 
00105 #define KLFERR_PROGERR_GS_OF 5
00106 
00107 #define KLFERR_PROGERR_EPSTOPDF 4
00108 // last error defined: 5
00109 
00110 
00112 
00120 class KLF_EXPORT KLFBackend
00121 {
00122 public:
00123 
00125 
00130   struct klfSettings {
00132     klfSettings() : tborderoffset(0), rborderoffset(0), bborderoffset(0), lborderoffset(0),
00133                     outlineFonts(true), execenv() { }
00135     QString tempdir;
00137     QString latexexec;
00139     QString dvipsexec;
00141     QString gsexec;
00146     QString epstopdfexec;
00147 
00151     double tborderoffset;
00155     double rborderoffset;
00159     double bborderoffset;
00163     double lborderoffset;
00164 
00169     bool outlineFonts;
00170 
00173     QStringList execenv;
00174   };
00175 
00177 
00179   struct klfInput {
00181     klfInput() : fg_color(0x00), bg_color(0xffffffff), dpi(600), bypassTemplate(false) { }
00183     QString latex;
00189     QString mathmode;
00192     QString preamble;
00195     unsigned long fg_color;
00201     unsigned long bg_color;
00204     int dpi;
00211     bool bypassTemplate;
00212   };
00213 
00215 
00217   struct klfOutput {
00227     int status;
00235     QString errorstr;
00236 
00238     QImage result;
00239 
00241     klfInput input;
00243     klfSettings settings;
00244 
00249     QByteArray pngdata_raw;
00268     QByteArray pngdata;
00270     QByteArray epsdata;
00272     QByteArray pdfdata;
00273   };
00274 
00328   static klfOutput getLatexFormula(const klfInput& in, const klfSettings& settings);
00329 
00356   static bool saveOutputToFile(const klfOutput& output, const QString& fileName,
00357                                const QString& format = QString(), QString* errorString = NULL);
00358 
00364   static bool saveOutputToDevice(const klfOutput& output, QIODevice *device,
00365                                  const QString& format = QString("PNG"), QString* errorString = NULL);
00366 
00374   static bool detectSettings(klfSettings *settings, const QString& extraPath = QString());
00375 
00376 
00377 private:
00378   KLFBackend();
00379 
00380   friend struct cleanup_caller;
00381   static void cleanup(QString tempfname);
00382 
00383   static QMutex __mutex;
00384 };
00385 
00386 
00388 bool KLF_EXPORT operator==(const KLFBackend::klfInput& a, const KLFBackend::klfInput& b);
00389 
00390 bool KLF_EXPORT klf_detect_execenv(KLFBackend::klfSettings *settings);
00391 
00392 #endif

Generated by doxygen 1.7.3