Changeset View
Changeset View
Standalone View
Standalone View
src/lib/latexrenderer.cpp
Show All 20 Lines | |||||
21 | #include "latexrenderer.h" | 21 | #include "latexrenderer.h" | ||
22 | using namespace Cantor; | 22 | using namespace Cantor; | ||
23 | 23 | | |||
24 | #include <KProcess> | 24 | #include <KProcess> | ||
25 | #include <QDebug> | 25 | #include <QDebug> | ||
26 | #include <QFileInfo> | 26 | #include <QFileInfo> | ||
27 | #include <QEventLoop> | 27 | #include <QEventLoop> | ||
28 | #include <QTemporaryFile> | 28 | #include <QTemporaryFile> | ||
29 | #include <KColorScheme> | ||||
29 | 30 | | |||
30 | #include <config-cantorlib.h> | 31 | #include <config-cantorlib.h> | ||
31 | #include "settings.h" | 32 | #include "settings.h" | ||
32 | 33 | | |||
33 | class Cantor::LatexRendererPrivate | 34 | class Cantor::LatexRendererPrivate | ||
34 | { | 35 | { | ||
35 | public: | 36 | public: | ||
36 | QString latexCode; | 37 | QString latexCode; | ||
37 | QString header; | 38 | QString header; | ||
38 | LatexRenderer::Method method; | 39 | LatexRenderer::Method method; | ||
39 | bool isEquationOnly; | 40 | bool isEquationOnly; | ||
40 | LatexRenderer::EquationType equationType; | 41 | LatexRenderer::EquationType equationType; | ||
41 | QString errorMessage; | 42 | QString errorMessage; | ||
42 | bool success; | 43 | bool success; | ||
43 | QString latexFilename; | 44 | QString latexFilename; | ||
44 | }; | 45 | }; | ||
45 | 46 | | |||
46 | static const QLatin1String tex("\\documentclass[12pt,fleqn]{article} \n "\ | 47 | static const QLatin1String tex("\\documentclass[12pt,fleqn]{article} \n "\ | ||
47 | "\\usepackage{latexsym,amsfonts,amssymb,ulem} \n "\ | 48 | "\\usepackage{latexsym,amsfonts,amssymb,ulem} \n "\ | ||
48 | "\\usepackage[dvips]{graphicx} \n "\ | 49 | "\\usepackage[dvips]{graphicx} \n "\ | ||
49 | "\\usepackage[utf8]{inputenc} \n "\ | 50 | "\\usepackage[utf8]{inputenc} \n "\ | ||
51 | "\\usepackage{xcolor} \n "\ | ||||
50 | "\\setlength\\textwidth{5in} \n "\ | 52 | "\\setlength\\textwidth{5in} \n "\ | ||
51 | "\\setlength{\\parindent}{0pt} \n "\ | 53 | "\\setlength{\\parindent}{0pt} \n "\ | ||
52 | "%1 \n "\ | 54 | "%1 \n "\ | ||
55 | "\\pagecolor[rgb]{%2,%3,%4} \n "\ | ||||
53 | "\\pagestyle{empty} \n "\ | 56 | "\\pagestyle{empty} \n "\ | ||
54 | "\\begin{document} \n "\ | 57 | "\\begin{document} \n "\ | ||
55 | "%2 \n "\ | 58 | "\\color[rgb]{%5,%6,%7} \n "\ | ||
59 | "%8 \n "\ | ||||
56 | "\\end{document}\n"); | 60 | "\\end{document}\n"); | ||
57 | 61 | | |||
58 | static const QLatin1String eqnHeader("\\begin{eqnarray*}%1\\end{eqnarray*} \n "); | 62 | static const QLatin1String eqnHeader("\\begin{eqnarray*}%1\\end{eqnarray*} \n "); | ||
59 | static const QLatin1String inlineEqnHeader("$%1$ \n"); | 63 | static const QLatin1String inlineEqnHeader("$%1$ \n"); | ||
60 | 64 | | |||
61 | LatexRenderer::LatexRenderer(QObject* parent) : QObject(parent), | 65 | LatexRenderer::LatexRenderer(QObject* parent) : QObject(parent), | ||
62 | d(new LatexRendererPrivate) | 66 | d(new LatexRendererPrivate) | ||
63 | { | 67 | { | ||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | |||||
172 | { | 176 | { | ||
173 | qDebug()<<"rendering using latex method"; | 177 | qDebug()<<"rendering using latex method"; | ||
174 | QString dir=QStandardPaths::writableLocation(QStandardPaths::TempLocation); | 178 | QString dir=QStandardPaths::writableLocation(QStandardPaths::TempLocation); | ||
175 | 179 | | |||
176 | //Check if the cantor subdir exists, if not, create it | 180 | //Check if the cantor subdir exists, if not, create it | ||
177 | QTemporaryFile *texFile=new QTemporaryFile(dir + QLatin1String("/cantor_tex-XXXXXX.tex")); | 181 | QTemporaryFile *texFile=new QTemporaryFile(dir + QLatin1String("/cantor_tex-XXXXXX.tex")); | ||
178 | texFile->open(); | 182 | texFile->open(); | ||
179 | 183 | | |||
184 | KColorScheme scheme(QPalette::Active); | ||||
185 | const QColor &backgroundColor=scheme.background().color(); | ||||
186 | const QColor &foregroundColor=scheme.foreground().color(); | ||||
180 | QString expressionTex=tex; | 187 | QString expressionTex=tex; | ||
181 | expressionTex=expressionTex.arg(d->header); | 188 | expressionTex=expressionTex.arg(d->header) | ||
189 | .arg(backgroundColor.redF()).arg(backgroundColor.greenF()).arg(backgroundColor.blueF()) | ||||
190 | .arg(foregroundColor.redF()).arg(foregroundColor.greenF()).arg(foregroundColor.blueF()); | ||||
182 | if(isEquationOnly()) | 191 | if(isEquationOnly()) | ||
183 | { | 192 | { | ||
184 | switch(equationType()) | 193 | switch(equationType()) | ||
185 | { | 194 | { | ||
186 | case FullEquation: expressionTex=expressionTex.arg(eqnHeader); break; | 195 | case FullEquation: expressionTex=expressionTex.arg(eqnHeader); break; | ||
187 | case InlineEquation: expressionTex=expressionTex.arg(inlineEqnHeader); break; | 196 | case InlineEquation: expressionTex=expressionTex.arg(inlineEqnHeader); break; | ||
188 | } | 197 | } | ||
189 | } | 198 | } | ||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |