JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtmathtext.h
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>)
3 with contributions from: Razi Alavizadeh
4
5
6
7 This software is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License (LGPL) as published by
9 the Free Software Foundation, either version 2.1 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License (LGPL) for more details.
16
17 You should have received a copy of the GNU Lesser General Public License (LGPL)
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21
22
23
24
25#ifndef JKQTMATHTEXT_H
26#define JKQTMATHTEXT_H
27
28#include <QFlags>
29#include <QObject>
30#include <QSettings>
31#include <QPainter>
32#include <QString>
33#include <QSet>
34#include <QFile>
35#include "jkqtmathtext/jkqtmathtext_imexport.h"
36#include "jkqtmathtext/jkqtmathtexttools.h"
37#include <QHash>
38#include <QPicture>
39#include <QImage>
40#include <QPixmap>
41#include <type_traits>
42#include <memory>
43#include <mutex>
44
45
46class JKQTMathTextNode; // forward
47class JKQTMathTextParser; // forward
48class JKQTMathTextVerticalListNode; // forward
49
50/*! \brief this class parses a mathematical markup string and can then draw the contained text/equation onto a <a href="http://doc.qt.io/qt-5/qpainter.html">QPainter</a>
51 \ingroup jkqtmathtext_render
52
53
54 JKQTMathText is a self-contained mathematical markup renderer for Qt. It is used to renderer
55 labels in JKQTPlotter/JKQTBasePlotter, but can be used independently.
56 The class does not depend on any library, except Qt.
57
58 The implementation is split over several classes:
59 - JKQTMathText implements drawing, based on a memory representatioj of the markup. It also provides an interface for class users.
60 - JKQTMathTextParser and its children like JKQTMathTextLatexParser parses mathamtical markup.
61 - The nodes summarized in \ref jkqtmathtext_items are used to build the memory representation of the markup.
62 .
63
64 In particular JKQTMathTextLatexParser actually parses e.g. a LaTeX string and draws it in pure C++. It does NOT rely
65 on an installed LaTeX for the rendering! See \ref jkqtmathtext_supportedlatex for a description of the supported LaTeX subset.
66
67 More generally these pages describe how the class renders math markup:
68 - \ref jkqtmathtext_renderingmodel for a description of the rendering model of JKQTMathTextLatexParser
69 - \ref jkqtmathtext_fonthandling for a description of the font handling in JKQTMathTextLatexParser
70 (which is modelled after LaTeX, but with tweaks especially for use in the context of GUI code)
71 - \ref jkqtmathtext_supportedlatex for a description of the supported LaTeX subset
72 .
73
74 \section JKQTMathTextUsageThreadSafety Thread-Safety/Re-Entrancy Guarantees
75 All functions in this class are reentrant. Therefore different instances off JKQTMathtext can be used in parallel in different threads.
76 DO NOT however use the same instance from multiple threads, as the functions are not thread-safe!
77
78 Also note that there are certain caches that reuse information (e.g. about fonts) from previous runs, which allow different instances
79 (also over different threads) to profit from each other. On the other hand, this strategy requires a bit of overhead due to synchronization,
80 but usually the speedup outweighs the overhead significantly!
81
82
83 \section JKQTMathTextUsage Usage
84
85 \see See \ref page_buildinstructions for detailed build-instructions and on how to link against JKQTMathText!
86
87
88 \subsection JKQTMathTextUsageParsing Parsing Functions
89 The class provieds two flavours of a parsing function:
90 - There is a function \c parse(markup, markupType) that accepts the markup, the type of markup (as enum DefaultParserTypes) and parser options.
91 This function determines the appropriate parser class, based on the markup type.
92 - A templated function parse<TParser>(markup, options) that gets a parser class to be used on the markup.
93 .
94
95 \subsection JKQTMathTextUsageDirect Drawing Functions
96 The class provides different variants of the drawing function draw() that paints using an
97 externlly provided <a href="https://doc.qt.io/qt-6/qpainter.html">QPainter</a>. These variants
98 either paint into a QRect, or starting from a single location (x,y).
99
100 The QRect-variants can align the render result inside the rectangle, whereas the
101 location-variants draw from a position that is on the left-hand side of the output's baseline:
102
103 \image html jkqtmathtext/jkqtmathtext_node_geo.png
104
105 Note that you first need to call one of the \ref JKQTMathTextUsageParsing so there is anything to render!
106
107
108
109 \subsection JKQTMathTextUsageConvenience Convenience Functions
110
111 Alternatively you can use these methods to directly generate a QPixmap or QPicture:
112 - drawIntoPixmap()
113 - drawIntoImage()
114 - drawIntoPicture()
115 .
116
117
118 \subsection JKQTMathTextSizing Determining the size of an equation
119
120 In addition there are also functions that allow to calculate the size of the equation,
121 before drawing it (just like the functions in <a href="http://doc.qt.io/qt-6/qfontmetrics.html">QFontMetrics</a>
122 or <a href="http://doc.qt.io/qt-6/qfontmetricsf.html">QFontMetricsF</a>):
123 - getSizeDetail()
124 - getSize()
125 - getAscent(), getDescent()
126 .
127
128
129 \subsection JKQTMathTextUsageQLabel Usage within a QLabel class JKQTMathTextLabel
130
131 Finally, there is also a QLabel-derived class JKQTMathTextLabel which can be used for drawing a LaTeX string onto a Qt form.
132
133 \see JKQTMathTextLabel
134
135
136 \subsection JKQTMathTextErrorHandling Error Handling
137
138 The class is designed to be as robust as possible and will still return some output, even if the equation contains some errors.
139 Nevertheless, several errors are detected while parsing. You can get a list of error messages using getErrorList() after calling parse().
140 Also parse() will return \c false if an error occured while parsing.
141
142 \subsection JKQTMathTextUsageExample Example Code
143 This small piece of C++ code may serve as an example of the usage and capabilities of the class:
144 \code
145 // create a JKQTMathText object.
146 JKQTMathText mathText;
147
148 // configure its properties to influence the rendering (e.g. fonts to use, font size, ...)
149 mathText.useXITS();
150 mathText.setFontSize(20);
151
152 // parse some LaTeX code (the Schroedinger's equation)
153 mathText.parse("$\\left[-\\frac{\\hbar^2}{2m}\\frac{\\partial^2}{\\partial x^2}+V(x)\\right]\\Psi(x)=\\mathrm{i}\\hbar\\frac{\\partial}{\\partial t}\\Psi(x)$");
154
155 // draw the result into a QPixmap
156 QPixmap result=mathText.drawIntoPixmap();
157 \endcode
158
159 Alternatively you can also use this class with a <a href="https://doc.qt.io/qt-6/qpainter.html">QPainter</a>:
160
161 \code
162 // use the draw() methods to draw the equation using a QPainter (here onto a QPixmap)
163 QPainter painter;
164
165 // first we determine the size of the render output:
166 const JKQTMathTextNodeSize size=getSizeDetail(painter);
167
168 // now we can us that size information to render:
169 mathText.draw(painter, Qt::AlignCenter, QRectF(0,0,pix.width(), pix.height()), false);
170 \endcode
171
172
173
174
175 \section JKQTMathTextToHTML Convert to HTML
176
177 The method toHtml() may be used to get a HTML representation of the LaTeX string, if possible (only for simple LaTeX equations!). Whether
178 the transformation was possible is returned as a call by value argument!
179
180
181 \section JKQTMathTextExamples Example Projects
182
183 Examples for the usage of this class can be found here:
184 - \ref JKQTMathTextSimpleExample
185 - \ref JKQTMathTextRenderCmdLineTool
186 - \ref JKQTMathTextTestApp
187 .
188
189
190
191 */
192class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
193 Q_OBJECT
194 public:
195 friend class JKQTMathTextParser;
196 friend class JKQTMathTextNode;
197
198 /** \brief minimum linewidth allowed in a JKQTMathText (given in pt) */
199 static const double ABS_MIN_LINEWIDTH;
200
201
202 /** \brief class constructor with a paren QObject \a parent and calls useGuiFonts() if \a useFontsForGUI \c =true */
203 JKQTMathText(QObject * parent = nullptr, bool useFontsForGUI=false);
204 /** \brief class destructor */
206
207
208/** @name Parsing Math Markup */
209/**@{*/
210 /** \brief options for parse() */
212 AddSpaceBeforeAndAfter = 0x01, /*!< \brief If set, a little bit of space is added before and after the text. */
213 StartWithMathMode = 0x02, /*!< \brief if set, the parser assumes the LaTeX string is in math-mode (as if surrounded by \c $ ) */
214 AllowLinebreaks = 0x04, /*!< \brief If set, linebreak (i.e. \c \\ or \c \\newline ) are allowed, otherwise a single line wihtout such linebreak commands is expected */
215 DefaultParseOptions=AllowLinebreaks,
216 };
217 Q_DECLARE_FLAGS(ParseOptions, ParseOption)
218 Q_FLAG(ParseOptions)
219 /** \brief lists the parser classes that are available by default (convenience interface to the templated parse()-funktion */
221 LatexParser, /*!< \brief use the LaTeX parser from JKQTMathTextLatexParser */
222 DefaultParser=LatexParser
223 };
224 /** \brief parse the given math \a markup string with a parser derived from \a markupType.
225 *
226 * \param markup the string of math markup
227 * \param markupType defines the language the \a markup is written in (and is used to derive the parser to use)
228 * \param options Options for parsing, \see ParseOptions
229 *
230 * \returns \c true on success.
231 */
232 bool parse(const QString &markup, DefaultParserTypes markupType=DefaultParser, ParseOptions options=DefaultParseOptions);
233 /** \brief parse the given math \a markup string, using the given parser class \a TParser
234 *
235 * \tparam TParser the parser (deived from JKQTMathTextParser) to be used
236 * \param markup the string of math markup
237 * \param options Options for parsing, \see ParseOptions
238 *
239 * \returns \c true on success.
240 */
241 template <class TParser>
242 inline bool parse(const QString &markup, ParseOptions options=DefaultParseOptions) {
243 static_assert(std::is_base_of<JKQTMathTextParser, TParser>::value, "in parse<TParser>() the type TParser has to be derived from JKQTMathTextParser to work!");
244 std::unique_ptr<TParser> p=std::unique_ptr<TParser>(new TParser(this));
245 deleteParsedNode();
246 clearErrorList();
247 parsedNode=p->parse(markup, options);
248 return parsedNode!=nullptr;
249 }
250 /** \brief returns the syntax tree of JKQTMathTextNode's that was created by the last parse() call */
252 /** \copydoc parsedNode */
254/**@}*/
255
256
257/** @name Determine the Size of the Output */
258/**@{*/
259
260 /** \brief get the size of the drawn representation. returns an invalid size if no text has been parsed. */
261 QSizeF getSize(QPainter& painter);
262 /** \brief get the rounded (using ceil) to an integer size of the drawn representation. returns \c QSize(0,0) if no text has been parsed. */
263 QSize getIntSize(QPainter& painter);
264 /** \brief return the descent, i.e. the distance from the baseline to the lowest part of the representation */
265 double getDescent(QPainter& painter);
266 /** \brief return the ascentt, i.e. the distance from the baseline to the highest part of the representation */
267 double getAscent(QPainter& painter);
268 /** \brief return the detailes sizes of the text */
269 void getSizeDetail(QPainter& painter, double& width, double& ascent, double& descent, double& strikeoutPos);
270 /** \brief return the detailes sizes of the text */
272/**@}*/
273
274
275/** @name Rendering */
276/**@{*/
277
278 /** \brief draw a representation to the object at the specified position \a x , \a y
279 *
280 * \param painter the <a href="http://doc.qt.io/qt-5/qpainter.html">QPainter</a> to use for drawing
281 * \param x position of the left border of the text/expression to be drawn (see sketch below)
282 * \param drawBoxes if \c true boxes defining the size of each node are drawn, example output: \image html jkqtmathtext/jkqtmathtext_drawboxes.png
283 *
284 * Here is an illustration of the geometry of the drawn text/expression:
285 * \image html jkqtmathtext/jkqtmathtext_node_geo.png
286 */
287 void draw(QPainter& painter, QPointF x, bool drawBoxes=false);
288 /** \brief draw a representation to the object at the specified position \a x , \a y
289 *
290 * \param painter the <a href="http://doc.qt.io/qt-5/qpainter.html">QPainter</a> to use for drawing
291 * \param x x-position of the left border of the text/expression to be drawn (see sketch below)
292 * \param y y-position of the baseline of the text/expression to be drawn (see sketch below)
293 * \param drawBoxes if \c true boxes defining the size of each node are drawn, example output: \image html jkqtmathtext/jkqtmathtext_drawboxes.png
294 *
295 * Here is an illustration of the geometry of the drawn text/expression:
296 * \image html jkqtmathtext/jkqtmathtext_node_geo.png
297 */
298 double draw(QPainter& painter, double x, double y, bool drawBoxes=false);
299 /** \brief draw into a rectangle \a rect with alignment defined in \a flags (see below)
300 *
301 * \param painter the <a href="http://doc.qt.io/qt-5/qpainter.html">QPainter</a> to use for drawing
302 * \param rect rectangle to draw the text/expression into (see sketch below)
303 * \param flags alignment within \a rect (see below), use e.g. <tt>Qt::AlignHCenter | Qt::AlignVCenter</tt> to center the expression inside \a rect
304 * The flags (dark-red is the rectangle \a rect) are interpreted in the following way:
305 * \image html jkqtmathtext/jkqtmathtext_draw_flags.png
306 * \param drawBoxes if \c true boxes defining the size of each node are drawn, example output: \image html jkqtmathtext/jkqtmathtext_drawboxes.png
307 *
308 *
309 *
310 * \see drawIntoPixmap(), drawIntoPicture(), getSize(), getSizeDetail()
311 */
312 void draw(QPainter& painter, unsigned int flags, QRectF rect, bool drawBoxes=false);
313
314 /** \brief render the last parse result into a <a href="https://doc.qt.io/qt-6/qpixmap.html">QPixmap</a>
315 *
316 * \param drawBoxes if \c true boxes defining the size of each node are drawn, example output: \image html jkqtmathtext/jkqtmathtext_drawboxes.png
317 * \param backgroundColor fill color for the returnes QPixmap
318 * \param sizeincrease margin around the tight size of the rendering result for the returned QPixmap
319 * \param devicePixelRatio the devicePixelRatio of the returned QPixmap
320 */
321 QPixmap drawIntoPixmap(bool drawBoxes=false, QColor backgroundColor=QColor(Qt::white), int sizeincrease=0, qreal devicePixelRatio=1.0);
322
323 /** \brief render the last parse result into a <a href="https://doc.qt.io/qt-6/qimage.html">QImage</a>
324 *
325 * \param drawBoxes if \c true boxes defining the size of each node are drawn, example output: \image html jkqtmathtext/jkqtmathtext_drawboxes.png
326 * \param backgroundColor fill color for the returnes QPixmap
327 * \param sizeincrease margin around the tight size of the rendering result for the returned QPixmap
328 * \param devicePixelRatio the devicePixelRatio of the returned QImage
329 * \param resolution_dpi resolution in dots/inch
330 */
331 QImage drawIntoImage(bool drawBoxes=false, QColor backgroundColor=QColor(Qt::white), int sizeincrease=0, qreal devicePixelRatio=1.0, unsigned int resolution_dpi=96);
332
333 /** \brief render the last parse result into a <a href="https://doc.qt.io/qt-6/qpicture.html">QPicture</a>
334 *
335 * \param drawBoxes if \c true boxes defining the size of each node are drawn, example output: \image html jkqtmathtext/jkqtmathtext_drawboxes.png
336 */
337 QPicture drawIntoPicture(bool drawBoxes=false);
338
339
340 /** \brief convert LaTeX to HTML. returns \c ok=true on success and \c ok=false else. */
341 QString toHtml(bool* ok=nullptr, double fontPointSize=10);
342/**@}*/
343
344/** @name Font Handling */
345/**@{*/
346 /** \brief options for the base font */
348 BaseFontBold = 0x01, /*!< \brief output is bold (equivalent to placinf text in <code>\textbf{...}</code>) */
349 BaseFontItalic = 0x02, /*!< \brief output is italic (equivalent to placinf text in <code>\textit{...}</code>) */
350 BaseFontUnderlined = 0x04, /*!< \brief output is underlined (equivalent to placinf text in <code>\underlined{...}</code>) */
351 BaseFontSmallCaps = 0x08, /*!< \brief output is small-caps (equivalent to placinf text in <code>\textsc{...}</code>) */
352 BaseFontDefault=0x00, /*!< \brief base font is used as is, without modifications */
353 };
355 Q_FLAG(BaseFontOptions)
356 /** \brief convert BaseFontOptions to a string (e.g. <code>BOLD+ITALIC</code> */
357 static QString BaseFontOptions2String(BaseFontOptions opt);
358 /** \brief convert a string (generated by BaseFontOptions2String() to BaseFontOptions */
359 static BaseFontOptions String2BaseFontOptions(const QString& s);
360 /** \copydoc fontColor */
361 void setFontColor(const QColor & __value);
362 /** \copydoc fontColor */
363 QColor getFontColor() const;
364 /** \copydoc setFontPointSize() */
365 void setFontSize(double __value);
366 /** \brief set the default font size in points
367 * \see getFontSize(), fontSize, fontSizeUnits */
368 void setFontPointSize(double __value);
369 /** \brief set the default font soze in pixels
370 * \see getFontSizePixels(), fontSize, fontSizeUnits */
371 void setFontSizePixels(double __value);
372 /** \brief returns the currently set default font size in points, if it was defined in points using setFontSize(), or -1 if it was set in pixels with setFontSizePixels()
373 * \see setFontSize(), fontSize, fontSizeUnits */
374 double getFontPointSize() const;
375 /** \copydoc getFontPointSize() */
376 double getFontSize() const;
377 /** \brief returns the currently set default font size in pixels, if it was defined in points using setFontSizePixels(), or -1 if it was set in points with setFontSize()
378 * \see setFontSizePixels(), fontSize, fontSizeUnits */
379 double getFontSizePixels() const;
380 /** \brief set (overwrite) the options applied to the base font
381 *
382 * \see BaseFontOptions
383 */
384 void setFontOptions(BaseFontOptions opts);
385 /** \brief en/disable the given base font option
386 *
387 * \see BaseFontOptions
388 */
389 void setFontOption(BaseFontOption opt,bool enabled=true);
390 /** \brief returns the options applied to the base font
391 *
392 * \see BaseFontOptions
393 */
394 BaseFontOptions getFontOptions() const;
395
396
397 /** \brief add a font pair to the table with font replacements
398 *
399 * e.g. if it is known that a certain font is not good for rendering, you can add an alternative with this function.
400 * These are automatically applied, when setting a new font name!
401 *
402 * \param nonUseFont the font not to use
403 * \param useFont replacement font for nonUseFont
404 *
405 * The entry in the encodings for this font is kept empty (or even deleted), so the default encoding of the font to be replaced is used!
406 */
407 void addReplacementFont(const QString& nonUseFont, const QString& useFont);
408 /** \brief add a font pair to the table with font replacements
409 *
410 * e.g. if it is known that a certain font is not good for rendering, you can add an alternative with this function.
411 * These are automatically applied, when setting a new font name!
412 *
413 * \param nonUseFont the font not to use
414 * \param useFont replacement font for nonUseFont
415 * \param useFontEncoding encoding of the replacement font
416 */
417 void addReplacementFont(const QString& nonUseFont, const QString& useFont, JKQTMathTextFontEncoding useFontEncoding);
418 /** \brief retrieves a replacement for the given font name \a nonUseFont, including its encoding. Returns the given default values \a defaultFont and/or \a defaultFontEncoding if one of the two is not found */
419 QPair<QString, JKQTMathTextFontEncoding> getReplacementFont(const QString &nonUseFont, const QString &defaultFont, JKQTMathTextFontEncoding defaultFontEncoding) const;
420
421 /** \brief retrieve the font and encoding to be used for \a font, which might optionally be typeset inside a math environment, specified by in_math_environment, possibly for the given font subclass \a subclass */
422 QPair<QString, JKQTMathTextFontEncoding> getFontData(JKQTMathTextEnvironmentFont font, bool in_math_environment=false) const;
423
424 /*! \brief set the font by parsing a special syntax defined in the description of JKQTMathTextFontSpecifier
425 *
426 * This allows to set the text-mode and math-mode roman fonts.
427 *
428 * \note This function is a shorthand for
429 * \code
430 * setFontRomanOrSpecial(JKQTMathTextFontSpecifier::fromFontSpec(fontName), encoding);
431 * \endcode
432 *
433 * \see JKQTMathTextFontSpecifier, setFontRoman(), setFontMathRoman(), \ref jkqtmathtext_fonthandling
434 */
435 void setFontRomanOrSpecial(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
436 /*! \brief set the font by an instance of JKQTMathTextFontSpecifier
437 *
438 * This allows to set the text-mode and math-mode roman fonts.
439 *
440 * \see JKQTMathTextFontSpecifier, setFontRoman(), setFontMathRoman(), \ref jkqtmathtext_fonthandling
441 */
442 void setFontRomanOrSpecial(const JKQTMathTextFontSpecifier & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
443 /*! \brief set font(s) from parsing a font specifier
444 *
445 * This function understands a font-specifier in the following forms:
446 * - \c fontRoman - set "roman" and "math-roman" to fontRoman "sans"/"math-sans" are reset to the default, when constructing the object
447 * - \c fontRoman/fontSans - set "roman" and "math-roman" to fontRoman and "sans" and "math-sans" to fontSans
448 * - \c fontRoman/fontSans/fontMathRoman/fontMathSans - sets all four majpr fonts
449 * - any above with addition:
450 * - \c +XITS use XITS for math/symbols, calls useXITS()
451 * - \c +ASANA use ASANA for math/symbols, calls useASANA()
452 * - \c +STIX use STIX for math/symbols, calls useSTIX()
453 * - \c +FIRA use Fira Math for math/symbols, calls useFiraMath()
454 * - \c +BOLD make font initially bold
455 * - \c +ITALIC make font initially italic
456 * - \c +UNDERLINED make font initially underlines
457 * - \c +SMALLCAPS make font initially smallcaps
458 * .
459 * - \c GUI use GUI-fonts, calls useGuiFonts()
460 * .
461 *
462 * Font names can also be one of the special names, specified in the documentation of JKQTMathTextFontSpecifier and JKQTMathTextFontSpecifier::transformFontNameAndDecodeSpecialFonts()
463 *
464 */
465 void setFontSpecial(const QString& fontSpec);
466
467 /** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEroman
468 *
469 * \see \ref jkqtmathtext_fonthandling
470 */
471 void setFontRoman(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
472 /** \brief set the font \a fontName and it's encoding \a encoding to be used for text and math, i.e. the logical font MTEroman and MTEmathRoman
473 *
474 * \see \ref jkqtmathtext_fonthandling
475 */
476 void setFontRomanAndMath(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
477 /** \brief retrieves the font to be used for text in the logical font MTEroman */
478 QString getFontRoman() const;
479 /** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEsans
480 *
481 * \see \ref jkqtmathtext_fonthandling
482 */
483 void setFontSans(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
484 /** \brief retrieves the font to be used for text in the logical font MTEsans */
485 QString getFontSans() const;
486 /** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEtypewriter
487 *
488 * \see \ref jkqtmathtext_fonthandling
489 */
490 void setFontTypewriter(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
491 /** \brief retrieves the font to be used for text in the logical font MTEtypewriter */
492 QString getFontTypewriter() const;
493 /** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEscript
494 *
495 * \see \ref jkqtmathtext_fonthandling
496 */
497 void setFontScript(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
498 /** \brief retrieves the font to be used for text in the logical font MTEscript */
499 QString getFontScript() const;
500 /** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEfraktur
501 *
502 * \see \ref jkqtmathtext_fonthandling
503 */
504 void setFontFraktur(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
505 /** \brief retrieves the font to be used for text in the logical font MTEfraktur */
506 QString getFontFraktur() const;
507 /** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEcaligraphic
508 *
509 * \see \ref jkqtmathtext_fonthandling
510 */
511 void setFontCaligraphic(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
512 /** \brief retrieves the font to be used for text in the logical font MTEcaligraphic */
513 QString getFontCaligraphic() const;
514 /** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEblackboard \see setFontBlackboardMode()
515 *
516 *
517 */
518 void setFontBlackboard(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
519 /** \copydoc blackboradFontMode */
520 JKQTMathTextBlackboradDrawingMode getFontBlackboradMode() const;
521 /** \copydoc blackboradFontMode */
522 void setFontBlackboradMode(JKQTMathTextBlackboradDrawingMode mode);
523
524 /** \brief retrieves the font to be used for text in the logical font MTEblackboard \see blackboradFontMode */
525 QString getFontBlackboard() const;
526 /** \brief set the font \a fontName and it's encoding \a encoding to be used for symbols in the logical font \a font
527 *
528 * \see \ref jkqtmathtext_fonthandling
529 */
530 void setFallbackFontSymbols(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
531 /** \brief retrieves the font to be used for symbols in the logical font \a font */
532 QString getFallbackFontSymbols() const;
533
534 /** \brief retrieves the encoding used for the symbol font to be used for symbols */
535 JKQTMathTextFontEncoding getFontEncodingFallbackFontSymbols() const;
536 /** \brief retrieves the encoding used for the script font */
537 JKQTMathTextFontEncoding getFontEncodingScript() const;
538 /** \brief retrieves the encoding used for the Fraktur font */
539 JKQTMathTextFontEncoding getFontEncodingFraktur() const;
540 /** \brief retrieves the encoding used for the typewriter font */
541 JKQTMathTextFontEncoding getFontEncodingTypewriter() const;
542 /** \brief retrieves the encoding used for the sans-serif font */
543 JKQTMathTextFontEncoding getFontEncodingSans() const;
544 /** \brief retrieves the encoding used for the roman font */
545 JKQTMathTextFontEncoding getFontEncodingRoman() const;
546 /** \brief retrieves the encoding used for the blackboard font */
547 JKQTMathTextFontEncoding getFontEncodingBlackboard() const;
548 /** \brief retrieves the encoding used for the caligraphic font */
549 JKQTMathTextFontEncoding getFontEncodingCaligraphic() const;
550
551
552 /** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEmathRoman
553 *
554 * \see \ref jkqtmathtext_fonthandling
555 */
556 void setFontMathRoman(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
557 /** \brief retrieves the font to be used for text in the logical font MTEroman */
558 QString getFontMathRoman() const;
559 /** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEmathSans
560 *
561 * \see \ref jkqtmathtext_fonthandling
562 */
563 void setFontMathSans(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
564 /** \brief retrieves the font to be used for text in the logical font MTEsans */
565 QString getFontMathSans() const;
566 /** \brief retrieves the encoding used for the math-mode sans-serif font */
567 JKQTMathTextFontEncoding getFontEncodingMathSans() const;
568 /** \brief retrieves the encoding used for the math-mode roman font */
569 JKQTMathTextFontEncoding getFontEncodingMathRoman() const;
570
571 /** \brief configures the class to use the STIX fonts in mathmode
572 *
573 * use STIX (1.x/2.x) fonts from <a href="https://www.stixfonts.org/">https://www.stixfonts.org/</a> in math-mode
574 * or in math and text-mode (if \a mathModeOnly \c ==false )
575 *
576 * If \c useAsFallbackSymbol is set \c ==true then the XITS fonts are also used as MTEFallbackSymbols
577 *
578 * \image html jkqtmathtext/jkqtmathtext_stix.png
579 *
580 * This function does not only use default font-names for STIX, but searches
581 * the font database of the system with several different variants, using JKQTMathTextFontSpecifier::getSTIXFamilies().
582 * It also sets the special math-variant of STIX for math mode and the normal variant for text-mode
583 *
584 * \see \ref jkqtmathtext_fonthandling
585 */
586 bool useSTIX(bool mathModeOnly=true, bool useAsFallbackSymbol=true);
587
588 /** \brief configures the class to use the XITS fonts in mathmode
589 *
590 * use XITS fonts from <a href="https://github.com/alif-type/xits">https://github.com/alif-type/xits</a> in math-mode
591 * or in math and text-mode (if \a mathModeOnly \c ==false ).
592 *
593 * If \c useAsFallbackSymbol is set \c ==true then the XITS fonts are also used as MTEFallbackSymbols
594 *
595 * \image html jkqtmathtext/jkqtmathtext_xits.png
596 *
597 * \note The XITS fonts can be compiled into JKQTPlotter, when the CMake-option \c JKQtPlotter_BUILD_INCLUDE_XITS_FONTS is set to ON (default: ON).
598 * Then the XITS fonts are added as Qt-Ressources to the library binary.
599 * If this is not the case, you have to provide the XITS fonts on the target system by other means, if you want
600 * to use them.
601 *
602 * This function does not only use default font-names for XITS, but searches
603 * the font database of the system with several different variants, using JKQTMathTextFontSpecifier::getXITSFamilies().
604 * It also sets the special math-variant of XITS for math mode and the normal variant for text-mode
605 *
606 * \see \ref jkqtmathtext_fonthandling
607 */
608 bool useXITS(bool mathModeOnly=true, bool useAsFallbackSymbol=true);
609
610 /** \brief configures the class to use the Fira Math fonts in mathmode
611 *
612 * use Fira Math fonts from <a href="https://github.com/firamath/firamath">https://github.com/firamath/firamath</a> in math-mode
613 * or in math and text-mode (if \a mathModeOnly \c ==false ).
614 *
615 * If \c useAsFallbackSymbol is set \c ==true then the Fira Math fonts are also used as MTEFallbackSymbols
616 *
617 * \image html jkqtmathtext/jkqtmathtext_usefira.png
618 *
619 * \note The Fira Math fonts can be compiled into JKQTPlotter, when the CMake-option \c JKQtPlotter_BUILD_INCLUDE_FIRAMATH_FONTS is set to ON (default: ON).
620 * Then the Fira Math fonts are added as Qt-Ressources to the library binary.
621 * If this is not the case, you have to provide the Fira Math fonts on the target system by other means, if you want
622 * to use them.
623 *
624 * This function does not only use default font-names for Fira Math, but searches
625 * the font database of the system with several different variants, using JKQTMathTextFontSpecifier::getFIRAFamilies().
626 * It also sets the special math-variant of Fira for math mode and the normal variant for text-mode
627 *
628 * \see \ref jkqtmathtext_fonthandling
629 */
630 bool useFiraMath(bool mathModeOnly=true, bool useAsFallbackSymbol=true);
631
632 /** \brief configures the class to use the ASANA fonts in mathmode
633 *
634 * use the ASANA fonts from <a href="https://ctan.org/tex-archive/fonts/Asana-Math/">https://ctan.org/tex-archive/fonts/Asana-Math/</a> in math-mode
635 * or in math and text-mode (if \a mathModeOnly \c ==false )
636 *
637 * If \c useAsFallbackSymbol is set \c ==true then the XITS fonts are also used as MTEFallbackSymbols
638 *
639 * \image html jkqtmathtext/jkqtmathtext_asana.png
640 *
641 * This function does not only use default font-names for ASANA, but searches
642 * the font database of the system with several different variants, using JKQTMathTextFontSpecifier::getASANAFamilies().
643 * It also sets the special math-variant of ASANA for math mode and the normal variant for text-mode
644 *
645 * \see \ref jkqtmathtext_fonthandling
646 */
647 bool useASANA(bool mathModeOnly=true, bool useAsFallbackSymbol=true);
648
649 /** \brief configures the class to be used for GUI output, i.e. tries to find fonts that are harmonious for the
650 * default GUI font, sets the default GUI font for "roman" and finds an oppposite font for "sans", which means that
651 * "sans" may actually be a serif font,when the app font is sans serif!
652 *
653 *
654 * \see \ref jkqtmathtext_fonthandling
655 */
656 bool useGuiFonts();
657
658 /** \brief sets \a timesFont (with its encoding \a encodingTimes ) for serif-text and \a sansFont (with its encoding \a encodingSans ) for both mathmode and textmode fonts
659 *
660 * \note use generic Unicode fonts, e.g. "Arial" and "Times New Roman" in math-mode.
661 * You should use fonts that contain as many of the mathematical symbols as possible
662 * to ensure good rendering results.
663 *
664 *
665 * <code>useAnyUnicode("Comic Sans MS", "Comic Sans MS")</code>:<br>\image html jkqtmathtext/jkqtmathtext_comicsans.png <br><br>
666 * <code>useAnyUnicodeForTextOnly("Comic Sans MS", "Comic Sans MS");</code>:<br/>\image html jkqtmathtext/jkqtmathtext_comicsans_textonly.png
667 * <code>useAnyUnicodeForMathOnly("Comic Sans MS", "Comic Sans MS");</code>:<br/>\image html jkqtmathtext/jkqtmathtext_comicsans_mathonly.png
668 *
669 * \see useAnyUnicodeForMathOnly(), useAnyUnicodeForTextOnly(), \ref jkqtmathtext_fonthandling
670 */
671 void useAnyUnicode(QString timesFont, const QString& sansFont, JKQTMathTextFontEncoding encodingTimes=JKQTMathTextFontEncoding::MTFEUnicode, JKQTMathTextFontEncoding encodingSans=JKQTMathTextFontEncoding::MTFEUnicode);
672 /** \brief sets \a timesFont (with its encoding \a encodingTimes ) for serif-text and \a sansFont (with its encoding \a encodingSans ) for mathmode fonts only
673 *
674 * \note use generic Unicode fonts, e.g. "Arial" and "Times New Roman" in math-mode.
675 * You should use fonts that contain as many of the mathematical symbols as possible to ensure good rendering results.
676 *
677 * <code>useAnyUnicode("Comic Sans MS", "Comic Sans MS")</code>:<br>\image html jkqtmathtext/jkqtmathtext_comicsans.png <br><br>
678 * <code>useAnyUnicodeForTextOnly("Comic Sans MS", "Comic Sans MS");</code>:<br/>\image html jkqtmathtext/jkqtmathtext_comicsans_textonly.png
679 * <code>useAnyUnicodeForMathOnly("Comic Sans MS", "Comic Sans MS");</code>:<br/>\image html jkqtmathtext/jkqtmathtext_comicsans_mathonly.png
680 *
681 * \see useAnyUnicodeForTextOnly(), useAnyUnicode(), \ref jkqtmathtext_fonthandling
682 */
683 void useAnyUnicodeForMathOnly(QString timesFont, const QString& sansFont, JKQTMathTextFontEncoding encodingTimes=JKQTMathTextFontEncoding::MTFEUnicode, JKQTMathTextFontEncoding encodingSans=JKQTMathTextFontEncoding::MTFEUnicode);
684 /** \brief sets \a timesFont (with its encoding \a encodingTimes ) for serif-text and \a sansFont (with its encoding \a encodingSans ) for both mathmode fonts only
685 *
686 * <code>useAnyUnicode("Comic Sans MS", "Comic Sans MS")</code>:<br>\image html jkqtmathtext/jkqtmathtext_comicsans.png <br><br>
687 * <code>useAnyUnicodeForTextOnly("Comic Sans MS", "Comic Sans MS");</code>:<br/>\image html jkqtmathtext/jkqtmathtext_comicsans_textonly.png
688 * <code>useAnyUnicodeForMathOnly("Comic Sans MS", "Comic Sans MS");</code>:<br/>\image html jkqtmathtext/jkqtmathtext_comicsans_mathonly.png
689 *
690 * \see useAnyUnicodeForMathOnly(), useAnyUnicode(), \ref jkqtmathtext_fonthandling
691 */
692 void useAnyUnicodeForTextOnly(QString timesFont, const QString& sansFont, JKQTMathTextFontEncoding encodingTimes=JKQTMathTextFontEncoding::MTFEUnicode, JKQTMathTextFontEncoding encodingSans=JKQTMathTextFontEncoding::MTFEUnicode);
693/**@}*/
694
695
696/** @name (Defining) Rendering Details */
697/**@{*/
698 /** \brief load the object settings from the given QSettings object with the given name prefix */
699 void loadSettings(const QSettings& settings, const QString& group=QString("mathtext/"));
700 /** \brief store the object settings to the given QSettings object with the given name prefix */
701 void saveSettings(QSettings& settings, const QString& group=QString("mathtext/")) const;
702
703 /** \copydoc brace_factor */
704 void setBraceFactor(double __value);
705 /** \copydoc brace_factor */
706 double getBraceFactor() const;
707 /** \copydoc subsuper_size_factor */
708 void setSubsuperSizeFactor(double __value);
709 /** \copydoc subsuper_size_factor */
710 double getSubsuperSizeFactor() const;
711 /** \copydoc subsuper_mode_selection_by_size_factor */
712 void setSubsuperModeSelectionBySizeFactor(double __value);
713 /** \copydoc subsuper_mode_selection_by_size_factor */
714 double getSubsuperModeSelectionBySizeFactor() const;
715 /** \copydoc operatorsubsuper_size_factor */
716 void setOperatorsubsuperSizeFactor(double __value);
717 /** \copydoc operatorsubsuper_size_factor */
718 double getOperatorsubsuperSizeFactor() const;
719 /** \copydoc operatorsubsuper_distance_factor */
720 void setOperatorsubsuperDistanceFactor(double __value);
721 /** \copydoc operatorsubsuper_distance_factor */
722 double getOperatorsubsuperDistanceFactor() const;
723 /** \copydoc operatorsubsuper_extraspace_factor */
724 void setOperatorsubsuperExtraSpaceFactor(double __value);
725 /** \copydoc operatorsubsuper_extraspace_factor */
726 double getOperatorsubsuperExtraSpaceFactor() const;
727 /** \copydoc mathoperator_width_factor */
728 void setMathoperatorWidthFactor(double __value);
729 /** \copydoc mathoperator_width_factor */
730 double getMathoperatorWidthFactor() const;
731 /** \copydoc intsubsuper_xcorrection_factor */
732 void setIntSubSuperXCorrectionFactor(double __value);
733 /** \copydoc intsubsuper_xcorrection_factor */
734 double getIntSubSuperXCorrectionFactor() const;
735 /** \copydoc intsubbesides_xcorrection_xfactor */
736 void setIntSubBesidesXCorrectionXFactor(double __value);
737 /** \copydoc intsubbesides_xcorrection_xfactor */
738 double getIntSubBesidesXCorrectionXFactor() const;
739 /** \copydoc bigmathoperator_font_factor */
740 void setBigMathoperatorFontFactor(double __value);
741 /** \copydoc bigmathoperator_font_factor */
742 double getBigMathoperatorFontFactor() const;
743 /** \copydoc super_shift_factor */
744 void setSuperShiftFactor(double __value);
745 /** \copydoc super_shift_factor */
746 double getSuperShiftFactor() const;
747 /** \copydoc sub_shift_factor */
748 void setSubShiftFactor(double __value);
749 /** \copydoc sub_shift_factor */
750 double getSubShiftFactor() const;
751 /** \copydoc special_super_shift_factor */
752 void setSpecialSuperShiftFactor(double __value);
753 /** \copydoc special_super_shift_factor */
754 double getSpecialSuperShiftFactor() const;
755 /** \copydoc special_sub_shift_factor */
756 void setSpecialSubShiftFactor(double __value);
757 /** \copydoc special_sub_shift_factor */
758 double getSpecialSubShiftFactor() const;
759 /** \copydoc underbrace_factor */
760 void setUnderbraceFactor(double __value);
761 /** \copydoc underbrace_factor */
762 double getUnderbraceFactor() const;
763 /** \copydoc underbrace_separation_xfactor */
764 void setUnderbraceSeparationXFactor(double __value);
765 /** \copydoc underbrace_separation_xfactor */
766 double getUnderbraceSeparationXFactor() const;
767 /** \copydoc underbrace_bracesize_xfactor */
768 void setUnderbraceBraceSizeXFactor(double __value);
769 /** \copydoc underbrace_bracesize_xfactor */
770 double getUnderbraceBraceSizeXFactor() const;
771 /** \copydoc underset_factor */
772 void setUndersetFactor(double __value);
773 /** \copydoc underset_factor */
774 double getUndersetFactor() const;
775 /** \copydoc frac_factor */
776 void setFracFactor(double __value);
777 /** \copydoc frac_factor */
778 double getFracFactor() const;
779 /** \copydoc frac_nested_factor */
780 void setFracNestedFactor(double __value);
781 /** \copydoc frac_nested_factor */
782 double getFracNestedFactor() const;
783
784
785 /** \copydoc frac_shift_factor */
786 void setFracShiftFactor(double __value);
787 /** \copydoc frac_shift_factor */
788 double getFracShiftFactor() const;
789 /** \copydoc brace_y_shift_factor */
790 void setBraceYShiftFactor(double __value);
791 /** \copydoc brace_y_shift_factor */
792 double getBraceYShiftFactor() const;
793
794 /** \copydoc decoration_height_factor */
795 void setDecorationHeightFactor(double __value);
796 /** \copydoc decoration_height_factor */
797 double getDecorationHeightFactor() const;
798 /** \copydoc decoration_separation_factor */
799 void setDecorationSeparationXFactor(double __value);
800 /** \copydoc decoration_separation_factor */
801 double getDecorationSeparationFactor() const;
802 /** \copydoc decoration_width_reduction_Xfactor */
803 void setDecorationWidthReductionFactor(double __value);
804 /** \copydoc decoration_width_reduction_Xfactor */
805 double getDecorationWidthReductionXFactor() const;
806
807
808 /** \copydoc sqrt_width_Xfactor */
809 void setSqrtWidthXFactor(double __value);
810 /** \copydoc sqrt_width_Xfactor */
811 double getSqrtWidthXFactor() const;
812 /** \copydoc sqrt_height_factor */
813 void setSqrtHeightFactor(double __value);
814 /** \copydoc sqrt_height_factor */
815 double getSqrtHeightFactor() const;
816 /** \copydoc sqrt_smallfont_factor */
817 void setSqrtSmallFontFactor(double __value);
818 /** \copydoc sqrt_smallfont_factor */
819 double getSqrtSmallFontFactor() const;
820
821 /** \copydoc matrix_linewidth_thin_factor */
822 double getMatrixLinewidthThinFactor();
823 /** \copydoc matrix_linewidth_thin_factor */
824 void setMatrixLinewidthThinFactor(double factor);
825 /** \copydoc matrix_linewidth_heavy_factor */
826 double getMatrixLinewidthHeavyFactor();
827 /** \copydoc matrix_linewidth_heavy_factor */
828 void setMatrixLinewidthHeavyFactor(double factor);
829 /** \copydoc matrix_line_separation_factor */
830 double getMatrixLineSeparationFactor();
831 /** \copydoc matrix_line_separation_factor */
832 void setMatrixLineSeparationFactor(double factor);
833 /** \copydoc matrix_xSeparation_factor */
834 double getMatrixXSeparationFactor();
835 /** \copydoc matrix_xSeparation_factor */
836 void setMatrixXSeparationFactor(double factor);
837 /** \copydoc matrix_ySeparation_factor */
838 double getMatrixYSeparationFactor();
839 /** \copydoc matrix_ySeparation_factor */
840 void setMatrixYSeparationFactor(double factor);
841 /** \copydoc matrix_xPadding_factor */
842 double getMatrixXPaddingFactor();
843 /** \copydoc matrix_xPadding_factor */
844 void setMatrixXPaddingFactor(double factor);
845 /** \copydoc matrix_yPadding_factor */
846 double getMatrixYPaddingFactor();
847 /** \copydoc matrix_yPadding_factor */
848 void setMatrixYPaddingFactor(double factor);
849/**@}*/
850
851
852/** @name Error Handling */
853/**@{*/
854 /** \copydoc error_list */
855 QStringList getErrorList() const;
856 /** \brief returns \c true when errors were registered in the system \see error_list */
857 bool hadErrors() const;
858 protected:
859 /** \copydoc error_list */
860 void addToErrorList(const QString& error);
861 /** \brief clears all registered errors (see error_list)
862 */
863 void clearErrorList();
864
865 /** \brief a list that will be filled with error messages while parsing, if any error occur
866 *
867 * This list of errors is (mostly) filled during a call to parse(). During rendering (e.g. with draw() )
868 * only very few errors will be detected, as most errors are caused by wrong markup.
869 *
870 * A call to parse() also clears this list.
871 *
872 * \see getErrorList(), hadErrors() and addToErrorList()
873 *
874 */
875 QStringList error_list;
876/**@}*/
877
878 /** \brief the syntax tree of JKQTMathTextNode's that was created by the last parse() call */
879 JKQTMathTextNode* parsedNode;
880 /** \brief this function moves a <code>delete parsedNode</code>-call into the cpp-file, as JKQTMathTextNode is "only" forward declared here and therefore, deleting it may cause undefined behaviour */
881 void deleteParsedNode();
882
883
884 /** \brief table with font replacements to use (e.g. if it is known that a certain font is not good for rendering, you can add
885 * an alternative using addReplacementFont(). These are automatically applied, when setting a new font name! */
886 QMap<QString, QString> fontReplacements;
887 /** \brief acompanies fontReplacements and collects the encodings of the replacement fonts, if no entry is present, the default encoding is used, as given to the setter! */
888 QMap<QString, JKQTMathTextFontEncoding> fontEncodingReplacements;
889
890 /** \brief font color */
891 QColor fontColor;
892 /** \brief base font size in the units defined in fontSizeUnits \see fontSizeUnits */
893 double fontSize;
894 /** \brief unit of fontSize */
895 JKQTMathTextEnvironment::FontSizeUnit fontSizeUnits;
896 /** \brief additional options for the base fonts */
897 BaseFontOptions fontOptions;
898 /** \brief sets all properties of JKQTMathTextEnvironment \a ev from the fon settings stored in this class (e.g. fontSize, fontOptions, ...) */
899 void modifyEnvironmentFromFontSettings(JKQTMathTextEnvironment& ev) const;
900
901
902 /** \brief stores information about the different fonts used by LaTeX markup */
904
905 /** \brief specifies how to draw blackboard font characters (i.e. \c \\mathbb{N} )
906 *
907 * Blackboard fonts are not widely available on target systems (viable fonts are e.g.
908 * <code>"Double Stroke", "CloisterOpenFace BT", "GoudyHandtooled BT", "Castellar", "MathJax_AMS", "Castellar Standard", "MathJax_AMS Standard", "Colonna MT"</code>).
909 * But the most important blackboard characters are usually available in the higher unicode
910 * codepoints of Fonts specialized for math (e.g. XIST, STIX, ASANA).
911 *
912 * Therefore JKQTMathText supports using these characters, or simulating a blackboard font in
913 * addition to using one of the fonts above. You can set that by setting
914 * JKQTMathText::setFontBlackboradMode() with one of the options from JKQTMathTextBlackboradDrawingMode:
915 * - MTBBDMfontDirectly: use a blackboard font specified by JKQTMathText::setFontBlackboard() \image html jkqtmathtext/jkqtmathtext_bb_font_directly.png using \c JKQTMathText::setFontBlackboard("Castellar")
916 * - MTBBDMsimulate: \image html jkqtmathtext/jkqtmathtext_bb_simulate.png using \c JKQTMathText::setFontBlackboard("Arial")
917 * - MTBBDMunicodeCharactersOrFontDirectly: \image html jkqtmathtext/jkqtmathtext_bb_unicode_or_font_directly.png using \c JKQTMathText::setFontBlackboard("Castellar")
918 * - MTBBDMunicodeCharactersOrSimulate: \image html jkqtmathtext/jkqtmathtext_bb_unicode_or_simulate.png using \c JKQTMathText::setFontBlackboard("Arial")
919 * .
920 *
921 * \see JKQTMathTextBlackboradDrawingMode, setFontBlackboard(), setBlackboardFontMode(), \ref jkqtmathtext_fonthandling
922 */
924
925
926 /** \brief for \c \\left / \c \\right braces: The brace is this factor higher than the child block it surrounds */
927 double brace_factor;
928 /** \brief resizing factor for font size in sub-/superscript */
929 double subsuper_size_factor;
930 /** \brief this factor is used to determine how to typeset sub-/superscript.
931 *
932 * If the ascent for superscript of descent for subscript of the previous character is \c >=subsuper_mode_selection_by_size_factor*ascent(currentFont)
933 * or \c <=subsuper_mode_selection_by_size_factor*descent(currentFont) respectively, the sub/superscript is typeset, aligned with the ascent or descent
934 * of the previous character. Otherwise it is aligned with the default method:
935 *
936 * <b>Default mode:</b>
937 * \image html jkqtmathtext_superscriptnode_getSizeInternal.png
938 * \image html jkqtmathtext_subscriptnode_getSizeInternal.png
939 *
940 * <b>Special mode:</b>
941 *
942 *
943 * This method fixes problems with characters that are significantyl larger that normal text character of the fonst, such as generated
944 * by \c \\sum,\\int,... .
945 */
946 double subsuper_mode_selection_by_size_factor;
947 /** \brief like subsuper_size_factor, but for operators (\c \\sum , \c \\int , ...) where the text is placed above/below the symbol */
948 double operatorsubsuper_size_factor;
949 /** \brief for operators (\c \\sum , \c \\int , ...) where the text is placed above/below the symbol, this is the distance between the operator symbol and the sub-/super-text if multiplied by xHeight
950 *
951 * \image html jkqtmathtext_subsuper_with_limits.png
952 */
953 double operatorsubsuper_distance_factor;
954 /** \brief for operators (\c \\sum , \c \\int , ...) where the text is placed above/below the symbol, this is the additional width added to the width of maximum width of the operator, above and below
955 *
956 * \image html jkqtmathtext_subsuper_with_limits.png
957 */
958 double operatorsubsuper_extraspace_factor;
959 /** \brief for integrals (\c \\int , \c \\oint , ...) the sub-/superscripts above/below the symbol have to be shifted a bit to the left/right to accomodate the shape of the operator symbol (i.e. some free space at the top-left and bottom-right)
960 *
961 * \image html jkqtmathtext/jkqtmathtext_doc_subsupershift_integral.png
962 *
963 * \image html jkqtmathtext/jkqtmathtext_doc_subsupershift_integral_boxes.png
964 *
965 * This factor is multiplied by the symbol width: xshift=intsubsuper_xcorrection_factor*symbolWidth
966 * Then the subscript below is placed at centerx(symbol)-xshift and the superscript at centerx(symbol)+shiftx.
967 * This is also used to correct a subset next to the symbol by shifting it to rightx(symbol)-xshift.
968 *
969 * This correction is applied to \\int, \\iint, \\iiint, \\oint, ...
970 */
971 double intsubsuper_xcorrection_factor;
972 /** \brief for integrals (\c \\int , \c \\oint , ...) the subscripts besides the symbol have to be shifted to the left a bit to the left to accomodate the shape of the operator symbol (i.e. some free space at the bottom-right)
973 *
974 * \image html jkqtmathtext/jkqtmathtext_doc_subsupershift_integral.png
975 *
976 * \image html jkqtmathtext/jkqtmathtext_doc_subsupershift_integral_boxes.png
977 *
978 * This factor is multiplied by the width of an x: xshift=intsubbesides_xcorrection_xfactor*xWidth
979 * Then the subscript besides the symbol is shifted by xshift to the left
980 *
981 * This correction is applied to \\int, \\iint, \\iiint, \\oint, ...
982 */
983 double intsubbesides_xcorrection_xfactor;
984 /** \brief factor, used to extend the size of an operator in math mode
985 *
986 * The next image demonstrates the effect of this property, which adds extra space
987 * around certain math operators in math mode:
988 *
989 * \image html jkqtmathtext/jkqtmathtext_mathoperator_width_factor.png
990 */
991 double mathoperator_width_factor;
992 /** \brief factor, used to increase the font size for big math operators, such as \c \\sum , \c \\prod , ...
993 *
994 */
995 double bigmathoperator_font_factor;
996 /** \brief relative shift of text in superscript to normal text, factor is multiplied by \c font.xHeight()
997 *
998 * \image html jkqtmathtext_superscriptnode_getSizeInternal.png
999 */
1000 double super_shift_factor;
1001 /** \brief relative shift of text in subscript to normal text, factor is multiplied by \c font.xHeight()
1002 *
1003 * \image html jkqtmathtext_subscriptnode_getSizeInternal.png
1004 */
1005 double sub_shift_factor;
1006 /** \brief relative shift of text in superscript to normal text in special superscript mode (after large previous nodes):
1007 * 0= superscript descent coincides with the previous node's baselineHeight, 1: top of previous node and top of the superscript nodes coincide
1008 *
1009 * \image html jkqtmathtext_specialsuperscriptnode_getSizeInternal.png
1010 */
1011 double special_super_shift_factor;
1012 /** \brief relative shift of text in subscript to normal text in special superscript mode (after large previous nodes):
1013 * 0=child's baseline at the descent of the previous node, 1: subscript-node starts at the descent of the previous node
1014 *
1015 * \image html jkqtmathtext_specialsubscriptnode_getSizeInternal.png
1016 */
1017 double special_sub_shift_factor;
1018
1019
1020 /** \brief scaling factor for font size of nominator and denominator of a fraction
1021 *
1022 * \image html jkqtmathtext/jkqtmathtext_frac_factor.png
1023 */
1024 double frac_factor;
1025 /** \brief scaling factor for font size of nominator and denominator of a nested fraction
1026 *
1027 * \image html jkqtmathtext/jkqtmathtext_frac_factor.png
1028 */
1029 double frac_nested_factor;
1030 /** \brief shift of denominator/nummerator away from central line of a frac
1031 *
1032 * \image html jkqtmathtext_fracnode_geo.png
1033 */
1034 double frac_shift_factor;
1035 /** \brief scaling factor for font of underbrace/overbrace text */
1036 double underbrace_factor;
1037 /** \brief scaling factor for font of underset/overset text */
1038 double underset_factor;
1039 /** \brief additional space between the main text to the curly brace and the brace to underbrace/overbrace, multiplied with height("x") */
1040 double underbrace_separation_xfactor;
1041 /** \brief height of the brace in underbrace/overbrace, multiplied with ascent */
1042 double underbrace_bracesize_xfactor;
1043 /** \brief fraction of the brace ascent that the brace is shifted downwards, when scaled */
1044 double brace_y_shift_factor;
1045 /** \brief size of the decorations (dot, tilde, ...), as fraction of the ascent
1046 *
1047 * \image html jkqtmathtext/decoration_sizing.png
1048 */
1049 double decoration_height_factor;
1050 /** \brief separation between the text and the decorations (dot, tilde, ...), as fraction of the ascent
1051 *
1052 * \image html jkqtmathtext/decoration_sizing.png
1053 */
1054 double decoration_separation_factor;
1055 /** \brief a decoration has a size, which is slightly smaller than the text- width. the width is reduced by \c decoration_width_reduction_Xfactor*width("X") and the position is centered around the child-box. Also an italic correction is applied:
1056 *
1057 * \image html jkqtmathtext/decoration_sizing.png
1058 */
1059 double decoration_width_reduction_Xfactor;
1060 /** \brief scaling factor for the small font used to indicate the degree of the sqrt */
1061 double sqrt_smallfont_factor;
1062 /** \brief width of the sqrt-symbol, as factor to width("X") */
1063 double sqrt_width_Xfactor;
1064 /** \brief height-increase of the sqrt-symbol, as factor of the child's height */
1065 double sqrt_height_factor;
1066
1067 /** \brief width of thin table lines, this factor is multiplied with the current \c font.linewidth()
1068 *
1069 * \image html jkqtmathtext/jkqtmathtext_matrix_geometry.png
1070 */
1071 double matrix_linewidth_thin_factor;
1072 /** \brief width of heavy table lines, this factor is multiplied with the current \c font.linewidth()
1073 *
1074 * \image html jkqtmathtext/jkqtmathtext_matrix_geometry.png
1075 */
1076 double matrix_linewidth_heavy_factor;
1077 /** \brief separation of double-lines in tables, this factor is multiplied with the \c font.linewidth()
1078 *
1079 * \image html jkqtmathtext/jkqtmathtext_matrix_geometry.png
1080 */
1081 double matrix_line_separation_factor;
1082 /** \brief x-separation of two columns, this factor is multiplied with the \c font.width("x")
1083 *
1084 * \image html jkqtmathtext/jkqtmathtext_matrix_geometry.png
1085 */
1086 double matrix_xSeparation_factor;
1087 /** \brief y-separation of two columns, this factor is multiplied with the \c font.width("x")
1088 *
1089 * \image html jkqtmathtext/jkqtmathtext_matrix_geometry.png
1090 */
1091 double matrix_ySeparation_factor;
1092 /** \brief x-padding of two columns, this factor is multiplied with the \c font.width("x")
1093 *
1094 * \image html jkqtmathtext/jkqtmathtext_matrix_geometry.png
1095 */
1096 double matrix_xPadding_factor;
1097 /** \brief y-padding of two columns, this factor is multiplied with the \c font.width("x")
1098 *
1099 * \image html jkqtmathtext/jkqtmathtext_matrix_geometry.png
1100 */
1101 double matrix_yPadding_factor;
1102
1103 /** \brief initial choice for "serif" font */
1104 static QString init_serifFont;
1105 /** \brief initial choice for "sans-erif" font */
1106 static QString init_sansFont;
1107 /** \brief initial choice for "fallback symbol" font */
1108 static QString init_symbolFont;
1109 /** \brief initial choice for "script" font */
1110 static QString init_scriptFont;
1111 /** \brief initial choice for "typewriter" font */
1112 static QString init_typewriterFont;
1113 /** \brief initial choice for "caligraphic" font */
1114 static QString init_caligraphicFont;
1115 /** \brief initial choice for "blackboard" font */
1116 static QString init_blackboardFont;
1117 /** \brief initial choice for "fraktur" font */
1118 static QString init_fracturFont;
1119 /** \brief used to check for the first construction of a JKQTMathText ... if \c true several static variables are initialized in the constructor */
1120 static bool s_firstStart;
1121 /** \brief mutex to protect the static members */
1122 static std::mutex s_mutex;
1123};
1124
1125
1126#endif // JKQTMATHTEXT_H
1127
1128
1129
1130
1131
1132
1133
1134
1135
this class parses a mathematical markup string and can then draw the contained text/equation onto a Q...
Definition jkqtmathtext.h:192
double getDescent(QPainter &painter)
return the descent, i.e. the distance from the baseline to the lowest part of the representation
void draw(QPainter &painter, QPointF x, bool drawBoxes=false)
draw a representation to the object at the specified position x , y
QFlags< ParseOption > ParseOptions
Definition jkqtmathtext.h:217
bool parse(const QString &markup, ParseOptions options=DefaultParseOptions)
parse the given math markup string, using the given parser class TParser
Definition jkqtmathtext.h:242
JKQTMathText(QObject *parent=nullptr, bool useFontsForGUI=false)
class constructor with a paren QObject parent and calls useGuiFonts() if useFontsForGUI =true
bool parse(const QString &markup, DefaultParserTypes markupType=DefaultParser, ParseOptions options=DefaultParseOptions)
parse the given math markup string with a parser derived from markupType.
QSizeF getSize(QPainter &painter)
get the size of the drawn representation. returns an invalid size if no text has been parsed.
double getAscent(QPainter &painter)
return the ascentt, i.e. the distance from the baseline to the highest part of the representation
double draw(QPainter &painter, double x, double y, bool drawBoxes=false)
draw a representation to the object at the specified position x , y
QString toHtml(bool *ok=nullptr, double fontPointSize=10)
convert LaTeX to HTML. returns ok=true on success and ok=false else.
BaseFontOption
options for the base font
Definition jkqtmathtext.h:347
QPicture drawIntoPicture(bool drawBoxes=false)
render the last parse result into a QPicture
const JKQTMathTextNode * getNodeTree() const
the syntax tree of JKQTMathTextNode's that was created by the last parse() call
ParseOption
options for parse()
Definition jkqtmathtext.h:211
void draw(QPainter &painter, unsigned int flags, QRectF rect, bool drawBoxes=false)
draw into a rectangle rect with alignment defined in flags (see below)
JKQTMathTextNodeSize getSizeDetail(QPainter &painter)
return the detailes sizes of the text
QImage drawIntoImage(bool drawBoxes=false, QColor backgroundColor=QColor(Qt::white), int sizeincrease=0, qreal devicePixelRatio=1.0, unsigned int resolution_dpi=96)
render the last parse result into a QImage
JKQTMathTextNode * getNodeTree()
returns the syntax tree of JKQTMathTextNode's that was created by the last parse() call
void getSizeDetail(QPainter &painter, double &width, double &ascent, double &descent, double &strikeoutPos)
return the detailes sizes of the text
~JKQTMathText()
class destructor
QSize getIntSize(QPainter &painter)
get the rounded (using ceil) to an integer size of the drawn representation. returns QSize(0,...
DefaultParserTypes
lists the parser classes that are available by default (convenience interface to the templated parse(...
Definition jkqtmathtext.h:220
@ LatexParser
use the LaTeX parser from JKQTMathTextLatexParser
Definition jkqtmathtext.h:221
QFlags< BaseFontOption > BaseFontOptions
Definition jkqtmathtext.h:354
static const double ABS_MIN_LINEWIDTH
minimum linewidth allowed in a JKQTMathText (given in pt)
Definition jkqtmathtext.h:199
QPixmap drawIntoPixmap(bool drawBoxes=false, QColor backgroundColor=QColor(Qt::white), int sizeincrease=0, qreal devicePixelRatio=1.0)
render the last parse result into a QPixmap
subclass representing one node in the syntax tree
Definition jkqtmathtextnode.h:37
base class for all math markup parsers used by JKQTMathText
Definition jkqtmathtextparser.h:43
subclass representing a list of nodes in the syntax tree, layed out vertically
Definition jkqtmathtextverticallistnode.h:50
#define JKQTMATHTEXT_LIB_EXPORT
Definition jkqtmathtext_imexport.h:108
JKQTMathTextEnvironmentFont
the available logical fonts (default is MTEroman)
Definition jkqtmathtexttools.h:284
JKQTMathTextBlackboradDrawingMode
used to specify how blackboard-fonts are drawn
Definition jkqtmathtexttools.h:193
JKQTMathTextFontEncoding
used to specify the font encoding used for drawing
Definition jkqtmathtexttools.h:175
@ MTFEStandard
Definition jkqtmathtexttools.h:179
@ MTFEUnicode
This assumes that symbols shall be taken from a Unicode font, which ideally offers full symbol suppor...
Definition jkqtmathtexttools.h:177
describes the current drawing environment (base fontname ...)
Definition jkqtmathtexttools.h:304
summarizes all information available on a font for a specific MTenvironmentFont
Definition jkqtmathtexttools.h:430
represents a font specifier for JKQTMathText. The font consists of two parts: the actual font and the...
Definition jkqtmathtexttools.h:96
beschreibt die Größe(n) eines Knotens
Definition jkqtmathtexttools.h:393