mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-24 17:41:39 +08:00
JKQTMAthText: improvements in font handling and documentation
This commit is contained in:
parent
db81286452
commit
07d3fdcd99
104
doc/dox/jkqtmathtext_fonthandling.dox
Normal file
104
doc/dox/jkqtmathtext_fonthandling.dox
Normal file
@ -0,0 +1,104 @@
|
||||
/*!
|
||||
|
||||
\defgroup jkqtmathtext_fonthandling Font Handling
|
||||
\ingroup jkqtmathtext_general
|
||||
|
||||
|
||||
|
||||
As LaTeX also does, fonts are set by font classes. These are defined in JKQTMathTextEnvironmentFont:
|
||||
- A "roman" (MTEroman / MTEmathRoman) font used as the standard font ( JKQTMathText::setFontRoman() and for use in math mode JKQTMathText::setFontMathRoman() )
|
||||
- A "sans-serif" (MTEsans / MTEmathSans) font which may be activated with \c \\sf ... ( JKQTMathText::setFontSans() and for use in math mode JKQTMathText::setFontMathSans() )
|
||||
- A "typewriter" (MTEtypewriter) font which may be activated with \c \\tt ... ( JKQTMathText::setFontTypewriter() )
|
||||
- A "script" (MTEscript) font which may be activated with \c \\script ... ( JKQTMathText::setFontScript() )
|
||||
- A "math-roman" (MTEmathRoman) font used as the standard font in math mode ( JKQTMathText::setFontMathRoman() )
|
||||
- A "math-sans-serif" (MTEmathSans) used as sans serif font in math mode ( JKQTMathText::setFontMathSans() )
|
||||
- A "blackboard" (MTEblackboard) font used to display double stroked characters ( JKQTMathText::setFontBlackboard() )
|
||||
- A "caligraphic" (MTEcaligraphic) font used to display caligraphic characters ( JKQTMathText::setFontCaligraphic() )
|
||||
- A "fraktur" (MTEfraktur) font used to display fraktur characters ( JKQTMathText::setFontFraktur() )
|
||||
- A fallback font MTEFallbackSymbols for (math) symbols, greek letters ... (if the symbols are not present in the currently used font). ( JKQTMathText::setFallbackFontSymbols() )
|
||||
.
|
||||
|
||||
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 \c \\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:
|
||||
\code
|
||||
JKQTMathText::setFontRoman(QGuiApplication::font().family(), MTFEUnicode);
|
||||
JKQTMathText::setFontMathRoman(QGuiApplication::font().family(), MTFEUnicode);
|
||||
JKQTMathText::setFontSize(QGuiApplication::font().pointSize());
|
||||
\endcode
|
||||
or the short hand:
|
||||
\code
|
||||
JKQTMathText::setFontRomanAndMath(QGuiApplication::font().family(), MTFEUnicode);
|
||||
\endcode
|
||||
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:
|
||||
\code
|
||||
JKQTMathText::setFontRomanAndMath("application+XITS", MTFEUnicode);
|
||||
\endcode
|
||||
In all cases the default GUI font is used for rendering default output. For \c \\sf to make a difference you can additionally
|
||||
set the "sans" class as a serif font, e.g.:
|
||||
\code
|
||||
JKQTMathText::setFontSans("serif");
|
||||
JKQTMathText::setFontMathSans("serif");
|
||||
\endcode
|
||||
Using the font name \c "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 \c set...() functions mentioned above. Additionally some short ahnds exist:
|
||||
- JKQTMathText::useSTIX() use the STIX fonts from <a href="https://www.stixfonts.org/">https://www.stixfonts.org/</a> in math-mode (or math- and text-mode, additionally also as MTEFallbackSymbols)<br>\image html jkqtmathtext/jkqtmathtext_stix.png
|
||||
- JKQTMathText::useXITS() use the XITS fonts from <a href="https://github.com/alif-type/xits">https://github.com/alif-type/xits</a> in math-mode (or math- and text-mode, additionally also as MTEFallbackSymbols). These are included by default in this library and also activated by default.<br>\image html jkqtmathtext/jkqtmathtext_xits.png
|
||||
- JKQTMathText::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 (or math- and text-mode, additionally also as MTEFallbackSymbols)<br>\image html jkqtmathtext/jkqtmathtext_asana.png
|
||||
- JKQTMathText::useAnyUnicode() set fonts for "roman" and "sans" in text- and math-mode with one call
|
||||
- JKQTMathText::useAnyUnicodeForMathOnly() set fonts for "roman" and "sans" in math-mode only with one call, leaves text-mode fonts as is
|
||||
- JKQTMathText::useAnyUnicodeForTextOnly() set fonts for "roman" and "sans" in text-mode only with one call, leaves math-mode fonts as is
|
||||
- JKQTMathText::setFontRomanAndMath() set "roman" font in text- and math-mode
|
||||
- JKQTMathText::setFontRomanOrSpecial() use an object of type JKQTMathTextFontSpecifier or a special string syntax (see struct documentation
|
||||
of JKQTMathTextFontSpecifier) to define the text- and math-mode "roman" fonts
|
||||
.
|
||||
|
||||
Here are some examples of using different, widely available, fonts:
|
||||
- using "Arial" <c>JKQTMathText::setFontRomanAndMath("Arial")</c>: \image html jkqtmathtext/jkqtmathtext_arial.png
|
||||
- using "Courier New" <c>JKQTMathText::setFontRomanAndMath("Courier New")</c>: \image html jkqtmathtext/jkqtmathtext_couriernew.png
|
||||
- using "Comic Sans MS" <c>JKQTMathText::setFontRomanAndMath("Comic Sans MS")</c>: \image html jkqtmathtext/jkqtmathtext_comicsans.png
|
||||
- using "Old English Text" <c>JKQTMathText::setFontRomanAndMath("Old English Text")</c>: \image html jkqtmathtext/jkqtmathtext_OldEnglish.png
|
||||
- using "Computer Modern" <c>JKQTMathText::setFontRomanAndMath("CMU Serif")</c>: \image html jkqtmathtext/jkqtmathtext_computermodern.png
|
||||
- using <a href="https://en.wikipedia.org/wiki/Fira_(typeface)">"Fira"</a> <c>JKQTMathText::setFontRoman("Fira Sans"); setFontMathRoman("Fira Math")</c>: \image html jkqtmathtext/jkqtmathtext_fira.png
|
||||
- using "MS Segoe UI" (the default Win 10/11 GUI font) <c>JKQTMathText::setFontRomanAndMath("MS Segoe UI")</c>: \image html jkqtmathtext/jkqtmathtext_mssegoeui.png
|
||||
- using <a href="https://dejavu-fonts.github.io/">"DejaVu Sans"</a> <c>JKQTMathText::setFontRomanAndMath("DejaVu Sans")</c>: \image html jkqtmathtext/jkqtmathtext_DejaVuSans.png
|
||||
- using <a href="https://dejavu-fonts.github.io/">"DejaVu Serif"</a> <c>JKQTMathText::setFontRomanAndMath("DejaVu Serif")</c>: \image html jkqtmathtext/jkqtmathtext_DejaVuSerif.png
|
||||
- using "XITS" <c>JKQTMathText::useXITS(false)</c>: \image html jkqtmathtext/jkqtmathtext_xits_all.png
|
||||
.
|
||||
|
||||
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</b>:
|
||||
- use fonts MTEmathRoman and MTEmathSans
|
||||
- whitespaces are mostly not drawn directly
|
||||
- symbol spacing is different
|
||||
- an example: \image html jkqtmathtext/schreq_mathmode.png
|
||||
.
|
||||
- <b>text-mode</b>:
|
||||
- use fonts MTEroman and MTEsans
|
||||
- whitespaces are evaluated directly
|
||||
- an example: \image html jkqtmathtext/schreq_normalmode.png
|
||||
.
|
||||
|
||||
Font Lookup for symbols works as follows in JKQTMathTextSymbolNode:
|
||||
- if a character is found in the current (or to be used) font, it is taken from there
|
||||
- if the character is not found, it is looked for in the fallback fonts MTEFallbackSymbols
|
||||
- as a last resort, some symbols can be created otherwise, so if neither of the two options above
|
||||
contain the required symbol, the symbol might be synthesized otherwise, or a rectangle with the size of "X" is drawn instead
|
||||
.
|
||||
|
||||
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:
|
||||
- "blackboard", the options are defined by setBlackboardFontMode(). See JKQTMathTextBlackboradDrawingMode
|
||||
.
|
||||
|
||||
*/
|
BIN
doc/images/jkqtmathtext/jkqtmathtext_comicsans_mathonly.png
Normal file
BIN
doc/images/jkqtmathtext/jkqtmathtext_comicsans_mathonly.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.2 KiB |
@ -11,6 +11,10 @@ jkqtmathtext_comicsans_textonly.png
|
||||
--fontroman=Comic Sans MS --sizeincrease=10
|
||||
Schrödinger's equation: $\left[-\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}+V\right]\Psi(x)=\mathrm{i}\hbar\frac{\partial}{\partial t}\Psi(x)$
|
||||
---
|
||||
jkqtmathtext_comicsans_mathonly.png
|
||||
--fontmathroman=Comic Sans MS --sizeincrease=10
|
||||
Schrödinger's equation: $\left[-\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}+V\right]\Psi(x)=\mathrm{i}\hbar\frac{\partial}{\partial t}\Psi(x)$
|
||||
---
|
||||
jkqtmathtext_couriernew.png
|
||||
--fontroman=Courier New --fontmathroman=Courier New --sizeincrease=10
|
||||
Schrödinger's equation: $\left[-\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}+V\right]\Psi(x)=\mathrm{i}\hbar\frac{\partial}{\partial t}\Psi(x)$
|
||||
@ -56,5 +60,5 @@ jkqtmathtext_xits.png
|
||||
Schrödinger's equation: $\left[-\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}+V\right]\Psi(x)=\mathrm{i}\hbar\frac{\partial}{\partial t}\Psi(x),\ \ x\in\mathbb{R}, \Psi(x)\in\mathbb{C}$
|
||||
---
|
||||
jkqtmathtext_stix.png
|
||||
--fontmathroman=STIX Two Math --fontroman=STIX Two Text --sizeincrease=10
|
||||
--fontmathroman=STIX Two Math --sizeincrease=10
|
||||
Schrödinger's equation: $\left[-\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}+V\right]\Psi(x)=\mathrm{i}\hbar\frac{\partial}{\partial t}\Psi(x),\ \ x\in\mathbb{R}, \Psi(x)\in\mathbb{C}$
|
||||
|
@ -47,7 +47,6 @@
|
||||
#include <QDebug>
|
||||
#include <QFontDatabase>
|
||||
#include <typeinfo>
|
||||
#include <QApplication>
|
||||
#include <QPainterPath>
|
||||
|
||||
|
||||
@ -294,7 +293,7 @@ bool JKQTMathText::parse(const QString &markup, DefaultParserTypes markuptType,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool JKQTMathText::useSTIX(bool mathModeOnly) {
|
||||
bool JKQTMathText::useSTIX(bool mathModeOnly, bool useAsFallbackSymbol) {
|
||||
|
||||
const JKQTMathTextFontSpecifier stixs=JKQTMathTextFontSpecifier::getSTIXFamilies();
|
||||
bool res=false;
|
||||
@ -305,18 +304,18 @@ bool JKQTMathText::useSTIX(bool mathModeOnly) {
|
||||
}
|
||||
if (!stixs.mathFontName().isEmpty()) {
|
||||
setFontMathRoman(stixs.mathFontName(), MTFEUnicode);
|
||||
setFallbackFontSymbols(stixs.mathFontName(), MTFEUnicode);
|
||||
if (useAsFallbackSymbol) setFallbackFontSymbols(stixs.fallbackSymbolsFontName(), MTFEUnicode);
|
||||
res=true;
|
||||
} else if (!stixs.fontName().isEmpty()) {
|
||||
setFontMathRoman(stixs.fontName(), MTFEUnicode);
|
||||
setFallbackFontSymbols(stixs.fontName(), MTFEUnicode);
|
||||
if (useAsFallbackSymbol) setFallbackFontSymbols(stixs.fallbackSymbolsFontName(), MTFEUnicode);
|
||||
res=true;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool JKQTMathText::useXITS(bool mathModeOnly)
|
||||
bool JKQTMathText::useXITS(bool mathModeOnly, bool useAsFallbackSymbol)
|
||||
{
|
||||
|
||||
const JKQTMathTextFontSpecifier xits=JKQTMathTextFontSpecifier::getXITSFamilies();
|
||||
@ -324,32 +323,32 @@ bool JKQTMathText::useXITS(bool mathModeOnly)
|
||||
|
||||
if (!mathModeOnly && !xits.fontName().isEmpty()) {
|
||||
setFontRoman(xits.fontName(), MTFEUnicode);
|
||||
setFallbackFontSymbols(xits.fontName(), MTFEUnicode);
|
||||
if (useAsFallbackSymbol) setFallbackFontSymbols(xits.fallbackSymbolsFontName(), MTFEUnicode);
|
||||
res=true;
|
||||
}
|
||||
if (!xits.mathFontName().isEmpty()) {
|
||||
setFontMathRoman(xits.mathFontName(), MTFEUnicode);
|
||||
setFallbackFontSymbols(xits.mathFontName(), MTFEUnicode);
|
||||
if (useAsFallbackSymbol) setFallbackFontSymbols(xits.fallbackSymbolsFontName(), MTFEUnicode);
|
||||
res=true;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool JKQTMathText::useASANA(bool mathModeOnly)
|
||||
bool JKQTMathText::useASANA(bool mathModeOnly, bool useAsFallbackSymbol)
|
||||
{
|
||||
|
||||
const JKQTMathTextFontSpecifier asana=JKQTMathTextFontSpecifier::getXITSFamilies();
|
||||
const JKQTMathTextFontSpecifier asana=JKQTMathTextFontSpecifier::getASANAFamilies();
|
||||
bool res=false;
|
||||
|
||||
if (!mathModeOnly && !asana.fontName().isEmpty()) {
|
||||
setFontRoman(asana.fontName(), MTFEUnicode);
|
||||
setFallbackFontSymbols(asana.fontName(), MTFEUnicode);
|
||||
if (useAsFallbackSymbol) setFallbackFontSymbols(asana.fallbackSymbolsFontName(), MTFEUnicode);
|
||||
res=true;
|
||||
}
|
||||
if (!asana.mathFontName().isEmpty()) {
|
||||
setFontMathRoman(asana.mathFontName(), MTFEUnicode);
|
||||
setFallbackFontSymbols(asana.mathFontName(), MTFEUnicode);
|
||||
if (useAsFallbackSymbol) setFallbackFontSymbols(asana.fallbackSymbolsFontName(), MTFEUnicode);
|
||||
res=true;
|
||||
}
|
||||
|
||||
@ -487,20 +486,13 @@ void JKQTMathText::setFontRomanOrSpecial(const QString &__value, JKQTMathTextFon
|
||||
void JKQTMathText::setFontRomanOrSpecial(const JKQTMathTextFontSpecifier &fontName, JKQTMathTextFontEncoding encoding)
|
||||
{
|
||||
if (!fontName.hasMathFontName()) {
|
||||
if (fontName.fontName().toUpper()=="XITS") useXITS(false);
|
||||
else if (fontName.fontName().toUpper()=="STIX") useSTIX(false);
|
||||
else if (fontName.fontName().toUpper()=="ASANA") useASANA(false);
|
||||
else {
|
||||
setFontRoman(fontName.fontName(), encoding);
|
||||
setFontMathRoman(fontName.fontName(), encoding);
|
||||
}
|
||||
} else {
|
||||
if (fontName.mathFontName().toUpper()=="XITS") useXITS(true);
|
||||
else if (fontName.mathFontName().toUpper()=="STIX") useSTIX(true);
|
||||
else if (fontName.mathFontName().toUpper()=="ASANA") useASANA(true);
|
||||
else setFontMathRoman(fontName.mathFontName(), encoding);
|
||||
setFontRoman(fontName.fontName(), encoding);
|
||||
setFontMathRoman(fontName.fontName(), encoding);
|
||||
} else {
|
||||
setFontRoman(fontName.fontName(), encoding);
|
||||
setFontMathRoman(fontName.mathFontName(), encoding);
|
||||
}
|
||||
if (fontName.hasFallbcakSymbolFontName()) setFallbackFontSymbols(fontName.fallbackSymbolsFontName(), encoding);
|
||||
}
|
||||
|
||||
void JKQTMathText::setFontRoman(const QString &__value, JKQTMathTextFontEncoding encoding)
|
||||
@ -510,6 +502,12 @@ void JKQTMathText::setFontRoman(const QString &__value, JKQTMathTextFontEncoding
|
||||
fontDefinitions[MTEroman].fontEncoding = f.second;
|
||||
}
|
||||
|
||||
void JKQTMathText::setFontRomanAndMath(const QString &fontName, JKQTMathTextFontEncoding encoding)
|
||||
{
|
||||
setFontRoman(fontName, encoding);
|
||||
setFontMathRoman(fontName, encoding);
|
||||
}
|
||||
|
||||
QString JKQTMathText::getFontRoman() const
|
||||
{
|
||||
return fontDefinitions[MTEroman].fontName;
|
||||
|
@ -61,10 +61,14 @@ class JKQTMathTextVerticalListNode; // forward
|
||||
.
|
||||
|
||||
In particular JKQTMathTextLatexParser actually parses e.g. a LaTeX string and draws it in pure C++. It does NOT rely
|
||||
on an installed LaTeX for the rendering!
|
||||
on an installed LaTeX for the rendering! See \ref jkqtmathtext_supportedlatex for a description of the supported LaTeX subset.
|
||||
|
||||
\see See \ref jkqtmathtext_supportedlatex for a description of the supported LaTeX subset
|
||||
and \ref jkqtmathtext_renderingmodel for a description of the rendering model of JKQTMathTextLatexParser.
|
||||
More generally these pages describe how the class renders math markup:
|
||||
- \ref jkqtmathtext_renderingmodel for a description of the rendering model of JKQTMathTextLatexParser
|
||||
- \ref jkqtmathtext_fonthandling for a description of the font handling in JKQTMathTextLatexParser
|
||||
(which is modelled after LaTeX, but with tweaks especially for use in the context of GUI code)
|
||||
- \ref jkqtmathtext_supportedlatex for a description of the supported LaTeX subset
|
||||
.
|
||||
|
||||
|
||||
\section JKQTMathTextUsage Usage
|
||||
@ -171,49 +175,6 @@ class JKQTMathTextVerticalListNode; // forward
|
||||
.
|
||||
|
||||
|
||||
\section JKQTMathTextInternalDetails Implementation Details
|
||||
\subsection JKQTMathTextSuppoertedFonts Font Handling
|
||||
|
||||
Several fonts are defined as properties to the class:
|
||||
- A "roman" (MTEroman / MTEmathRoman) font used as the standard font ( setFontRoman() and for use in math mode setFontMathRoman() )
|
||||
- A "sans-serif" (MTEsans / MTEmathSans) font which may be activated with \c \\sf ... ( setFontSans() and for use in math mode setFontMathSans() )
|
||||
- A "typewriter" (MTEtypewriter) font which may be activated with \c \\tt ... ( setFontTypewriter() )
|
||||
- A "script" (MTEscript) font which may be activated with \c \\script ... ( setFontScript() )
|
||||
- A "math-roman" (MTEmathRoman) font used as the standard font in math mode ( setFontMathRoman() )
|
||||
- A "math-sans-serif" (MTEmathSans) used as sans serif font in math mode ( setFontMathSans() )
|
||||
- A "blackboard" (MTEblackboard) font used to display double stroked characters ( setFontBlackboard() )
|
||||
- A "caligraphic" (MTEcaligraphic) font used to display caligraphic characters ( setFontCaligraphic() )
|
||||
- A "fraktur" (MTEfraktur) font used to display fraktur characters ( setFontFraktur() )
|
||||
- A fallback font MTEFallbackSymbols for (math) symbols, greek letters ... (if the symbols are not present in the currently used font). ( setFallbackFontSymbols() )
|
||||
.
|
||||
|
||||
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:
|
||||
- useSTIX() use the STIX fonts from <a href="https://www.stixfonts.org/">https://www.stixfonts.org/</a> in math-mode<br>\image html jkqtmathtext/jkqtmathtext_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 jkqtmathtext/jkqtmathtext_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 jkqtmathtext/jkqtmathtext_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 jkqtmathtext/jkqtmathtext_timesnewroman.png
|
||||
<br>using "Arial": \image html jkqtmathtext/jkqtmathtext_arial.png
|
||||
<br>using "Courier New": \image html jkqtmathtext/jkqtmathtext_couriernew.png
|
||||
<br>using "Comic Sans MS": \image html jkqtmathtext/jkqtmathtext_comicsans.png
|
||||
<br>using "Old English Text": \image html jkqtmathtext/jkqtmathtext_OldEnglish.png
|
||||
<br>using "Computer Modern": \image html jkqtmathtext/jkqtmathtext_computermodern.png
|
||||
<br>using "Fira": \image html jkqtmathtext/jkqtmathtext_fira.png
|
||||
<br>using "MS Segoe UI": \image html jkqtmathtext/jkqtmathtext_mssegoeui.png
|
||||
<br>using "DejaVu Sans": \image html jkqtmathtext/jkqtmathtext_DejaVuSans.png
|
||||
<br>using "DejaVu Serif": \image html jkqtmathtext/jkqtmathtext_DejaVuSerif.png
|
||||
.
|
||||
|
||||
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 (MTEmathRoman and MTEmathSans, whitespaces are mostly not drawn directly, symbol spacing is different)</b> \c $...$: <br>\image html jkqtmathtext/schreq_mathmode.png
|
||||
- <b>normal mode (MTEroman and MTEsans is used, whitespaces are evaluated directly)</b>: <br>\image html jkqtmathtext/schreq_normalmode.png
|
||||
.
|
||||
|
||||
Font Lookup for symbols works as follows in JKQTMathTextSymbolNode:
|
||||
- if a character is found in the current (or to be used) font, it is taken from there
|
||||
- if the character is not found, it is looked for in the fallback fonts MTEFallbackSymbols
|
||||
- as a last resort, some symbols can be created otherwise, so if neither of the two options above
|
||||
contain the required symbol, the symbol might be synthesized otherwise, or a rectangle with the size of "X" is drawn instead
|
||||
.
|
||||
|
||||
*/
|
||||
class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
@ -230,10 +191,10 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
JKQTMathText(QObject * parent = nullptr);
|
||||
/** \brief class destructor */
|
||||
~JKQTMathText();
|
||||
/** \brief load the object settings from the given QSettings object with the given name prefix */
|
||||
void loadSettings(const QSettings& settings, const QString& group=QString("mathtext/"));
|
||||
/** \brief store the object settings to the given QSettings object with the given name prefix */
|
||||
void saveSettings(QSettings& settings, const QString& group=QString("mathtext/")) const;
|
||||
|
||||
|
||||
/** @name Parsing Math Markup */
|
||||
/**@{*/
|
||||
/** \brief options for parse() */
|
||||
enum ParseOption {
|
||||
AddSpaceBeforeAndAfter = 0x01, /*!< \brief If set, a little bit of space is added before and after the text. */
|
||||
@ -271,7 +232,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
std::unique_ptr<TParser> p=std::unique_ptr<TParser>(new TParser(this));
|
||||
if (parsedNode) delete parsedNode;
|
||||
parsedNode=nullptr;
|
||||
clearErrorList();
|
||||
clearErrorList();
|
||||
parsedNode=p->parse(markup, options);
|
||||
return parsedNode!=nullptr;
|
||||
}
|
||||
@ -279,6 +240,11 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
JKQTMathTextNode* getNodeTree() ;
|
||||
/** \copydoc parsedNode */
|
||||
const JKQTMathTextNode *getNodeTree() const;
|
||||
/**@}*/
|
||||
|
||||
|
||||
/** @name Determine the Size of the Output */
|
||||
/**@{*/
|
||||
|
||||
/** \brief get the size of the drawn representation. returns an invalid size if no text has been parsed. */
|
||||
QSizeF getSize(QPainter& painter);
|
||||
@ -292,6 +258,12 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
void getSizeDetail(QPainter& painter, double& width, double& ascent, double& descent, double& strikeoutPos);
|
||||
/** \brief return the detailes sizes of the text */
|
||||
JKQTMathTextNodeSize getSizeDetail(QPainter& painter);
|
||||
/**@}*/
|
||||
|
||||
|
||||
/** @name Rendering */
|
||||
/**@{*/
|
||||
|
||||
/** \brief draw a representation to the object at the specified position \a x , \a y
|
||||
*
|
||||
* \param painter the <a href="http://doc.qt.io/qt-5/qpainter.html">QPainter</a> to use for drawing
|
||||
@ -356,8 +328,11 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
|
||||
/** \brief convert LaTeX to HTML. returns \c ok=true on success and \c ok=false else. */
|
||||
QString toHtml(bool* ok=nullptr, double fontPointSize=10);
|
||||
/**@}*/
|
||||
|
||||
/** \copydoc fontColor */
|
||||
/** @name Font Handling */
|
||||
/**@{*/
|
||||
/** \copydoc fontColor */
|
||||
void setFontColor(const QColor & __value);
|
||||
/** \copydoc fontColor */
|
||||
QColor getFontColor() const;
|
||||
@ -377,6 +352,8 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
/** \brief returns the currently set default font size in pixels, if it was defined in points using setFontSizePixels(), or -1 if it was set in points with setFontSize()
|
||||
* \see setFontSizePixels(), fontSize, fontSizeUnits */
|
||||
double getFontSizePixels() const;
|
||||
|
||||
|
||||
/** \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.
|
||||
@ -404,36 +381,70 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
/** \brief retrieve the font and encoding to be used for \a font, which might optionally be typeset inside a math environment, specified by in_math_environment, possibly for the given font subclass \a subclass */
|
||||
QPair<QString, JKQTMathTextFontEncoding> getFontData(JKQTMathTextEnvironmentFont font, bool in_math_environment=false) const;
|
||||
|
||||
/*! \brief calls setFontRoman(), or calls useXITS() if \a __value \c =="XITS". calls useSTIX() if \a __value \c =="STIX", ...
|
||||
|
||||
\see setFontRoman(), useXITS(), useSTIX() for more information */
|
||||
/*! \brief set the font by parsing a special syntax defined in the description of JKQTMathTextFontSpecifier
|
||||
*
|
||||
* This allows to set the text-mode and math-mode roman fonts.
|
||||
*
|
||||
* \note This function is a shorthand for
|
||||
* \code
|
||||
* setFontRomanOrSpecial(JKQTMathTextFontSpecifier::fromFontSpec(fontName), encoding);
|
||||
* \endcode
|
||||
*
|
||||
* \see JKQTMathTextFontSpecifier, setFontRoman(), setFontMathRoman(), \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void setFontRomanOrSpecial(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
|
||||
/*! \brief calls setFontRoman(), or calls useXITS() if \a __value \c =="XITS". calls useSTIX() if \a __value \c =="STIX", ...
|
||||
|
||||
\see setFontRoman(), useXITS(), useSTIX() for more information */
|
||||
/*! \brief set the font by an instance of JKQTMathTextFontSpecifier
|
||||
*
|
||||
* This allows to set the text-mode and math-mode roman fonts.
|
||||
*
|
||||
* \see JKQTMathTextFontSpecifier, setFontRoman(), setFontMathRoman(), \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void setFontRomanOrSpecial(const JKQTMathTextFontSpecifier & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
|
||||
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEroman */
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEroman
|
||||
*
|
||||
* \see \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void setFontRoman(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text and math, i.e. the logical font MTEroman and MTEmathRoman
|
||||
*
|
||||
* \see \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void setFontRomanAndMath(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
|
||||
/** \brief retrieves the font to be used for text in the logical font MTEroman */
|
||||
QString getFontRoman() const;
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEsans */
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEsans
|
||||
*
|
||||
* \see \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void setFontSans(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
|
||||
/** \brief retrieves the font to be used for text in the logical font MTEsans */
|
||||
QString getFontSans() const;
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEtypewriter */
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEtypewriter
|
||||
*
|
||||
* \see \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void setFontTypewriter(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
|
||||
/** \brief retrieves the font to be used for text in the logical font MTEtypewriter */
|
||||
QString getFontTypewriter() const;
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEscript */
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEscript
|
||||
*
|
||||
* \see \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void setFontScript(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
|
||||
/** \brief retrieves the font to be used for text in the logical font MTEscript */
|
||||
QString getFontScript() const;
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEfraktur */
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEfraktur
|
||||
*
|
||||
* \see \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void setFontFraktur(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
|
||||
/** \brief retrieves the font to be used for text in the logical font MTEfraktur */
|
||||
QString getFontFraktur() const;
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEcaligraphic */
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEcaligraphic
|
||||
*
|
||||
* \see \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void setFontCaligraphic(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
|
||||
/** \brief retrieves the font to be used for text in the logical font MTEcaligraphic */
|
||||
QString getFontCaligraphic() const;
|
||||
@ -449,7 +460,10 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
|
||||
/** \brief retrieves the font to be used for text in the logical font MTEblackboard \see blackboradFontMode */
|
||||
QString getFontBlackboard() const;
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for symbols in the logical font \a font */
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for symbols in the logical font \a font
|
||||
*
|
||||
* \see \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void setFallbackFontSymbols(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
|
||||
/** \brief retrieves the font to be used for symbols in the logical font \a font */
|
||||
QString getFallbackFontSymbols() const;
|
||||
@ -472,11 +486,17 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
JKQTMathTextFontEncoding getFontEncodingCaligraphic() const;
|
||||
|
||||
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEmathRoman */
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEmathRoman
|
||||
*
|
||||
* \see \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void setFontMathRoman(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
|
||||
/** \brief retrieves the font to be used for text in the logical font MTEroman */
|
||||
QString getFontMathRoman() const;
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEmathSans */
|
||||
/** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEmathSans
|
||||
*
|
||||
* \see \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void setFontMathSans(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
|
||||
/** \brief retrieves the font to be used for text in the logical font MTEsans */
|
||||
QString getFontMathSans() const;
|
||||
@ -488,15 +508,26 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
/** \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
|
||||
* or in math and text-mode (if \a mathModeOnly \c ==false )
|
||||
*
|
||||
* If \c useAsFallbackSymbol is set \c ==true then the XITS fonts are also used as MTEFallbackSymbols
|
||||
*
|
||||
* \image html jkqtmathtext/jkqtmathtext_stix.png
|
||||
*
|
||||
* This function does not only use default font-names for STIX, but searches
|
||||
* the font database of the system with several different variants, using JKQTMathTextFontSpecifier::getSTIXFamilies().
|
||||
* It also sets the special math-variant of STIX for math mode and the normal variant for text-mode
|
||||
*
|
||||
* \see \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
bool useSTIX(bool mathModeOnly=true);
|
||||
bool useSTIX(bool mathModeOnly=true, bool useAsFallbackSymbol=true);
|
||||
|
||||
/** \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.
|
||||
* use XITS fonts from <a href="https://github.com/alif-type/xits">https://github.com/alif-type/xits</a> in math-mode
|
||||
* or in math and text-mode (if \a mathModeOnly \c ==false ).
|
||||
*
|
||||
* If \c useAsFallbackSymbol is set \c ==true then the XITS fonts are also used as MTEFallbackSymbols
|
||||
*
|
||||
* \image html jkqtmathtext/jkqtmathtext_xits.png
|
||||
*
|
||||
@ -504,16 +535,31 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
* Then the XITS fonts are added as Qt-Ressources to the library binary.
|
||||
* If this is not the case, you have to provide the XITS fonts on the target system by other means, if you want
|
||||
* to use them.
|
||||
*
|
||||
* This function does not only use default font-names for XITS, but searches
|
||||
* the font database of the system with several different variants, using JKQTMathTextFontSpecifier::getXITSFamilies().
|
||||
* It also sets the special math-variant of XITS for math mode and the normal variant for text-mode
|
||||
*
|
||||
* \see \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
bool useXITS(bool mathModeOnly=true);
|
||||
bool useXITS(bool mathModeOnly=true, bool useAsFallbackSymbol=true);
|
||||
|
||||
/** \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
|
||||
* or in math and text-mode (if \a mathModeOnly \c ==false )
|
||||
*
|
||||
* If \c useAsFallbackSymbol is set \c ==true then the XITS fonts are also used as MTEFallbackSymbols
|
||||
*
|
||||
* \image html jkqtmathtext/jkqtmathtext_asana.png
|
||||
*
|
||||
* This function does not only use default font-names for ASANA, but searches
|
||||
* the font database of the system with several different variants, using JKQTMathTextFontSpecifier::getASANAFamilies().
|
||||
* It also sets the special math-variant of ASANA for math mode and the normal variant for text-mode
|
||||
*
|
||||
* \see \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
bool useASANA(bool mathModeOnly=true);
|
||||
bool useASANA(bool mathModeOnly=true, bool useAsFallbackSymbol=true);
|
||||
|
||||
/** \brief sets \a timesFont (with its encoding \a encodingTimes ) for serif-text and \a sansFont (with its encoding \a encodingSans ) for both mathmode and textmode fonts
|
||||
*
|
||||
@ -521,11 +567,12 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
* You should use fonts that contain as many of the mathematical symbols as possible
|
||||
* to ensure good rendering results.
|
||||
*
|
||||
* <code>useAnyUnicode("Times New Roman", "Times New Roman")</code>:<br>\image html jkqtmathtext/jkqtmathtext_timesnewroman.png <br><br>
|
||||
* <code>useAnyUnicode("Arial", "Arial")</code>:<br>\image html jkqtmathtext/jkqtmathtext_arial.png <br><br>
|
||||
* <code>useAnyUnicode("Courier New", "Courier New")</code>:<br>\image html jkqtmathtext/jkqtmathtext_couriernew.png <br><br>
|
||||
*
|
||||
* <code>useAnyUnicode("Comic Sans MS", "Comic Sans MS")</code>:<br>\image html jkqtmathtext/jkqtmathtext_comicsans.png <br><br>
|
||||
* <code>useAnyUnicodeForTextOnly("Comic Sans MS", "Comic Sans MS");</code>:<br/>\image html jkqtmathtext/jkqtmathtext_comicsans_textonly.png
|
||||
* <code>useAnyUnicodeForMathOnly("Comic Sans MS", "Comic Sans MS");</code>:<br/>\image html jkqtmathtext/jkqtmathtext_comicsans_mathonly.png
|
||||
*
|
||||
* \see useAnyUnicodeForMathOnly(), useAnyUnicodeForTextOnly(), \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void useAnyUnicode(QString timesFont, const QString& sansFont, JKQTMathTextFontEncoding encodingTimes=JKQTMathTextFontEncoding::MTFEUnicode, JKQTMathTextFontEncoding encodingSans=JKQTMathTextFontEncoding::MTFEUnicode);
|
||||
/** \brief sets \a timesFont (with its encoding \a encodingTimes ) for serif-text and \a sansFont (with its encoding \a encodingSans ) for mathmode fonts only
|
||||
@ -533,19 +580,31 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
* \note 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.
|
||||
*
|
||||
* \see useAnyUnicodeForTextOnly(), useAnyUnicode()
|
||||
* <code>useAnyUnicode("Comic Sans MS", "Comic Sans MS")</code>:<br>\image html jkqtmathtext/jkqtmathtext_comicsans.png <br><br>
|
||||
* <code>useAnyUnicodeForTextOnly("Comic Sans MS", "Comic Sans MS");</code>:<br/>\image html jkqtmathtext/jkqtmathtext_comicsans_textonly.png
|
||||
* <code>useAnyUnicodeForMathOnly("Comic Sans MS", "Comic Sans MS");</code>:<br/>\image html jkqtmathtext/jkqtmathtext_comicsans_mathonly.png
|
||||
*
|
||||
* \see useAnyUnicodeForTextOnly(), useAnyUnicode(), \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void useAnyUnicodeForMathOnly(QString timesFont, const QString& sansFont, JKQTMathTextFontEncoding encodingTimes=JKQTMathTextFontEncoding::MTFEUnicode, JKQTMathTextFontEncoding encodingSans=JKQTMathTextFontEncoding::MTFEUnicode);
|
||||
/** \brief sets \a timesFont (with its encoding \a encodingTimes ) for serif-text and \a sansFont (with its encoding \a encodingSans ) for both mathmode fonts only
|
||||
*
|
||||
* \see useAnyUnicodeForMathOnly(), useAnyUnicode()
|
||||
*
|
||||
* <code>useAnyUnicode("Comic Sans MS", "Comic Sans MS")</code>:<br>\image html jkqtmathtext/jkqtmathtext_comicsans.png <br><br>
|
||||
* <code>useAnyUnicodeForTextOnly("Comic Sans MS", "Comic Sans MS");</code>:<br/>\image html jkqtmathtext/jkqtmathtext_comicsans_textonly.png
|
||||
* <code>useAnyUnicodeForMathOnly("Comic Sans MS", "Comic Sans MS");</code>:<br/>\image html jkqtmathtext/jkqtmathtext_comicsans_mathonly.png
|
||||
*
|
||||
* \see useAnyUnicodeForMathOnly(), useAnyUnicode(), \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
void useAnyUnicodeForTextOnly(QString timesFont, const QString& sansFont, JKQTMathTextFontEncoding encodingTimes=JKQTMathTextFontEncoding::MTFEUnicode, JKQTMathTextFontEncoding encodingSans=JKQTMathTextFontEncoding::MTFEUnicode);
|
||||
/**@}*/
|
||||
|
||||
|
||||
/** @name (Defining) Rendering Details */
|
||||
/**@{*/
|
||||
/** \brief load the object settings from the given QSettings object with the given name prefix */
|
||||
void loadSettings(const QSettings& settings, const QString& group=QString("mathtext/"));
|
||||
/** \brief store the object settings to the given QSettings object with the given name prefix */
|
||||
void saveSettings(QSettings& settings, const QString& group=QString("mathtext/")) const;
|
||||
|
||||
/** \copydoc brace_factor */
|
||||
void setBraceFactor(double __value);
|
||||
@ -607,7 +666,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
void setUnderbraceFactor(double __value);
|
||||
/** \copydoc underbrace_factor */
|
||||
double getUnderbraceFactor() const;
|
||||
/** \copydoc underbrace_separation_xfactor */
|
||||
/** \copydoc underbrace_separation_xfactor */
|
||||
void setUnderbraceSeparationXFactor(double __value);
|
||||
/** \copydoc underbrace_separation_xfactor */
|
||||
double getUnderbraceSeparationXFactor() const;
|
||||
@ -647,7 +706,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
/** \copydoc decoration_separation_factor */
|
||||
double getDecorationSeparationFactor() const;
|
||||
/** \copydoc decoration_width_reduction_Xfactor */
|
||||
void setDecorationWidthReductionFactor(double __value);
|
||||
void setDecorationWidthReductionFactor(double __value);
|
||||
/** \copydoc decoration_width_reduction_Xfactor */
|
||||
double getDecorationWidthReductionXFactor() const;
|
||||
|
||||
@ -693,8 +752,11 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
double getMatrixYPaddingFactor();
|
||||
/** \copydoc matrix_yPadding_factor */
|
||||
void setMatrixYPaddingFactor(double factor);
|
||||
/**@}*/
|
||||
|
||||
|
||||
/** @name Error Handling */
|
||||
/**@{*/
|
||||
/** \copydoc error_list */
|
||||
QStringList getErrorList() const;
|
||||
/** \brief returns \c true when errors were registered in the system \see error_list */
|
||||
@ -706,6 +768,22 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
*/
|
||||
void clearErrorList();
|
||||
|
||||
/** \brief a list that will be filled with error messages while parsing, if any error occur
|
||||
*
|
||||
* This list of errors is (mostly) filled during a call to parse(). During rendering (e.g. with draw() )
|
||||
* only very few errors will be detected, as most errors are caused by wrong markup.
|
||||
*
|
||||
* A call to parse() also clears this list.
|
||||
*
|
||||
* \see getErrorList(), hadErrors() and addToErrorList()
|
||||
*
|
||||
*/
|
||||
QStringList error_list;
|
||||
/**@}*/
|
||||
|
||||
/** \brief the syntax tree of JKQTMathTextNode's that was created by the last parse() call */
|
||||
JKQTMathTextNode* parsedNode;
|
||||
|
||||
|
||||
|
||||
/** \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
|
||||
@ -741,7 +819,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
* - MTBBDMunicodeCharactersOrSimulate: \image html jkqtmathtext/jkqtmathtext_bb_unicode_or_simulate.png using \c JKQTMathText::setFontBlackboard("Arial")
|
||||
* .
|
||||
*
|
||||
* \see setFontBlackboard() setBlackboardFontMode()
|
||||
* \see JKQTMathTextBlackboradDrawingMode, setFontBlackboard(), setBlackboardFontMode(), \ref jkqtmathtext_fonthandling
|
||||
*/
|
||||
JKQTMathTextBlackboradDrawingMode blackboradFontMode;
|
||||
|
||||
@ -923,21 +1001,6 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
*/
|
||||
double matrix_yPadding_factor;
|
||||
|
||||
/** \brief a list that will be filled with error messages while parsing, if any error occur
|
||||
*
|
||||
* This list of errors is (mostly) filled during a call to parse(). During rendering (e.g. with draw() )
|
||||
* only very few errors will be detected, as most errors are caused by wrong markup.
|
||||
*
|
||||
* A call to parse() also clears this list.
|
||||
*
|
||||
* \see getErrorList(), hadErrors() and addToErrorList()
|
||||
*
|
||||
*/
|
||||
QStringList error_list;
|
||||
|
||||
/** \brief the syntax tree of JKQTMathTextNode's that was created by the last parse() call */
|
||||
JKQTMathTextNode* parsedNode;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
@ -45,14 +45,16 @@ void initJKQTMathTextResources()
|
||||
|
||||
JKQTMathTextFontSpecifier::JKQTMathTextFontSpecifier():
|
||||
m_fontName(""),
|
||||
m_mathFontName("")
|
||||
m_mathFontName(""),
|
||||
m_transformOnOutput(true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
JKQTMathTextFontSpecifier::JKQTMathTextFontSpecifier(const QString &_fontName, const QString &_mathFontName):
|
||||
m_fontName(_fontName),
|
||||
m_mathFontName(_mathFontName)
|
||||
m_mathFontName(_mathFontName),
|
||||
m_transformOnOutput(true)
|
||||
{
|
||||
|
||||
}
|
||||
@ -90,15 +92,28 @@ QString JKQTMathTextFontSpecifier::getFontSpec() const
|
||||
|
||||
QString JKQTMathTextFontSpecifier::fontName() const
|
||||
{
|
||||
return transformFontName(m_fontName);
|
||||
if (m_transformOnOutput) return transformFontNameAndDecodeSpecialFonts(m_fontName, false);
|
||||
else return m_fontName;
|
||||
}
|
||||
|
||||
QString JKQTMathTextFontSpecifier::mathFontName() const
|
||||
{
|
||||
return transformFontName(m_mathFontName);
|
||||
if (m_transformOnOutput) return transformFontNameAndDecodeSpecialFonts(m_mathFontName, true);
|
||||
else return m_mathFontName;
|
||||
}
|
||||
|
||||
QString JKQTMathTextFontSpecifier::transformFontName(const QString &fontName)
|
||||
QString JKQTMathTextFontSpecifier::fallbackSymbolsFontName() const
|
||||
{
|
||||
if (m_transformOnOutput) return transformFontNameAndDecodeSpecialFonts(m_fallbackSymbolFont, true);
|
||||
else return m_fallbackSymbolFont;
|
||||
}
|
||||
|
||||
void JKQTMathTextFontSpecifier::setFallbackSymbolsFontName(const QString &name)
|
||||
{
|
||||
m_fallbackSymbolFont=name;
|
||||
}
|
||||
|
||||
QString JKQTMathTextFontSpecifier::transformFontName(const QString &fontName, bool mathmode)
|
||||
{
|
||||
const QString fnt=fontName.trimmed().toLower();
|
||||
QFont testFnt;
|
||||
@ -168,17 +183,20 @@ QString JKQTMathTextFontSpecifier::transformFontName(const QString &fontName)
|
||||
return fontName;
|
||||
}
|
||||
|
||||
QString JKQTMathTextFontSpecifier::transformFontNameAndDecodeSpecialFonts(const QString &fontName)
|
||||
QString JKQTMathTextFontSpecifier::transformFontNameAndDecodeSpecialFonts(const QString &fontName, bool mathmode)
|
||||
{
|
||||
const QString fnt=fontName.toLower().trimmed();
|
||||
if (fnt=="xits") {
|
||||
return getXITSFamilies().fontName();
|
||||
if (mathmode) return getXITSFamilies().mathFontName();
|
||||
else return getXITSFamilies().fontName();
|
||||
} else if (fnt=="asana") {
|
||||
return getASANAFamilies().fontName();
|
||||
if (mathmode) return getASANAFamilies().mathFontName();
|
||||
else return getASANAFamilies().fontName();
|
||||
} else if (fnt=="stix") {
|
||||
return getSTIXFamilies().fontName();
|
||||
if (mathmode) return getSTIXFamilies().mathFontName();
|
||||
else return getSTIXFamilies().fontName();
|
||||
}
|
||||
return transformFontName(fontName);
|
||||
return transformFontName(fontName, mathmode);
|
||||
}
|
||||
|
||||
bool JKQTMathTextFontSpecifier::hasFontName() const
|
||||
@ -191,6 +209,11 @@ bool JKQTMathTextFontSpecifier::hasMathFontName() const
|
||||
return !m_mathFontName.isEmpty();
|
||||
}
|
||||
|
||||
bool JKQTMathTextFontSpecifier::hasFallbcakSymbolFontName() const
|
||||
{
|
||||
return !m_fallbackSymbolFont.isEmpty();
|
||||
}
|
||||
|
||||
JKQTMathTextFontSpecifier JKQTMathTextFontSpecifier::getXITSFamilies()
|
||||
{
|
||||
#if (QT_VERSION<QT_VERSION_CHECK(6, 0, 0))
|
||||
@ -210,6 +233,7 @@ JKQTMathTextFontSpecifier JKQTMathTextFontSpecifier::getXITSFamilies()
|
||||
|
||||
static JKQTMathTextFontSpecifier fontSpec;
|
||||
if (fontSpec.m_fontName.isEmpty() && fontSpec.m_mathFontName.isEmpty()) {
|
||||
fontSpec.m_transformOnOutput=false;
|
||||
for (int i=0; i<fontFamilies.size(); i++) {
|
||||
if (fontFamilies.at(i).contains("XITS Math")) {
|
||||
fontSpec.m_mathFontName=fontFamilies.at(i);
|
||||
@ -225,6 +249,7 @@ JKQTMathTextFontSpecifier JKQTMathTextFontSpecifier::getXITSFamilies()
|
||||
} else if (!fontSpec.m_mathFontName.isEmpty() && fontSpec.m_fontName.isEmpty()) {
|
||||
fontSpec.m_fontName=fontSpec.m_mathFontName;
|
||||
}
|
||||
fontSpec.m_fallbackSymbolFont=fontSpec.m_mathFontName;
|
||||
}
|
||||
|
||||
return fontSpec;
|
||||
@ -245,6 +270,7 @@ JKQTMathTextFontSpecifier JKQTMathTextFontSpecifier::getASANAFamilies()
|
||||
|
||||
static JKQTMathTextFontSpecifier fontSpec;
|
||||
if (fontSpec.m_fontName.isEmpty() && fontSpec.m_mathFontName.isEmpty()) {
|
||||
fontSpec.m_transformOnOutput=false;
|
||||
for (int i=0; i<fontFamilies.size(); i++) {
|
||||
if (fontFamilies.at(i).contains("Asana Math")) {
|
||||
fontSpec.m_mathFontName=fontFamilies.at(i);
|
||||
@ -260,6 +286,7 @@ JKQTMathTextFontSpecifier JKQTMathTextFontSpecifier::getASANAFamilies()
|
||||
} else if (!fontSpec.m_mathFontName.isEmpty() && fontSpec.m_fontName.isEmpty()) {
|
||||
fontSpec.m_fontName=fontSpec.m_mathFontName;
|
||||
}
|
||||
fontSpec.m_fallbackSymbolFont=fontSpec.m_mathFontName;
|
||||
}
|
||||
|
||||
|
||||
@ -273,6 +300,7 @@ JKQTMathTextFontSpecifier JKQTMathTextFontSpecifier::getSTIXFamilies()
|
||||
|
||||
static JKQTMathTextFontSpecifier fontSpec;
|
||||
if (fontSpec.m_fontName.isEmpty() && fontSpec.m_mathFontName.isEmpty()) {
|
||||
fontSpec.m_transformOnOutput=false;
|
||||
#if (QT_VERSION<QT_VERSION_CHECK(6, 0, 0))
|
||||
QFontDatabase fdb;
|
||||
const auto fontFamilies=fdb.families();
|
||||
@ -310,6 +338,7 @@ JKQTMathTextFontSpecifier JKQTMathTextFontSpecifier::getSTIXFamilies()
|
||||
} else if (!fontSpec.m_mathFontName.isEmpty() && fontSpec.m_fontName.isEmpty()) {
|
||||
fontSpec.m_fontName=fontSpec.m_mathFontName;
|
||||
}
|
||||
fontSpec.m_fallbackSymbolFont=fontSpec.m_mathFontName;
|
||||
}
|
||||
return fontSpec;
|
||||
}
|
||||
|
@ -56,7 +56,16 @@ 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)
|
||||
\ingroup jkqtmathtext_tools
|
||||
|
||||
\section JKQTMathTextFontSpecifier_specialNames Special FOnt Names
|
||||
\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
|
||||
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
|
||||
- \c times / \c serif - a general serif font
|
||||
@ -75,14 +84,19 @@ JKQTMATHTEXT_LIB_EXPORT void initJKQTMathTextResources();
|
||||
- \c title
|
||||
- \c general
|
||||
.
|
||||
|
||||
Also some sepcial fonts are defined:
|
||||
- xits XITS fonts
|
||||
- stix STIX fonts
|
||||
- asana ASANA fonts
|
||||
*/
|
||||
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextFontSpecifier {
|
||||
JKQTMathTextFontSpecifier();
|
||||
JKQTMathTextFontSpecifier(const QString& fontName, const QString& mathFontName);
|
||||
/** \brief construct a JKQTMathTextFontSpecifier, by parsing a \a fontSpec string with the form \c "FONT_NAME[+MATH_FONT_NAME]". */
|
||||
/** \brief construct a JKQTMathTextFontSpecifier, by parsing a \a fontSpec string as defined in the struct description, see \ref JKQTMathTextFontSpecifier_specialNames . */
|
||||
static JKQTMathTextFontSpecifier fromFontSpec(const QString& fontSpec);
|
||||
|
||||
/** \brief initialises the object with values from parsing a \a fontSpec string with the form \c "FONT_NAME[+MATH_FONT_NAME]". */
|
||||
/** \brief initialises the object with values from parsing a \a fontSpec string as defined in the struct description, see \ref JKQTMathTextFontSpecifier_specialNames . */
|
||||
void setFontSpec(const QString& fontSpec);
|
||||
|
||||
/** \brief returns the object's constents as a fontSpec string with the form \c "FONT_NAME[+MATH_FONT_NAME]". */
|
||||
@ -91,19 +105,25 @@ struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextFontSpecifier {
|
||||
QString fontName() const;
|
||||
/** \copydoc m_mathFontName */
|
||||
QString mathFontName() const;
|
||||
/** \copydoc m_fallbackSymbolFont */
|
||||
QString fallbackSymbolsFontName() const;
|
||||
|
||||
/** \copydoc m_fontName */
|
||||
void setFontName(const QString& name);
|
||||
/** \copydoc m_mathFontName */
|
||||
void setmathFontName(const QString& name);
|
||||
/** \copydoc fallbackSymbolsFontName */
|
||||
void setFallbackSymbolsFontName(const QString& name);
|
||||
/** \brief finds actual fonts for some predefined special font names, as listed in \ref JKQTMathTextFontSpecifier_specialNames */
|
||||
static QString transformFontName(const QString& fontName);
|
||||
static QString transformFontName(const QString& fontName, bool mathmode=false);
|
||||
/** \brief same as transformFontName(), but also finds the actual name for XITS, STIX, ASANA,... */
|
||||
static QString transformFontNameAndDecodeSpecialFonts(const QString& fontName);
|
||||
static QString transformFontNameAndDecodeSpecialFonts(const QString& fontName, bool mathmode=false);
|
||||
/** \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;
|
||||
/** \brief leiefert \c true, wenn ein fallbcakSymbolsFontName() verfügbar ist */
|
||||
bool hasFallbcakSymbolFontName() const;
|
||||
|
||||
/** \brief initialize with the font-families from the XITS package for text and math */
|
||||
static JKQTMathTextFontSpecifier getXITSFamilies();
|
||||
@ -118,6 +138,10 @@ private:
|
||||
QString m_fontName;
|
||||
/** \brief specifies the math font to use in addition to fontName */
|
||||
QString m_mathFontName;
|
||||
/** \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;
|
||||
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user