diff --git a/doc/dox/jkqtmathtext_supportedlatex.dox b/doc/dox/jkqtmathtext_supportedlatex.dox
index dce5b5433f..0677471e9c 100644
--- a/doc/dox/jkqtmathtext_supportedlatex.dox
+++ b/doc/dox/jkqtmathtext_supportedlatex.dox
@@ -34,7 +34,12 @@
- \c \\textfrak{...} \c \\mathfrak{...} : draw the contained text in fraktur font face \image html jkqtmathtext/jkqtmathtext_frak.png
- \c \\textscript{...} \c \\mathscript{...} : draw the contained text in script font face \image html jkqtmathtext/jkqtmathtext_script.png
- \c \\textbb{...} \c \\mathbb{...} : draw the contained text in blackboard font face \image html jkqtmathtext/jkqtmathtext_bb.png
- The class JKQTMathText also supports simulating blackboard fonts, if they are not available as an actual font on the system. Then the example would look like this: \image html jkqtmathtext/jkqtmathtext_bb_sim.png
+ Blackboard fonts are not widely available on target systems (viable fonts are e.g. "Double Stroke", "CloisterOpenFace BT", "GoudyHandtooled BT", "Castellar", "MathJax_AMS", "Castellar Standard", "MathJax_AMS Standard", "Colonna MT"
). But the most important blackboard characters are usually available in the higher unicode codepoints of Fonts specialized for math (e.g. XIST, STIX, ASANA). Therefore JKQTMathText supports using these characters, or simulating a blackboard font in addition to using one of the fonts above. You can set that by setting JKQTMathText::setFontBlackboradMode() with one of the options from JKQTMathTextBlackboradDrawingMode:
+ - MTBBDMfontDirectly: use a blackboard font specified by JKQTMathText::setFontBlackboard() \image html jkqtmathtext/jkqtmathtext_bb_font_directly.png using \c JKQTMathText::setFontBlackboard("Castellar")
+ - MTBBDMsimulate: \image html jkqtmathtext/jkqtmathtext_bb_simulate.png using \c JKQTMathText::setFontBlackboard("Arial")
+ - MTBBDMunicodeCharactersOrFontDirectly: \image html jkqtmathtext/jkqtmathtext_bb_unicode_or_font_directly.png using \c JKQTMathText::setFontBlackboard("Castellar")
+ - MTBBDMunicodeCharactersOrSimulate: \image html jkqtmathtext/jkqtmathtext_bb_unicode_or_simulate.png using \c JKQTMathText::setFontBlackboard("Arial")
+ .
- \c \\script{...} \c \\textscript{...} \c \\mathscript{...} : draw the contained text in a script font face \image html jkqtmathtext/jkqtmathtext_fonts.png
- \c \\sc{...} : draw the text in small caps \image html jkqtmathtext/jkqtmathtext_sc.png
- \c \\ul{...} \c \\underline{...} \c \\underlined{...} : draw the text with underlining \image html jkqtmathtext/jkqtmathtext_ul.png
diff --git a/doc/dox/whatsnew.dox b/doc/dox/whatsnew.dox
index 1c0fe11cf1..3d90084b72 100644
--- a/doc/dox/whatsnew.dox
+++ b/doc/dox/whatsnew.dox
@@ -53,6 +53,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
IMPROVED/NEW/breaking: refactored LaTeX parser in JKQTMathText
REMOVED/breaking: \c \\v[a-zA-Z] and shorthand for \c \\vec{a-zA-Z} was removed, implementation of \c \\bbR,\c \\bbC,... changed
IMPROVED/REWORKED rendering of text in text- and math-mode. Now it is more consistent with the output of LaTeX itself
+ IMPROVED/REWORKED rendering of blackboard font: now several different rendering modes can be selected using JKQTMathText::setFontBlackboradMode()
BREAKING/REWORKED: The \\verb!...!-command now works the same as in LaTeX
NEW: now supports new decoration instructions: \c \\cancel, \c \\xcancel, \c \\bcancel, \c \\sout, \c \\ocirc, \c \\widetilde, \c \\widehat, \c \\breve
NEW: reworked drawing of decorations: improved appearance and positioning!
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_bb.png b/doc/images/jkqtmathtext/jkqtmathtext_bb.png
index c34b4b41fd..282917bff6 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_bb.png and b/doc/images/jkqtmathtext/jkqtmathtext_bb.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_bb_font_directly.png b/doc/images/jkqtmathtext/jkqtmathtext_bb_font_directly.png
new file mode 100644
index 0000000000..096cfa7de0
Binary files /dev/null and b/doc/images/jkqtmathtext/jkqtmathtext_bb_font_directly.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_bb_sim.png b/doc/images/jkqtmathtext/jkqtmathtext_bb_sim.png
deleted file mode 100644
index 9754055af1..0000000000
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_bb_sim.png and /dev/null differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_bb_simulate.png b/doc/images/jkqtmathtext/jkqtmathtext_bb_simulate.png
new file mode 100644
index 0000000000..67ab273425
Binary files /dev/null and b/doc/images/jkqtmathtext/jkqtmathtext_bb_simulate.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_bb_unicode_or_font_directly.png b/doc/images/jkqtmathtext/jkqtmathtext_bb_unicode_or_font_directly.png
new file mode 100644
index 0000000000..34dc467f01
Binary files /dev/null and b/doc/images/jkqtmathtext/jkqtmathtext_bb_unicode_or_font_directly.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_bb_unicode_or_simulate.png b/doc/images/jkqtmathtext/jkqtmathtext_bb_unicode_or_simulate.png
new file mode 100644
index 0000000000..736e264277
Binary files /dev/null and b/doc/images/jkqtmathtext/jkqtmathtext_bb_unicode_or_simulate.png differ
diff --git a/doc/jkqtmathtext_docimages_formating.jkmt b/doc/jkqtmathtext_docimages_formating.jkmt
index 85f3301f31..3a4c0594f1 100644
--- a/doc/jkqtmathtext_docimages_formating.jkmt
+++ b/doc/jkqtmathtext_docimages_formating.jkmt
@@ -21,11 +21,24 @@ jkqtmathtext_script.png
{\backslash}textscript: \textscript{Script text}\ \ \ \ \ {\backslash}mathscript: $\mathscript{L}=T-V$
---
jkqtmathtext_bb.png
-{\backslash}mathbb: $x\in\mathbb{R}, z\in\mathbb{C}$\ \ \ \ \ {\backslash}textbb: \textbb{Blackboard text}
+--fontblackboard=Arial --fontblackboardmode=default
+{\backslash}mathbb: $x\in\mathbb{R}, z\in\mathbb{C}, \mathbb{1, \pi}$\ \ \ \ \ {\backslash}textbb: \textbb{Blackboard text! 123 \pi \"A\"o}
---
-jkqtmathtext_bb_sim.png
---fontblackboardsimulated=XITS Math
-{\backslash}mathbb: $x\in\mathbb{R}, z\in\mathbb{C}$\ \ \ \ \ {\backslash}textbb: \textbb{Blackboard text}
+jkqtmathtext_bb_font_directly.png
+--fontblackboardmode=font_directly
+{\backslash}mathbb: $x\in\mathbb{R}, z\in\mathbb{C}, \mathbb{1, \pi}$\ \ \ \ \ {\backslash}textbb: \textbb{Blackboard text! 123 \pi \"A\"o}
+---
+jkqtmathtext_bb_simulate.png
+--fontblackboard=Arial --fontblackboardmode=simulate
+{\backslash}mathbb: $x\in\mathbb{R}, z\in\mathbb{C}, \mathbb{1, \pi}$\ \ \ \ \ {\backslash}textbb: \textbb{Blackboard text! 123 \pi \"A\"o}
+---
+jkqtmathtext_bb_unicode_or_font_directly.png
+--fontblackboardmode=unicode_or_font_directly
+{\backslash}mathbb: $x\in\mathbb{R}, z\in\mathbb{C}, \mathbb{1, \pi}$\ \ \ \ \ {\backslash}textbb: \textbb{Blackboard text! 123 \pi \"A\"o}
+---
+jkqtmathtext_bb_unicode_or_simulate.png
+--fontblackboard=Arial --fontblackboardmode=unicode_or_simulate
+{\backslash}mathbb: $x\in\mathbb{R}, z\in\mathbb{C}, \mathbb{1, \pi}$\ \ \ \ \ {\backslash}textbb: \textbb{Blackboard text! 123 \pi \"A\"o}
---
jkqtmathtext_ol.png
{\backslash}ol: \ol{overlined text}
diff --git a/examples/jkqtmathtext_test/testform.cpp b/examples/jkqtmathtext_test/testform.cpp
index 42127e9240..dbdd86436b 100644
--- a/examples/jkqtmathtext_test/testform.cpp
+++ b/examples/jkqtmathtext_test/testform.cpp
@@ -283,7 +283,7 @@ TestForm::TestForm(QWidget *parent) :
ui->cmbEncodingBlackboard->setCurrentIndex(static_cast(mt.getFontEncodingBlackboard()));
ui->cmbUnicodeSymbol->setCurrentFont(QFont(mt.getFallbackFontSymbols()));
ui->cmbEncodingSymbol->setCurrentIndex(static_cast(mt.getFontEncodingFallbackFontSymbols()));
- ui->chkSimulateBlackboard->setChecked(mt.isFontBlackboardSimulated());
+ ui->cmdBlackboradMode->setCurrentText(JKQTMathTextBlackboradDrawingMode2String(mt.getFontBlackboradMode()));
@@ -297,7 +297,7 @@ TestForm::TestForm(QWidget *parent) :
connect(ui->chkBigBox, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
connect(ui->chkAntiAlias, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
connect(ui->chkAntiAliasText, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
- connect(ui->chkSimulateBlackboard, SIGNAL(toggled(bool)), this, SLOT(updateMath()));
+ connect(ui->cmdBlackboradMode, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
connect(ui->cmbLastAlign, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
connect(ui->cmbFont, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
connect(ui->cmbScript, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
@@ -446,7 +446,7 @@ QString TestForm::getFonts(const JKQTMathText& mt) const
str<<"Script: "<chkSimulateBlackboard->isChecked());
+ mt.setFontBlackboradMode(String2JKQTMathTextBlackboradDrawingMode(ui->cmdBlackboradMode->currentText()));
if (ui->cmbFont->currentIndex()==1) qDebug()<<"useXITS: "<cmbFont->currentIndex()==2) qDebug()<<"useSTIX: "<
- -
-
-
- simulate blackboard
-
-
-
-
@@ -528,6 +521,38 @@
+ -
+
+
+ 0
+
+
-
+
+ unicode_or_font_directly
+
+
+ -
+
+ unicode_or_simulate
+
+
+ -
+
+ font_directly
+
+
+ -
+
+ simulate
+
+
+ -
+
+ default
+
+
+
+
-
diff --git a/lib/jkqtcommon/jkqtpstringtools.h b/lib/jkqtcommon/jkqtpstringtools.h
index 7fd0a8f096..f93dbefab1 100644
--- a/lib/jkqtcommon/jkqtpstringtools.h
+++ b/lib/jkqtcommon/jkqtpstringtools.h
@@ -55,6 +55,11 @@ JKQTCOMMON_LIB_EXPORT Qt::BrushStyle jkqtp_String2QBrushStyle(const QString& sty
*/
JKQTCOMMON_LIB_EXPORT std::string jkqtp_UnicodeToUTF8(uint32_t codepoint);
+/** \copydoc jkqtp_UnicodeToUTF8() */
+inline QString jkqtp_UnicodeToUTF8Q(uint32_t codepoint) {
+ return QString::fromStdString(jkqtp_UnicodeToUTF8(codepoint));
+}
+
/** \brief convert a double to a string, using the loacle "C"
* \ingroup jkqtptools_string
*/
diff --git a/lib/jkqtmathtext/jkqtmathtext.cpp b/lib/jkqtmathtext/jkqtmathtext.cpp
index 3a4573b1b3..728e39c0f0 100644
--- a/lib/jkqtmathtext/jkqtmathtext.cpp
+++ b/lib/jkqtmathtext/jkqtmathtext.cpp
@@ -99,7 +99,7 @@ JKQTMathText::JKQTMathText(QObject* parent):
sqrt_height_factor=1.2;
sqrt_smallfont_factor=0.57;
- blackboardSimulated=true;
+ blackboradFontMode=MTBBDMdefault;
static QString serifFont="serif";
@@ -166,8 +166,10 @@ JKQTMathText::JKQTMathText(QObject* parent):
setFontCaligraphic(decorativeFont, estimateJKQTMathTextFontEncoding(decorativeFont));
if (blackboardFont!="blackboard") {
setFontBlackboard(blackboardFont, estimateJKQTMathTextFontEncoding(blackboardFont));
+ setFontBlackboradMode(MTBBDMunicodeCharactersOrFontDirectly);
} else {
- setFontBlackboardSimulated(blackboardFont=="blackboard");
+ setFontBlackboard(sansFont, estimateJKQTMathTextFontEncoding(sansFont));
+ setFontBlackboradMode(MTBBDMunicodeCharactersOrSimulate);
}
setFontScript(scriptFont, estimateJKQTMathTextFontEncoding(scriptFont));
setFontFraktur(fracturFont, estimateJKQTMathTextFontEncoding(fracturFont));
@@ -638,20 +640,19 @@ JKQTMathTextFontEncoding JKQTMathText::getFontEncodingMathRoman() const
void JKQTMathText::setFontBlackboard(const QString &__value, JKQTMathTextFontEncoding encoding)
{
- blackboardSimulated=false;
auto f=getReplacementFont(__value, __value, encoding);
fontDefinitions[MTEblackboard].fontName = f.first;
fontDefinitions[MTEblackboard].fontEncoding = f.second;
}
-void JKQTMathText::setFontBlackboardSimulated(bool doSimulate)
+JKQTMathTextBlackboradDrawingMode JKQTMathText::getFontBlackboradMode() const
{
- blackboardSimulated=doSimulate;
+ return blackboradFontMode;
}
-bool JKQTMathText::isFontBlackboardSimulated() const
+void JKQTMathText::setFontBlackboradMode(JKQTMathTextBlackboradDrawingMode mode)
{
- return blackboardSimulated;
+ blackboradFontMode=mode;
}
QString JKQTMathText::getFontBlackboard() const
diff --git a/lib/jkqtmathtext/jkqtmathtext.h b/lib/jkqtmathtext/jkqtmathtext.h
index efc845ae8b..7aed476aca 100644
--- a/lib/jkqtmathtext/jkqtmathtext.h
+++ b/lib/jkqtmathtext/jkqtmathtext.h
@@ -373,11 +373,12 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
*
*/
void setFontBlackboard(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
- /** \copydoc blackboardSimulated */
- void setFontBlackboardSimulated(bool doSimulate);
- /** \copydoc blackboardSimulated \see setFontBlackboardSimulated() */
- bool isFontBlackboardSimulated() const;
- /** \brief retrieves the font to be used for text in the logical font MTEblackboard \see setFontBlackboardSimulated() */
+ /** \copydoc blackboradFontMode */
+ JKQTMathTextBlackboradDrawingMode getFontBlackboradMode() const;
+ /** \copydoc blackboradFontMode */
+ void setFontBlackboradMode(JKQTMathTextBlackboradDrawingMode mode);
+
+ /** \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 */
void setFallbackFontSymbols(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard);
@@ -635,17 +636,26 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
/** \brief stores information about the different fonts used by LaTeX markup */
QHash fontDefinitions;
- /** \brief if enabled, the blackboard-characters are simulated by using font outlines only
+
+ /** \brief specifies how to draw blackboard font characters (i.e. \c \\mathbb{N} )
*
- * A possible choice for a blackboard font (Castellar) looks like this:
- * \image html jkqtmathtext/jkqtmathtext_bb.png
- * If such a font is not available, you can set this property blackboardSimulated
- * to \c true and chose a font, like e.g. Arial to output blackboard-letters as:
- * \image html jkqtmathtext/jkqtmathtext_bb_sim.png
+ * Blackboard fonts are not widely available on target systems (viable fonts are e.g.
+ *
"Double Stroke", "CloisterOpenFace BT", "GoudyHandtooled BT", "Castellar", "MathJax_AMS", "Castellar Standard", "MathJax_AMS Standard", "Colonna MT"
).
+ * But the most important blackboard characters are usually available in the higher unicode
+ * codepoints of Fonts specialized for math (e.g. XIST, STIX, ASANA).
*
- * \see setFontBlackboard() setFontBlackboardSimulated()
+ * Therefore JKQTMathText supports using these characters, or simulating a blackboard font in
+ * addition to using one of the fonts above. You can set that by setting
+ * JKQTMathText::setFontBlackboradMode() with one of the options from JKQTMathTextBlackboradDrawingMode:
+ * - MTBBDMfontDirectly: use a blackboard font specified by JKQTMathText::setFontBlackboard() \image html jkqtmathtext/jkqtmathtext_bb_font_directly.png using \c JKQTMathText::setFontBlackboard("Castellar")
+ * - MTBBDMsimulate: \image html jkqtmathtext/jkqtmathtext_bb_simulate.png using \c JKQTMathText::setFontBlackboard("Arial")
+ * - MTBBDMunicodeCharactersOrFontDirectly: \image html jkqtmathtext/jkqtmathtext_bb_unicode_or_font_directly.png using \c JKQTMathText::setFontBlackboard("Castellar")
+ * - MTBBDMunicodeCharactersOrSimulate: \image html jkqtmathtext/jkqtmathtext_bb_unicode_or_simulate.png using \c JKQTMathText::setFontBlackboard("Arial")
+ * .
+ *
+ * \see setFontBlackboard() setBlackboardFontMode()
*/
- bool blackboardSimulated;
+ JKQTMathTextBlackboradDrawingMode blackboradFontMode;
/** \brief resizing factor for braces in math mode */
diff --git a/lib/jkqtmathtext/jkqtmathtexttools.cpp b/lib/jkqtmathtext/jkqtmathtexttools.cpp
index 124c0558dc..369414846a 100644
--- a/lib/jkqtmathtext/jkqtmathtexttools.cpp
+++ b/lib/jkqtmathtext/jkqtmathtexttools.cpp
@@ -548,6 +548,19 @@ QFont JKQTMathTextEnvironment::getFont(JKQTMathText* parent) const {
return f;
}
+JKQTMathTextEnvironment JKQTMathTextEnvironment::exchangedFontForRoman() const
+{
+ if (insideMath) return exchangedFontFor(MTEmathRoman);
+ else return exchangedFontFor(MTEroman);
+}
+
+JKQTMathTextEnvironment JKQTMathTextEnvironment::exchangedFontFor(JKQTMathTextEnvironmentFont font) const
+{
+ JKQTMathTextEnvironment newEnv=*this;
+ newEnv.font=font;
+ return newEnv;
+}
+
QString JKQTMathTextEnvironment::toHtmlStart(JKQTMathTextEnvironment defaultEv, JKQTMathText* parentMathText) const {
QString s;
if (fontSizeUnit==POINTS) s=s+"font-size: "+QLocale::c().toString(fontSize)+"pt; ";
@@ -845,3 +858,37 @@ JKQTMathTextVerticalOrientation String2JKQTMathTextVerticalOrientation(QString t
if (tokenName=="c" || tokenName=="center" || tokenName=="centered") return MTVOCentered;
return MTVOCentered;
}
+
+QString JKQTMathTextBlackboradDrawingMode2String(JKQTMathTextBlackboradDrawingMode mode)
+{
+ switch(mode) {
+ case MTBBDMfontDirectly: return "font_directly";
+ case MTBBDMsimulate: return "simulate";
+ case MTBBDMunicodeCharactersOrFontDirectly: return "unicode_or_font_directly";
+ case MTBBDMunicodeCharactersOrSimulate: return "unicode_or_simulate";
+ }
+ return "font_directly";
+}
+
+
+JKQTMathTextBlackboradDrawingMode String2JKQTMathTextBlackboradDrawingMode(QString mode)
+{
+ mode=mode.toLower().simplified().trimmed();
+ if (mode=="font_directly" || mode=="font" || mode=="directly") return MTBBDMfontDirectly;
+ if (mode=="simulate") return MTBBDMsimulate;
+ if (mode=="unicode_or_font_directly" || mode=="unicode_or_font" || mode=="unicode_or_directly") return MTBBDMunicodeCharactersOrFontDirectly;
+ if (mode=="unicode_or_simulate") return MTBBDMunicodeCharactersOrSimulate;
+ if (mode=="default") return MTBBDMdefault;
+ return MTBBDMdefault;
+}
+
+void JKQTMathTextDrawStringSimBlackboard(QPainter &painter, const QFont &f, const QColor& color, double x, double y, const QString &txt)
+{
+ const QFontMetricsF fm(f, painter.device());
+ const QPen p(color, fm.lineWidth()/4.0, Qt::SolidLine);
+ painter.setPen(p);
+ QPainterPath path;
+ path.addText(QPointF(x, y), f, txt);
+ path.addText(QPointF(x+fm.lineWidth()/2.0, y), f, txt);
+ painter.drawPath(path);
+}
diff --git a/lib/jkqtmathtext/jkqtmathtexttools.h b/lib/jkqtmathtext/jkqtmathtexttools.h
index 265a0c4d04..c3b97dd67a 100644
--- a/lib/jkqtmathtext/jkqtmathtexttools.h
+++ b/lib/jkqtmathtext/jkqtmathtexttools.h
@@ -139,6 +139,31 @@ enum JKQTMathTextFontEncoding {
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextFontEncoding estimateJKQTMathTextFontEncoding(QFont font);
+/** \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);
+
+
/** \brief convert MTfontEncoding to a string
* \ingroup jkqtmathtext_tools
@@ -277,6 +302,10 @@ struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEnvironment {
/** \brief build a QFont object from the settings in this object */
QFont getFont(JKQTMathText* parent) const;
+ /** \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;
/** \brief return the encoding of the given Font */
JKQTMathTextFontEncoding getFontEncoding(JKQTMathText *parent) const;
/** \brief generate a HTML prefix that formats the text after it according to the settings in this object
@@ -364,6 +393,14 @@ JKQTMATHTEXT_LIB_EXPORT QPainterPath JKQTMathTextMakeArrow(double x, double y, d
*/
JKQTMATHTEXT_LIB_EXPORT QPainterPath JKQTMathTextMakeDArrow(double x, double y, double width, double arrowW, bool left=false, bool right=true);
+/** \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);
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextTBRData {
explicit JKQTMathTextTBRData(const QFont& f, const QString& text, QPaintDevice *pd);
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp
index 22282745df..8d5a4adebb 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp
@@ -54,26 +54,8 @@ QString JKQTMathTextTextBaseNode::getText() const
return text;
}
-void JKQTMathTextTextBaseNode::drawString(QPainter &painter, const JKQTMathTextEnvironment ¤tEv, double x, double y, const QString &txt) const {
- const QFont f=currentEv.getFont(parentMathText);
- drawString(painter, currentEv, f, x, y, txt);
-}
-void JKQTMathTextTextBaseNode::drawString(QPainter &painter, const JKQTMathTextEnvironment ¤tEv, const QFont &f, double x, double y, const QString &txt) const
-{
- const QFontMetricsF fm(f, painter.device());
- const QPen p(currentEv.color, fm.lineWidth()/2.0, Qt::SolidLine);
- painter.setPen(p);
- if (currentEv.font==MTEblackboard && parentMathText->isFontBlackboardSimulated()) {
- QPainterPath path;
- path.addText(QPointF(x, y), f, txt);
- path.addText(QPointF(x+fm.lineWidth()/2.0, y), f, txt);
- painter.drawPath(path);
- } else {
- painter.setFont(f);
- painter.drawText(QPointF(x, y), txt);
- }
-}
+
QString JKQTMathTextTextBaseNode::textTransform(const QString &text, const JKQTMathTextEnvironment &/*currentEv*/) const
{
@@ -91,10 +73,34 @@ bool JKQTMathTextTextBaseNode::toHtml(QString &html, JKQTMathTextEnvironment cur
+QHash JKQTMathTextTextNode::blackboardUnicodeTable=QHash();
+
+void JKQTMathTextTextNode::fillStaticTables() {
+ if (blackboardUnicodeTable.size()>0) return;
+
+ blackboardUnicodeTable['C']=0x2102;
+ blackboardUnicodeTable['H']=0x210D;
+ blackboardUnicodeTable['N']=0x2115;
+ blackboardUnicodeTable['P']=0x2119;
+ blackboardUnicodeTable['Q']=0x211A;
+ blackboardUnicodeTable['R']=0x211D;
+ blackboardUnicodeTable['Z']=0x2124;
+
+ for (const QChar ch: QString("ABDEFGIJKLMOSTUVWXYZ")) {
+ blackboardUnicodeTable[ch]=0x1D538+(ch.unicode()-QChar('A').unicode());
+ }
+ for (const QChar ch: QString("abcdefghijklmnopqrstuvwxyz")) {
+ blackboardUnicodeTable[ch]=0x1D552+(ch.unicode()-QChar('a').unicode());
+ }
+ for (const QChar ch: QString("0123456789")) {
+ blackboardUnicodeTable[ch]=0x1D7D8+(ch.unicode()-QChar('0').unicode());
+ }
+}
JKQTMathTextTextNode::JKQTMathTextTextNode(JKQTMathText* _parent, const QString& textIn, bool addWhitespace, bool stripInnerWhitepace):
JKQTMathTextTextBaseNode(_parent, "")
{
+ fillStaticTables();
QString textTransformed=textIn;
if (stripInnerWhitepace) {
@@ -117,28 +123,26 @@ JKQTMathTextTextNode::~JKQTMathTextTextNode() = default;
void JKQTMathTextTextNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
QStringList textpart;
- QList fontForcedUpright;
+ QList fontMode;
QList textpartXPos;
- getSizeInternalAndData(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos,textpart, fontForcedUpright, textpartXPos);
+ getSizeInternalAndData(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos,textpart, fontMode, textpartXPos);
}
-void JKQTMathTextTextNode::getSizeInternalAndData(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos, QStringList &textpart, QList &fontForcedUpright, QList &textpartXPos)
+void JKQTMathTextTextNode::getSizeInternalAndData(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos, QStringList &textpart, QList &fontMode, QList &textpartXPos)
{
textpart.clear();
- fontForcedUpright.clear();
+ fontMode.clear();
const QString txt=textTransform(text, currentEv);
- if (currentEv.insideMath && currentEv.insideMathForceDigitsUpright) {
- splitTextForMathMode(txt, textpart, fontForcedUpright);
- } else {
- textpart.append(text);
- fontForcedUpright.append(false);
- }
-
+ splitTextForLayout(painter, currentEv, txt, textpart, fontMode);
const QFont f=currentEv.getFont(parentMathText);
- const QFont fnonItalic=JKQTMathTextGetNonItalic(f);
- const QFontMetricsF fmNonItalic(fnonItalic, painter.device());
+ const QFont fUpright=JKQTMathTextGetNonItalic(f);
+ const QFont fFallbackSym=currentEv.exchangedFontFor(MTEFallbackSymbols).getFont(parentMathText);
+ const QFont fRoman=currentEv.exchangedFontForRoman().getFont(parentMathText);
+ const QFontMetricsF fmUpright(fUpright, painter.device());
const QFontMetricsF fm(f, painter.device());
+ const QFontMetricsF fmFallbackSym(fFallbackSym, painter.device());
+ const QFontMetricsF fmRoman(fRoman, painter.device());
#if (QT_VERSION>=QT_VERSION_CHECK(5, 15, 0))
const double sp=fm.horizontalAdvance(' ');
#else
@@ -148,8 +152,26 @@ void JKQTMathTextTextNode::getSizeInternalAndData(QPainter &painter, JKQTMathTex
double ascent=0;
double descent=0;
for (int i=0; i0 && textpart[i].at(textpart[i].size()-1).isSpace()) {
@@ -166,7 +188,7 @@ void JKQTMathTextTextNode::getSizeInternalAndData(QPainter &painter, JKQTMathTex
strikeoutPos=fm.strikeOutPos();
}
-void JKQTMathTextTextNode::splitTextForMathMode(const QString &txt, QStringList &textpart, QList &fontForcedUpright)
+void JKQTMathTextTextNode::splitTextForLayout(QPainter &painter, JKQTMathTextEnvironment currentEv, const QString &txt, QStringList &textpart, QList &fontMode) const
{
auto isForcedUprightChar=[](const QChar& c) {
return c.isDigit()
@@ -174,37 +196,82 @@ void JKQTMathTextTextNode::splitTextForMathMode(const QString &txt, QStringList
|| c==QChar(0x2329) || c==QChar(0x232A) || c==QChar(0x2308) || c==QChar(0x2309) || c==QChar(0x230A) || c==QChar(0x230B);
};
+ //const QFont f=currentEv.getFont(parentMathText);
+ //const QFont fUpright=JKQTMathTextGetNonItalic(f);
+ const QFont fFallbackSym=currentEv.exchangedFontFor(MTEFallbackSymbols).getFont(parentMathText);
+ const QFont fRoman=currentEv.exchangedFontForRoman().getFont(parentMathText);
+ //const QFontMetricsF fm(f, painter.device());
+ //const QFontMetricsF fmUpright(fUpright, painter.device());
+ const QFontMetricsF fmFallbackSym(fFallbackSym, painter.device());
+ const QFontMetricsF fmRoman(fRoman, painter.device());
+ const JKQTMathTextBlackboradDrawingMode bbMode=parentMathText->getFontBlackboradMode();
+
textpart.clear();
- fontForcedUpright.clear();
+ fontMode.clear();
QString currentSection="";
- bool currentSectionForcedUpright=false;
+ FontMode currentSectionFontMode=FMasDefined;
int i=0;
while (i0) {
textpart.append(currentSection);
- fontForcedUpright.append(currentSectionForcedUpright);
+ fontMode.append(currentSectionFontMode);
}
}
@@ -215,25 +282,49 @@ double JKQTMathTextTextNode::draw(QPainter& painter, double x, double y, JKQTMat
double overallHeight=0;
double sp=0;
QStringList textpart;
- QList fontForcedUpright;
QList textpartXPos;
- getSizeInternalAndData(painter, currentEv, width, baselineHeight, overallHeight, sp, textpart, fontForcedUpright, textpartXPos);
+ QList fontMode;
+ getSizeInternalAndData(painter, currentEv, width, baselineHeight, overallHeight, sp, textpart, fontMode, textpartXPos);
const QFont f=currentEv.getFont(parentMathText);
- const QFont fnonItalic=JKQTMathTextGetNonItalic(f);
+ const QFont fUpright=JKQTMathTextGetNonItalic(f);
+ const QFont fFallbackSym=currentEv.exchangedFontFor(MTEFallbackSymbols).getFont(parentMathText);
+ const QFont fRoman=currentEv.exchangedFontForRoman().getFont(parentMathText);
const QFontMetricsF fm(f, painter.device());
- const QFontMetricsF fmNonItalic(fnonItalic, painter.device());
+ const QFontMetricsF fmUpright(fUpright, painter.device());
+ const QFontMetricsF fmFallbackSym(fFallbackSym, painter.device());
+ const QFontMetricsF fmRoman(fRoman, painter.device());
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
painter.setFont(f);
+ painter.setPen(currentEv.color);
//qDebug()<<"JKQTMathTextTextNode: text="<& fontForcedUpright);
- /** \brief transforms the \a text before sizing/drawing (may e.g. exchange special letters for other unicode symbols etc.) */
+ void getSizeInternalAndData(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, QStringList& textpart, QList& fontMode, QList& textpartXPos) ;
+ /** \brief split text for Math-Modelayout into sections, where each section has a defined way of output
+ *
+ * \param painter the QPainter to use for sizing/drawing
+ * \param currentEv the environment that defines the formatting of the text
+ * \param txt the text to split up
+ * \param[out] textpart the input \A txt split up into sections
+ * \param[out] fontMode formating of each section in \a textpart
+ */
+ void splitTextForLayout(QPainter &painter, JKQTMathTextEnvironment currentEv, const QString& txt, QStringList& textpart, QList& fontMode) const;
+ /** \brief translation table for blackboard-font characters from "normal" Latin-1 encoding to unicode-encoding of blackboards */
+ static QHash blackboardUnicodeTable;
+ /** \brief fill static data */
+ static void fillStaticTables();
+ /** \copydoc JKQTMathTextTextBaseNode::textTransform() */
virtual QString textTransform(const QString& text, const JKQTMathTextEnvironment& currentEv) const override;
};
diff --git a/tools/jkqtmathtext_render/README.md b/tools/jkqtmathtext_render/README.md
index 3bd8c4c537..70f174562a 100644
--- a/tools/jkqtmathtext_render/README.md
+++ b/tools/jkqtmathtext_render/README.md
@@ -68,7 +68,7 @@ The tool supports these command-line options:
- `--fontmathroman=FONT`: set the math-mode roman font
- `--fontmathsans=FONT`: set the math-mode sans font
- `--fontblackboard=FONT`: use the given font as blackboard-font and de-activate the simulate-feature
- - `--fontblackboardsimulated=FONT`: use the given font as blackboard-font and activate the simulate-feature
+ - `--fontblackboardmode=default|font_directly|simulate|unicode_or_font_directly|unicode_or_simulate`: use the given drawing mode for blackboard fonts
- `--fonttypewriter=FONT`: set the typewriter font
- `--fontscript=FONT`: set the script font
- `--fontcaligraphic=FONT`: set the caligraphic font
diff --git a/tools/jkqtmathtext_render/jkqtmathtext_render.cpp b/tools/jkqtmathtext_render/jkqtmathtext_render.cpp
index a8cff0df2a..fab81afd9d 100644
--- a/tools/jkqtmathtext_render/jkqtmathtext_render.cpp
+++ b/tools/jkqtmathtext_render/jkqtmathtext_render.cpp
@@ -69,7 +69,7 @@ int main(int argc, char* argv[])
parser.addOption(outputDirectoryOption);
QCommandLineOption listsymbolsOption("listsymbols", "list all symbols in the given output file and generate images.", "listsymbols", "");
parser.addOption(listsymbolsOption);
- QCommandLineOption drawBoxesOption("drawboxes", "draw boxes.");
+ QCommandLineOption drawBoxesOption(QStringList()<<"drawboxes"<<"showboxes", "draw boxes.");
parser.addOption(drawBoxesOption);
QCommandLineOption verboseOption("verbose", "verbose output.");
parser.addOption(verboseOption);
@@ -77,8 +77,6 @@ int main(int argc, char* argv[])
parser.addOption(fontOption);
QCommandLineOption fontsizeOption("fontsize", "font size.", "fontsize", "12");
parser.addOption(fontsizeOption);
- QCommandLineOption fontBlackboardSimOption("fontblackboardsimulated", "set the blackboard font and activate simulated-mode.", "fontblackboardsimulated", "");
- parser.addOption(fontBlackboardSimOption);
QCommandLineOption fontRomanOption("fontroman", "set the text-mode roman font to use.", "fontroman", "");
parser.addOption(fontRomanOption);
QCommandLineOption fontSansOption("fontsans", "set the text-mode sans font to use.", "fontsans", "");
@@ -101,6 +99,8 @@ int main(int argc, char* argv[])
parser.addOption(fontcaligraphicOption);
QCommandLineOption fontblackboardOption("fontblackboard", "set the blackboard font to use.", "fontblackboard", "");
parser.addOption(fontblackboardOption);
+ QCommandLineOption fontblackboardmodeOption("fontblackboardmode", "set the usage mode for the blackboard font.", "fontblackboardmode", "default");
+ parser.addOption(fontblackboardmodeOption);
QCommandLineOption textcolorOption("textcolor", "set the color of the text.", "textcolor", "black");
parser.addOption(textcolorOption);
QCommandLineOption sizeincreaseOption("sizeincrease", "additional pixels around output.", "sizeincrease", "2");
@@ -260,7 +260,6 @@ int main(int argc, char* argv[])
int resolution_dpi = parser.value(resolutionOption).toInt();
QColor backgroundColor = jkqtp_String2QColor(parser.value(backgroundOption));
QColor textColor = jkqtp_String2QColor(parser.value(textcolorOption));
- QString fontBlackboardSim = parser.value(fontBlackboardSimOption);
QString fontBlackboard=parser.value(fontblackboardOption);
QString fontRoman=parser.value(fontRomanOption);
QString fontSans=parser.value(fontSansOption);
@@ -272,15 +271,15 @@ int main(int argc, char* argv[])
QString fontScript=parser.value(fontScriptOption);
QString fontFraktur=parser.value(fontFrakturOption);
QString fontCaligraphic=parser.value(fontcaligraphicOption);
+ JKQTMathTextBlackboradDrawingMode fontBlackboardMode=String2JKQTMathTextBlackboradDrawingMode(parser.value(fontblackboardmodeOption));
if (cmdoptions[i].size()>0) {
for (const QString& key: cmdoptions[i].keys()) {
- if (key=="drawboxes") drawBoxes=true;
+ if (key=="drawboxes" || key=="showboxes") drawBoxes=true;
else if (key=="fontsize") fontsize=cmdoptions[i].value(key).toDouble();
else if (key=="sizeincrease") sizeincrease=cmdoptions[i].value(key).toInt();
else if (key=="background") backgroundColor=jkqtp_String2QColor(cmdoptions[i].value(key));
else if (key=="textcolor") textColor=jkqtp_String2QColor(cmdoptions[i].value(key));
- else if (key=="fontblackboardsimulated") fontBlackboardSim=cmdoptions[i].value(key);
else if (key=="fontblackboard") fontBlackboard=cmdoptions[i].value(key);
else if (key=="font") processFont(cmdoptions[i].value(key), fonts, mathFont);
else if (key=="fontroman") fontRoman=cmdoptions[i].value(key);
@@ -293,6 +292,10 @@ int main(int argc, char* argv[])
else if (key=="fontscript") fontScript=cmdoptions[i].value(key);
else if (key=="fontcaligraphic") fontCaligraphic=cmdoptions[i].value(key);
else if (key=="fontfraktur") fontFraktur=cmdoptions[i].value(key);
+ else if (key=="fontblackboardmode") fontBlackboardMode=String2JKQTMathTextBlackboradDrawingMode(cmdoptions[i].value(key));
+ else {
+ std::cerr<<"unknown command-line option --"<0) mathText.setFallbackFontSymbols(fontFallbackSymbol, MTFEUnicode);
if (fontFallbackSymbol_symbolencoding.size()>0) mathText.setFallbackFontSymbols(fontFallbackSymbol_symbolencoding, MTFEWinSymbol);
- if (fontBlackboardSim.size()>0) {
- mathText.setFontBlackboard(fontBlackboardSim, MTFEUnicode);
- mathText.setFontBlackboardSimulated(true);
- }
if (fontBlackboard.size()>0) {
mathText.setFontBlackboard(fontBlackboard, MTFEUnicode);
- mathText.setFontBlackboardSimulated(false);
}
+ mathText.setFontBlackboradMode(fontBlackboardMode);
mathText.setFontSize(fontsize);
mathText.setFontColor(textColor);