diff --git a/doc/dox/whatsnew.dox b/doc/dox/whatsnew.dox index 89d8fd5d6e..f8cf251afd 100644 --- a/doc/dox/whatsnew.dox +++ b/doc/dox/whatsnew.dox @@ -66,6 +66,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
  • NEW: added \c \\shaded{color}{...}
  • NEW: added \c \\acute{X}, \c \\grave{X}, \c \\acute{X}
  • NEW: added functions to set the font-size in pixels (as alternative to the existing functions that set them in points), implements request #76 from user:igormironchik
  • +
  • NEW: added \c \\userfont{SystemFontName}{Text}
  • diff --git a/doc/images/jkqtmathtext/jkqtmathtext_userfont.png b/doc/images/jkqtmathtext/jkqtmathtext_userfont.png new file mode 100644 index 0000000000..9a7fac561d Binary files /dev/null and b/doc/images/jkqtmathtext/jkqtmathtext_userfont.png differ diff --git a/examples/jkqtmathtext_test/testform.cpp b/examples/jkqtmathtext_test/testform.cpp index 38e90368e1..e6877c064c 100644 --- a/examples/jkqtmathtext_test/testform.cpp +++ b/examples/jkqtmathtext_test/testform.cpp @@ -64,8 +64,9 @@ TestForm::TestForm(QWidget *parent) : ui->cmbTestset->addItem("math: like in label at bottom", "$\\left(\\left[\\sqrt{2\\pi\\cdot\\int_{-\\infty}^\\infty f(x)\\;\\mathrm{d}x}\\right]\\right)$"); ui->cmbTestset->addItem("text: like in label at bottom)", "\\left(\\left[\\sqrt{2\\pi\\cdot\\int_{-\\infty}^\\infty f(x)\\;\\mathrm{d}x}\\right]\\right)"); ui->cmbTestset->addItem("text 0", "text"); - ui->cmbTestset->addItem("text 1", "text \\mathbf{bold}"); - ui->cmbTestset->addItem("text 2", "text \\mathbf{bold}\\textcolor{red}{RED}"); + ui->cmbTestset->addItem("text (bold)", "text \\mathbf{bold}"); + ui->cmbTestset->addItem("textcolor", "text \\mathbf{bold}\\textcolor{red}{RED}"); + ui->cmbTestset->addItem("userfont", "text, \\userfont{Arial}{Arial}, \\userfont{Comic Sans MS}{Comic Sans MS}"); const auto mathDecoExample=[](const QString& deco)->QString { return "\\"+deco+"{x}\\"+deco+"{i}\\"+deco+"{X}\\"+deco+"{\\psi}\\"+deco+"{abc}"; }; ui->cmbTestset->addItem("decoration: math", "$"+mathDecoExample("vec")+" -- "+mathDecoExample("grave")+" -- "+mathDecoExample("acute")+" -- "+mathDecoExample("dot")+" -- "+mathDecoExample("ddot")+" -- "+mathDecoExample("ocirc")+" -- "+mathDecoExample("overline")+" -- "+mathDecoExample("underline")+" -- "+mathDecoExample("hat")+" -- "+mathDecoExample("widehat")+" -- "+mathDecoExample("check")+" -- "+mathDecoExample("widecheck")+" -- "+mathDecoExample("breve")+" -- "+mathDecoExample("tilde")+" -- "+mathDecoExample("widetilde")+" -- "+mathDecoExample("uul")+" -- "+mathDecoExample("ool")+" -- "+mathDecoExample("bar")+" -- "+mathDecoExample("arrow")+" -- "+mathDecoExample("cancel")+" -- "+mathDecoExample("bcancel")+" -- "+mathDecoExample("xcancel")+" -- "+mathDecoExample("sout")+"$"); ui->cmbTestset->addItem("decoration: text", "Text \\ul{underlined Text Equator} -- \\ol{overlined Text Equator} -- \\sout{striked out Text Equator} -- \\cancel{canceled out Text Equator} -- \\bcancel{b-canceled out Text Equator} -- \\xcancel{x-canceled out Text Equator}"); diff --git a/lib/jkqtmathtext/jkqtmathtext.cpp b/lib/jkqtmathtext/jkqtmathtext.cpp index 3860a81dcc..719aac0bbd 100644 --- a/lib/jkqtmathtext/jkqtmathtext.cpp +++ b/lib/jkqtmathtext/jkqtmathtext.cpp @@ -1806,6 +1806,8 @@ JKQTMathTextNode* JKQTMathText::parseInstruction(bool *_foundError, bool* getNew } QStringList JKQTMathText::parseStringParams(bool get, size_t Nparams, bool *foundError) { + const bool old_parsingMathEnvironment=parsingMathEnvironment; + auto reset_parsingMathEnvironment=JKQTPFinally([&]() { parsingMathEnvironment=old_parsingMathEnvironment; }); if (*foundError) *foundError=false; if (Nparams<=0) return QStringList(); else { @@ -1813,24 +1815,21 @@ QStringList JKQTMathText::parseStringParams(bool get, size_t Nparams, bool *foun for (size_t n=0; n0 || (n==0 && get)) getToken(); if (currentToken==MTTopenbrace) { - getToken(); - if (currentToken==MTTtext) { - params.append(currentTokenName); - if (getToken()!=MTTclosebrace) { + bool ok=true; + QString thisparam=""; + while (ok) { + getToken(); + if (currentToken==MTTtext) { + thisparam+=currentTokenName; + } else if (currentToken==MTTwhitespace) { + thisparam+=" "; + } else if (currentToken==MTTclosebrace) { + params.append(thisparam); + ok=false; + } else { if (*foundError) *foundError=true; return params; } - } else if (currentToken==MTTwhitespace) { - params.append(" "); - if (getToken()!=MTTclosebrace) { - if (*foundError) *foundError=true; - return params; - } - } else if (currentToken==MTTclosebrace) { - params.append(""); - } else { - if (*foundError) *foundError=true; - return params; } } else { if (*foundError) *foundError=true; diff --git a/lib/jkqtmathtext/jkqtmathtext.h b/lib/jkqtmathtext/jkqtmathtext.h index 2a0d2d5601..ba168aed82 100644 --- a/lib/jkqtmathtext/jkqtmathtext.h +++ b/lib/jkqtmathtext/jkqtmathtext.h @@ -122,6 +122,7 @@ class JKQTMathTextNode; // forward - \c \\ol{...} \c \\overline{...} \c \\overlined{...} : draw the text with overlining \image html jkqtmathtext/jkqtmathtext_ol.png - \c \\tt{...} \c \\texttt{...} \c \\mathtt{...} : draw text in typewriter font \image html jkqtmathtext/jkqtmathtext_fonts.png - \c \\textcolor{color}{...} \c \\color{color} \c \\mathcolor{color}{...} : draw colored text \image html jkqtmathtext/jkqtmathtext_colored.png + - \c \\userfont{font}{...} : draw text in a user-specific font, available on the system \image html jkqtmathtext/jkqtmathtext_userfont.png (generated by default, \\userfont{Arial}{Arial}, \\userfont{Comic Sans MS}{Comic Sans MS} ) - \c \\boxed{...} : draw text with a box around it \image html jkqtmathtext/jkqtmathtext_boxed.png - \c \\doublebox{...} : draw text with a rounded box around it \image html jkqtmathtext/jkqtmathtext_doublebox.png - \c \\ovalbox{...} : draw text with a rounded box around it \image html jkqtmathtext/jkqtmathtext_ovalboxed.png diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp index 5690f4c4c2..85b81ad830 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp @@ -162,6 +162,13 @@ void JKQTMathTextModifiedTextPropsInstructionNode::fillInstructions() instructions["mathcolor"] = i; instructions["color"]= i; } + { + InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& parameters) { + ev.customFontName=parameters.value(0, ""); + ev.font=MTECustomFont; + }, 1); + instructions["userfont"] = i; + } { InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { ev.italic=true; ev.insideMath=true; @@ -248,36 +255,60 @@ void JKQTMathTextModifiedTextPropsInstructionNode::fillInstructions() ev.font=JKQTMathTextEnvironmentFont::MTEcaligraphic; ev.italic=false; }, 0); + instructions["mathcal"]= i; + } + { + InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { + ev.font=JKQTMathTextEnvironmentFont::MTEcaligraphic; + }, 0); instructions["cal"] = i; instructions["textcal"] = i; - instructions["mathcal"]= i; + } + { + InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { + ev.font=JKQTMathTextEnvironmentFont::MTEcaligraphic; + ev.italic=false; + ev.bold=true; + }, 0); + instructions["mathbfcal"]= i; } { InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { ev.font=JKQTMathTextEnvironmentFont::MTEcaligraphic; ev.bold=true; }, 0); - instructions["fcal"] = i; + instructions["bbfcal"] = i; instructions["textfcal"] = i; - instructions["mathfcal"]= i; + } + { + InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { + ev.font=JKQTMathTextEnvironmentFont::MTEfraktur; + }, 0); + instructions["frak"] = i; + instructions["textfrak"] = i; } { InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { ev.font=JKQTMathTextEnvironmentFont::MTEfraktur; ev.italic=false; }, 0); - instructions["frak"] = i; - instructions["textfrak"] = i; instructions["mathfrak"]= i; } { InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { ev.font=JKQTMathTextEnvironmentFont::MTEfraktur; ev.bold=true; + ev.italic=false; }, 0); - instructions["ffrak"] = i; - instructions["textffrak"] = i; - instructions["mathffrak"]= i; + instructions["mathbffrak"]= i; + } + { + InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { + ev.font=JKQTMathTextEnvironmentFont::MTEfraktur; + ev.bold=true; + }, 0); + instructions["bffrak"] = i; + instructions["textbffrak"] = i; } { InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { @@ -291,54 +322,91 @@ void JKQTMathTextModifiedTextPropsInstructionNode::fillInstructions() { InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { ev.font=JKQTMathTextEnvironmentFont::MTEtypewriter; - ev.italic=false; }, 0); instructions["tt"] = i; instructions["texttt"] = i; + } + { + InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { + ev.font=JKQTMathTextEnvironmentFont::MTEtypewriter; + ev.italic=false; + }, 0); instructions["mathtt"]= i; } + { + InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { + ev.font=JKQTMathTextEnvironmentFont::MTEtypewriter; + ev.bold=true; + }, 0); + instructions["bftt"] = i; + instructions["textbftt"] = i; + } + { + InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { + ev.font=JKQTMathTextEnvironmentFont::MTEtypewriter; + ev.italic=false; + ev.bold=true; + }, 0); + instructions["mathbftt"]= i; + } + { + InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { + ev.font=JKQTMathTextEnvironmentFont::MTEsans; + }, 0); + instructions["sf"] = i; + instructions["textsf"] = i; + } { InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { ev.font=JKQTMathTextEnvironmentFont::MTEsans; ev.italic=false; }, 0); - instructions["sf"] = i; - instructions["textsf"] = i; - instructions["mathsf"]= i; + instructions["mathsf"] = i; } { InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { ev.font=JKQTMathTextEnvironmentFont::MTEsans; ev.italic=true; }, 0); - instructions["sfit"] = i; - instructions["textsfit"] = i; - instructions["mathsfit"]= i; + instructions["itsf"] = i; + instructions["textitsf"] = i; + instructions["mathitsf"]= i; + } + { + InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { + ev.font=JKQTMathTextEnvironmentFont::MTEscript; + }, 0); + instructions["script"] = i; + instructions["scr"] = i; + instructions["textscript"] = i; + instructions["textscr"] = i; } { InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { ev.font=JKQTMathTextEnvironmentFont::MTEscript; ev.italic=false; }, 0); - instructions["script"] = i; - instructions["scr"] = i; - instructions["textscript"] = i; - instructions["textscr"] = i; instructions["mathscript"] = i; instructions["mathscr"]= i; } + { + InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { + ev.font=JKQTMathTextEnvironmentFont::MTEscript; + ev.bold=true; + }, 0); + instructions["bfscript"] = i; + instructions["bfscr"] = i; + instructions["textbfscript"] = i; + instructions["textbfscr"] = i; + } { InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) { ev.font=JKQTMathTextEnvironmentFont::MTEscript; ev.bold=true; ev.italic=false; }, 0); - instructions["fscript"] = i; - instructions["fscr"] = i; - instructions["textfscript"] = i; - instructions["textfscr"] = i; - instructions["mathfscript"] = i; - instructions["mathfscr"]= i; + instructions["mathbfscript"] = i; + instructions["mathbfscr"]= i; } { InstructionProperties i([](JKQTMathTextEnvironment& ev, const QStringList& /*parameters*/) {