2022-06-08 21:38:26 +08:00
/*
Copyright ( c ) 2008 - 2022 Jan W . Krieger ( < jan @ jkrieger . de > )
with contributions from : Razi Alavizadeh
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
the Free Software Foundation , either version 2.1 of the License , or
( 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
Copyright : ( c ) 2010 - 2019
Author : Jan krieger < jan @ jkrieger . de > , http : //www.jkrieger.de/
*/
# ifndef JKQTMATHTEXTTOOLS_H
# define JKQTMATHTEXTTOOLS_H
# include <QObject>
# include <QSettings>
# include <QPainter>
# include <QString>
# include <QSet>
# include <QFile>
# include "jkqtmathtext/jkqtmathtext_imexport.h"
# include <QWidget>
# include <QLabel>
# include <QHash>
# include <QPainterPath>
2022-08-07 23:41:27 +08:00
# include <QtMath>
2022-06-08 21:38:26 +08:00
class JKQTMathText ; // forward
/** \brief initialized Qt-ressources necessary for JKQTMathText
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-08 21:38:26 +08:00
*/
JKQTMATHTEXT_LIB_EXPORT void initJKQTMathTextResources ( ) ;
/*! \brief represents a font specifier for JKQTMathText. The font consists of two parts: the actual font and the font used for math output (which may be empty)
2022-06-20 04:36:38 +08:00
\ ingroup jkqtmathtext_tools
2022-06-08 21:38:26 +08:00
2022-08-21 20:49:48 +08:00
\ section JKQTMathTextFontSpecifier_specialSyntax Font Definition Syntax
JKQTMathTextFontSpecifier : : fromFontSpec ( ) defines a special syntax that when parsed allows to seth the font ,
a math - mode alternative :
- \ c FONTNAME : set the text - mode font only
- \ c FONTNAME + MATH_FONTNAME : set the text - and math - mode fonts
\ section JKQTMathTextFontSpecifier_specialNames Special Font Names
2022-06-08 21:38:26 +08:00
This object also implements replacing special font names with actual fonts . Supported special font names are :
- \ c default / \ c app / \ c application - the applications default font
2022-09-01 20:36:34 +08:00
- \ c application - sf - a font for " sans " , based on the application font
2022-06-08 21:38:26 +08:00
- \ c times / \ c serif - a general serif font
- \ c sans - serif - a general sans - serif font
- \ c typewriter - a general typewrter / monospaced font
- \ c cursive
- \ c decorative
- \ c fantasy
- \ c monospace
- \ c system
.
If copiled with Qt > 5.3 you can also use these :
- \ c fixed
- \ c smallest_readable
- \ c title
- \ c general
.
2022-08-21 20:49:48 +08:00
Also some sepcial fonts are defined :
- xits XITS fonts
- stix STIX fonts
- asana ASANA fonts
2022-09-01 20:36:34 +08:00
- fira Fira fonts
2022-06-08 21:38:26 +08:00
*/
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextFontSpecifier {
JKQTMathTextFontSpecifier ( ) ;
JKQTMathTextFontSpecifier ( const QString & fontName , const QString & mathFontName ) ;
2022-08-21 20:49:48 +08:00
/** \brief construct a JKQTMathTextFontSpecifier, by parsing a \a fontSpec string as defined in the struct description, see \ref JKQTMathTextFontSpecifier_specialNames . */
2022-06-08 21:38:26 +08:00
static JKQTMathTextFontSpecifier fromFontSpec ( const QString & fontSpec ) ;
2022-08-21 20:49:48 +08:00
/** \brief initialises the object with values from parsing a \a fontSpec string as defined in the struct description, see \ref JKQTMathTextFontSpecifier_specialNames . */
2022-06-08 21:38:26 +08:00
void setFontSpec ( const QString & fontSpec ) ;
/** \brief returns the object's constents as a fontSpec string with the form \c "FONT_NAME[+MATH_FONT_NAME]". */
QString getFontSpec ( ) const ;
/** \copydoc m_fontName */
QString fontName ( ) const ;
/** \copydoc m_mathFontName */
QString mathFontName ( ) const ;
2022-08-21 20:49:48 +08:00
/** \copydoc m_fallbackSymbolFont */
QString fallbackSymbolsFontName ( ) const ;
2022-06-08 21:38:26 +08:00
/** \copydoc m_fontName */
void setFontName ( const QString & name ) ;
/** \copydoc m_mathFontName */
void setmathFontName ( const QString & name ) ;
2022-08-21 20:49:48 +08:00
/** \copydoc fallbackSymbolsFontName */
void setFallbackSymbolsFontName ( const QString & name ) ;
2022-06-08 21:38:26 +08:00
/** \brief finds actual fonts for some predefined special font names, as listed in \ref JKQTMathTextFontSpecifier_specialNames */
2022-08-21 20:49:48 +08:00
static QString transformFontName ( const QString & fontName , bool mathmode = false ) ;
2022-06-08 21:38:26 +08:00
/** \brief same as transformFontName(), but also finds the actual name for XITS, STIX, ASANA,... */
2022-08-21 20:49:48 +08:00
static QString transformFontNameAndDecodeSpecialFonts ( const QString & fontName , bool mathmode = false ) ;
2022-06-08 21:38:26 +08:00
/** \brief leiefert \c true, wenn ein fontName() verfügbar ist */
bool hasFontName ( ) const ;
/** \brief leiefert \c true, wenn ein mathFontName() verfügbar ist */
bool hasMathFontName ( ) const ;
2022-08-21 20:49:48 +08:00
/** \brief leiefert \c true, wenn ein fallbcakSymbolsFontName() verfügbar ist */
2022-09-01 20:36:34 +08:00
bool hasFallbackSymbolFontName ( ) const ;
2022-06-08 21:38:26 +08:00
/** \brief initialize with the font-families from the XITS package for text and math */
static JKQTMathTextFontSpecifier getXITSFamilies ( ) ;
/** \brief initialize with the font-families from the XITS package for text and math */
static JKQTMathTextFontSpecifier getASANAFamilies ( ) ;
/** \brief initialize with the font-families from the STIX package for text and math */
static JKQTMathTextFontSpecifier getSTIXFamilies ( ) ;
2022-09-01 20:36:34 +08:00
/** \brief initialize with the font-families from the Fira (Math) package for text and math */
static JKQTMathTextFontSpecifier getFIRAFamilies ( ) ;
/** \brief initialize with the default app font-families for "roman" text and math and tries to find a matching fallback-font. This may be used to initialize serif-fonts
*
* This method encodes some pre - coded knowledge of suitable combinations of fonts for different systems .
* e . g . on newer windows systems , the font " Segoe UI " is used for the GUI . . . a suitable math
* font with symbols is " Segoe UI Symbol " . . .
*/
static JKQTMathTextFontSpecifier getAppFontFamilies ( ) ;
/** \brief initialize with the default app font-families for "serif" text and math and tries to find a matching fallback-font. This may be used to initialize sans-serif-fonts
*
* This method encodes some pre - coded knowledge of suitable combinations of fonts for different systems .
*
* This function e . g . checks whether the default app font is sans - serif and then looks for a serif
* font for the " sans " font class ( so the two can be distinguished ) and vice - versa .
*/
static JKQTMathTextFontSpecifier getAppFontSFFamilies ( ) ;
2022-06-08 21:38:26 +08:00
private :
/** \brief specifies the main font name */
QString m_fontName ;
/** \brief specifies the math font to use in addition to fontName */
QString m_mathFontName ;
2022-08-21 20:49:48 +08:00
/** \brief specifies a font to be used for fallbackSymbols */
QString m_fallbackSymbolFont ;
/** \brief if set \c true the fonts are transformed when fontname() or mathFontName() is called by calling transformFontNameAndDecodeSpecialFonts() */
bool m_transformOnOutput ;
2022-06-08 21:38:26 +08:00
} ;
/** \brief used to specify the font encoding used for drawing
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-08 21:38:26 +08:00
*/
enum JKQTMathTextFontEncoding {
2022-07-04 02:30:12 +08:00
MTFEWinSymbol = 0 , /*!< \brief This assumes that symbols shall be taken from a MS Windows style Symbol font */
MTFEUnicode = 1 , /*!< \brief This assumes that symbols shall be taken from a Unicode font, which ideally offers full symbol support (e.g. the XITS fonts, STIX fonts from <a href="http://www.stixfonts.org/">http://www.stixfonts.org/</a>)*/
MTFELatin1 = 2 , /*!< \brief the encoding of a standard Latin1 TTF font (i.e. we can only expect letters,number and not many special characters) */
MTFEStandard = MTFELatin1
2022-06-08 21:38:26 +08:00
} ;
2022-07-04 02:30:12 +08:00
/** \brief this function tries to determine the JKQTMathTextFontEncoding of a given font (HEURISTICS!!!)
* \ ingroup jkqtmathtext_tools
*/
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextFontEncoding estimateJKQTMathTextFontEncoding ( QFont font ) ;
2022-08-10 18:12:30 +08:00
/** \brief used to specify how blackboard-fonts are drawn
* \ ingroup jkqtmathtext_tools
*
* \ see JKQTMathTextBlackboradDrawingMode2String ( ) , String2JKQTMathTextBlackboradDrawingMode ( )
*/
enum JKQTMathTextBlackboradDrawingMode {
MTBBDMfontDirectly = 0 , /*!< \brief draw using the font specified by JKQTMathText::setFontBlackboard() \image html jkqtmathtext/jkqtmathtext_bb_font_directly.png */
MTBBDMsimulate , /*!< \brief simulate a blackboard font (i.e. draw the characters' outline only), based on the font specified by JKQTMathText::setFontBlackboard() (e.g. Arial or another sans-serif font is a good choice) \image html jkqtmathtext/jkqtmathtext_bb_simulate.png */
MTBBDMunicodeCharactersOrFontDirectly , /*!< \brief use the currently set font and look for special unicode-characters in it, uses the fallbackSymbolFont as fallback, use MTBBDMfontDirectly for characters that are not available \image html jkqtmathtext/jkqtmathtext_bb_unicode_or_font_directly.png */
MTBBDMunicodeCharactersOrSimulate , /*!< \brief use the currently set font and look for special unicode-characters in it, uses the fallbackSymbolFont as fallback, use MTBBDMsimulate for characters that are not available \image html jkqtmathtext/jkqtmathtext_bb_unicode_or_simulate.png */
MTBBDMdefault = MTBBDMunicodeCharactersOrFontDirectly /*!< \brief default drawing mode, same as MTBBDMunicodeCharactersOrFontDirectly */
} ;
/** \brief this converts a JKQTMathTextBlackboradDrawingMode into a string
* \ ingroup jkqtmathtext_tools
* \ see String2JKQTMathTextBlackboradDrawingMode ( ) , JKQTMathTextBlackboradDrawingMode
*/
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextBlackboradDrawingMode2String ( JKQTMathTextBlackboradDrawingMode mode ) ;
/** \brief this converts a QString into a JKQTMathTextBlackboradDrawingMode
* \ ingroup jkqtmathtext_tools
* \ see JKQTMathTextBlackboradDrawingMode2String ( ) , JKQTMathTextBlackboradDrawingMode
*/
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBlackboradDrawingMode String2JKQTMathTextBlackboradDrawingMode ( QString mode ) ;
2022-07-04 02:30:12 +08:00
2022-06-08 21:38:26 +08:00
/** \brief convert MTfontEncoding to a string
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-08 21:38:26 +08:00
*/
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextFontEncoding2String ( JKQTMathTextFontEncoding e ) ;
2022-06-19 21:11:06 +08:00
/** \brief types of available braces
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-19 21:11:06 +08:00
*/
enum JKQTMathTextBraceType {
MTBTParenthesis = 0 , /*!< \brief parantheses () \image html jkqtmathtext/jkqtmathtext_brace_round.png */
MTBTSquareBracket , /*!< \brief brackets [] \image html jkqtmathtext/jkqtmathtext_brace_rect.png */
MTBTCurlyBracket , /*!< \brief curly braces {} \image html jkqtmathtext/jkqtmathtext_brace_curly.png */
MTBTAngleBracket , /*!< \brief angle backets <> \image html jkqtmathtext/jkqtmathtext_brace_tri.png */
MTBTCeilBracket , /*!< \brief ceil brackets \image html jkqtmathtext/jkqtmathtext_brace_ceil.png */
MTBTFloorBracket , /*!< \brief floor brackets \image html jkqtmathtext/jkqtmathtext_brace_floor.png */
MTBTDoubleLine , /*!< \brief double-line brackets (norm ||...||) \image html jkqtmathtext/jkqtmathtext_brace_dblline.png */
MTBTSingleLine , /*!< \brief single-line brackets (abs |...|) \image html jkqtmathtext/jkqtmathtext_brace_oneline.png */
2022-08-08 04:20:47 +08:00
MTBTTopCorner , /*!< \brief top-corner brackets \image html jkqtmathtext/jkqtmathtext_brace_ucorner.png */
MTBTBottomCorner , /*!< \brief bottom-corner brackets \image html jkqtmathtext/jkqtmathtext_brace_lcorner.png */
2022-06-19 21:11:06 +08:00
MTBTNone , /*!< \brief no bracket */
MTBTAny , /*!< \brief any bracket, used by JKQTMathText::parseLatexString() */
MTBTUnknown /*!< \brief an unknown tokenName presented to TokenName2JKQTMathTextBraceType() */
} ;
/** \brief convert a JKQTMathTextBraceType into a string
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-19 21:11:06 +08:00
*/
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextBraceType2String ( JKQTMathTextBraceType type ) ;
/** \brief convert a string \a tokenName describing a LaTeX Token or Instruction into an opening or closing JKQTMathTextBraceType
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-19 21:11:06 +08:00
*/
2022-08-03 15:55:45 +08:00
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceType TokenName2JKQTMathTextBraceType ( const QString & tokenName , bool * isOpening = nullptr ) ;
2022-06-19 21:11:06 +08:00
/** \brief convert a string \a tokenName describing a LaTeX Instruction into an opening JKQTMathTextBraceType
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-19 21:11:06 +08:00
*
* This returns a JKQTMathTextBraceType for which isPrintableJKQTMathTextBraceType ( ) is \ c true , or MTBTUnknown ,
* never MTBTNone or MTBTAny .
*/
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceType InstructionName2OpeningJKQTMathTextBraceType ( const QString & tokenName ) ;
/** \brief convert a string \a tokenName describing a LaTeX Instruction into an opening or closing JKQTMathTextBraceType
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-19 21:11:06 +08:00
*
* This returns a JKQTMathTextBraceType for which isPrintableJKQTMathTextBraceType ( ) is \ c true , or MTBTUnknown ,
* never MTBTNone or MTBTAny .
*/
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceType InstructionName2JKQTMathTextBraceType ( const QString & tokenName ) ;
/** \brief return \c true if \a type represents a printable type of brace (including MTBTNone), basically \c true
* for any JKQTMathTextBraceType that can be used as parameter to JKQTMathTextBraceNode
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-19 21:11:06 +08:00
*/
JKQTMATHTEXT_LIB_EXPORT bool isPrintableJKQTMathTextBraceType ( JKQTMathTextBraceType type ) ;
/** \brief returns true, if the given token/instruction-Name \a token ("{", "(", ..., "lceil", ".", ...) matches the given \a type (returns true, when \a type == MTBTAny )
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-19 21:11:06 +08:00
*
* This accepts TokenName2JKQTMathTextBraceType ( toke ) = = MTBTNone for any \ a type , iff \ a acceptMTBTNone \ a = = true .
*
* Optionally returns in \ a tokenEqualsNone whether \ a token was encoding for MTBTNone .
*/
JKQTMATHTEXT_LIB_EXPORT bool TokenNameMatchesJKQTMathTextBraceType ( const QString & token , JKQTMathTextBraceType type , bool acceptMTBTNone , bool * tokenEqualsNone = nullptr ) ;
/** \brief returns true, if the given instruction-Name \a token ("|", "{", ..., "lceil", ".", ...) matches the given \a type (returns true, when \a type == MTBTAny )
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-19 21:11:06 +08:00
*
* This accepts TokenName2JKQTMathTextBraceType ( toke ) = = MTBTNone for any \ a type , iff \ a acceptMTBTNone \ a = = true .
*
* Optionally returns in \ a tokenEqualsNone whether \ a token was encoding for MTBTNone .
*/
JKQTMATHTEXT_LIB_EXPORT bool InstructionNameMatchesJKQTMathTextBraceType ( const QString & token , JKQTMathTextBraceType type , bool acceptMTBTNone , bool * tokenEqualsNone = nullptr ) ;
2022-06-08 21:38:26 +08:00
/** \brief the available logical fonts (default is MTEroman)
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-08 21:38:26 +08:00
*/
enum JKQTMathTextEnvironmentFont {
MTEroman , /*!< \brief roman font, e.g. <code>\\rm{}</code> */
MTEsans , /*!< \brief sans-serif font, e.g. <code>\\sf{}</code> */
MTEmathRoman , /*!< \brief math-mode roman font, e.g. <code>\\mathrm{}</code> */
MTEmathSans , /*!< \brief math-mode sans-serif font, e.g. <code>\\mathsf{}</code> */
MTEtypewriter , /*!< \brief typewriter font, e.g. <code>\\tt{},\\mathtt{}</code> */
MTEscript , /*!< \brief script font, e.g. <code>\\script{},\\mathscript{}</code> */
MTEblackboard , /*!< \brief blackboard font, e.g. <code>\\mathbb{}</code> */
MTEcaligraphic , /*!< \brief caligraphic font, e.g. <code>\\mathcal{}</code> */
MTEfraktur , /*!< \brief fraktur font, e.g. <code>\\mathfrak{}</code> */
2022-07-06 04:03:08 +08:00
MTEFallbackSymbols , /*!< \brief symbol font */
2022-06-08 21:38:26 +08:00
2022-07-04 02:30:12 +08:00
MTECurrentFont , /*!< \brief internal enum value that specifies that the currently set font shall be used \internal */
MTECustomFont , /*!< \brief internal enum value that specifies that a custom font specified elsewhere shall be used \internal */
2022-06-08 21:38:26 +08:00
} ;
/** \brief describes the current drawing environment (base fontname ...)
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-08 21:38:26 +08:00
*/
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEnvironment {
2022-07-05 03:02:43 +08:00
/** \brief units for the property JKQTMathTextEnvironment::fontSize (Points/PT or Pixels) */
enum FontSizeUnit {
POINTS ,
PIXELS
} ;
/** \brief convert a FontSizeUnit to a string \see FontSizeUnit,String2FontSizeUnit() */
static QString FontSizeUnit2String ( FontSizeUnit unit ) ;
/** \brief convert a string into a FontSizeUnit \see FontSizeUnit,FontSizeUnit2String() */
static FontSizeUnit String2FontSizeUnit ( QString unit ) ;
2022-06-08 21:38:26 +08:00
JKQTMathTextEnvironment ( ) ;
/** \brief current font color */
QColor color ;
/** \brief current font */
JKQTMathTextEnvironmentFont font ;
2022-07-04 02:30:12 +08:00
/** \brief custom font, when font==MTECustomFont */
QString customFontName ;
2022-07-05 03:02:43 +08:00
/** \brief current font size the unit is determined by fontSizeUnit */
2022-06-08 21:38:26 +08:00
double fontSize ;
2022-07-05 03:02:43 +08:00
/** \brief the unit of the font size fontSize */
FontSizeUnit fontSizeUnit ;
2022-06-08 21:38:26 +08:00
/** \brief is the text currently bold? */
bool bold ;
/** \brief is the text currently italic? */
bool italic ;
/** \brief is the text currently in small caps? */
2022-08-19 18:16:00 +08:00
QFont : : Capitalization capitalization ;
2022-06-08 21:38:26 +08:00
/** \brief is the text currently underlined? */
bool underlined ;
/** \brief is the text currently overlined? */
bool overline ;
/** \brief is the text currently stroke through? */
bool strike ;
/** \brief is the text currently are we inside a math environment? */
bool insideMath ;
2022-08-02 17:38:40 +08:00
/** \brief if \a insideMath \c ==true and this is \c true (the default), then digits are forced to be typeset in upright, otherwise they are typeset as defined by the other properties */
bool insideMathForceDigitsUpright ;
2022-08-19 18:16:00 +08:00
/** \brief if \c true the commands like \c \\frac{}{} are executes as \c \\tfrac{}{} . This implements \c \\textstyle or if \c false \c \\displaystyle
*
* \ image html jkqtmathtext / jkqtmathtext_mathstyle . png
*/
bool insideMathUseTextStyle ;
/** \brief sets insideMath \c =true and insideMathForceDigitsUpright \c =true and \c insideMathUseTextStyle=!displaystyle*/
void beginMathMode ( bool displaystyle = true ) ;
/** \brief sets insideMath \c =false */
2022-08-02 17:38:40 +08:00
void endMathMode ( ) ;
2022-08-19 18:16:00 +08:00
/** \brief determines whether to use displaystyle or textstyle for math-instructions like \c \\frace{}{} or \c \\int_x
*
* \ image html jkqtmathtext / jkqtmathtext_mathstyle . png
*/
bool isMathDisplayStyle ( ) const ;
/** \brief determines whether to use displaystyle or textstyle for math-instructions like \c \\frace{}{} or \c \\int_x
*
* \ image html jkqtmathtext / jkqtmathtext_mathstyle . png
*/
bool isMathTextStyle ( ) const ;
2022-06-08 21:38:26 +08:00
2022-08-03 21:23:14 +08:00
/** \brief build a <a href="https://doc.qt.io/qt-5/qfont.html">QFont</a> object from the settings in this object */
2022-08-17 05:05:04 +08:00
QFont getFont ( const JKQTMathText * parent ) const ;
2022-08-10 18:12:30 +08:00
/** \brief return a copy of this object with the font exchanged for \a font */
JKQTMathTextEnvironment exchangedFontFor ( JKQTMathTextEnvironmentFont font ) const ;
/** \brief return a copy of this object with the font exchanged for the matching roman font */
JKQTMathTextEnvironment exchangedFontForRoman ( ) const ;
2022-07-04 02:30:12 +08:00
/** \brief return the encoding of the given Font */
JKQTMathTextFontEncoding getFontEncoding ( JKQTMathText * parent ) const ;
2022-06-08 21:38:26 +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 )
2022-08-07 23:41:27 +08:00
* \ param parentMathText the JKQTMathText object currently in use ( used to e . g . look up font names )
*
2022-06-08 21:38:26 +08:00
* \ see toHtmlAfter ( )
*/
2022-08-02 17:38:40 +08:00
QString toHtmlStart ( JKQTMathTextEnvironment defaultEv , JKQTMathText * parentMathText ) const ;
2022-06-08 21:38:26 +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 )
2022-08-07 23:41:27 +08:00
* \ param parentMathText the JKQTMathText object currently in use ( used to e . g . look up font names )
*
2022-06-08 21:38:26 +08:00
* \ see toHtmlAfter ( )
*/
2022-08-02 17:38:40 +08:00
QString toHtmlAfter ( JKQTMathTextEnvironment defaultEv , JKQTMathText * parentMathText ) const ;
2022-06-08 21:38:26 +08:00
} ;
2022-08-03 21:23:14 +08:00
/** \brief beschreibt die Größe(n) eines Knotens
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-08 21:38:26 +08:00
*/
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNodeSize {
JKQTMathTextNodeSize ( ) ;
2022-08-03 21:23:14 +08:00
/** \brief width of whole block */
2022-06-08 21:38:26 +08:00
double width ;
2022-08-03 21:23:14 +08:00
/** \brief baselineHeight of whole block */
2022-06-08 21:38:26 +08:00
double baselineHeight ;
2022-08-03 21:23:14 +08:00
/** \brief overallHeight of whole block */
2022-06-08 21:38:26 +08:00
double overallHeight ;
2022-08-03 21:23:14 +08:00
/** \brief strikeoutPos of whole block */
2022-06-08 21:38:26 +08:00
double strikeoutPos ;
2022-08-18 04:56:57 +08:00
/** \brief x-correction (<0 = move to the left) for subscripts, i.e. approximately at the height of the baseline
*
* \ image html jkqtmathtext / jkqtmathtext_doc_subsuper_italiccorrection . png
*
* \ image html jkqtmathtext / jkqtmathtext_doc_subsuper_italiccorrection_boxes . png
*/
double baselineXCorrection ;
/** \brief x-correction (>0 = move to the right) for superscripts, i.e. approximately at the top of the box */
double topXCorrection ;
2022-08-07 23:41:27 +08:00
/** \brief calculate the descent */
inline double getDescent ( ) const { return overallHeight - baselineHeight ; }
/** \brief calculate the overall size in floating-point precision */
inline QSizeF getSize ( ) const { return QSizeF ( width , overallHeight ) ; }
/** \brief calculate the overall size in floating-point precision */
2022-08-07 23:57:52 +08:00
inline QSize getIntSize ( ) const { return QSize ( qCeil ( width + 1.0 ) , qCeil ( overallHeight + 1.0 ) ) ; }
2022-06-08 21:38:26 +08:00
} ;
/** \brief summarizes all information available on a font for a specific MTenvironmentFont
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-08 21:38:26 +08:00
* \ see fontDefinitions
*/
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextFontDefinition {
JKQTMathTextFontDefinition ( ) ;
/** \brief name of the font */
QString fontName ;
/** \brief specifies the encoding of the font (default is \c MTFEwinSymbol ) */
JKQTMathTextFontEncoding fontEncoding ;
} ;
2022-06-27 05:42:06 +08:00
/** \brief create a QPainterPath for drawing horizontal braces, use QPainter::fillPath() with a vanishing line-width to draw this
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-09 20:30:15 +08:00
*
2022-06-09 20:42:25 +08:00
* \ image html jkqtmathtext / JKQTMathTextMakeHBracePath . png
2022-06-27 05:42:06 +08:00
*
* \ param x x - center - position of the brace
* \ param ybrace y - center - position of the brace
* \ param width with of the overall brace
2022-07-24 20:50:28 +08:00
* \ param bw height of the brace
2022-06-27 05:42:06 +08:00
* \ param lineWidth linewidth when drawing , used for correcting so the brace exactly fills the rectangle and not overshoots it
* \ param cubicshrink
* \ param cubiccontrolfac
* \ param lineWidthShrinkFactor the width of the tips is lineWidth reduced by this factor
* \ param lineWidthGrowFactor the width of the horizontal bars is increased by this factor from lineWidth
2022-06-08 21:38:26 +08:00
*/
2022-08-07 23:41:27 +08:00
JKQTMATHTEXT_LIB_EXPORT QPainterPath JKQTMathTextMakeHBracePath ( double x , double ybrace , double width , double bw , double lineWidth , double cubicshrink = 0.5 , double cubiccontrolfac = 0.3 , double lineWidthShrinkFactor = 0.6 , double lineWidthGrowFactor = 0.9 ) ;
2022-06-08 21:38:26 +08:00
/** \brief create a QPainterPath for drawing horizontal arrows
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-09 20:30:15 +08:00
*
2022-06-09 20:42:25 +08:00
* \ image html jkqtmathtext / JKQTMathTextMakeArrow . png
2022-06-08 21:38:26 +08:00
*/
JKQTMATHTEXT_LIB_EXPORT QPainterPath JKQTMathTextMakeArrow ( double x , double y , double width , double arrowW , bool left = false , bool right = true ) ;
/** \brief create a QPainterPath for drawing horizontal double arrows
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-09 20:30:15 +08:00
*
2022-06-09 20:42:25 +08:00
* \ image html jkqtmathtext / JKQTMathTextMakeDArrow . png
2022-06-08 21:38:26 +08:00
*/
JKQTMATHTEXT_LIB_EXPORT QPainterPath JKQTMathTextMakeDArrow ( double x , double y , double width , double arrowW , bool left = false , bool right = true ) ;
2022-08-10 18:12:30 +08:00
/** \brief draw a given \a txt in the font \a f using additional informaion (but not currentEv::getFont() ) from \a currentEv at (\a x , \a y ) using the given \a painter
*
* This function implements drawing of synthesized fonts , e . g . MTEblackboard when JKQTMathText : : isFontBlackboardSimulated ( ) is \ c true .
*
* example output :
* \ image html jkqtmathtext / jkqtmathtext_bb_unicode_or_simulate . png
*/
JKQTMATHTEXT_LIB_EXPORT void JKQTMathTextDrawStringSimBlackboard ( QPainter & painter , const QFont & f , const QColor & color , double x , double y , const QString & txt ) ;
2022-06-08 21:38:26 +08:00
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextTBRData {
explicit JKQTMathTextTBRData ( 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 JKQTMathTextTBRData & other ) const ;
} ;
2022-06-09 20:30:15 +08:00
2022-06-08 21:38:26 +08:00
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextTBRDataH {
explicit JKQTMathTextTBRDataH ( const QFont & f , const QString & text , QPaintDevice * pd ) ;
QString text ;
QFont f ;
int ldpiX , ldpiY , pdpiX , pdpiY ;
bool operator = = ( const JKQTMathTextTBRDataH & other ) const ;
} ;
# if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
inline size_t qHash ( const JKQTMathTextTBRDataH & data , size_t /*seed=0*/ ) {
# else
inline uint qHash ( const JKQTMathTextTBRDataH & data ) {
# endif
return qHash ( data . f . family ( ) ) + qHash ( data . text ) ;
}
/** \brief calculates the tight bounding rectangle around \a text, uses internal hashing to not redo a calculation that has already been performed
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-08 21:38:26 +08:00
*/
JKQTMATHTEXT_LIB_EXPORT QRectF JKQTMathTextGetTightBoundingRect ( const QFont & fm , const QString & text , QPaintDevice * pd ) ;
/** \brief returns a copy of \a f, but with the italic-property set to \c false
2022-06-20 04:36:38 +08:00
* \ ingroup jkqtmathtext_tools
2022-06-08 21:38:26 +08:00
*/
JKQTMATHTEXT_LIB_EXPORT QFont JKQTMathTextGetNonItalic ( const QFont & f ) ;
2022-07-31 05:30:47 +08:00
/** \brief types of horizontal alignment
* \ ingroup jkqtmathtext_tools
*
* \ image html jkqtmathtext_horizontalalignment . png
*
* \ see JKQTMathTextVerticalOrientation2String ( ) , String2JKQTMathTextVerticalOrientation ( ) , JKQTMathTextVerticalListNode
*/
enum JKQTMathTextHorizontalAlignment {
MTHALeft , /*!< \brief align left */
MTHACentered , /*!< \brief align centered */
MTHARight , /*!< \brief align right */
} ;
/** \brief convert a JKQTMathTextHorizontalAlignment into a string
* \ ingroup jkqtmathtext_tools
*/
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextHorizontalAlignment2String ( JKQTMathTextHorizontalAlignment type ) ;
/** \brief convert a string \a tokenName into a JKQTMathTextHorizontalAlignment
* \ ingroup jkqtmathtext_tools
*/
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextHorizontalAlignment String2JKQTMathTextHorizontalAlignment ( QString tokenName ) ;
/** \brief type of ffractions represented by JKQTMathTextFracNode
* \ ingroup jkqtmathtext_tools
*
* \ image html jkqtmathtext_verticalorientation . png
*
2022-08-13 19:37:13 +08:00
* \ see JKQTMathTextVerticalOrientation2String ( ) , String2JKQTMathTextVerticalOrientation ( ) , JKQTMathTextVerticalListNode , JKQTMathTextVerbatimNode
2022-07-31 05:30:47 +08:00
*/
enum JKQTMathTextVerticalOrientation {
MTVOTop , /*!< \brief baseline of the whole block is at the top of the first */
MTVOFirstLine , /*!< \brief baseline of the whole block is at the baseline of the first line */
MTVOCentered , /*!< \brief baseline of the whole block is at the center of all lines */
MTVOLastLine , /*!< \brief baseline of the whole block is at the baseline of the last line */
MTVOBottom , /*!< \brief baseline of the whole block is at the bottom of the last line */
} ;
/** \brief convert a JKQTMathTextVerticalOrientation into a QString
* \ ingroup jkqtmathtext_tools
2022-08-13 19:37:13 +08:00
*
* \ see JKQTMathTextVerticalOrientation2String ( ) , String2JKQTMathTextVerticalOrientation ( ) , JKQTMathTextVerticalListNode , JKQTMathTextVerbatimNode
2022-07-31 05:30:47 +08:00
*/
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextVerticalOrientation2String ( JKQTMathTextVerticalOrientation mode ) ;
/** \brief returns the JKQTMathTextVerticalOrientation corresponding to \a instructionName
* \ ingroup jkqtmathtext_tools
2022-08-13 19:37:13 +08:00
*
* \ see JKQTMathTextVerticalOrientation2String ( ) , String2JKQTMathTextVerticalOrientation ( ) , JKQTMathTextVerticalListNode , JKQTMathTextVerbatimNode
2022-07-31 05:30:47 +08:00
*/
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextVerticalOrientation String2JKQTMathTextVerticalOrientation ( QString mode ) ;
2022-08-13 19:37:13 +08:00
/** \brief defines, how lines are beeing spaced by the node
* \ ingroup jkqtmathtext_tool
*
* \ image html jkqtmathtext_verticallist . png
*
* \ see JKQTMathTextLineSpacingMode2String ( ) , String2JKQTMathTextLineSpacingMode ( ) , JKQTMathTextVerticalListNode
*/
enum JKQTMathTextLineSpacingMode {
MTSMDefaultSpacing , /*!< space the lines with equilibrated spacing, i.e. the baselines are at least \c QFontMetricsF::lineSpacing()*JKQTMathTextVerticalListNode::lineSpacingFactor apart, but even more, if the height of the text bloxk is larger than the the font's ascent+descent */
MTSMMinimalSpacing /*!< space the lines as tight as possible, i.e. each line is separated by \c QFontMetricsF::leading()*JKQTMathTextVerticalListNode::lineSpacingFactor from the next line. This is a s compact as possible */
} ;
/** \brief convert a SpacingMode to a String
* \ ingroup jkqtmathtext_tools
*
* \ see JKQTMathTextLineSpacingMode2String ( ) , String2JKQTMathTextLineSpacingMode ( ) , JKQTMathTextVerticalListNode
*/
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextLineSpacingMode2String ( JKQTMathTextLineSpacingMode mode ) ;
/** \brief convert a String to a SpacingMode
* \ ingroup jkqtmathtext_tools
*
* \ see JKQTMathTextLineSpacingMode2String ( ) , String2JKQTMathTextLineSpacingMode ( ) , JKQTMathTextVerticalListNode
*/
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextLineSpacingMode String2JKQTMathTextLineSpacingMode ( QString mode ) ;
2022-06-08 21:38:26 +08:00
# endif // JKQTMATHTEXTTOOLS_H