JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
Collaboration diagram for Font Handling:

As LaTeX also does, fonts are set by font classes. These are defined in JKQTMathTextEnvironmentFont:

The default font class is "roman" (i.e. MTEroman in text-mode and MTEmathRoman in math-mode). You can switch to "sans-serif" by using LaTeX commands like \sf .

Especially when using the library in the context of a GUI, usually a sans-serif font is used to typeset text in the GUI as these are generally better readable on a screen than serif fonts. Therefore when using JKQTMathText for GUI rendering, it makes sense to redefine the class "roman" with the GUI font. You can e.g. write:

JKQTMathText::setFontRoman(QGuiApplication::font().family(), MTFEUnicode);
JKQTMathText::setFontMathRoman(QGuiApplication::font().family(), MTFEUnicode);
JKQTMathText::setFontSize(QGuiApplication::font().pointSize());
void setFontMathRoman(const QString &fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard)
set the font fontName and it's encoding encoding to be used for text in the logical font MTEmathRoman
void setFontRoman(const QString &fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard)
set the font fontName and it's encoding encoding to be used for text in the logical font MTEroman
void setFontSize(double __value)
set the default font size in points
@ MTFEUnicode
This assumes that symbols shall be taken from a Unicode font, which ideally offers full symbol suppor...
Definition jkqtmathtexttools.h:177

or the short hand:

JKQTMathText::setFontRomanAndMath(QGuiApplication::font().family(), MTFEUnicode);
void setFontRomanAndMath(const QString &fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard)
set the font fontName and it's encoding encoding to be used for text and math, i.e....

With JKQTMathTextFontSpecifier::fromFontSpec() there is a third way that allows to use a special string syntax (handy for INI files) to define fonts, see JKQTMathTextFontSpecifier . You can e.g. simply write:

In all cases the default GUI font is used for rendering default output. For \sf to make a difference you can additionally set the "sans" class as a serif font, e.g.:

void setFontMathSans(const QString &fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard)
set the font fontName and it's encoding encoding to be used for text in the logical font MTEmathSans
void setFontSans(const QString &fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard)
set the font fontName and it's encoding encoding to be used for text in the logical font MTEsans

Using the font name "serif" will cause Qt to lookup a suitable serif font.

These fonts are generic font classes, which font is actually used can be configured in JKQTMathText class with the set...() functions mentioned above. Additionally some short ahnds exist:

Here are some examples of using different, widely available, fonts:

Math-mode is activated by enclosing your equation in $...$ or \[...\] . This mode is optimized for mathematical equations. Here is an example of the difference:

Font Lookup for symbols works as follows in JKQTMathTextSymbolNode:

In "normal text", i.e. JKQTMathTextTextNode no font-lookup is perfomed, i.e. if a acharacter is not available in the selected font, it is not typeset (or typeset with a replacement, like a box). There are exceptions to this rule however: For some special fonts a lookup or synthetisation of the characters is performed. Currently this is implemented for: