From 7e12fb331eb1182bdb621b8ee5f9c42f9179d09c Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Mon, 1 Aug 2022 13:39:34 +0200 Subject: [PATCH] JKQTMathText: added support for \c \\char"HEX , \c \\char'OCTAL and \c \\charDECIMAL for inserting any uicode character code --- doc/dox/todo.dox | 1 - doc/dox/whatsnew.dox | 1 + doc/images/jkqtmathtext/jkqtmathtext_char.png | Bin 0 -> 1608 bytes examples/jkqtmathtext_test/testform.cpp | 2 + lib/jkqtcommon/private/jkqtcommon_precomp.h | 8 ++++ lib/jkqtmathtext/jkqtmathtext.cpp | 44 +++++++++++++++++- lib/jkqtmathtext/jkqtmathtext.h | 1 + 7 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 doc/images/jkqtmathtext/jkqtmathtext_char.png diff --git a/doc/dox/todo.dox b/doc/dox/todo.dox index b8b46b0d44..6c0d7dfaa1 100644 --- a/doc/dox/todo.dox +++ b/doc/dox/todo.dox @@ -39,7 +39,6 @@ This page lists several todos and wishes for future version of JKQTPlotter
  • JKQTMathText:
  • diff --git a/doc/images/jkqtmathtext/jkqtmathtext_char.png b/doc/images/jkqtmathtext/jkqtmathtext_char.png new file mode 100644 index 0000000000000000000000000000000000000000..f1fc08924ded47274bfbcf4c99a12d4c963eefcc GIT binary patch literal 1608 zcmV-O2DkZ%P)2I00001b5ch_0Itp) z=>Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D01|XXSaefwW^{L9 za%BKVa%E+1b7*gLUR4MM000HQNklQIs zgFE@W-#$J*jt9M57ig3Keji8r>2`nO^B)J;$+*BUe-iZ|V{?k_WD-5^CY&m6Q3ka3 zJ<2Z2RO;17tg@3Z$lL7-)BIWBjf)>!XeUp7d;aI|{WzkfFA-k%HWND4tLOcA zQDVN6ctHT)KlM|^FALngm3Q*_v>v?Jr2&`o2c|vU$$SrvJFU)l8$4C~x>$cF{{V2< z3+^PmRpiS-4u`*D_O4P7FNwc`q6e@;g~u|CpVv^IlI8P>VgmcbPw*(bY||4=QKq7f z1s^-wvUnS#)`L_|cB)4YL1;Uk94I?}rCu)#bIOnrbl-NJ|->PzBLz{ILdIU2H5US<>yAKLNY44%|eL`aGmgeuEl0?fcrz=SE@3IRZ_ za;Y}s)N(qebd2pjWO^wu&Qm>6F_i<+K`#k&%3vUM76~cBUjl?3d@8Fq2_1KkOIKRS zQyqI4?xZW)Hv^1-SHz3rA;1BMuEmicFeEBb`P=OV$xJ4oXekb+be>(y{E z*h$b}0!4E!8o(Lis38SNmk04k;DQ?N+7)F9>cuoP;*+8(g)FC@O=+VN+HFYZ0m`=aHlhBDwr{>=E z$#8~vbcR?+@-U`{6;Px(+cBF1aK$_?JvR;;10Bfx;%Cy&41tl%(Y!R1y`CAulnzQ} z@Fc#{D(lcnC4lgN( zcJvN>!(p^^nw;E|VJ~6IY#_)|J=n%vS`eW2?vy$^N&WW`z6cIZ5~nLSP4=!8#&qgj zv9#h)baL<}WcY3@8zl$!1lri&y(|gyk@NtW+ItnEmm_Ck%FG zYULFQizy1aVSx(tc{+QG?o{*7lcmbTestset->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}"); + ui->cmbTestset->addItem("text: \\char", "A: \\char65, circonflex: \\char\"109 accent: \\char\'351"); + ui->cmbTestset->addItem("math: \\char", "A: $\\char65$, circonflex: $\\char\"109$ accent: $\\char\'351"); ui->cmbTestset->addItem("unicode", "star: \\unicode{2605}, circonflex: \\unicode{109} emoticons: \\usym{1F440} \\usym{1F929}"); ui->cmbTestset->addItem("UTF8", "star: \\utfeight{e29885} emoticons \\utfeight{F09F9881} \\utfeight{f09f98bb}"); const auto mathDecoExample=[](const QString& deco)->QString { return "\\"+deco+"{x}\\"+deco+"{i}\\"+deco+"{X}\\"+deco+"{\\psi}\\"+deco+"{abc}"; }; diff --git a/lib/jkqtcommon/private/jkqtcommon_precomp.h b/lib/jkqtcommon/private/jkqtcommon_precomp.h index cb977877e6..06ccba6f6a 100644 --- a/lib/jkqtcommon/private/jkqtcommon_precomp.h +++ b/lib/jkqtcommon/private/jkqtcommon_precomp.h @@ -70,8 +70,16 @@ #include #include #include +#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0)) +#include +#include +#else +#include +#endif + #include "jkqtcommon/jkqtpmathtools.h" #include "jkqtcommon/jkqtpcodestructuring.h" #include "jkqtcommon/jkqtpdebuggingtools.h" +#include "jkqtcommon/jkqtpstringtools.h" #endif // jkqtcommon_precomp_h diff --git a/lib/jkqtmathtext/jkqtmathtext.cpp b/lib/jkqtmathtext/jkqtmathtext.cpp index dfa9541e12..43c62d4b0b 100644 --- a/lib/jkqtmathtext/jkqtmathtext.cpp +++ b/lib/jkqtmathtext/jkqtmathtext.cpp @@ -1301,7 +1301,8 @@ JKQTMathText::tokenType JKQTMathText::getToken() { if (c=='\\') { //---------------------------------------------------------- // parsing accent instructions like \ss \"{a} ... - if (!parsingMathEnvironment){ + const QString next5=parseString.mid(currentTokenID, 5); + if (!parsingMathEnvironment && next5!="\\char"){ for (int len: accentLetters_LenBackslash) { const QString acc=parseString.mid(currentTokenID, len); if (acc.size()==len && accentLetters.contains(acc)) { @@ -1343,6 +1344,47 @@ JKQTMathText::tokenType JKQTMathText::getToken() { if (currentTokenName.size()==0) error_list.append(tr("error @ ch. %1: parser encountered empty istruction").arg(currentTokenID)); if (currentTokenName=="newline") return MTTinstructionNewline; if (currentTokenName=="linebreak") return MTTinstructionNewline; + if (currentTokenName=="char") { + QString num=""; + currentTokenID++; + c=parseString[currentTokenID]; + if (c=='"') { + // match '\char"HEXDIGITS' + currentTokenID++; + c=parseString[currentTokenID]; + while ((currentTokenIDA: \\char65, circonflex: \\char\"109 accent: \\char\'351) - \c \\unicode{HEX} and \c \\usym{HEX} : draws a unicode character from its 32-bit codepoint \image html jkqtmathtext/jkqtmathtext_unicode.png (generated by star: \\unicode{2605}, circonflex: \\unicode{109} emoticons: \\usym{1F440} \\usym{1F929}) - \c \\utfeight{HEX} : draws a unicode character from its UTF-8 encoding \image html jkqtmathtext/jkqtmathtext_utf8.png (generated by star: \\utfeight{e29885} emoticons \\utfeight{F09F9881} \\utfeight{f09f98bb}) - \c ^{...} \c _{...} : display the contents of braces in superscript/subscript \image html jkqtmathtext/jkqtmathtext_supersub.png