From 18b0ef61f1609e6a91be86be7c132aea67effc28 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Sun, 24 Jul 2022 22:31:38 +0200 Subject: [PATCH] JKQTMathText: added instruction \\userfont --- doc/dox/whatsnew.dox | 1 + .../jkqtmathtext/jkqtmathtext_userfont.png | Bin 0 -> 1559 bytes examples/jkqtmathtext_test/testform.cpp | 5 +- lib/jkqtmathtext/jkqtmathtext.cpp | 29 +++-- lib/jkqtmathtext/jkqtmathtext.h | 1 + .../nodes/jkqtmathtextinstructionnode.cpp | 118 ++++++++++++++---- 6 files changed, 112 insertions(+), 42 deletions(-) create mode 100644 doc/images/jkqtmathtext/jkqtmathtext_userfont.png 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 0000000000000000000000000000000000000000..9a7fac561d8693ab243d0aa227bd33fd38186753 GIT binary patch literal 1559 zcmV+y2I%>TP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D01|XXSaefwW^{L9 za%BKVa%E+1b7*gLUR4MM000G!NklA2 zWXJ7pzVbg=2!;{1+HLpOSCS-_ycJ2}$y<>mp1c)F;>lZ)B%c4{Ry?=cuflD6N?@PI z{b=(2A*%yWVdsp*KSV~Te6QWf8+!fX+|VbvtG9xNvOWoz;p*2laQbr_=x)~JUJn;I zWz)SJ;`;B5&wcs@H2j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! zOMn+cx@Yc~`-MQ!G>bY9p4G(q#1KG zkBE}7pWSc06z9|hhV;Vg_6~GI1T{vKx@&9RvNdSZ`mu-caIVRaa#zKkG3eXu_Sw4? zpTOh3d%Ay5nf}6;mYk!0?e2xs=RS-a@7)PL`d0kBPw>ax(&P*udncmbTestset->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*/) {