30#ifndef JKQTMATHTEXTTOOLS_H
31#define JKQTMATHTEXTTOOLS_H
39#include "jkqtmathtext/jkqtmathtext_imexport.h"
43#include <QPainterPath>
45#include <QFontMetrics>
46#include <QFontMetricsF>
394 JKQTMathTextNodeSize(
double width=0,
double baselineHeight=0,
double overallHeight=0,
double strikeoutPos=0,
double baselineXCorrection=0,
double topXCorrection=0);
413 inline double getDescent()
const {
return overallHeight-baselineHeight; }
415 inline double getAscent()
const {
return baselineHeight; }
417 inline double getHeight()
const {
return overallHeight; }
419 inline QSizeF
getSize()
const {
return QSizeF(width, overallHeight); }
421 inline QSize
getIntSize()
const {
return QSize(qCeil(width+1.0), qCeil(overallHeight+1.0)); }
479JKQTMATHTEXT_LIB_EXPORT void JKQTMathTextDrawStringSimBlackboard(QPainter& painter,
const QFont& f,
const QColor &color,
double x,
double y,
const QString& txt);
712enum JKQTMathTextLineSpacingMode {
this class parses a mathematical markup string and can then draw the contained text/equation onto a Q...
Definition jkqtmathtext.h:192
#define JKQTMATHTEXT_LIB_EXPORT
Definition jkqtmathtext_imexport.h:108
JKQTMathTextVerticalOrientation
type of ffractions represented by JKQTMathTextFracNode
Definition jkqtmathtexttools.h:682
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBlackboradDrawingMode String2JKQTMathTextBlackboradDrawingMode(QString mode)
this converts a QString into a JKQTMathTextBlackboradDrawingMode
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)
create a QPainterPath for drawing horizontal braces, use QPainter::fillPath() with a vanishing line-w...
JKQTMATHTEXT_LIB_EXPORT qreal JKQTMathTextGetRightBearing(const QFont &fm, const QChar &text, QPaintDevice *pd)
calculates the right bearing of text (from QFontMetricsF::rightBearing()), uses internal hashing to n...
JKQTMATHTEXT_LIB_EXPORT bool isPrintableJKQTMathTextBraceType(JKQTMathTextBraceType type)
return true if type represents a printable type of brace (including MTBTNone), basically true for any...
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextLineSpacingMode2String(JKQTMathTextLineSpacingMode mode)
convert a SpacingMode to a String
JKQTMATHTEXT_LIB_EXPORT QPainterPath JKQTMathTextMakeDArrow(double x, double y, double width, double arrowW, bool left=false, bool right=true)
create a QPainterPath for drawing horizontal double arrows
JKQTMATHTEXT_LIB_EXPORT QFont JKQTMathTextGetNonItalic(const QFont &f)
returns a copy of f, but with the italic-property set to false
JKQTMathTextHorizontalAlignment
types of horizontal alignment
Definition jkqtmathtexttools.h:661
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextBraceType2String(JKQTMathTextBraceType type)
convert a JKQTMathTextBraceType into a string
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceType InstructionName2JKQTMathTextBraceType(const QString &tokenName)
convert a string tokenName describing a LaTeX Instruction into an opening or closing JKQTMathTextBrac...
JKQTMATHTEXT_LIB_EXPORT QRectF JKQTMathTextGetTightBoundingRect(const QFont &fm, const QString &text, QPaintDevice *pd)
calculates the tight bounding rectangle around text (from QFontMetricsF::tightBoundingRect()),...
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextHorizontalAlignment2String(JKQTMathTextHorizontalAlignment type)
convert a JKQTMathTextHorizontalAlignment into a string
JKQTMathTextEnvironmentFont
the available logical fonts (default is MTEroman)
Definition jkqtmathtexttools.h:284
JKQTMATHTEXT_LIB_EXPORT QRectF JKQTMathTextGetBoundingRect(const QFont &fm, const QString &text, QPaintDevice *pd)
calculates the bounding rectangle around text (from (using QFontMetricsF::boundingRect()),...
JKQTMathTextBraceType
types of available braces
Definition jkqtmathtexttools.h:222
JKQTMATHTEXT_LIB_EXPORT qreal JKQTMathTextGetHorAdvance(const QFont &fm, const QString &text, QPaintDevice *pd)
calculates the horizontal advance of text (from QFontMetricsF::horizontalAdvance() or QFontMetricsF::...
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextHorizontalAlignment String2JKQTMathTextHorizontalAlignment(QString tokenName)
convert a string tokenName into a JKQTMathTextHorizontalAlignment
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextBlackboradDrawingMode2String(JKQTMathTextBlackboradDrawingMode mode)
this converts a JKQTMathTextBlackboradDrawingMode into a string
JKQTMATHTEXT_LIB_EXPORT qreal JKQTMathTextGetLeftBearing(const QFont &fm, const QChar &text, QPaintDevice *pd)
calculates the left bearing of text (from QFontMetricsF::leftBearing()), uses internal hashing to not...
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceType TokenName2JKQTMathTextBraceType(const QString &tokenName, bool *isOpening=nullptr)
convert a string tokenName describing a LaTeX Token or Instruction into an opening or closing JKQTMat...
JKQTMATHTEXT_LIB_EXPORT qreal JKQTMathTextGetFontAscent(const QFont &fm, QPaintDevice *pd)
calculates the ascent of font (from QFontMetricsF::ascent()), uses internal hashing to not redo a cal...
JKQTMATHTEXT_LIB_EXPORT qreal JKQTMathTextGetFontLeading(const QFont &fm, QPaintDevice *pd)
calculates the leading of font (from QFontMetricsF::leading()), uses internal hashing to not redo a c...
JKQTMathTextBlackboradDrawingMode
used to specify how blackboard-fonts are drawn
Definition jkqtmathtexttools.h:193
JKQTMATHTEXT_LIB_EXPORT QPainterPath JKQTMathTextMakeArrow(double x, double y, double width, double arrowW, bool left=false, bool right=true)
create a QPainterPath for drawing horizontal arrows
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextLineSpacingMode String2JKQTMathTextLineSpacingMode(QString mode)
convert a String to a SpacingMode
JKQTMATHTEXT_LIB_EXPORT qreal JKQTMathTextGetFontStrikoutPos(const QFont &fm, QPaintDevice *pd)
calculates the strikeout-pos of font (from QFontMetricsF::strikeoutPos()), uses internal hashing to n...
JKQTMATHTEXT_LIB_EXPORT bool TokenNameMatchesJKQTMathTextBraceType(const QString &token, JKQTMathTextBraceType type, bool acceptMTBTNone, bool *tokenEqualsNone=nullptr)
returns true, if the given token/instruction-Name token ("{", "(", ..., "lceil", "....
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextVerticalOrientation2String(JKQTMathTextVerticalOrientation mode)
convert a JKQTMathTextVerticalOrientation into a QString
JKQTMATHTEXT_LIB_EXPORT void initJKQTMathTextResources()
initialized Qt-ressources necessary for JKQTMathText
JKQTMATHTEXT_LIB_EXPORT qreal JKQTMathTextGetFontDescent(const QFont &fm, QPaintDevice *pd)
calculates the descent of font (from QFontMetricsF::descent()), uses internal hashing to not redo a c...
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextFontEncoding2String(JKQTMathTextFontEncoding e)
convert MTfontEncoding to a string
JKQTMATHTEXT_LIB_EXPORT bool InstructionNameMatchesJKQTMathTextBraceType(const QString &token, JKQTMathTextBraceType type, bool acceptMTBTNone, bool *tokenEqualsNone=nullptr)
returns true, if the given instruction-Name token ("|", "{", ..., "lceil", ".", .....
JKQTMATHTEXT_LIB_EXPORT qreal JKQTMathTextGetFontLineSpacing(const QFont &fm, QPaintDevice *pd)
calculates the line spacing of font (from QFontMetricsF::lineSpacing()), uses internal hashing to not...
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceType InstructionName2OpeningJKQTMathTextBraceType(const QString &tokenName)
convert a string tokenName describing a LaTeX Instruction into an opening JKQTMathTextBraceType
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextVerticalOrientation String2JKQTMathTextVerticalOrientation(QString mode)
returns the JKQTMathTextVerticalOrientation corresponding to instructionName
JKQTMathTextFontEncoding
used to specify the font encoding used for drawing
Definition jkqtmathtexttools.h:175
JKQTMATHTEXT_LIB_EXPORT qreal JKQTMathTextGetFontLineWidth(const QFont &fm, QPaintDevice *pd)
calculates the line width of font (from QFontMetricsF::lineWidth()), uses internal hashing to not red...
JKQTMATHTEXT_LIB_EXPORT qreal JKQTMathTextGetFontHeight(const QFont &fm, QPaintDevice *pd)
calculates the height of font (from QFontMetricsF::height()), uses internal hashing to not redo a cal...
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextFontEncoding estimateJKQTMathTextFontEncoding(QFont font)
this function tries to determine the JKQTMathTextFontEncoding of a given font (HEURISTICS!...
@ MTVOCentered
baseline of the whole block is at the center of all lines
Definition jkqtmathtexttools.h:685
@ MTVOLastLine
baseline of the whole block is at the baseline of the last line
Definition jkqtmathtexttools.h:686
@ MTVOBottom
baseline of the whole block is at the bottom of the last line
Definition jkqtmathtexttools.h:687
@ MTVOTop
baseline of the whole block is at the top of the first
Definition jkqtmathtexttools.h:683
@ MTVOFirstLine
baseline of the whole block is at the baseline of the first line
Definition jkqtmathtexttools.h:684
@ MTHALeft
align left
Definition jkqtmathtexttools.h:662
@ MTHACentered
align centered
Definition jkqtmathtexttools.h:663
@ MTHARight
align right
Definition jkqtmathtexttools.h:664
@ MTEmathSans
math-mode sans-serif font, e.g. \mathsf{}
Definition jkqtmathtexttools.h:288
@ MTECustomFont
internal enum value that specifies that a custom font specified elsewhere shall be used
Definition jkqtmathtexttools.h:297
@ MTEscript
script font, e.g. \script{},\mathscript{}
Definition jkqtmathtexttools.h:290
@ MTEfraktur
fraktur font, e.g. \mathfrak{}
Definition jkqtmathtexttools.h:293
@ MTEsans
sans-serif font, e.g. \sf{}
Definition jkqtmathtexttools.h:286
@ MTEroman
roman font, e.g. \rm{}
Definition jkqtmathtexttools.h:285
@ MTEFallbackSymbols
symbol font
Definition jkqtmathtexttools.h:294
@ MTEtypewriter
typewriter font, e.g. \tt{},\mathtt{}
Definition jkqtmathtexttools.h:289
@ MTEblackboard
blackboard font, e.g. \mathbb{}
Definition jkqtmathtexttools.h:291
@ MTEcaligraphic
caligraphic font, e.g. \mathcal{}
Definition jkqtmathtexttools.h:292
@ MTEmathRoman
math-mode roman font, e.g. \mathrm{}
Definition jkqtmathtexttools.h:287
@ MTECurrentFont
internal enum value that specifies that the currently set font shall be used
Definition jkqtmathtexttools.h:296
@ MTBTAny
any bracket, used by JKQTMathText::parseLatexString()
Definition jkqtmathtexttools.h:234
@ MTBTNone
no bracket
Definition jkqtmathtexttools.h:233
@ MTBTFloorBracket
floor brackets
Definition jkqtmathtexttools.h:228
@ MTBTSquareBracket
brackets []
Definition jkqtmathtexttools.h:224
@ MTBTUnknown
an unknown tokenName presented to TokenName2JKQTMathTextBraceType()
Definition jkqtmathtexttools.h:235
@ MTBTDoubleLine
double-line brackets (norm ||...||)
Definition jkqtmathtexttools.h:229
@ MTBTAngleBracket
angle backets <>
Definition jkqtmathtexttools.h:226
@ MTBTCeilBracket
ceil brackets
Definition jkqtmathtexttools.h:227
@ MTBTSingleLine
single-line brackets (abs |...|)
Definition jkqtmathtexttools.h:230
@ MTBTBottomCorner
bottom-corner brackets
Definition jkqtmathtexttools.h:232
@ MTBTCurlyBracket
curly braces {}
Definition jkqtmathtexttools.h:225
@ MTBTParenthesis
parantheses ()
Definition jkqtmathtexttools.h:223
@ MTBTTopCorner
top-corner brackets
Definition jkqtmathtexttools.h:231
@ MTBBDMsimulate
simulate a blackboard font (i.e. draw the characters' outline only), based on the font specified by J...
Definition jkqtmathtexttools.h:195
@ MTBBDMunicodeCharactersOrSimulate
use the currently set font and look for special unicode-characters in it, uses the fallbackSymbolFont...
Definition jkqtmathtexttools.h:197
@ MTBBDMfontDirectly
draw using the font specified by JKQTMathText::setFontBlackboard()
Definition jkqtmathtexttools.h:194
@ MTBBDMunicodeCharactersOrFontDirectly
use the currently set font and look for special unicode-characters in it, uses the fallbackSymbolFont...
Definition jkqtmathtexttools.h:196
@ MTBBDMdefault
default drawing mode, same as MTBBDMunicodeCharactersOrFontDirectly
Definition jkqtmathtexttools.h:198
@ MTFELatin1
the encoding of a standard Latin1 TTF font (i.e. we can only expect letters,number and not many speci...
Definition jkqtmathtexttools.h:178
@ MTFEStandard
Definition jkqtmathtexttools.h:179
@ MTFEUnicode
This assumes that symbols shall be taken from a Unicode font, which ideally offers full symbol suppor...
Definition jkqtmathtexttools.h:177
@ MTFEWinSymbol
This assumes that symbols shall be taken from a MS Windows style Symbol font.
Definition jkqtmathtexttools.h:176
describes the current drawing environment (base fontname ...)
Definition jkqtmathtexttools.h:304
QColor color
current font color
Definition jkqtmathtexttools.h:317
bool insideMathUseTextStyle
if true the commands like \frac{}{} are executes as \tfrac{}{} . This implements \textstyle or if fal...
Definition jkqtmathtexttools.h:347
FontSizeUnit
units for the property JKQTMathTextEnvironment::fontSize (Points/PT or Pixels)
Definition jkqtmathtexttools.h:306
@ POINTS
Definition jkqtmathtexttools.h:307
static FontSizeUnit String2FontSizeUnit(QString unit)
convert a string into a FontSizeUnit
bool italic
is the text currently italic?
Definition jkqtmathtexttools.h:330
bool overline
is the text currently overlined?
Definition jkqtmathtexttools.h:336
bool bold
is the text currently bold?
Definition jkqtmathtexttools.h:328
bool insideMathForceDigitsUpright
if insideMath ==true and this is true (the default), then digits are forced to be typeset in upright,...
Definition jkqtmathtexttools.h:342
bool isMathTextStyle() const
determines whether to use displaystyle or textstyle for math-instructions like \frace{}{} or \int_x
JKQTMathTextFontEncoding getFontEncoding(JKQTMathText *parent) const
return the encoding of the given Font
QString toHtmlStart(JKQTMathTextEnvironment defaultEv, JKQTMathText *parentMathText) const
generate a HTML prefix that formats the text after it according to the settings in this object
bool underlined
is the text currently underlined?
Definition jkqtmathtexttools.h:334
JKQTMathTextEnvironment()
QString toHtmlAfter(JKQTMathTextEnvironment defaultEv, JKQTMathText *parentMathText) const
generate a HTML postfix that formats the text in front of it according to the settings in this object
QFont::Capitalization capitalization
is the text currently in small caps?
Definition jkqtmathtexttools.h:332
bool strike
is the text currently stroke through?
Definition jkqtmathtexttools.h:338
void endMathMode()
sets insideMath =false
void beginMathMode(bool displaystyle=true)
sets insideMath =true and insideMathForceDigitsUpright =true and insideMathUseTextStyle=!...
JKQTMathTextEnvironment exchangedFontFor(JKQTMathTextEnvironmentFont font) const
return a copy of this object with the font exchanged for font
QFont getFont(const JKQTMathText *parent) const
build a QFont object from the settings in this object
JKQTMathTextEnvironmentFont font
current font
Definition jkqtmathtexttools.h:319
static QString FontSizeUnit2String(FontSizeUnit unit)
convert a FontSizeUnit to a string
bool isMathDisplayStyle() const
determines whether to use displaystyle or textstyle for math-instructions like \frace{}{} or \int_x
bool insideMath
is the text currently are we inside a math environment?
Definition jkqtmathtexttools.h:340
QString customFontName
custom font, when font==MTECustomFont
Definition jkqtmathtexttools.h:321
FontSizeUnit fontSizeUnit
the unit of the font size fontSize
Definition jkqtmathtexttools.h:325
double fontSize
current font size the unit is determined by fontSizeUnit
Definition jkqtmathtexttools.h:323
JKQTMathTextEnvironment exchangedFontForRoman() const
return a copy of this object with the font exchanged for the matching roman font
summarizes all information available on a font for a specific MTenvironmentFont
Definition jkqtmathtexttools.h:430
JKQTMathTextFontEncoding fontEncoding
specifies the encoding of the font (default is MTFEwinSymbol )
Definition jkqtmathtexttools.h:435
JKQTMathTextFontDefinition()
QString fontName
name of the font
Definition jkqtmathtexttools.h:433
represents a font specifier for JKQTMathText. The font consists of two parts: the actual font and the...
Definition jkqtmathtexttools.h:96
QString fontName() const
specifies the main font name
QString fallbackSymbolsFontName() const
specifies a font to be used for fallbackSymbols
static JKQTMathTextFontSpecifier fromFontSpec(const QString &fontSpec)
construct a JKQTMathTextFontSpecifier, by parsing a fontSpec string as defined in the struct descript...
static JKQTMathTextFontSpecifier getFIRAFamilies()
initialize with the font-families from the Fira (Math) package for text and math
QString m_fontName
specifies the main font name
Definition jkqtmathtexttools.h:160
bool hasFallbackSymbolFontName() const
leiefert true, wenn ein fallbcakSymbolsFontName() verfügbar ist
static JKQTMathTextFontSpecifier getXITSFamilies()
initialize with the font-families from the XITS package for text and math
void setFontName(const QString &name)
specifies the main font name
void setFallbackSymbolsFontName(const QString &name)
specifies a font to be used for fallbackSymbols
static JKQTMathTextFontSpecifier getASANAFamilies()
initialize with the font-families from the XITS package for text and math
QString getFontSpec() const
returns the object's constents as a fontSpec string with the form "FONT_NAME[+MATH_FONT_NAME]".
QString m_mathFontName
specifies the math font to use in addition to fontName
Definition jkqtmathtexttools.h:162
JKQTMathTextFontSpecifier(const QString &fontName, const QString &mathFontName)
static JKQTMathTextFontSpecifier getAppFontSFFamilies()
initialize with the default app font-families for "sans-serif" text and math and tries to find a matc...
bool hasFontName() const
leiefert true, wenn ein fontName() verfügbar ist
static QString transformFontName(const QString &fontName, bool mathmode=false)
finds actual fonts for some predefined special font names, as listed in Special Font Names
JKQTMathTextFontSpecifier()
static JKQTMathTextFontSpecifier getSTIXFamilies()
initialize with the font-families from the STIX package for text and math
bool m_transformOnOutput
if set true the fonts are transformed when fontname() or mathFontName() is called by calling transfor...
Definition jkqtmathtexttools.h:166
static JKQTMathTextFontSpecifier getAppFontFamilies()
initialize with the default app font-families for "roman" text and math and tries to find a matching ...
QString m_fallbackSymbolFont
specifies a font to be used for fallbackSymbols
Definition jkqtmathtexttools.h:164
bool hasMathFontName() const
leiefert true, wenn ein mathFontName() verfügbar ist
void setmathFontName(const QString &name)
specifies the math font to use in addition to fontName
void setFontSpec(const QString &fontSpec)
initialises the object with values from parsing a fontSpec string as defined in the struct descriptio...
QString mathFontName() const
specifies the math font to use in addition to fontName
static QString transformFontNameAndDecodeSpecialFonts(const QString &fontName, bool mathmode=false)
same as transformFontName(), but also finds the actual name for XITS, STIX, ASANA,...
beschreibt die Größe(n) eines Knotens
Definition jkqtmathtexttools.h:393
double baselineXCorrection
x-correction (<0 = move to the left) for subscripts, i.e. approximately at the height of the baseline
Definition jkqtmathtexttools.h:409
double getHeight() const
calculate the height (=baselineHeight), for convenience and naming
Definition jkqtmathtexttools.h:417
QSizeF getSize() const
calculate the overall size in floating-point precision
Definition jkqtmathtexttools.h:419
QSize getIntSize() const
calculate the overall size in floating-point precision
Definition jkqtmathtexttools.h:421
double topXCorrection
x-correction (>0 = move to the right) for superscripts, i.e. approximately at the top of the box
Definition jkqtmathtexttools.h:411
double getDescent() const
calculate the descent (overallHeight-baselineHeight)
Definition jkqtmathtexttools.h:413
double overallHeight
overallHeight of whole block
Definition jkqtmathtexttools.h:400
double strikeoutPos
strikeoutPos of whole block, i.e. distance of the strikeout position from the baseline
Definition jkqtmathtexttools.h:402
JKQTMathTextNodeSize(double width=0, double baselineHeight=0, double overallHeight=0, double strikeoutPos=0, double baselineXCorrection=0, double topXCorrection=0)
double width
width of whole block
Definition jkqtmathtexttools.h:396
double baselineHeight
baselineHeight of whole block, i.e. the ascent
Definition jkqtmathtexttools.h:398
double getAscent() const
calculate the ascent (=baselineHeight), for convenience and naming
Definition jkqtmathtexttools.h:415
JKQTMathTextNodeSize sliceToNodeSize() const
helper function, which generates a copy of this object, used to suppress slicing warning due to GSL E...
Definition jkqtmathtexttools.h:423