2015-07-11 18:56:02 +08:00
/*
2019-01-12 23:01:55 +08:00
Copyright ( c ) 2008 - 2019 Jan W . Krieger ( < jan @ jkrieger . de > )
2018-12-14 05:33:42 +08:00
with contributions from : Razi Alavizadeh
2015-07-11 18:56:02 +08:00
2015-07-12 22:34:27 +08:00
2015-07-11 18:56:02 +08:00
This software is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License ( LGPL ) as published by
2019-02-08 00:24:46 +08:00
the Free Software Foundation , either version 2.1 of the License , or
2015-07-11 18:56:02 +08:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License ( LGPL ) for more details .
You should have received a copy of the GNU Lesser General Public License ( LGPL )
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
/*
Name : jkqtmathtext . h
2019-01-19 16:40:52 +08:00
Copyright : ( c ) 2010 - 2019
2015-07-11 18:56:02 +08:00
Author : Jan krieger < jan @ jkrieger . de > , http : //www.jkrieger.de/
*/
# ifndef JKQTMATHTEXT_H
# define JKQTMATHTEXT_H
# include <QObject>
# include <QSettings>
# include <QPainter>
# include <QString>
# include <QSet>
# include <QFile>
2019-05-18 19:22:46 +08:00
# include "jkqtcommon/jkqtp_imexport.h"
2015-07-11 18:56:02 +08:00
# include <QWidget>
# include <QLabel>
# include <QHash>
2018-12-03 01:30:12 +08:00
2019-01-20 17:49:29 +08:00
/** \brief initialized Qt-ressources necessary for JKQTMathText
2019-01-10 04:23:24 +08:00
* \ ingroup jkqtmathtext
*/
2019-02-03 21:04:48 +08:00
JKQTP_LIB_EXPORT void initJKQTMathTextResources ( ) ;
2018-12-03 01:30:12 +08:00
2019-01-26 20:00:40 +08:00
/*! \brief this class parses a LaTeX string and can then draw the contained text/equation onto a <a href="http://doc.qt.io/qt-5/qpainter.html">QPainter</a>
2015-07-11 18:56:02 +08:00
\ ingroup jkqtmathtext
2019-01-19 16:40:52 +08:00
2019-01-20 17:49:29 +08:00
JKQTMathText is a self - contained LaTeX - renderer for Qt . It is used to renderer
2019-01-20 23:15:10 +08:00
labels in JKQTPlotter / JKQTBasePlotter , but can be used independently .
2019-01-19 23:54:31 +08:00
The class does not depend on any library , except Qt .
In particular it actually parses a LaTeX string and draws it in pure C + + . It does NOT rely
on an installed LaTeX for the rendering !
2019-01-20 17:49:29 +08:00
\ section JKQTMathTextUsage Usage
\ subsection JKQTMathTextUsageDirect Direct Usage
2019-01-19 23:54:31 +08:00
This small piece of C + + code may serve as an example of the usage and capabilities of the class :
2019-01-19 16:40:52 +08:00
\ code
2019-01-20 17:49:29 +08:00
// create a JKQTMathText object.
JKQTMathText mathText ;
2019-01-19 16:40:52 +08:00
// configure its properties to influence the rendering (e.g. fonts to use, font size, ...)
mathText . useXITS ( ) ;
2019-01-26 03:16:04 +08:00
mathText . setFontSize ( 20 ) ;
2019-01-19 16:40:52 +08:00
// parse some LaTeX code (the Schroedinger's equation)
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)$ " ) ;
// use the draw() methods to draw the equation using a QPainter (here onto a QPixmap)
QPainter painter ;
QPixmap pix ( 600 , 400 ) ;
painter . begin ( & pix ) ;
mathText . draw ( painter , Qt : : AlignCenter , QRectF ( 0 , 0 , pix . width ( ) , pix . height ( ) ) , false ) ;
painter . end ( ) ;
\ endcode
2019-01-19 23:54:31 +08:00
2019-01-20 17:49:29 +08:00
\ subsection JKQTMathTextSizing Determining the size of an equation
2019-01-19 23:54:31 +08:00
In addition there are also functions that allow to calculate the size of the equation , before drawing it ( just like the functions in < a href = " http://doc.qt.io/qt-5/qfontmetrics.html " > QFontMetrics < / a > and < a href = " http://doc.qt.io/qt-5/qfontmetricsf.html " > QFontMetricsF < / a > ) :
- getSizeDetail ( )
- getSize ( )
- getAscent ( ) , getDescent ( )
.
2019-01-20 17:49:29 +08:00
\ subsection JKQTMathTextErrorHandling Error Handling
2019-01-19 23:54:31 +08:00
The class is designed to be as robust as possible and will still return some output , even if the equation contains some errors .
2019-01-26 20:00:40 +08:00
Nevertheless , several errors are detected while parsing . You can get a list of error messages using getErrorList ( ) after calling parse ( ) .
2019-01-19 23:54:31 +08:00
Also parse ( ) will return \ c false if an error occured while parsing .
2019-01-20 17:49:29 +08:00
\ subsection JKQTMathTextUsageQLabel Usage within a QLabel class JKQTMathTextLabel
2019-01-19 23:54:31 +08:00
2019-01-20 17:49:29 +08:00
Finally , there is also a QLabel - derived class JKQTMathTextLabel which can be used for drawing a LaTeX string onto a Qt form .
2019-01-19 23:54:31 +08:00
2019-01-20 17:49:29 +08:00
\ see JKQTMathTextLabel
2019-01-19 23:54:31 +08:00
2019-01-20 17:49:29 +08:00
\ section JKQTMathTextExamples Examples
2019-01-19 23:54:31 +08:00
Examples for the usage of this class can be found here :
2019-01-20 17:49:29 +08:00
- \ ref JKQTMathTextSimpleExample
2019-01-19 23:54:31 +08:00
.
2019-01-20 17:49:29 +08:00
\ section JKQTMathTextSuppoertedLaTeX Supported LaTeX Subset
2019-01-20 23:15:10 +08:00
\ subsection JKQTMathTextSuppoertedLaTeXSimple Simple Instructions
2015-07-11 18:56:02 +08:00
The supported LaTeX subset is listes below . Please note that some commands are used differently than in actual LaTeX .
For example \ c \ \ bf is just a renamed form of \ c \ \ textbf and used as \ c \ \ bf { . . . } and NOT as \ c { \ \ bf . . . } .
- \ c $ : enter / leave math mode
2019-01-20 23:15:10 +08:00
- \ c \ \ bf { . . . } \ c \ \ textbf { . . . } \ c \ \ mathbf { . . . } : draw the contained text in bold face \ image html jkqtmathtext_bold . png
- \ c \ \ it { . . . } \ c \ \ textit { . . . } \ c \ \ mathit { . . . } : draw the contained text in italic face \ image html jkqtmathtext_italic . png
- \ c \ \ rm { . . . } \ c \ \ textrm { . . . } \ c \ \ mathrm { . . . } \ c \ \ mbox { . . . } : draw the contained text in normal upright roman font face \ image html jkqtmathtext_fonts . png
- \ c \ \ sf { . . . } \ c \ \ textsf { . . . } \ c \ \ mathsf { . . . } : draw the contained text in normal upright sans - serif font face \ image html jkqtmathtext_fonts . png
- \ c \ \ script { . . . } \ c \ \ textscript { . . . } \ c \ \ mathscript { . . . } : draw the contained text in a script font face \ image html jkqtmathtext_fonts . png
- \ c \ \ sc { . . . } : draw the text in small caps \ image html jkqtmathtext_sc . png
- \ c \ \ ul { . . . } \ c \ \ underline { . . . } \ c \ \ underlined { . . . } : draw the text with underlining \ image html jkqtmathtext_ul . png
- \ c \ \ ol { . . . } \ c \ \ overline { . . . } \ c \ \ overlined { . . . } : draw the text with overlining \ image html jkqtmathtext_ol . png
- \ c \ \ tt { . . . } \ c \ \ texttt { . . . } \ c \ \ mathtt { . . . } : draw text in typewriter font \ image html jkqtmathtext_fonts . png
- \ c \ \ textcolor { color } { . . . } \ c \ \ color { color } \ c \ \ mathcolor { color } { . . . } : draw colored text \ image html jkqtmathtext_colored . png
- \ c \ \ boxed { . . . } : draw text with a box around it \ image html jkqtmathtext_boxed . png
- \ c \ \ colorbox { color } { . . . } : draw a colored box around text \ image html jkqtmathtext_colorbox . png
- \ c \ \ alpha . . . : display the according greek letter \ image html jkqtmathtext_greek . png
- \ c ^ { . . . } \ c _ { . . . } : display the contents of braces in superscript / subscript \ image html jkqtmathtext_supersub . png
< br > Special subscript / superscript typesetting applies , when the sub / super follows \ c \ \ sum \ c \ \ Prod . . . : \ image html jkqtmathtext_specialsubsuper . png
2015-07-11 18:56:02 +08:00
- \ c \ \ { / \ \ } : display opening / closing brace
- \ c \ \ _ : display underscore
- \ c \ \ sum \ c \ \ prod \ c \ \ int . . . : plot special symbol . Note that depending on the fontEncoding the available
symbols may differ ( there are not all symbols defined in the MS Windows Symbol
font ! ) . Best coverage should be given by Unicode font encoding with a good
2019-01-20 23:15:10 +08:00
unicode font installed ! < br > \ image html jkqtmathtext_symbols . png
- < code > \ \ vec { x } \ \ dot { x } \ \ ddot { x } \ \ overline { x } \ \ underline { x } \ \ hat { x } \ \ tilde { x } \ \ uul { x } \ \ ool { x } \ \ bar { x } \ \ arrow { x } < / code > : Decorations over / under symbols \ image html jkqtmathtext_mathdeco . png
- < code > \ \ verb { don ' t parse this _aaa \ LaTeX } < / code > : interpret enclosed text as verbose \ image html jkqtmathtext_verb . png
2015-07-11 18:56:02 +08:00
.
2019-01-20 23:15:10 +08:00
\ subsection JKQTMathTextSuppoertedLaTeXBraces Braces . . .
2015-07-11 18:56:02 +08:00
Braces in math mode are adjusted in size , so they are a small bit ( factor \ c brace_factor ) larger than the contents .
To enable this you have to write braces with \ c \ \ left and \ c \ \ right . These types of braces are defined ( slight
differences to LaTeX standard ) :
2019-01-20 23:15:10 +08:00
- \ c \ \ left ( \ c \ \ right ) : default meaning ( ) , \ image html jkqtmathtext_brace_round . png
- \ c \ \ left [ \ c \ \ right ] : default meaning [ ] , \ image html jkqtmathtext_brace_rect . png
- \ c \ \ left \ \ { \ c \ \ right \ \ } : default meaning { } , \ image html jkqtmathtext_brace_curly . png
- \ c \ \ left < \ c \ \ right > : " averaging " braces , \ image html jkqtmathtext_brace_tri . png
- \ c \ c \ \ left \ \ lfloor \ c \ \ right \ \ rfloor : floor braces , \ image html jkqtmathtext_brace_floor . png
- \ c \ \ left ~ \ c \ \ right ~ \ c \ \ left \ \ lceil \ c \ \ right \ \ rceil : ceil braces , \ image html jkqtmathtext_brace_ceil . png
- \ c \ \ left | \ c \ \ right | : absolute value braces | | , \ image html jkqtmathtext_brace_oneline . png
- \ c \ \ left \ | \ c \ \ right \ | : norm braces | | | | , \ image html jkqtmathtext_brace_dblline . png
- You can use \ c \ \ left . or \ c \ \ right . to have only right or only left brace
.
\ subsection JKQTMathTextSuppoertedLaTeXUnderOver Undersetting , Oversetting , Underbraces , Overbraces . . .
There are also instructions that allow to under / overset braces , arrows , . . . :
- < code > $ \ underbrace { x + x + . . . + x } { k \ \ mathrm { times } } $ < / code > \ image html jkqtmathtext_brace_underbrace . png
- < code > $ \ overbrace { x + x + . . . + x } { k \ \ mathrm { times } } $ < / code > \ image html jkqtmathtext_brace_overbrace . png
- < code > $ \ overset { main } { over } $ < / code > \ image html jkqtmathtext_brace_overset . png
- < code > $ \ underset { main } { under } $ < / code > \ image html jkqtmathtext_brace_underset . png
.
\ subsection JKQTMathTextSuppoertedLaTeXMatrix Matrix / Array Type Instructions
Several Matrix / Array - typed LaTeX instructions are supported :
- < code > $ \ frac { . . . } { . . . } $ < / code > , < code > $ \ tfrac { . . . } { . . . } $ < / code > ( 70 % smaller font ) , < code > $ \ dfrac { . . . } { . . . } $ < / code > \ image html jkqtmathtext_brace_frac . png
2019-05-18 17:41:17 +08:00
- < code > $ \ sfrac { . . . } { . . . } $ < / code > \ image html mathparser / MTFMsfrac . png
- < code > $ \ stfrac { . . . } { . . . } $ < / code > ( 70 % smaller font ) \ image html mathparser / MTFMstfrac . png
2019-01-20 23:15:10 +08:00
- < code > $ \ stackrel { . . . } { . . . } $ $ \ binom { . . . } { . . . } $ < / code > \ image html jkqtmathtext_brace_stackrel . png
- < code > $ \ begin { cases } . . . & . . . \ \ . . . & . . . \ end { cases } $ < / code > \ image html jkqtmathtext_brace_begincases . png
- < code > $ \ begin { array } a & b & . . . \ \ c & d & . . . \ end { array } $ < / code > < code > $ \ begin { matrix } a & b & . . . \ \ c & d & . . . \ end { matrix } $ < / code > \ image html jkqtmathtext_array . png
- < code > $ \ begin { pmatrix } a & b & . . . \ \ c & d & . . . \ end { pmatrix } $ < / code > \ image html jkqtmathtext_pmatrix . png
- < code > $ \ begin { bmatrix } a & b & . . . \ \ c & d & . . . \ end { bmatrix } $ < / code > \ image html jkqtmathtext_bmatrix . png
- < code > $ \ begin { Bmatrix } a & b & . . . \ \ c & d & . . . \ end { Bmatrix } $ < / code > \ image html jkqtmathtext_bbmatrix . png
- < code > $ \ begin { vmatrix } a & b & . . . \ \ c & d & . . . \ end { vmatrix } $ < / code > \ image html jkqtmathtext_vmatrix . png
- < code > $ \ begin { Vmatrix } a & b & . . . \ \ c & d & . . . \ end { Vmatrix } $ < / code > \ image html jkqtmathtext_vvmatrix . png
2015-07-11 18:56:02 +08:00
.
2019-01-20 17:49:29 +08:00
\ section JKQTMathTextSuppoertedFonts Font Handling
2019-01-19 23:54:31 +08:00
2015-07-11 18:56:02 +08:00
Several fonts are defined as properties to the class :
2019-03-07 06:18:29 +08:00
- A " roman " font used as the standard font ( setFontRoman ( ) )
- A " sans-serif " font which may be activated with \ c \ \ sf . . . ( setFontSans ( ) )
2019-01-26 03:16:04 +08:00
- A " typewriter " font which may be activated with \ c \ \ tt . . . ( setFontTypewriter ( ) )
- A " script " font which may be activated with \ c \ \ script . . . ( setFontScript ( ) )
- A greek font which is used to display greek letters \ c \ \ alpha . . . ( setFontGreek ( ) )
2015-07-11 18:56:02 +08:00
- A symbol font used to display special ( math ) symbols .
- A " roman " font used as the standard font in math mode
- A " sans-serif " used as sans serif font in math mode
2019-01-26 03:16:04 +08:00
- A " blackboard " font used to display double stroked characters ( setFontBlackboard ( ) )
- A " caligraphic " font used to display caligraphic characters ( setFontCaligraphic ( ) )
2015-07-11 18:56:02 +08:00
.
2019-01-19 23:54:31 +08:00
2019-01-26 20:00:40 +08:00
These fonts are generic font classes , which font is actually used can be configured in JKQTMathText class with the \ c set . . . ( ) functions mentioned above . You can also use these functions to set the fonts used for math rendering in math - mode :
2019-01-19 16:40:52 +08:00
- useSTIX ( ) use the STIX fonts from < a href = " https://www.stixfonts.org/ " > https : //www.stixfonts.org/</a> in math-mode<br>\image html jkqtmathparser_stix.png
- useXITS ( ) use the XITS fonts from < a href = " https://github.com/alif-type/xits " > https : //github.com/alif-type/xits</a> in math-mode. These are included by default in this library and also activated by default.<br>\image html jkqtmathparser_xits.png
- useASANA ( ) 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<br>\image html jkqtmathparser_asana.png
- useAnyUnicode ( ) use generic Unicode fonts , e . g . " Arial " and " Times New Roman " in math - mode . You should use fonts that contain as many of the mathematical symbols as possible to ensure good rendering results . < br > using " Times New Roman " : \ image html jkqtmathparser_timesnewroman . png
< br > using " Arial " : \ image html jkqtmathparser_arial . png
2019-01-19 23:54:31 +08:00
< br > using " Courier New " : \ image html jkqtmathparser_couriernew . png
< br > using " Comic Sans MS " : \ image html jkqtmathparser_comicsans . png
2019-01-19 23:24:19 +08:00
.
2019-01-19 16:40:52 +08:00
2019-01-19 23:54:31 +08:00
Math - mode is activated by enclosing your equation in \ c $ . . . $ or \ c \ \ [ . . . \ \ ] . This mode is optimized for mathematical equations . Here is an example of the difference :
- < b > math - mode ( XITS fonts are used , whitespaces are mostly not drawn directly , symbol spacing is different ) < / b > \ c $ . . . $ : < br > \ image html jkqtmathparser_schreq_mathmode . png
- < b > normal mode ( Times new Roman is used , whitespaces are evaluated directly ) < / b > : < br > \ image html jkqtmathparser_schreq_normalmode . png
.
2019-01-19 16:40:52 +08:00
2019-01-20 17:49:29 +08:00
\ section JKQTMathTextToHTML Convert to HTML
2019-01-19 23:54:31 +08:00
2015-07-11 18:56:02 +08:00
The method toHtml ( ) may be used to get a HTML representation of the LaTeX string , if possible ( only for simple LaTeX equations ! ) . Whether
the transformation was possible is returned as a call by value argument !
*/
2019-02-03 21:04:48 +08:00
class JKQTP_LIB_EXPORT JKQTMathText : public QObject {
2015-07-11 18:56:02 +08:00
Q_OBJECT
public :
2019-02-08 00:24:46 +08:00
/** \brief minimum linewidth allowed in a JKQTMathText (given in pt) */
static const double ABS_MIN_LINEWIDTH ;
2015-07-11 18:56:02 +08:00
/** \brief class constructor */
2019-01-20 17:49:29 +08:00
JKQTMathText ( QObject * parent = nullptr ) ;
2015-07-11 18:56:02 +08:00
/** \brief class destructor */
2019-01-20 17:49:29 +08:00
~ JKQTMathText ( ) ;
2015-07-11 18:56:02 +08:00
/** \brief load the object settings from the given QSettings object with the given name prefix */
2019-02-08 00:24:46 +08:00
void loadSettings ( const QSettings & settings , const QString & group = QString ( " mathtext/ " ) ) ;
2015-07-11 18:56:02 +08:00
/** \brief store the object settings to the given QSettings object with the given name prefix */
2019-02-08 00:24:46 +08:00
void saveSettings ( QSettings & settings , const QString & group = QString ( " mathtext/ " ) ) const ;
2015-07-11 18:56:02 +08:00
/** \brief parse the given enhanced string. Returns \c true on success. */
bool parse ( QString text ) ;
/** \brief get the size of the drawn representation. returns an invalid size if no text has been parsed. */
QSizeF getSize ( QPainter & painter ) ;
/** \brief return the descent, i.e. the distance from the baseline to the lowest part of the representation */
double getDescent ( QPainter & painter ) ;
/** \brief return the ascentt, i.e. the distance from the baseline to the highest part of the representation */
double getAscent ( QPainter & painter ) ;
/** \brief return the detailes sizes of the text */
void getSizeDetail ( QPainter & painter , double & width , double & ascent , double & descent , double & strikeoutPos ) ;
2019-01-26 20:00:40 +08:00
/** \brief draw a representation to the <a href="http://doc.qt.io/qt-5/qpainter.html">QPainter</a> object at the specified position */
2015-07-11 18:56:02 +08:00
void draw ( QPainter & painter , double x , double y , bool drawBoxes = false ) ;
/** \brief overloaded version of draw(QPainter& painter, double x, double y).
*
* This version draws the text inside the given rectangle according to the specified flags .
*/
2019-05-01 20:58:19 +08:00
void draw ( QPainter & painter , unsigned int flags , QRectF rect , bool drawBoxes = false ) ;
2015-07-11 18:56:02 +08:00
2019-01-19 16:40:52 +08:00
/** \brief configures the class to use the STIX fonts in mathmode
*
* use STIX ( 1. x / 2. x ) fonts from < a href = " https://www.stixfonts.org/ " > https : //www.stixfonts.org/</a> in math-mode
*
* \ image html jkqtmathparser_stix . png
*/
2015-07-11 18:56:02 +08:00
void useSTIX ( ) ;
2019-01-19 16:40:52 +08:00
/** \brief configures the class to use the XITS fonts in mathmode
*
* use XITS fonts from < a href = " https://github.com/alif-type/xits " > https : //github.com/alif-type/xits</a> in math-mode.
* These are included by default in this library and also activated by default .
*
* \ image html jkqtmathparser_xits . png
*/
2015-07-11 18:56:02 +08:00
void useXITS ( ) ;
2019-01-19 16:40:52 +08:00
/** \brief configures the class to use the ASANA fonts in mathmode
*
* 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
*
* \ image html jkqtmathparser_asana . png
*/
2015-07-11 18:56:02 +08:00
void useASANA ( ) ;
2019-01-19 16:40:52 +08:00
/** \brief configures the class to use a unicode font for symbols in mathmode
*
* use generic Unicode fonts , e . g . " Arial " and " Times New Roman " in math - mode .
* You should use fonts that contain as many of the mathematical symbols as possible to ensure good rendering results .
*
* < code > setAnyUnicode ( " Times New Roman " , " Times New Roman " ) < / code > : < br > \ image html jkqtmathparser_timesnewroman . png
* < code > setAnyUnicode ( " Arial " , " Arial " ) < / code > : < br > \ image html jkqtmathparser_arial . png
2019-01-19 23:24:19 +08:00
* < code > setAnyUnicode ( " Courier New " , " Courier New " ) < / code > : < br > \ image html jkqtmathparser_couriernew . png
* < code > setAnyUnicode ( " Comic Sans MS " , " Comic Sans MS " ) < / code > : < br > \ image html jkqtmathparser_comicsans . png
2019-03-07 06:18:29 +08:00
*
* The parameter \ a fullMathUnicodeFont specifies , whether the unicode fonts encode also math symbols , or are
* limited to latin + greek + basic symbols .
2019-01-19 16:40:52 +08:00
*/
2019-03-07 06:18:29 +08:00
void useAnyUnicode ( QString timesFont = QString ( " " ) , const QString & sansFont = QString ( " " ) , bool fullMathUnicodeFont = false ) ;
2015-07-11 18:56:02 +08:00
2019-01-26 19:28:44 +08:00
void useLatexFonts ( QString prefix = QString ( " " ) , const QString & postfix = QString ( " " ) ) ;
2015-07-11 18:56:02 +08:00
/** \brief convert LaTeX to HTML. returns \c ok=true on success and \c ok=false else. */
2018-11-18 18:59:30 +08:00
QString toHtml ( bool * ok = nullptr , double fontPointSize = 10 ) ;
2015-07-11 18:56:02 +08:00
/*! \brief used to specify the font encoding used for drawing
- \ c MTFEwinSymbol : This assumes that symbols shal be taken from a MS Windows style Symbol font
- \ c MTFElatex : This assumes that symbols shal be taken from the CM ( computer modern ) fonts , used by LaTeX
- \ c MTFEunicode : This assumes that symbols shall be taken from a Unicode font
( e . g . the STIX fonts from < a href = " http://www.stixfonts.org/ " > http : //www.stixfonts.org/</a>)
2019-03-07 06:18:29 +08:00
- \ c MTFEunicodeLimited : This assumes that the fonts used are Unicode , but only offer a limited set of symbols .
Especially math symbols are missing from this encoding
2015-07-11 18:56:02 +08:00
.
*/
enum MTfontEncoding {
MTFEwinSymbol ,
MTFEunicode ,
2019-03-07 06:18:29 +08:00
MTFEunicodeLimited ,
2015-07-11 18:56:02 +08:00
MTFElatex
} ;
2019-05-18 02:46:52 +08:00
/*! \copydoc fontColor */
2019-02-08 00:24:46 +08:00
inline void setFontColor ( const QColor & __value )
2019-01-10 04:23:24 +08:00
{
this - > fontColor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontColor */
2019-02-08 00:24:46 +08:00
inline QColor getFontColor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontColor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontSize */
2019-02-08 00:24:46 +08:00
inline void setFontSize ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > fontSize = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontSize */
2019-02-08 00:24:46 +08:00
inline double getFontSize ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontSize ;
}
2019-05-06 01:31:20 +08:00
/** \brief add a font pair to the table with font replacements
*
* e . g . if it is known that a certain font is not good for rendering , you can add an alternative with this function .
* These are automatically applied , when setting a new font name !
*
* \ param nonUseFont the font not to use
* \ param useFont replacement font for nonUseFont
*/
void addReplacementFont ( const QString & nonUseFont , const QString & useFont ) ;
2019-05-18 02:46:52 +08:00
/*! \copydoc fontRoman */
2019-02-08 00:24:46 +08:00
inline void setFontRoman ( const QString & __value )
2019-01-10 04:23:24 +08:00
{
2019-05-06 01:31:20 +08:00
this - > fontRoman = fontReplacements . value ( __value , __value ) ;
2019-02-08 00:24:46 +08:00
}
/*! \brief sets the property fontRoman ( \copybrief fontRoman ) to \a __value, or calls useXITS() if \a __value \c =="XITS". calls useSTIX() if \a __value \c =="STIX", ...
\ see fontRoman for more information */
void setFontRomanOrSpecial ( const QString & __value ) ;
2019-05-18 02:46:52 +08:00
/*! \copydoc fontRoman */
2019-02-08 00:24:46 +08:00
inline QString getFontRoman ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontRoman ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontSans */
2019-02-08 00:24:46 +08:00
inline void setFontSans ( const QString & __value )
2019-01-10 04:23:24 +08:00
{
2019-05-06 01:31:20 +08:00
this - > fontSans = fontReplacements . value ( __value , __value ) ;
2019-01-10 04:23:24 +08:00
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontSans */
2019-02-08 00:24:46 +08:00
inline QString getFontSans ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontSans ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontTypewriter */
2019-02-08 00:24:46 +08:00
inline void setFontTypewriter ( const QString & __value )
2019-01-10 04:23:24 +08:00
{
this - > fontTypewriter = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontTypewriter */
2019-02-08 00:24:46 +08:00
inline QString getFontTypewriter ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontTypewriter ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontScript */
2019-02-08 00:24:46 +08:00
inline void setFontScript ( const QString & __value )
2019-01-10 04:23:24 +08:00
{
this - > fontScript = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontScript */
2019-02-08 00:24:46 +08:00
inline QString getFontScript ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontScript ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontGreek */
2019-02-08 00:24:46 +08:00
inline void setFontGreek ( const QString & __value )
2019-01-10 04:23:24 +08:00
{
this - > fontGreek = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontGreek */
2019-02-08 00:24:46 +08:00
inline QString getFontGreek ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontGreek ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontSymbol */
2019-02-08 00:24:46 +08:00
inline void setFontSymbol ( const QString & __value )
2019-01-10 04:23:24 +08:00
{
this - > fontSymbol = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontSymbol */
2019-02-08 00:24:46 +08:00
inline QString getFontSymbol ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontSymbol ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontBraces */
2019-02-08 00:24:46 +08:00
inline void setFontBraces ( const QString & __value )
2019-01-10 04:23:24 +08:00
{
this - > fontBraces = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontBraces */
2019-02-08 00:24:46 +08:00
inline QString getFontBraces ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontBraces ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontIntegrals */
2019-02-08 00:24:46 +08:00
inline void setFontIntegrals ( const QString & __value )
2019-01-10 04:23:24 +08:00
{
this - > fontIntegrals = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontIntegrals */
2019-02-08 00:24:46 +08:00
inline QString getFontIntegrals ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontIntegrals ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontCaligraphic */
2019-02-08 00:24:46 +08:00
inline void setFontCaligraphic ( const QString & __value )
2019-01-10 04:23:24 +08:00
{
this - > fontCaligraphic = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontCaligraphic */
2019-02-08 00:24:46 +08:00
inline QString getFontCaligraphic ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontCaligraphic ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontBlackboard */
2019-02-08 00:24:46 +08:00
inline void setFontBlackboard ( const QString & __value )
2019-01-10 04:23:24 +08:00
{
this - > fontBlackboard = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontBlackboard */
2019-02-08 00:24:46 +08:00
inline QString getFontBlackboard ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontBlackboard ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontLatexPrefix */
2019-02-08 00:24:46 +08:00
inline void setFontLatexPrefix ( const QString & __value )
2019-01-10 04:23:24 +08:00
{
this - > fontLatexPrefix = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontLatexPrefix */
2019-02-08 00:24:46 +08:00
inline QString getFontLatexPrefix ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontLatexPrefix ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontLatexPostfix */
2019-02-08 00:24:46 +08:00
inline void setFontLatexPostfix ( const QString & __value )
2019-01-10 04:23:24 +08:00
{
this - > fontLatexPostfix = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontLatexPostfix */
2019-02-08 00:24:46 +08:00
inline QString getFontLatexPostfix ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > fontLatexPostfix ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontEncoding */
2019-02-08 00:24:46 +08:00
inline void setFontEncoding ( const MTfontEncoding & __value )
2019-01-10 04:23:24 +08:00
{
this - > fontEncoding = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc fontEncoding */
2019-02-08 00:24:46 +08:00
inline MTfontEncoding getFontEncoding ( ) const
2019-01-10 04:23:24 +08:00
{
2019-03-07 06:18:29 +08:00
return this - > fontEncoding ;
2019-01-10 04:23:24 +08:00
}
2019-05-19 04:41:38 +08:00
/*! \copydoc useSTIXfonts */
2019-01-26 03:16:04 +08:00
inline bool isUsingSTIXfonts ( ) const {
2019-01-10 04:23:24 +08:00
return this - > useSTIXfonts ;
}
2019-05-19 04:41:38 +08:00
/*! \copydoc useXITSfonts */
2019-01-26 03:16:04 +08:00
inline bool isUsingXITSfonts ( ) const {
2019-01-10 04:23:24 +08:00
return this - > useXITSfonts ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc brace_factor */
2019-02-08 00:24:46 +08:00
inline void setBraceFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > brace_factor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc brace_factor */
2019-02-08 00:24:46 +08:00
inline double getBraceFactor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > brace_factor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc subsuper_size_factor */
2019-02-08 00:24:46 +08:00
inline void setSubsuperSizeFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > subsuper_size_factor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc subsuper_size_factor */
2019-02-08 00:24:46 +08:00
inline double getSubsuperSizeFactor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > subsuper_size_factor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc italic_correction_factor */
2019-02-08 00:24:46 +08:00
inline void setItalicCorrectionFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > italic_correction_factor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc italic_correction_factor */
2019-02-08 00:24:46 +08:00
inline double getItalicCorrectionFactor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > italic_correction_factor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc operatorsubsuper_size_factor */
2019-02-08 00:24:46 +08:00
inline void setOperatorsubsuperSizeFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > operatorsubsuper_size_factor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc operatorsubsuper_size_factor */
2019-02-08 00:24:46 +08:00
inline double getOperatorsubsuperSizeFactor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > operatorsubsuper_size_factor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc mathoperator_width_factor */
2019-02-08 00:24:46 +08:00
inline void setMathoperatorWidthFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > mathoperator_width_factor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc mathoperator_width_factor */
2019-02-08 00:24:46 +08:00
inline double getMathoperatorWidthFactor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > mathoperator_width_factor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc super_shift_factor */
2019-02-08 00:24:46 +08:00
inline void setSuperShiftFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > super_shift_factor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc super_shift_factor */
2019-02-08 00:24:46 +08:00
inline double getSuperShiftFactor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > super_shift_factor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc sub_shift_factor */
2019-02-08 00:24:46 +08:00
inline void setSubShiftFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > sub_shift_factor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc sub_shift_factor */
2019-02-08 00:24:46 +08:00
inline double getSubShiftFactor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > sub_shift_factor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc brace_shrink_factor */
2019-02-08 00:24:46 +08:00
inline void setBraceShrinkFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > brace_shrink_factor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc brace_shrink_factor */
2019-02-08 00:24:46 +08:00
inline double getBraceShrinkFactor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > brace_shrink_factor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc underbrace_factor */
2019-02-08 00:24:46 +08:00
inline void setUnderbraceFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > underbrace_factor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc underbrace_factor */
2019-02-08 00:24:46 +08:00
inline double getUnderbraceFactor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > underbrace_factor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc undersetFactor */
2019-02-08 00:24:46 +08:00
inline void setUndersetFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
2019-01-26 20:00:40 +08:00
this - > undersetFactor = __value ;
2019-01-10 04:23:24 +08:00
}
2019-05-18 02:46:52 +08:00
/*! \copydoc undersetFactor */
2019-02-08 00:24:46 +08:00
inline double getUndersetFactor ( ) const
2019-01-10 04:23:24 +08:00
{
2019-01-26 20:00:40 +08:00
return this - > undersetFactor ;
2019-01-10 04:23:24 +08:00
}
2019-05-18 02:46:52 +08:00
/*! \copydoc frac_factor */
2019-02-08 00:24:46 +08:00
inline void setFracFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > frac_factor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc frac_factor */
2019-02-08 00:24:46 +08:00
inline double getFracFactor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > frac_factor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc frac_shift_factor */
2019-02-08 00:24:46 +08:00
inline void setFracShiftFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > frac_shift_factor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc frac_shift_factor */
2019-02-08 00:24:46 +08:00
inline double getFracShiftFactor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > frac_shift_factor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc brace_y_shift_factor */
2019-02-08 00:24:46 +08:00
inline void setBraceYShiftFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > brace_y_shift_factor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc brace_y_shift_factor */
2019-02-08 00:24:46 +08:00
inline double getBraceYShiftFactor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > brace_y_shift_factor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc decoration_height_factor */
2019-02-08 00:24:46 +08:00
inline void setDecorationHeightFactor ( double __value )
2019-01-10 04:23:24 +08:00
{
this - > decoration_height_factor = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc decoration_height_factor */
2019-02-08 00:24:46 +08:00
inline double getDecorationHeightFactor ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > decoration_height_factor ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc expensiveRendering */
2019-02-08 00:24:46 +08:00
inline void setExpensiveRendering ( bool __value )
2019-01-10 04:23:24 +08:00
{
this - > expensiveRendering = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc expensiveRendering */
2019-02-08 00:24:46 +08:00
inline bool getExpensiveRendering ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > expensiveRendering ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc useUnparsed */
2019-02-08 00:24:46 +08:00
inline void setUseUnparsed ( bool __value )
2019-01-10 04:23:24 +08:00
{
this - > useUnparsed = __value ;
}
2019-05-18 02:46:52 +08:00
/*! \copydoc useUnparsed */
2019-02-08 00:24:46 +08:00
inline bool isUsingUnparsed ( ) const
2019-01-10 04:23:24 +08:00
{
return this - > useUnparsed ;
}
2019-05-19 04:41:38 +08:00
/*! \copydoc error_list */
2019-01-26 20:00:40 +08:00
inline QStringList getErrorList ( ) const {
2019-01-10 04:23:24 +08:00
return this - > error_list ;
}
2015-07-11 18:56:02 +08:00
protected :
/** \brief the available fonts */
2019-02-11 05:21:19 +08:00
enum MTenvironmentFont {
MTEroman ,
MTEsans ,
MTEtypewriter ,
MTEscript ,
MTEblackboard ,
MTEcaligraphic
} ;
2015-07-11 18:56:02 +08:00
/** \brief describes the current drawing environment (base fontname ...) */
struct MTenvironment {
MTenvironment ( ) ;
2019-02-11 05:21:19 +08:00
/** \brief current font color */
2015-07-11 18:56:02 +08:00
QColor color ;
2019-02-11 05:21:19 +08:00
/** \brief current font */
2015-07-11 18:56:02 +08:00
MTenvironmentFont font ;
2019-02-11 05:21:19 +08:00
/** \brief current font size [pt] */
2015-07-11 18:56:02 +08:00
double fontSize ;
2019-02-11 05:21:19 +08:00
/** \brief is the text currently bold? */
2015-07-11 18:56:02 +08:00
bool bold ;
2019-02-11 05:21:19 +08:00
/** \brief is the text currently italic? */
2015-07-11 18:56:02 +08:00
bool italic ;
2019-02-11 05:21:19 +08:00
/** \brief is the text currently in small caps? */
2015-07-11 18:56:02 +08:00
bool smallCaps ;
2019-02-11 05:21:19 +08:00
/** \brief is the text currently underlined? */
2015-07-11 18:56:02 +08:00
bool underlined ;
2019-02-11 05:21:19 +08:00
/** \brief is the text currently overlined? */
2015-07-11 18:56:02 +08:00
bool overline ;
2019-02-11 05:21:19 +08:00
/** \brief is the text currently stroke through? */
2015-07-11 18:56:02 +08:00
bool strike ;
2019-02-11 05:21:19 +08:00
/** \brief is the text currently are we inside a math environment? */
2015-07-11 18:56:02 +08:00
bool insideMath ;
2019-02-11 05:21:19 +08:00
/** \brief build a QFont object from the settings in this object */
2019-01-20 17:49:29 +08:00
QFont getFont ( JKQTMathText * parent ) const ;
2019-02-11 05:21:19 +08:00
/** \brief generate a HTML prefix that formats the text after it according to the settings in this object
*
* \ param defaultEv environment before applying the current object ( to detect changes )
* \ see toHtmlAfter ( )
*/
2015-07-11 18:56:02 +08:00
QString toHtmlStart ( MTenvironment defaultEv ) const ;
2019-02-11 05:21:19 +08:00
/** \brief generate a HTML postfix that formats the text in front of it according to the settings in this object
*
* \ param defaultEv environment before applying the current object ( to detect changes )
* \ see toHtmlAfter ( )
*/
2015-07-11 18:56:02 +08:00
QString toHtmlAfter ( MTenvironment defaultEv ) const ;
} ;
2019-02-11 05:21:19 +08:00
/** \brief beschreibt die Größe eines Knotens */
struct MTnodeSize {
MTnodeSize ( ) ;
double width ;
double baselineHeight ;
double overallHeight ;
double strikeoutPos ;
} ;
2015-07-11 18:56:02 +08:00
public :
2019-02-11 05:21:19 +08:00
/** \brief subclass representing one node in the syntax tree
2019-05-31 20:01:49 +08:00
* \ ingroup jkqtmathtext_items
2019-02-11 05:21:19 +08:00
*
* \ image html jkqtmathtext_node_geo . png
*/
2015-07-11 18:56:02 +08:00
class MTnode {
public :
2019-01-20 17:49:29 +08:00
MTnode ( JKQTMathText * parent ) ;
2019-01-10 04:23:24 +08:00
virtual ~ MTnode ( ) ;
2019-02-11 05:21:19 +08:00
/** \brief determine the size of the node, calls getSizeInternal() implementation of the actual type \see getSizeInternal()
*
* \ param painter painter to use for determining the size
* \ param currentEv current environment object
* \ param [ out ] width width of the block / node
* \ param [ out ] baselineHeight distance from the bottom of the block / node - box to the baseline
* \ param [ out ] overallHeight overall height ( bottom to top ) of the node , the ascent is \ c overallHeight - baselineHeight
* \ param [ out ] strikeoutPos position of the strikeout - line
* \ param [ in ] prevNodeSize optional parameter , describing the size of the previous node ( on the left ) . This may be used for layout of some nodes ( e . g . sub / super to move correctly next to large parantheses . . . )
*
*/
void getSize ( QPainter & painter , MTenvironment currentEv , double & width , double & baselineHeight , double & overallHeight , double & strikeoutPos , const MTnodeSize * prevNodeSize = nullptr ) ;
/** \brief draw the contents at the designated position
*
* \ param painter QPainter to use
* \ param x x - position , where the drawing starts [ Pixel ]
* \ param y Y - position of the baseline , where the drawing starts [ Pixel ]
* \ param currentEv JKQTMathText : : MTenvironment object describing the current drawing environment / settings
* \ param [ in ] prevNodeSize optional parameter , describing the size of the previous node ( on the left ) . This may be used for layout of some nodes ( e . g . sub / super to move correctly next to large parantheses . . . )
* \ return the x position which to use for the next part of the text
*/
virtual double draw ( QPainter & painter , double x , double y , MTenvironment currentEv , const MTnodeSize * prevNodeSize = nullptr ) = 0 ;
/** \brief convert node to HTML and returns \c true on success
* \ param [ out ] html new HTML code is APPENDED to this string
* \ param currentEv JKQTMathText : : MTenvironment object describing the current drawing environment / settings
* \ param defaultEv JKQTMathText : : MTenvironment object describing the default drawing environment / settings when starting to interpret a node tree
* \ return \ c true on success
*/
2019-01-20 17:49:29 +08:00
virtual bool toHtml ( QString & html , JKQTMathText : : MTenvironment currentEv , JKQTMathText : : MTenvironment defaultEv ) ;
2015-07-11 18:56:02 +08:00
2019-02-11 05:21:19 +08:00
/** \brief returns the drawing of colored boxes (for DEBUGGING) around the actual output of the node is enabled */
bool getDrawBoxes ( ) const ;
/** \brief enables the drawing of colored boxes (for DEBUGGING) around the actual output of the node */
2019-01-26 20:00:40 +08:00
virtual void setDrawBoxes ( bool draw ) ;
2019-02-11 05:21:19 +08:00
/** \brief return the name of this class as a string */
2018-11-25 21:53:26 +08:00
virtual QString getTypeName ( ) const ;
2015-07-11 18:56:02 +08:00
protected :
2019-02-10 01:46:12 +08:00
/** \brief determine the size of the node, overwrite this function in derived classes
*
* \ param painter painter to use for determining the size
* \ param currentEv current environment object
* \ param [ out ] width width of the block / node
* \ param [ out ] baselineHeight distance from the bottom of the block / node - box to the baseline
* \ param [ out ] overallHeight overall height ( bottom to top ) of the node , the ascent is \ c overallHeight - baselineHeight
* \ param [ out ] strikeoutPos position of the strikeout - line
2019-02-11 05:21:19 +08:00
* \ param [ in ] prevNodeSize optional parameter , describing the size of the previous node ( on the left ) . This may be used for layout of some nodes ( e . g . sub / super to move correctly next to large parantheses . . . )
2019-02-10 01:46:12 +08:00
*
*/
2019-02-11 05:21:19 +08:00
virtual void getSizeInternal ( QPainter & painter , MTenvironment currentEv , double & width , double & baselineHeight , double & overallHeight , double & strikeoutPos , const MTnodeSize * prevNodeSize = nullptr ) = 0 ;
2019-02-10 01:46:12 +08:00
2019-02-11 05:21:19 +08:00
/** \brief parent JKQTMathText object (required for several drawing operations */
2019-01-20 17:49:29 +08:00
JKQTMathText * parent ;
2019-02-11 05:21:19 +08:00
/** \brief enables the drawing of colored boxes (for DEBUGGING) around the actual output of the node */
2015-07-11 18:56:02 +08:00
bool drawBoxes ;
2019-02-11 05:21:19 +08:00
/** \brief draws colored boxes (for DEBUGGING) around the actual output of the node
*
* \ param painter QPainter to use
* \ param x x - position , where the drawing starts [ Pixel ]
* \ param y Y - position of the baseline , where the drawing starts [ Pixel ]
* \ param currentEv JKQTMathText : : MTenvironment object describing the current drawing environment / settings
*/
2019-01-20 17:49:29 +08:00
void doDrawBoxes ( QPainter & painter , double x , double y , JKQTMathText : : MTenvironment currentEv ) ;
2015-07-11 18:56:02 +08:00
} ;
2019-05-31 20:01:49 +08:00
/** \brief subclass representing one text node in the syntax tree
* \ ingroup jkqtmathtext_items
*/
2015-07-11 18:56:02 +08:00
class MTtextNode : public MTnode {
public :
2019-01-26 19:28:44 +08:00
MTtextNode ( JKQTMathText * parent , const QString & text , bool addWhitespace , bool stripInnerWhitepace = false ) ;
2019-02-11 05:21:19 +08:00
virtual ~ MTtextNode ( ) override ;
/** \copydoc MTnode::draw() */
virtual double draw ( QPainter & painter , double x , double y , MTenvironment currentEv , const MTnodeSize * prevNodeSize = nullptr ) override ;
/** \copydoc MTnode::toHtml() */
virtual bool toHtml ( QString & html , JKQTMathText : : MTenvironment currentEv , JKQTMathText : : MTenvironment defaultEv ) override ;
2019-05-19 04:41:38 +08:00
/*! \copydoc text */
2019-01-26 20:00:40 +08:00
inline QString getText ( ) const {
2019-01-10 04:23:24 +08:00
return this - > text ;
}
virtual QString getTypeName ( ) const override ;
2015-07-11 18:56:02 +08:00
protected :
2019-02-10 01:46:12 +08:00
/** \copydoc MTnode::getSizeInternal() */
2019-02-11 05:21:19 +08:00
virtual void getSizeInternal ( QPainter & painter , MTenvironment currentEv , double & width , double & baselineHeight , double & overallHeight , double & strikeoutPos , const MTnodeSize * prevNodeSize = nullptr ) override ;
2015-07-11 18:56:02 +08:00
QString text ;
2019-02-11 05:21:19 +08:00
/** \brief transforms the text before sizing/drawing (may e.g. exchange special letters for other unicode symbols etc.) */
2019-01-20 17:49:29 +08:00
virtual QString textTransform ( const QString & text , JKQTMathText : : MTenvironment currentEv , bool forSize = false ) ;
2015-07-11 18:56:02 +08:00
} ;
2019-05-31 20:01:49 +08:00
/** \brief subclass representing one text node in the syntax tree
* \ ingroup jkqtmathtext_items
*/
2015-07-11 18:56:02 +08:00
class MTplainTextNode : public MTtextNode {
public :
2019-01-26 19:28:44 +08:00
MTplainTextNode ( JKQTMathText * parent , const QString & text , bool addWhitespace , bool stripInnerWhitepace = false ) ;
2019-02-11 05:21:19 +08:00
/** \copydoc MTnode::getTypeName() */
virtual QString getTypeName ( ) const override ;
2015-07-11 18:56:02 +08:00
protected :
2019-02-11 05:21:19 +08:00
/** \copydoc MTtextNode::textTransform() */
virtual QString textTransform ( const QString & text , JKQTMathText : : MTenvironment currentEv , bool forSize = false ) override ;
2015-07-11 18:56:02 +08:00
} ;
2019-05-31 20:01:49 +08:00
/** \brief subclass representing one whitepsace node in the syntax tree
* \ ingroup jkqtmathtext_items
*/
2015-07-11 18:56:02 +08:00
class MTwhitespaceNode : public MTtextNode {
public :
2019-01-20 17:49:29 +08:00
MTwhitespaceNode ( JKQTMathText * parent ) ;
2019-02-11 05:21:19 +08:00
virtual ~ MTwhitespaceNode ( ) override ;
/** \copydoc MTnode::getTypeName() */
virtual QString getTypeName ( ) const override ;
2015-07-11 18:56:02 +08:00
/** \brief convert node to HTML and returns \c true on success */
2019-02-11 05:21:19 +08:00
/** \copydoc MTnode::toHtml() */
virtual bool toHtml ( QString & html , JKQTMathText : : MTenvironment currentEv , JKQTMathText : : MTenvironment defaultEv ) override ;
2015-07-11 18:56:02 +08:00
} ;
2019-05-31 20:01:49 +08:00
/** \brief subclass representing one symbol (e.g. \c \\alpha , \c \\cdot ...) node in the syntax tree
* \ ingroup jkqtmathtext_items
*/
2015-07-11 18:56:02 +08:00
class MTsymbolNode : public MTnode {
public :
2019-01-26 19:28:44 +08:00
MTsymbolNode ( JKQTMathText * parent , const QString & name , bool addWhitespace ) ;
2019-02-11 05:21:19 +08:00
virtual ~ MTsymbolNode ( ) override ;
/** \copydoc MTnode::getTypeName() */
virtual QString getTypeName ( ) const override ;
/** \copydoc MTnode::draw() */
virtual double draw ( QPainter & painter , double x , double y , MTenvironment currentEv , const MTnodeSize * prevNodeSize = nullptr ) override ;
/** \copydoc MTnode::toHtml() */
virtual bool toHtml ( QString & html , JKQTMathText : : MTenvironment currentEv , JKQTMathText : : MTenvironment defaultEv ) override ;
2019-05-19 04:41:38 +08:00
/*! \copydoc symbolName */
2019-03-07 06:18:29 +08:00
inline QString getSymbolName ( ) const {
return this - > symbolName ;
2019-01-10 04:23:24 +08:00
}
2019-03-07 06:18:29 +08:00
QString getSymbolFontName ( ) const ;
2015-07-11 18:56:02 +08:00
protected :
2019-02-10 01:46:12 +08:00
/** \copydoc MTnode::getSizeInternal() */
2019-02-11 05:21:19 +08:00
virtual void getSizeInternal ( QPainter & painter , MTenvironment currentEv , double & width , double & baselineHeight , double & overallHeight , double & strikeoutPos , const MTnodeSize * prevNodeSize = nullptr ) override ;
2015-07-11 18:56:02 +08:00
/** \brief this string will be sent to the drawText method with properly set fonts */
QString symbol ;
/** \brief the symbol name supplied to the constructor */
QString symbolName ;
/** \brief these fonts may be used for symbols */
enum symbolFont { MTSFdefault , MTSFsymbol , MTSFgreek , MTSFbraces , MTSFintegrals , MTSFcaligraphic , MTSFblackboard } ;
/** \brief changes the font name according to a given symbolFont value */
2019-03-07 06:18:29 +08:00
QFont getFontName ( symbolFont f , QFont & fi ) const ;
2015-07-11 18:56:02 +08:00
/** \brief magnification factor for the font size */
symbolFont font ;
/** \brief magnification factor for the font size */
double fontFactor ;
/** \brief 0: leave italic setting as is, >0: set italic, <0 set italic to false */
char italic ;
/** \brief 0: leave bold setting as is, >0: set bold, <0 set bold to false */
char bold ;
/** \brief this corrects the y position of a symbol: draws at y <- y+ height*yfactor) */
double yfactor ;
/** \brief indicates whether to draw a bar (like for \c \\hbar ) */
bool drawBar ;
bool heightIsAscent ;
bool exactAscent ;
bool extendWidthInMathmode ;
} ;
2019-02-10 01:46:12 +08:00
/** \brief subclass representing a list of nodes in the syntax tree
2019-05-31 20:01:49 +08:00
* \ ingroup jkqtmathtext_items
2019-02-10 01:46:12 +08:00
*/
2015-07-11 18:56:02 +08:00
class MTlistNode : public MTnode {
public :
2019-01-20 17:49:29 +08:00
MTlistNode ( JKQTMathText * parent ) ;
2019-02-11 05:21:19 +08:00
virtual ~ MTlistNode ( ) override ;
/** \copydoc MTnode::getTypeName() */
virtual QString getTypeName ( ) const override ;
/** \copydoc MTnode::draw() */
virtual double draw ( QPainter & painter , double x , double y , MTenvironment currentEv , const MTnodeSize * prevNodeSize = nullptr ) override ;
2015-07-11 18:56:02 +08:00
void addNode ( MTnode * n ) { nodes . append ( n ) ; }
2019-02-11 05:21:19 +08:00
/** \copydoc MTnode::toHtml() */
virtual bool toHtml ( QString & html , JKQTMathText : : MTenvironment currentEv , JKQTMathText : : MTenvironment defaultEv ) override ;
/** \copydoc MTnode::setDrawBoxes() */
virtual void setDrawBoxes ( bool draw ) override ;
2019-05-19 04:41:38 +08:00
/*! \copydoc nodes */
2019-01-26 20:00:40 +08:00
inline QList < MTnode * > getNodes ( ) const {
2019-01-10 04:23:24 +08:00
return this - > nodes ;
}
2015-07-11 18:56:02 +08:00
protected :
2019-02-10 01:46:12 +08:00
/** \copydoc MTnode::getSizeInternal() */
2019-02-11 05:21:19 +08:00
virtual void getSizeInternal ( QPainter & painter , MTenvironment currentEv , double & width , double & baselineHeight , double & overallHeight , double & strikeoutPos , const MTnodeSize * prevNodeSize = nullptr ) override ;
2015-07-11 18:56:02 +08:00
QList < MTnode * > nodes ;
QSet < QString > subsupOperations ;
} ;
2019-05-31 20:01:49 +08:00
/** \brief subclass representing an instruction node with exactly one argument in the syntax tree
* \ ingroup jkqtmathtext_items
*/
2015-07-11 18:56:02 +08:00
class MTinstruction1Node : public MTnode {
public :
2019-01-26 19:28:44 +08:00
MTinstruction1Node ( JKQTMathText * parent , const QString & name , MTnode * child , const QStringList & parameters = QStringList ( ) ) ;
2019-02-11 05:21:19 +08:00
virtual ~ MTinstruction1Node ( ) override ;
/** \copydoc MTnode::getTypeName() */
virtual QString getTypeName ( ) const override ;
/** \copydoc MTnode::draw() */
virtual double draw ( QPainter & painter , double x , double y , MTenvironment currentEv , const MTnodeSize * prevNodeSize = nullptr ) override ;
2015-07-11 18:56:02 +08:00
/** \brief convert node to HTML and returns \c true on success */
2019-02-11 05:21:19 +08:00
/** \copydoc MTnode::toHtml() */
virtual bool toHtml ( QString & html , JKQTMathText : : MTenvironment currentEv , JKQTMathText : : MTenvironment defaultEv ) override ;
/** \copydoc MTnode::setDrawBoxes() */
virtual void setDrawBoxes ( bool draw ) override ;
/*! \brief returns the child node */
inline MTnode * getChild ( ) const {
2019-01-10 04:23:24 +08:00
return this - > child ;
}
2019-05-19 04:41:38 +08:00
/*! \copydoc name */
2019-01-26 20:00:40 +08:00
inline QString getName ( ) const {
2019-01-10 04:23:24 +08:00
return this - > name ;
}
2019-05-19 04:41:38 +08:00
/*! \copydoc parameters */
2019-01-26 20:00:40 +08:00
inline QStringList getParameters ( ) const {
2019-01-10 04:23:24 +08:00
return this - > parameters ;
}
2015-07-11 18:56:02 +08:00
protected :
2019-02-10 01:46:12 +08:00
/** \copydoc MTnode::getSizeInternal() */
2019-02-11 05:21:19 +08:00
virtual void getSizeInternal ( QPainter & painter , MTenvironment currentEv , double & width , double & baselineHeight , double & overallHeight , double & strikeoutPos , const MTnodeSize * prevNodeSize = nullptr ) override ;
2019-01-20 17:49:29 +08:00
bool setupMTenvironment ( JKQTMathText : : MTenvironment & ev ) ;
2018-12-08 21:19:52 +08:00
2015-07-11 18:56:02 +08:00
MTnode * child ;
QString name ;
QStringList parameters ;
} ;
2019-02-11 05:21:19 +08:00
/** \brief subclass representing an subscript node with exactly one argument in the syntax tree
2019-05-31 20:01:49 +08:00
* \ ingroup jkqtmathtext_items
2019-02-11 05:21:19 +08:00
*
* \ image html jkqtmathtext_subscriptnode_getSizeInternal . png
*/
2015-07-11 18:56:02 +08:00
class MTsubscriptNode : public MTnode {
public :
2019-01-20 17:49:29 +08:00
MTsubscriptNode ( JKQTMathText * parent , MTnode * child ) ;
2019-02-11 05:21:19 +08:00
virtual ~ MTsubscriptNode ( ) override ;
/** \copydoc MTnode::draw() */
virtual double draw ( QPainter & painter , double x , double y , MTenvironment currentEv , const MTnodeSize * prevNodeSize = nullptr ) override ;
/** \copydoc MTnode::getTypeName() */
virtual QString getTypeName ( ) const override ; /*! \brief returns the child node */
inline MTnode * getChild ( ) const {
2019-01-10 04:23:24 +08:00
return this - > child ;
}
2019-02-11 05:21:19 +08:00
/** \copydoc MTnode::toHtml() */
virtual bool toHtml ( QString & html , JKQTMathText : : MTenvironment currentEv , JKQTMathText : : MTenvironment defaultEv ) override ;
/** \copydoc MTnode::setDrawBoxes() */
virtual void setDrawBoxes ( bool draw ) override ;
2015-07-11 18:56:02 +08:00
protected :
2019-02-10 01:46:12 +08:00
/** \copydoc MTnode::getSizeInternal() */
2019-02-11 05:21:19 +08:00
virtual void getSizeInternal ( QPainter & painter , MTenvironment currentEv , double & width , double & baselineHeight , double & overallHeight , double & strikeoutPos , const MTnodeSize * prevNodeSize = nullptr ) override ;
2015-07-11 18:56:02 +08:00
MTnode * child ;
} ;
2019-02-11 05:21:19 +08:00
/** \brief subclass representing an superscript node with exactly one argument in the syntax tree
2019-05-31 20:01:49 +08:00
* \ ingroup jkqtmathtext_items
2019-02-11 05:21:19 +08:00
*
* \ image html jkqtmathtext_subscriptnode_getSizeInternal . png
*
* \ note a MTlistNode might modify the positioning slightly for special cases ( e . g . \ c \ \ int , \ c \ \ sum . . . or after braces )
*/
2015-07-11 18:56:02 +08:00
class MTsuperscriptNode : public MTnode {
public :
2019-01-20 17:49:29 +08:00
MTsuperscriptNode ( JKQTMathText * parent , MTnode * child ) ;
2019-02-11 05:21:19 +08:00
virtual ~ MTsuperscriptNode ( ) override ;
/** \copydoc MTnode::draw() */
virtual double draw ( QPainter & painter , double x , double y , MTenvironment currentEv , const MTnodeSize * prevNodeSize = nullptr ) override ;
/*! \brief returns the child node */
2019-01-26 20:00:40 +08:00
inline MTnode * getChild ( ) const {
2019-01-10 04:23:24 +08:00
return this - > child ;
}
2019-02-11 05:21:19 +08:00
/** \copydoc MTnode::getTypeName() */
virtual QString getTypeName ( ) const override ;
/** \copydoc MTnode::toHtml() */
virtual bool toHtml ( QString & html , JKQTMathText : : MTenvironment currentEv , JKQTMathText : : MTenvironment defaultEv ) override ;
/** \copydoc MTnode::setDrawBoxes() */
virtual void setDrawBoxes ( bool draw ) override ;
2015-07-11 18:56:02 +08:00
protected :
2019-02-10 01:46:12 +08:00
/** \copydoc MTnode::getSizeInternal() */
2019-02-11 05:21:19 +08:00
virtual void getSizeInternal ( QPainter & painter , MTenvironment currentEv , double & width , double & baselineHeight , double & overallHeight , double & strikeoutPos , const MTnodeSize * prevNodeSize = nullptr ) override ;
2015-07-11 18:56:02 +08:00
MTnode * child ;
} ;
2019-05-31 20:01:49 +08:00
/** \brief subclass representing a brace node
* \ ingroup jkqtmathtext_items
*/
2015-07-11 18:56:02 +08:00
class MTbraceNode : public MTnode {
public :
2019-01-26 19:28:44 +08:00
MTbraceNode ( JKQTMathText * parent , const QString & openbrace , const QString & closebrace , MTnode * child , bool showRightBrace = true ) ;
2019-02-11 05:21:19 +08:00
virtual ~ MTbraceNode ( ) override ;
/** \copydoc MTnode::draw() */
virtual double draw ( QPainter & painter , double x , double y , MTenvironment currentEv , const MTnodeSize * prevNodeSize = nullptr ) override ;
/** \copydoc MTnode::toHtml() */
virtual bool toHtml ( QString & html , JKQTMathText : : MTenvironment currentEv , JKQTMathText : : MTenvironment defaultEv ) override ;
/** \copydoc MTnode::setDrawBoxes() */
virtual void setDrawBoxes ( bool draw ) override ;
/** \copydoc MTnode::getTypeName() */
virtual QString getTypeName ( ) const override ;
/*! \brief returns the child node */
inline MTnode * getChild ( ) const {
2019-01-10 04:23:24 +08:00
return this - > child ;
}
2019-05-19 04:41:38 +08:00
/*! \copydoc openbrace */
2019-01-26 20:00:40 +08:00
inline QString getOpenbrace ( ) const {
2019-01-10 04:23:24 +08:00
return this - > openbrace ;
}
2019-05-19 04:41:38 +08:00
/*! \copydoc closebrace */
2019-01-26 20:00:40 +08:00
inline QString getClosebrace ( ) const {
2019-01-10 04:23:24 +08:00
return this - > closebrace ;
}
2019-05-19 04:41:38 +08:00
/*! \copydoc showRightBrace */
2019-01-26 03:16:04 +08:00
inline bool getShowRightBrace ( ) const {
2019-01-10 04:23:24 +08:00
return this - > showRightBrace ;
}
2015-07-11 18:56:02 +08:00
protected :
2019-02-10 01:46:12 +08:00
/** \copydoc MTnode::getSizeInternal() */
2019-02-11 05:21:19 +08:00
virtual void getSizeInternal ( QPainter & painter , MTenvironment currentEv , double & width , double & baselineHeight , double & overallHeight , double & strikeoutPos , const MTnodeSize * prevNodeSize = nullptr ) override ;
2015-07-11 18:56:02 +08:00
MTnode * child ;
QString openbrace ;
QString closebrace ;
bool showRightBrace ;
void getBraceWidth ( QPainter & painter , MTenvironment currentEv , double baselineHeight , double overallHeight , double & bracewidth , double & braceheight ) ;
} ;
2019-05-31 20:01:49 +08:00
/** \brief subclass representing a sqrt node
* \ ingroup jkqtmathtext_items
*/
2015-07-11 18:56:02 +08:00
class MTsqrtNode : public MTnode {
public :
2019-01-20 17:49:29 +08:00
MTsqrtNode ( JKQTMathText * parent , MTnode * child , int degree = 2 ) ;
2019-02-11 05:21:19 +08:00
virtual ~ MTsqrtNode ( ) override ;
/** \copydoc MTnode::draw() */
virtual double draw ( QPainter & painter , double x , double y , MTenvironment currentEv , const MTnodeSize * prevNodeSize = nullptr ) override ;
/** \copydoc MTnode::toHtml() */
virtual bool toHtml ( QString & html , JKQTMathText : : MTenvironment currentEv , JKQTMathText : : MTenvironment defaultEv ) override ;
/** \copydoc MTnode::setDrawBoxes() */
virtual void setDrawBoxes ( bool draw ) override ;
2019-05-01 20:58:19 +08:00
virtual QString getTypeName ( ) const override ;
2019-02-11 05:21:19 +08:00
/*! \brief returns the child node */
inline MTnode * getChild ( ) const {
2019-01-10 04:23:24 +08:00
return this - > child ;
}
2019-05-19 04:41:38 +08:00
/*! \copydoc degree */
2019-01-26 20:00:40 +08:00
inline int getDegree ( ) const {
2019-01-10 04:23:24 +08:00
return this - > degree ;
}
2015-07-11 18:56:02 +08:00
protected :
2019-02-10 01:46:12 +08:00
/** \copydoc MTnode::getSizeInternal() */
2019-02-11 05:21:19 +08:00
virtual void getSizeInternal ( QPainter & painter , MTenvironment currentEv , double & width , double & baselineHeight , double & overallHeight , double & strikeoutPos , const MTnodeSize * prevNodeSize = nullptr ) override ;
2015-07-11 18:56:02 +08:00
MTnode * child ;
int degree ;
} ;
enum MTfracMode {
2019-05-18 17:41:17 +08:00
MTFMfrac , /*!< \brief normal fraction \image html mathparser/MTFMfrac.png */
MTFMdfrac , /*!< \brief normal fraction, without scaling of under/over text \image html mathparser/MTFMdfrac.png */
MTFMtfrac , /*!< \brief text fraction (smaller than MTFMfrac) \image html mathparser/MTFMtfrac.png */
MTFMsfrac , /*!< \brief slanted fraction \image html mathparser/MTFMsfrac.png */
MTFMstfrac , /*!< \brief slanted text fraction \image html mathparser/MTFMstfrac.png */
MTFMunderbrace , /*!< \brief curly underbrace \image html mathparser/MTFMunderbrace.png */
MTFMoverbrace , /*!< \brief curly overbrace \image html mathparser/MTFMoverbrace.png */
MTFMstackrel , /*!< \brief binom/fraction without line \image html mathparser/MTFMstackrel.png */
MTFMunderset , /*!< \brief underset text \image html mathparser/MTFMunderset.png */
MTFMoverset /*!< \brief overset text \image html mathparser/MTFMoverset.png */
2015-07-11 18:56:02 +08:00
} ;
static QString fracModeToString ( MTfracMode mode ) ;
2019-05-31 20:01:49 +08:00
/** \brief subclass representing a \\frac node
* \ ingroup jkqtmathtext_items
*/
2015-07-11 18:56:02 +08:00
class MTfracNode : public MTnode {
public :
2019-01-20 17:49:29 +08:00
MTfracNode ( JKQTMathText * parent , MTnode * child_top , MTnode * child_bottom , MTfracMode mode ) ;
2019-02-11 05:21:19 +08:00
virtual ~ MTfracNode ( ) override ;
2019-05-01 20:58:19 +08:00
virtual QString getTypeName ( ) const override ;
2019-02-11 05:21:19 +08:00
/** \copydoc MTnode::draw() */
virtual double draw ( QPainter & painter , double x , double y , MTenvironment currentEv , const MTnodeSize * prevNodeSize = nullptr ) override ;
/** \copydoc MTnode::toHtml() */
virtual bool toHtml ( QString & html , JKQTMathText : : MTenvironment currentEv , JKQTMathText : : MTenvironment defaultEv ) override ;
/** \copydoc MTnode::setDrawBoxes() */
virtual void setDrawBoxes ( bool draw ) override ;
/*! \brief returns the 1st child node */
inline MTnode * getChild1 ( ) const {
2019-01-10 04:23:24 +08:00
return this - > child1 ;
}
2019-02-11 05:21:19 +08:00
/*! \brief returns the 2nd child node */
inline MTnode * getChild2 ( ) const {
2019-01-10 04:23:24 +08:00
return this - > child2 ;
}
2019-05-19 04:41:38 +08:00
/*! \copydoc mode */
2019-01-26 20:00:40 +08:00
inline MTfracMode getMode ( ) const {
2019-01-10 04:23:24 +08:00
return this - > mode ;
}
2015-07-11 18:56:02 +08:00
protected :
2019-02-10 01:46:12 +08:00
/** \copydoc MTnode::getSizeInternal() */
2019-02-11 05:21:19 +08:00
virtual void getSizeInternal ( QPainter & painter , MTenvironment currentEv , double & width , double & baselineHeight , double & overallHeight , double & strikeoutPos , const MTnodeSize * prevNodeSize = nullptr ) override ;
2015-07-11 18:56:02 +08:00
MTnode * child1 ;
MTnode * child2 ;
MTfracMode mode ;
} ;
2019-05-31 20:01:49 +08:00
/** \brief subclass representing a \\begin{matrix} node
* \ ingroup jkqtmathtext_items
*/
2015-07-11 18:56:02 +08:00
class MTmatrixNode : public MTnode {
public :
2019-01-20 17:49:29 +08:00
MTmatrixNode ( JKQTMathText * parent , QVector < QVector < MTnode * > > children ) ;
2019-02-10 01:46:12 +08:00
virtual ~ MTmatrixNode ( ) override ;
2019-02-11 05:21:19 +08:00
/** \copydoc MTnode::getTypeName() */
2019-02-10 01:46:12 +08:00
virtual QString getTypeName ( ) const override ;
2019-02-11 05:21:19 +08:00
virtual double draw ( QPainter & painter , double x , double y , MTenvironment currentEv , const MTnodeSize * prevNodeSize = nullptr ) override ;
2019-02-10 01:46:12 +08:00
virtual bool toHtml ( QString & html , JKQTMathText : : MTenvironment currentEv , JKQTMathText : : MTenvironment defaultEv ) override ;
2019-02-11 05:21:19 +08:00
/*! \brief returns the child nodes */
inline QVector < QVector < MTnode * > > getChildren ( ) const {
2019-01-10 04:23:24 +08:00
return this - > children ;
}
2019-05-19 04:41:38 +08:00
/*! \copydoc columns */
2019-01-26 20:00:40 +08:00
inline int getColumns ( ) const {
2019-01-10 04:23:24 +08:00
return this - > columns ;
}
2019-05-19 04:41:38 +08:00
/*! \copydoc lines */
2019-01-26 03:16:04 +08:00
inline int getLines ( ) const {
2019-01-10 04:23:24 +08:00
return this - > lines ;
}
2015-07-11 18:56:02 +08:00
protected :
2019-02-10 01:46:12 +08:00
/** \copydoc MTnode::getSizeInternal() */
2019-02-11 05:21:19 +08:00
virtual void getSizeInternal ( QPainter & painter , MTenvironment currentEv , double & width , double & baselineHeight , double & overallHeight , double & strikeoutPos , const MTnodeSize * prevNodeSize = nullptr ) override ;
/** \copydoc MTnode::setDrawBoxes() */
virtual void setDrawBoxes ( bool draw ) override ;
2015-07-11 18:56:02 +08:00
QVector < QVector < MTnode * > > children ;
int columns ;
int lines ;
} ;
enum MTdecoration {
2019-05-18 17:41:17 +08:00
MTDvec , /*!< \brief vector arrow over block \image html mathparser/MTDvec.png */
MTDhat , /*!< \brief hat over block \image html mathparser/MTDhat.png */
MTDdot , /*!< \brief single dot over block \image html mathparser/MTDvec.png */
MTDddot , /*!< \brief double dot over block \image html mathparser/MTDddot.png */
MTDbar , /*!< \brief bar over block \image html mathparser/MTDbar.png */
MTDarrow , /*!< \brief arrow over block \image html mathparser/MTDarrow.png */
MTDoverline , /*!< \brief overline over block \image html mathparser/MTDoverline.png */
MTDdoubleoverline , /*!< \brief double overline over block \image html mathparser/MTDdoubleoverline.png */
MTDunderline , /*!< \brief underline under block \image html mathparser/MTDunderline.png */
MTDdoubleunderline , /*!< \brief double underline under block \image html mathparser/MTDdoubleunderline.png */
MTDtilde /*!< \brief tilde over block \image html mathparser/MTDtilde.png */
2015-07-11 18:56:02 +08:00
} ;
static QString decorationToString ( MTdecoration mode ) ;
2019-05-31 20:01:49 +08:00
/** \brief subclass representing a decorated text m (e.g. \c \\vec \c \\hat ...) node
* \ ingroup jkqtmathtext_items
*/
2015-07-11 18:56:02 +08:00
class MTdecoratedNode : public MTnode {
public :
2019-01-20 17:49:29 +08:00
MTdecoratedNode ( JKQTMathText * parent , MTdecoration decoration , MTnode * child ) ;
2019-02-11 05:21:19 +08:00
virtual ~ MTdecoratedNode ( ) override ;
/** \copydoc MTnode::draw() */
virtual double draw ( QPainter & painter , double x , double y , MTenvironment currentEv , const MTnodeSize * prevNodeSize = nullptr ) override ;
/** \copydoc MTnode::toHtml() */
virtual bool toHtml ( QString & html , JKQTMathText : : MTenvironment currentEv , JKQTMathText : : MTenvironment defaultEv ) override ;
/** \copydoc MTnode::setDrawBoxes() */
virtual void setDrawBoxes ( bool draw ) override ;
2019-05-01 20:58:19 +08:00
virtual QString getTypeName ( ) const override ;
2019-02-11 05:21:19 +08:00
/*! \brief returns the child node */
inline MTnode * getChild ( ) const {
2019-01-10 04:23:24 +08:00
return this - > child ;
}
2019-05-19 04:41:38 +08:00
/*! \copydoc decoration */
2019-01-26 20:00:40 +08:00
inline MTdecoration getDecoration ( ) const {
2019-01-10 04:23:24 +08:00
return this - > decoration ;
}
2015-07-11 18:56:02 +08:00
protected :
2019-02-10 01:46:12 +08:00
/** \copydoc MTnode::getSizeInternal() */
2019-02-11 05:21:19 +08:00
virtual void getSizeInternal ( QPainter & painter , MTenvironment currentEv , double & width , double & baselineHeight , double & overallHeight , double & strikeoutPos , const MTnodeSize * prevNodeSize = nullptr ) override ;
2015-07-11 18:56:02 +08:00
MTnode * child ;
MTdecoration decoration ;
} ;
protected :
2019-05-06 01:31:20 +08:00
/** \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
* an alternative using addReplacementFont ( ) . These are automatically applied , when setting a new font name ! */
QMap < QString , QString > fontReplacements ;
2015-07-11 18:56:02 +08:00
/** \brief font color */
2019-01-10 04:23:24 +08:00
QColor fontColor ;
/*! \brief default value for property fontColor.
\ see fontColor for more information */
2019-01-26 20:00:40 +08:00
QColor default_fontColor ;
2015-07-11 18:56:02 +08:00
/** \brief base font size in points */
2019-01-10 04:23:24 +08:00
double fontSize ;
/*! \brief default value for property fontSize.
\ see fontSize for more information */
2019-01-26 20:00:40 +08:00
double default_fontSize ;
2015-07-11 18:56:02 +08:00
/** \brief roman font */
2019-01-10 04:23:24 +08:00
QString fontRoman ;
/*! \brief default value for property fontRoman.
\ see fontRoman for more information */
2019-01-26 20:00:40 +08:00
QString default_fontRoman ;
2015-07-11 18:56:02 +08:00
/** \brief sans-serif font */
2019-01-10 04:23:24 +08:00
QString fontSans ;
/*! \brief default value for property fontSans.
\ see fontSans for more information */
2019-01-26 20:00:40 +08:00
QString default_fontSans ;
2015-07-11 18:56:02 +08:00
/** \brief typewriter font */
2019-01-10 04:23:24 +08:00
QString fontTypewriter ;
/*! \brief default value for property fontTypewriter.
\ see fontTypewriter for more information */
2019-01-26 20:00:40 +08:00
QString default_fontTypewriter ;
2015-07-11 18:56:02 +08:00
/** \brief script font */
2019-01-10 04:23:24 +08:00
QString fontScript ;
/*! \brief default value for property fontScript.
\ see fontScript for more information */
2019-01-26 20:00:40 +08:00
QString default_fontScript ;
2015-07-11 18:56:02 +08:00
/** \brief greek font */
2019-01-10 04:23:24 +08:00
QString fontGreek ;
/*! \brief default value for property fontGreek.
\ see fontGreek for more information */
2019-01-26 20:00:40 +08:00
QString default_fontGreek ;
2015-07-11 18:56:02 +08:00
/** \brief symbol font, used for math symbols. */
2019-01-10 04:23:24 +08:00
QString fontSymbol ;
/*! \brief default value for property fontSymbol.
\ see fontSymbol for more information */
2019-01-26 20:00:40 +08:00
QString default_fontSymbol ;
2015-07-11 18:56:02 +08:00
/** \brief symbol font, used for braces in math mode. */
2019-01-10 04:23:24 +08:00
QString fontBraces ;
/*! \brief default value for property fontBraces.
\ see fontBraces for more information */
2019-01-26 20:00:40 +08:00
QString default_fontBraces ;
2015-07-11 18:56:02 +08:00
/** \brief symbol font, used for integrals in math mode. */
2019-01-10 04:23:24 +08:00
QString fontIntegrals ;
/*! \brief default value for property fontIntegrals.
\ see fontIntegrals for more information */
2019-01-26 20:00:40 +08:00
QString default_fontIntegrals ;
2015-07-11 18:56:02 +08:00
/** \brief font used for caligraphic symbols (escepcially in math environments) */
2019-01-10 04:23:24 +08:00
QString fontCaligraphic ;
/*! \brief default value for property fontCaligraphic.
\ see fontCaligraphic for more information */
2019-01-26 20:00:40 +08:00
QString default_fontCaligraphic ;
2015-07-11 18:56:02 +08:00
/** \brief font used for blackboard (double-stroke) symbols (escepcially in math environments) */
2019-01-10 04:23:24 +08:00
QString fontBlackboard ;
/*! \brief default value for property fontBlackboard.
\ see fontBlackboard for more information */
2019-01-26 20:00:40 +08:00
QString default_fontBlackboard ;
2015-07-11 18:56:02 +08:00
/** \brief prefix for LaTeX fonts */
2019-01-10 04:23:24 +08:00
QString fontLatexPrefix ;
/*! \brief default value for property fontLatexPrefix.
\ see fontLatexPrefix for more information */
2019-01-26 20:00:40 +08:00
QString default_fontLatexPrefix ;
2015-07-11 18:56:02 +08:00
/** \brief postfix for LaTeX fonts */
2019-01-10 04:23:24 +08:00
QString fontLatexPostfix ;
/*! \brief default value for property fontLatexPostfix.
\ see fontLatexPostfix for more information */
2019-01-26 20:00:40 +08:00
QString default_fontLatexPostfix ;
2015-07-11 18:56:02 +08:00
/** \brief specifies the encoding of special character fonts (default is \c MTFEwinSymbol ) */
2019-01-10 04:23:24 +08:00
MTfontEncoding fontEncoding ;
/*! \brief default value for property fontEncoding.
\ see fontEncoding for more information */
2019-01-26 20:00:40 +08:00
MTfontEncoding default_fontEncoding ;
2015-07-11 18:56:02 +08:00
/** \brief resizing factor for braces in math mode */
2019-01-10 04:23:24 +08:00
double brace_factor ;
/*! \brief default value for property brace_factor.
\ see brace_factor for more information */
2019-01-26 20:00:40 +08:00
double default_brace_factor ;
2015-07-11 18:56:02 +08:00
/** \brief shrinking the width of braces in math mode 0: reduce to 0 pixel width, 1: leave unchanged*/
2019-01-10 04:23:24 +08:00
double brace_shrink_factor ;
/*! \brief default value for property brace_shrink_factor.
\ see brace_shrink_factor for more information */
2019-01-26 20:00:40 +08:00
double default_brace_shrink_factor ;
2015-07-11 18:56:02 +08:00
/** \brief resizing factor for font size in sub-/superscript */
2019-01-10 04:23:24 +08:00
double subsuper_size_factor ;
/*! \brief default value for property subsuper_size_factor.
\ see subsuper_size_factor for more information */
2019-01-26 20:00:40 +08:00
double default_subsuper_size_factor ;
2015-07-11 18:56:02 +08:00
/** \brief fraction of a whitespace by which to shift a sub-/superscript left/right when the previous text is italic */
2019-01-10 04:23:24 +08:00
double italic_correction_factor ;
/*! \brief default value for property italic_correction_factor.
\ see italic_correction_factor for more information */
2019-01-26 20:00:40 +08:00
double default_italic_correction_factor ;
2015-07-11 18:56:02 +08:00
/** \brief like subsuper_size_factor, but for operators (\\sum, \\int) where the text is placed above/below the symbol */
2019-01-10 04:23:24 +08:00
double operatorsubsuper_size_factor ;
/*! \brief default value for property operatorsubsuper_size_factor.
\ see operatorsubsuper_size_factor for more information */
2019-01-26 20:00:40 +08:00
double default_operatorsubsuper_size_factor ;
2015-07-11 18:56:02 +08:00
/** \brief factor, used to extend the size of an operator in math mode */
2019-01-10 04:23:24 +08:00
double mathoperator_width_factor ;
/*! \brief default value for property mathoperator_width_factor.
\ see mathoperator_width_factor for more information */
2019-01-26 20:00:40 +08:00
double default_mathoperator_width_factor ;
2015-07-11 18:56:02 +08:00
/** \brief relative shift of text in superscript to normal text:
* 0 = baseline kept , 1 : baseline shifted to top of normal text */
2019-01-10 04:23:24 +08:00
double super_shift_factor ;
/*! \brief default value for property super_shift_factor.
\ see super_shift_factor for more information */
2019-01-26 20:00:40 +08:00
double default_super_shift_factor ;
2015-07-11 18:56:02 +08:00
/** \brief relative shift of text in subscript to normal text:
* 0 = baseline kept , 1 : baseline shifted to bottom of normal text */
2019-01-10 04:23:24 +08:00
double sub_shift_factor ;
/*! \brief default value for property sub_shift_factor.
\ see sub_shift_factor for more information */
2019-01-26 20:00:40 +08:00
double default_sub_shift_factor ;
2015-07-11 18:56:02 +08:00
/** \brief indicates whether to use STIX fonts or not */
2019-01-10 04:23:24 +08:00
bool useSTIXfonts ;
/*! \brief default value for property useSTIXfonts.
\ see useSTIXfonts for more information */
2019-01-26 20:00:40 +08:00
bool default_useSTIXfonts ;
2015-07-11 18:56:02 +08:00
/** \brief indicates whether to use XITS fonts or not */
2019-01-10 04:23:24 +08:00
bool useXITSfonts ;
2019-02-08 00:24:46 +08:00
/** \brief the first call to useXITS() determines this name for the default XITS fonts */
QString defaultXITSFontName ;
/** \brief the call to useXITS() determines this name for the default XITS Math fonts */
QString defaultXITSMathFontName ;
2019-01-10 04:23:24 +08:00
/*! \brief default value for property useXITSfonts.
\ see useXITSfonts for more information */
2019-01-26 20:00:40 +08:00
bool default_useXITSfonts ;
2015-07-11 18:56:02 +08:00
/** \brief indicates whether to use XITS fonts or not */
2019-01-10 04:23:24 +08:00
bool useASANAfonts ;
/*! \brief default value for property useASANAfonts.
\ see useASANAfonts for more information */
2019-01-26 20:00:40 +08:00
bool default_useASANAfonts ;
2015-07-11 18:56:02 +08:00
/** \brief scaling factor for font of nominator and denominator of a fraction */
2019-01-10 04:23:24 +08:00
double frac_factor ;
/*! \brief default value for property frac_factor.
\ see frac_factor for more information */
2019-01-26 20:00:40 +08:00
double default_frac_factor ;
2015-07-11 18:56:02 +08:00
/** \brief shift of denominator/nummerator away from central line of a frac */
2019-01-10 04:23:24 +08:00
double frac_shift_factor ;
/*! \brief default value for property frac_shift_factor.
\ see frac_shift_factor for more information */
2019-01-26 20:00:40 +08:00
double default_frac_shift_factor ;
2015-07-11 18:56:02 +08:00
/** \brief scaling factor for font of underbrace/overbrace text */
2019-01-10 04:23:24 +08:00
double underbrace_factor ;
/*! \brief default value for property underbrace_factor.
\ see underbrace_factor for more information */
2019-01-26 20:00:40 +08:00
double default_underbrace_factor ;
2015-07-11 18:56:02 +08:00
/** \brief scaling factor for font of underset/overset text */
2019-01-26 20:00:40 +08:00
double undersetFactor ;
/*! \brief default value for property undersetFactor.
\ see undersetFactor for more information */
double default_undersetFactor ;
2015-07-11 18:56:02 +08:00
/** \brief fraction of the brace ascent that the brace is shifted downwards, when scaled */
2019-01-10 04:23:24 +08:00
double brace_y_shift_factor ;
/*! \brief default value for property brace_y_shift_factor.
\ see brace_y_shift_factor for more information */
2019-01-26 20:00:40 +08:00
double default_brace_y_shift_factor ;
2015-07-11 18:56:02 +08:00
/** \brief size of the decorations (dot, tilde, ...), as fractio of the baselineheight */
2019-01-10 04:23:24 +08:00
double decoration_height_factor ;
/*! \brief default value for property decoration_height_factor.
\ see decoration_height_factor for more information */
2019-01-26 20:00:40 +08:00
double default_decoration_height_factor ;
2015-07-11 18:56:02 +08:00
/** \brief switches on some options that will grant better rendering at the expense of higher time consumption */
2019-01-10 04:23:24 +08:00
bool expensiveRendering ;
/*! \brief default value for property expensiveRendering.
\ see expensiveRendering for more information */
2019-01-26 20:00:40 +08:00
bool default_expensiveRendering ;
2015-07-11 18:56:02 +08:00
/** \brief a list that will be filled with error messages while parsing, if any error occur */
QStringList error_list ;
/** \brief used by the parser. This is used to implement brace pairs with \\right. */
bool showRightBrace ;
/** \brief the result of parsing the last string supplied to the object via parse() */
MTnode * parsedNode ;
/** \brief a tree containing the unparsed text as a single node */
MTnode * unparsedNode ;
/** \brief if true, the unparsedNode is drawn */
bool useUnparsed ;
inline MTnode * getTree ( ) const {
if ( useUnparsed ) return unparsedNode ;
return parsedNode ;
}
/** \brief the token types that may arrise in the string */
enum tokenType {
MTTnone ,
MTTtext ,
MTTinstruction ,
MTTunderscore ,
MTThat ,
MTTdollar ,
MTTopenbrace ,
MTTclosebrace ,
MTTwhitespace ,
MTTampersand
} ;
/** \brief tokenizer for the LaTeX parser */
tokenType getToken ( ) ;
/** \brief parse a LaTeX string */
2019-01-26 19:28:44 +08:00
MTnode * parseLatexString ( bool get , const QString & quitOnClosingBrace = QString ( " " ) , const QString & quitOnEnvironmentEnd = QString ( " " ) ) ;
2015-07-11 18:56:02 +08:00
/** \brief parse a LaTeX math environment */
MTnode * parseMath ( bool get ) ;
/** \brief used by the tokenizer. type of the current token */
tokenType currentToken ;
/** \brief used by the tokenizer. Name of the current token, id applicable */
QString currentTokenName ;
/** \brief used by the tokenizer. Points to the currently read character in parseString */
int currentTokenID ;
/** \brief used by the tokenizer. The string to be parsed */
QString parseString ;
/** \brief used by the parser. indicates whether we are in a math environment */
bool parsingMathEnvironment ;
public :
2019-05-19 04:41:38 +08:00
/*! \copydoc parsedNode */
2019-01-26 20:00:40 +08:00
inline MTnode * getParsedNode ( ) const {
2019-01-10 04:23:24 +08:00
return this - > parsedNode ;
}
2015-07-11 18:56:02 +08:00
struct tbrData {
explicit tbrData ( const QFont & f , const QString & text , QPaintDevice * pd ) ;
QFontMetricsF fm ;
QString text ;
QRectF tbr ;
QFont f ;
int ldpiX , ldpiY , pdpiX , pdpiY ;
//QPaintDevice *pd;
bool operator = = ( const tbrData & other ) const ;
} ;
struct tbrDataH {
explicit tbrDataH ( const QFont & f , const QString & text , QPaintDevice * pd ) ;
QString text ;
QFont f ;
int ldpiX , ldpiY , pdpiX , pdpiY ;
bool operator = = ( const tbrDataH & other ) const ;
} ;
2019-01-20 17:49:29 +08:00
static QList < JKQTMathText : : tbrData > tbrs ;
static QHash < JKQTMathText : : tbrDataH , QRectF > tbrh ;
2019-02-11 05:21:19 +08:00
static QRectF getTightBoundingRect ( const QFont & fm , const QString & text , QPaintDevice * pd ) ;
2015-07-11 18:56:02 +08:00
} ;
2019-01-20 17:49:29 +08:00
inline uint qHash ( const JKQTMathText : : tbrDataH & data ) {
2015-07-11 18:56:02 +08:00
return qHash ( data . f . family ( ) ) + qHash ( data . text ) ;
}
2019-01-19 16:40:52 +08:00
2019-01-20 17:49:29 +08:00
/*! \brief A QLabel-derived class that draws an equation with LaTeX markup using JKQTMathText
2019-01-19 16:40:52 +08:00
\ ingroup jkqtmathtext
2019-01-20 17:49:29 +08:00
\ see JKQTMathText
2019-01-19 16:40:52 +08:00
*/
2019-02-03 21:04:48 +08:00
class JKQTP_LIB_EXPORT JKQTMathTextLabel : public QLabel {
2015-07-11 18:56:02 +08:00
Q_OBJECT
public :
2019-01-20 17:49:29 +08:00
explicit JKQTMathTextLabel ( QWidget * parent = nullptr ) ;
virtual ~ JKQTMathTextLabel ( ) ;
2015-07-11 18:56:02 +08:00
2019-01-20 17:49:29 +08:00
/** \brief returns the internal JKQTMathText instance used for drawing
2019-01-19 23:54:31 +08:00
*
* Use this function to set the font , font size and other properties of the used renderer .
*/
2019-01-20 17:49:29 +08:00
JKQTMathText * getMathText ( ) const ;
2019-01-19 23:54:31 +08:00
/** \brief set the equation to draw */
2015-07-11 18:56:02 +08:00
void setMath ( const QString & text , bool doRepaint = true ) ;
protected :
2019-01-20 17:49:29 +08:00
JKQTMathText * m_mathText ;
2015-07-11 18:56:02 +08:00
QString lastText ;
QPixmap buffer ;
bool repaintDo ;
void internalPaint ( ) ;
void paintEvent ( QPaintEvent * event ) ;
} ;
# endif // JKQTMATHTEXT_H