From e469dbb9ae75f29cd43643bf0e9422e9f04c88c0 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Mon, 25 Jul 2022 23:29:32 +0200 Subject: [PATCH] JKQTMathText: added instruction \\utfeight{HEX} --- doc/dox/whatsnew.dox | 2 +- .../jkqtmathtext/jkqtmathtext_unicode.png | Bin 1042 -> 3091 bytes examples/jkqtmathtext_test/testform.cpp | 2 +- lib/jkqtmathtext/jkqtmathtext.h | 2 +- .../nodes/jkqtmathtextinstructionnode.cpp | 29 ++++++++++++------ 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/doc/dox/whatsnew.dox b/doc/dox/whatsnew.dox index 06131a38bb..3e52467834 100644 --- a/doc/dox/whatsnew.dox +++ b/doc/dox/whatsnew.dox @@ -67,7 +67,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
  • 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} instruction
  • -
  • NEW: added \c \\unicode{HEX} instruction to draw unicide characters by code
  • +
  • NEW: added \c \\unicode{HEX} and \c \\utfeight{HEX} instruction to draw unicide characters by code
  • diff --git a/doc/images/jkqtmathtext/jkqtmathtext_unicode.png b/doc/images/jkqtmathtext/jkqtmathtext_unicode.png index fe4cb185a03a6f33cf7dc0767d4949701191dde4..5a8ecef507a19a408f4fe5d71eac4014e2c541e0 100644 GIT binary patch delta 3041 zcmV<73m){62$L8giBL{Q4GJ0x0000DNk~Le0005|0000V2m$~A0B=k4rI8_0e+!C9 zL_t(|UhSMssANYKfM=~+w^?aGVqPYbh_S)Ns0o@ZvI#mHvuy?AP6%_;VBcio~m=I>YP)j>ejvQ=DnWR^-+tt=brz% zefsw8esgZEXvezk88%zkAd2UK92k5aA#@apon+`NH`qhXsf6f7JIrb#FTL_g|8q7I5N!{-9~-# z+i#jIihrS{OC4W#m)58L?gS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tnrJ`gs7ClOl`jEOA?#=P_cpcNt5^@m(9Tgtm1Y(5$)k8GE(J$-qa zlp(PtPkA&@n=2om)Zhc99I%tHf1Fo#j98rhahcBiTd)xYAN&L0F{z!v=k}m2Nwr`< z8Vx6`jsDo@_iqi_gH`zQyV35%r9tCd+SpKF1UMe!OIOVE~8DBD)b!!U)PHN0$T9f1^<^PSjET zaVim|th|HJ3A%+gSG28HLbO(+(ju}9A}ij+Qyy7YX%LCA95+CM(I_gmZA*@lfc$C_ z9q@J+4w?jo<)T6Y$lCJ56!T8dqLf~8#}uQioR_bcE5Nqz`3)+%axBm|tS6bd5GTxM zWC;}|4$!eJaPIeWjx%()e=Z8uH>|QoLYY{zSg3YRfDbh5!N;?pD%lI@%C?rwQT$V)D|nrEs0tw{>ReflMZO1I8~-xUD+PVCYH>7*)O;i=FW=1SOzkrstUh zb(o3QkAhA=GFCUp;O}4WL|)g4eOq6bo<;~DKftDd{U8lC>aK z^rFpn3@fC&1ltI^f7Z5y1|y{;WyMha*oG3=g$W^p@;1TQp%eSI9*^>%p>8CPP%X=> zjJe5M`WfMFiFn1sd9aY$3Tz-+S}<70ad<$^Z~FUWMIHp z7Tsf`p*=O497I1QM)k=5Y%8ctwMna803vq68E*WGv>xiA0YwIsMNu_eKn*pgsO yY)LRCwj>x6CR-AWi7g4n#FhkOVoQP%x7#=6sK+&4{#8Bz0000cmbTestset->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("unicode", "star: \\unicode{2605}, circonflex: \\unicode{109}"); + ui->cmbTestset->addItem("unicode", "star: \\unicode{2605}, circonflex: \\unicode{109} emoticons on UTF-8: \\utfeight{F09F9881} \\utfeight{f09f98bb}"); 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.h b/lib/jkqtmathtext/jkqtmathtext.h index 41b5cc7e58..550ce704dc 100644 --- a/lib/jkqtmathtext/jkqtmathtext.h +++ b/lib/jkqtmathtext/jkqtmathtext.h @@ -133,7 +133,7 @@ class JKQTMathTextNode; // forward - \c \\fcolorbox{bordercolor}{backgroundcolor}{...} : draw a colored, filled box \image html jkqtmathtext/jkqtmathtext_fcolorbox.png - \c \\colorbox{color}{...} : draw a colored box around text \image html jkqtmathtext/jkqtmathtext_colorbox.png - \c \\alpha ... : display the according greek letter \image html jkqtmathtext/jkqtmathtext_greek.png - - \c \\unicode{HEX} : draws a unicode character \image html jkqtmathtext/jkqtmathtext_unicode.png (generated by star: \\unicode{2605}, circonflex: \\unicode{109}) + - \c \\unicode{HEX} and \\utfeight{HEX} : draws a unicode character \image html jkqtmathtext/jkqtmathtext_unicode.png (generated by star: \\unicode{2605}, circonflex: \\unicode{109} emoticons on UTF-8: \\utfeight{F09F9881} \\utfeight{f09f98bb}) - \c ^{...} \c _{...} : display the contents of braces in superscript/subscript \image html jkqtmathtext/jkqtmathtext_supersub.png
    Special subscript/superscript typesetting applies, when the sub/super follows \c \\sum \c \\Prod ...: \image html jkqtmathtext/jkqtmathtext_specialsubsuper.png - \c \\{ / \\} : display opening/closing brace diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp index 1e25d5f2b6..9b28a9f623 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp @@ -90,7 +90,6 @@ double JKQTMathTextSimpleInstructionNode::draw(QPainter &painter, double x, doub painter.setFont(f); painter.drawText(x,y,txt); - return x+bb.width(); } @@ -134,7 +133,7 @@ void JKQTMathTextSimpleInstructionNode::getSizeInternal(QPainter &painter, JKQTM const QString txt=executeInstruction(); const QRectF bb=fm.boundingRect(txt); width=bb.width(); - baselineHeight=bb.height()+bb.y(); + baselineHeight=-bb.y(); overallHeight=bb.height(); strikeoutPos=fm.strikeOutPos(); } @@ -146,18 +145,30 @@ void JKQTMathTextSimpleInstructionNode::fillInstructions() { InstructionProperties i([](const QStringList& parameters) -> QString { bool ok=false; - const int code=parameters.value(0, "0").toInt(&ok, 16); + qlonglong code=parameters.value(0, "0").toLongLong(&ok, 16); ok=ok&&(code>=0); - if (ok&&(code<=0xFFFF)) return QChar(code); - else if (ok&&(code>0xFFFF && code<0xFFFFFFFF)) { - const char16_t unicodeSmile[] = { char16_t((code&0xFFFF0000)>>16), char16_t(code&0xFFFF), 0 }; - return QString::fromUtf16(unicodeSmile); - } + if (ok&&(code<=0xFFFF)) return QChar(static_cast(code)); return QChar(0); }, 1); instructions["unicode"]= i; } - + { + InstructionProperties i([](const QStringList& parameters) -> QString { + bool ok=false; + qlonglong code=parameters.value(0, "0").toLongLong(&ok, 16); + ok=ok&&(code>=0); + if (ok) { + QByteArray bytes; + while (code!=0) { + bytes.prepend(static_cast(code&0xFF)); + code=code>>8; + } + return QString::fromUtf8(bytes); + } + return QChar(0); + }, 1); + instructions["utfeight"]= i; + } } QString JKQTMathTextSimpleInstructionNode::executeInstruction() const