[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
Classes | Static Public Member Functions | List of all members
KLFBackend Class Reference

The main engine for KLatexFormula. More...

#include <klfbackend.h>

Classes

struct  klfInput
 Specific input to KLFBackend::getLatexFormula() More...
 
struct  klfOutput
 KLFBackend::getLatexFormula() result. More...
 
struct  klfSettings
 General settings for KLFBackend::getLatexFormula() More...
 

Static Public Member Functions

static klfOutput getLatexFormula (const klfInput &in, const klfSettings &settings)
 The function that processes everything. More...
 
static bool saveOutputToFile (const klfOutput &output, const QString &fileName, const QString &format=QString(), QString *errorString=NULL)
 Save the output to image file. More...
 
static bool saveOutputToDevice (const klfOutput &output, QIODevice *device, const QString &format=QString("PNG"), QString *errorString=NULL)
 Saves the given output into the given device. More...
 
static bool detectSettings (klfSettings *settings, const QString &extraPath=QString())
 Detects the system settings and stores the guessed values in settings. More...
 

Detailed Description

The main engine for KLatexFormula.

The main engine for KLatexFormula, providing core functionality of transforming LaTeX code into graphics.

Don't instanciate this class, use the static function KLFBackend::getLatexFormula() to do all the processing.

Author
Philippe Faist <phili.nosp@m.ppe..nosp@m.faist.nosp@m.@blu.nosp@m.ewin..nosp@m.ch>

Definition at line 120 of file klfbackend.h.

Member Function Documentation

bool KLFBackend::detectSettings ( klfSettings settings,
const QString extraPath = QString() 
)
static
KLFBackend::klfOutput KLFBackend::getLatexFormula ( const klfInput in,
const klfSettings settings 
)
static

The function that processes everything.

Pass on a valid klfInput input object, as well as a klfSettings object filled with your input and settings, and you will get output in klfOutput.

If an error occurs, klfOutput::status is non-zero and klfOutput::errorstr contains an explicit error in human-readable form. The latter is Qt-Translated with QObject::tr() with "KLFBackend" comment.

Usage example:

* ...
* // this could have been declared at some more global scope
* bool ok = KLFBackend::detectSettings(&settings);
* if (!ok) {
* // vital program not found
* raise_error("error in your system: are latex,dvips and gs installed?");
* return;
* }
*
* input.latex = "\\int_{\\Sigma}\\!(\\vec{\\nabla}\\times\\vec u)\\,d\\vec S ="
* " \\oint_C \\vec{u}\\cdot d\\vec r";
* input.mathmode = "\\[ ... \\]";
* input.preamble = "\\usepackage{somerequiredpackage}\n";
* input.fg_color = qRgb(255, 168, 88); // beige
* input.bg_color = qRgba(0, 64, 64, 255); // dark turquoise
* input.dpi = 300;
*
*
* if (out.status != 0) {
* // an error occurred. an appropriate error string is in out.errorstr
* display_error_to_user(out.errorstr);
* return;
* }
*
* myLabel->setPixmap(QPixmap(out.result));
*
* // write contents of 'out.pdfdata' to a file to get a PDF file (for example)
* {
* QFile fpdf(fname);
* fpdf.open(IO_WriteOnly | IO_Raw);
* fpdf.writeBlock(out.pdfdata);
* }
* ...
*
Note
This function is safe for threads; it locks a mutex at the beginning and unlocks it at the end; so if a call to this function is issued while a first call is already being processed in another thread, the second waits for the first call to finish.
Todo:
Hi-Res bounding box adjustment. Shouldn't be too hard to do, but needs tests to see how this works... [ Currently: only integer-valued BoundingBox: is adjusted. ]

Definition at line 208 of file klfbackend.cpp.

References QString::arg(), KLFBackend::klfSettings::bborderoffset, KLFBackend::klfInput::bg_color, KLFBackend::klfInput::bypassTemplate, QString::contains(), QDateTime::currentDateTime(), QByteArray::data(), KLFBackend::klfInput::dpi, KLFBackend::klfSettings::dvipsexec, KLFBackend::klfSettings::epstopdfexec, KLFBackend::klfSettings::execenv, QFile::exists(), KLFBackend::klfInput::fg_color, QByteArray::find(), QString::fromLatin1(), QString::fromLocal8Bit(), KLFBackend::klfSettings::gsexec, QByteArray::indexOf(), QString::isEmpty(), QStringList::join(), klf_cur_environ(), KLF_FUNC_NAME, klfDbg, KLFERR_BADEPSBBOX, KLFERR_DVIPSNONORMALEXIT, KLFERR_EPSREADFAIL, KLFERR_EPSREADFAIL_OF, KLFERR_EPSTOPDFNONORMALEXIT, KLFERR_EPSWRITEFAIL, KLFERR_GSNONORMALEXIT, KLFERR_LATEXNONORMALEXIT, KLFERR_MISSINGLATEXFORMULA, KLFERR_MISSINGMATHMODETHREEDOTS, KLFERR_NODVIFILE, KLFERR_NODVIPSPROG, KLFERR_NOEPSBBOX, KLFERR_NOEPSFILE, KLFERR_NOEPSFILE_OF, KLFERR_NOEPSTOPDFPROG, KLFERR_NOERROR, KLFERR_NOGSPROG, KLFERR_NOLATEXPROG, KLFERR_NOPDFFILE, KLFERR_NOPNGFILE, KLFERR_PDFREADFAIL, KLFERR_PNGREADFAIL, KLFERR_PROGERR_DVIPS, KLFERR_PROGERR_EPSTOPDF, KLFERR_PROGERR_GS, KLFERR_PROGERR_GS_OF, KLFERR_PROGERR_LATEX, KLFERR_TEXWRITEFAIL, KLFBackend::klfInput::latex, KLFBackend::klfSettings::latexexec, KLFBackend::klfSettings::lborderoffset, KLFBackend::klfInput::mathmode, QString::number(), QFile::open(), KLFBackend::klfSettings::outlineFonts, KLFBackend::klfInput::preamble, KLFBlockProcess::processExitStatus(), KLFBlockProcess::processNormalExit(), KLFBackend::klfSettings::rborderoffset, KLFBlockProcess::readStderrString(), KLFBlockProcess::readStdoutString(), QByteArray::replace(), QString::replace(), QProcess::setWorkingDirectory(), QByteArray::size(), KLFBlockProcess::startProcess(), KLFBackend::klfOutput::status, QString::stripWhiteSpace(), KLFBackend::klfSettings::tborderoffset, KLFBackend::klfSettings::tempdir, and QObject::tr().

bool KLFBackend::saveOutputToDevice ( const klfOutput output,
QIODevice device,
const QString format = QString("PNG"),
QString errorString = NULL 
)
static

Saves the given output into the given device.

Overloaded function, provided for convenience. Behaves very much like saveOutputToFile(), except that the format cannot be guessed.

Definition at line 691 of file klfbackend.cpp.

References KLFBackend::klfOutput::epsdata, QByteArray::isEmpty(), QString::operator(), KLFBackend::klfOutput::pdfdata, KLFBackend::klfOutput::pngdata, KLFBackend::klfOutput::result, QImage::save(), and QObject::tr().

Referenced by saveOutputToFile().

bool KLFBackend::saveOutputToFile ( const klfOutput output,
const QString fileName,
const QString format = QString(),
QString errorString = NULL 
)
static

Save the output to image file.

This function can be used to write output obtained with the getLatexFormula() function, to a file named fileName with format format.

Parameters
outputthe data to save (e.g. as returned by getLatexFormula() )
fileNamethe file name to save to. If empty or equal to "-" then standard output is used.
formatthe format to use to save to fileName
errorStringif a valid pointer, then when an error occurs this string is set to a text describing the error.

If format is an empty string, then format is guessed from filename extension; if no extension is found then format defaults to PNG.

fileName 's extension is NOT adjusted if it does not match an explicitely given format, for example

saveOutputToFile(output, "myfile.jpg", "PDF");

will output PDF data to the file "myfile.jpg".

If errorString is non-NULL, then it is set to a human-readable description of the error that occurred if this function returns FALSE. It is left untouched if success.

Returns
TRUE if success or FALSE if failure.

qWarning()s are emitted in case of failure.

Definition at line 726 of file klfbackend.cpp.

References QString::isEmpty(), QFile::open(), saveOutputToDevice(), and QObject::tr().


The documentation for this class was generated from the following files:

Generated by doxygen 1.8.5