JKQTMathText: added instruction \\userfont

This commit is contained in:
jkriege2 2022-07-24 22:31:38 +02:00
parent cfcf01f9ff
commit 18b0ef61f1
6 changed files with 112 additions and 42 deletions

View File

@ -66,6 +66,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>NEW: added \c \\shaded{color}{...} </li>
<li>NEW: added \c \\acute{X}, \c \\grave{X}, \c \\acute{X}</li>
<li>NEW: added functions to set the font-size in pixels (as alternative to the existing functions that set them in points), implements request <a href="https://github.com/jkriege2/JKQtPlotter/issues/76">#76</a> from <a href="https://github.com/igormironchik">user:igormironchik</a> </li>
<li>NEW: added \c \\userfont{SystemFontName}{Text}</li>
</ul></li>
</ul>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -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}");

View File

@ -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,25 +1815,22 @@ QStringList JKQTMathText::parseStringParams(bool get, size_t Nparams, bool *foun
for (size_t n=0; n<Nparams; n++) {
if (n>0 || (n==0 && get)) getToken();
if (currentToken==MTTopenbrace) {
bool ok=true;
QString thisparam="";
while (ok) {
getToken();
if (currentToken==MTTtext) {
params.append(currentTokenName);
if (getToken()!=MTTclosebrace) {
if (*foundError) *foundError=true;
return params;
}
thisparam+=currentTokenName;
} else if (currentToken==MTTwhitespace) {
params.append(" ");
if (getToken()!=MTTclosebrace) {
if (*foundError) *foundError=true;
return params;
}
thisparam+=" ";
} else if (currentToken==MTTclosebrace) {
params.append("");
params.append(thisparam);
ok=false;
} else {
if (*foundError) *foundError=true;
return params;
}
}
} else {
if (*foundError) *foundError=true;
return params;

View File

@ -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 <code>default, \\userfont{Arial}{Arial}, \\userfont{Comic Sans MS}{Comic Sans MS}</code> )
- \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

View File

@ -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,19 +322,45 @@ 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;
}
{
@ -311,34 +368,45 @@ void JKQTMathTextModifiedTextPropsInstructionNode::fillInstructions()
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*/) {