Changeset View
Changeset View
Standalone View
Standalone View
src/mathrendertask.cpp
Show All 27 Lines | |||||
28 | #include <KProcess> | 28 | #include <KProcess> | ||
29 | #include <QScopedPointer> | 29 | #include <QScopedPointer> | ||
30 | #include <QApplication> | 30 | #include <QApplication> | ||
31 | #include <QDebug> | 31 | #include <QDebug> | ||
32 | 32 | | |||
33 | #include "lib/renderer.h" | 33 | #include "lib/renderer.h" | ||
34 | #include "lib/latexrenderer.h" | 34 | #include "lib/latexrenderer.h" | ||
35 | 35 | | |||
36 | static const QLatin1String mathTex("\\documentclass%9{standalone}"\ | 36 | static const QLatin1String mathTex("\\documentclass%9{minimal}"\ | ||
37 | "\\usepackage{amsfonts,amssymb}"\ | 37 | "\\usepackage{amsfonts,amssymb}"\ | ||
38 | "\\usepackage{amsmath}"\ | 38 | "\\usepackage{amsmath}"\ | ||
39 | "\\usepackage[utf8]{inputenc}"\ | 39 | "\\usepackage[utf8]{inputenc}"\ | ||
40 | "\\usepackage[active,displaymath,textmath,tightpage]{preview}"\ | ||||
40 | "\\usepackage{color}"\ | 41 | "\\usepackage{color}"\ | ||
41 | /* | | |||
42 | "\\setlength\\textwidth{5in}"\ | | |||
43 | "\\setlength{\\parindent}{0pt}"\ | | |||
44 | "\\pagestyle{empty}"\ | | |||
45 | */ | | |||
46 | "\\begin{document}"\ | 42 | "\\begin{document}"\ | ||
47 | "\\pagecolor[rgb]{%1,%2,%3}"\ | 43 | "\\begin{preview}"\ | ||
44 | "$"\ | ||||
45 | "\\colorbox[rgb]{%1,%2,%3}{"\ | ||||
48 | "\\color[rgb]{%4,%5,%6}"\ | 46 | "\\color[rgb]{%4,%5,%6}"\ | ||
49 | "\\fontsize{%7}{%7}\\selectfont"\ | 47 | "\\fontsize{%7}{%7}\\selectfont"\ | ||
50 | "%8"\ | 48 | "%8}"\ | ||
49 | "$"\ | ||||
50 | "\\end{preview}" | ||||
51 | "\\end{document}"); | 51 | "\\end{document}"); | ||
52 | 52 | | |||
53 | static const QLatin1String eqnHeader("$\\displaystyle %1$"); | 53 | static const QLatin1String eqnHeader("$\\displaystyle %1$"); | ||
54 | static const QLatin1String inlineEqnHeader("$%1$"); | 54 | static const QLatin1String inlineEqnHeader("$%1$"); | ||
55 | 55 | | |||
56 | MathRenderTask::MathRenderTask( | 56 | MathRenderTask::MathRenderTask( | ||
57 | int jobId, | 57 | int jobId, | ||
58 | const QString& code, | 58 | const QString& code, | ||
Show All 18 Lines | 76 | { | |||
77 | qDebug()<<"MathRenderTask::run " << m_jobId; | 77 | qDebug()<<"MathRenderTask::run " << m_jobId; | ||
78 | QSharedPointer<MathRenderResult> result(new MathRenderResult()); | 78 | QSharedPointer<MathRenderResult> result(new MathRenderResult()); | ||
79 | 79 | | |||
80 | const QString& tempDir=QStandardPaths::writableLocation(QStandardPaths::TempLocation); | 80 | const QString& tempDir=QStandardPaths::writableLocation(QStandardPaths::TempLocation); | ||
81 | 81 | | |||
82 | QTemporaryFile texFile(tempDir + QDir::separator() + QLatin1String("cantor_tex-XXXXXX.tex")); | 82 | QTemporaryFile texFile(tempDir + QDir::separator() + QLatin1String("cantor_tex-XXXXXX.tex")); | ||
83 | texFile.open(); | 83 | texFile.open(); | ||
84 | 84 | | |||
85 | // Verify that standalone.cls available for rendering and could be founded | 85 | // make sure we have preview.sty available | ||
86 | if (!tempDir.contains(QLatin1String("standalone.cls"))) | 86 | if (!tempDir.contains(QLatin1String("preview.cls"))) | ||
87 | { | 87 | { | ||
88 | QString file = QStandardPaths::locate(QStandardPaths::AppDataLocation, QLatin1String("latex/standalone.cls")); | 88 | QString file = QStandardPaths::locate(QStandardPaths::AppDataLocation, QLatin1String("latex/preview.sty")); | ||
89 | 89 | | |||
90 | if (file.isEmpty()) | 90 | if (file.isEmpty()) | ||
91 | file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("cantor/latex/standalone.cls")); | 91 | file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("cantor/latex/preview.sty")); | ||
92 | 92 | | |||
93 | if (file.isEmpty()) | 93 | if (file.isEmpty()) | ||
94 | { | 94 | { | ||
95 | result->successful = false; | 95 | result->successful = false; | ||
96 | result->errorMessage = QString::fromLatin1("needed for math render standalone.cls file not found in Cantor data directory"); | 96 | result->errorMessage = QString::fromLatin1("LaTeX style file preview.sty not found."); | ||
97 | finalize(result); | 97 | finalize(result); | ||
98 | return; | 98 | return; | ||
99 | } | 99 | } | ||
100 | else | 100 | else | ||
101 | QFile::copy(file, tempDir + QDir::separator() + QLatin1String("standalone.cls")); | 101 | QFile::copy(file, tempDir + QDir::separator() + QLatin1String("preview.sty")); | ||
102 | } | 102 | } | ||
103 | QString expressionTex=mathTex; | 103 | QString expressionTex=mathTex; | ||
104 | 104 | | |||
105 | expressionTex=expressionTex | 105 | expressionTex=expressionTex | ||
106 | .arg(m_backgroundColor.redF()).arg(m_backgroundColor.greenF()).arg(m_backgroundColor.blueF()) | 106 | .arg(m_backgroundColor.redF()).arg(m_backgroundColor.greenF()).arg(m_backgroundColor.blueF()) | ||
107 | .arg(m_foregroundColor.redF()).arg(m_foregroundColor.greenF()).arg(m_foregroundColor.blueF()); | 107 | .arg(m_foregroundColor.redF()).arg(m_foregroundColor.greenF()).arg(m_foregroundColor.blueF()); | ||
108 | int fontPointSize = QApplication::font().pointSize(); | 108 | int fontPointSize = QApplication::font().pointSize(); | ||
109 | expressionTex=expressionTex.arg(fontPointSize); | 109 | expressionTex=expressionTex.arg(fontPointSize); | ||
▲ Show 20 Lines • Show All 137 Lines • Show Last 20 Lines |