JKQTMathText: added support for \c \\char"HEX , \c \\char'OCTAL and \c \\charDECIMAL for inserting any uicode character code

This commit is contained in:
jkriege2 2022-08-01 13:39:34 +02:00
parent de80fa666b
commit 7e12fb331e
7 changed files with 55 additions and 2 deletions

View File

@ -39,7 +39,6 @@ This page lists several todos and wishes for future version of JKQTPlotter
<li></li>
</ul></li>
<li>JKQTMathText:<ul>
<li>add instruction for unicode-characters \\charDDDD, \\char"XXXX ...</li>
<li>check sub/superscript with italic text in math mode, possibly a correction is necessary</li>
<li>explore where QFontMetricsF::horizontalAdvance() can be used (for Qt >=5.15)</li>
<li>add support for \\bigl,\\bigr,\\Bigr,... commands for fixed-size but large paramtheses</li>

View File

@ -73,6 +73,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>NEW: added support for flushleft/flushright/center-environments with linebreaks</li>
<li>NEW: added support for framed/shaded/snugshade-environments with linebreaks and framed</li>
<li>NEW: added support for -- and --- for en- and em-dashes</li>
<li>NEW: added support for \c \\char"HEX , \c \\char'OCTAL and \c \\charDECIMAL for inserting any uicode character code</li>
</ul></li>
</ul>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -68,6 +68,8 @@ TestForm::TestForm(QWidget *parent) :
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}");
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}"; };

View File

@ -70,8 +70,16 @@
#include <string>
#include <utility>
#include <vector>
#if (QT_VERSION>=QT_VERSION_CHECK(6, 0, 0))
#include<QRegularExpression>
#include<QRegularExpressionMatch>
#else
#include<QRegExp>
#endif
#include "jkqtcommon/jkqtpmathtools.h"
#include "jkqtcommon/jkqtpcodestructuring.h"
#include "jkqtcommon/jkqtpdebuggingtools.h"
#include "jkqtcommon/jkqtpstringtools.h"
#endif // jkqtcommon_precomp_h

View File

@ -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 ((currentTokenID<parseString.size()) && (c.isDigit() || QString("aAbBcCdDeEfF").contains(c))) {
num+=c;
currentTokenID++;
c=parseString[currentTokenID];
}
if (currentTokenID<parseString.size()) currentTokenID--;
currentTokenName=QString::fromStdString(jkqtp_UnicodeToUTF8(num.toLongLong(nullptr, 16)));
return currentToken=MTTtext;
} else if (c=='`' || c=='\'') {
// match '\char"OCTALDIGITS'
currentTokenID++;
c=parseString[currentTokenID];
while ((currentTokenID<parseString.size()) && (QString("01234567").contains(c))) {
num+=c;
currentTokenID++;
c=parseString[currentTokenID];
}
if (currentTokenID<parseString.size()) currentTokenID--;
currentTokenName=QString::fromStdString(jkqtp_UnicodeToUTF8(num.toLongLong(nullptr, 8)));
return currentToken=MTTtext;
} else if (c.isDigit()) {
// match '\charDECIMALDIGITS'
while ((currentTokenID<parseString.size()) && (c.isDigit())) {
num+=c;
currentTokenID++;
c=parseString[currentTokenID];
}
if (currentTokenID<parseString.size()) currentTokenID--;
currentTokenName=QString::fromStdString(jkqtp_UnicodeToUTF8(num.toLongLong(nullptr, 10)));
return currentToken=MTTtext;
}
}
return currentToken=MTTinstruction;
//----------------------------------------------------------
// check for $ character

View File

@ -133,6 +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 \\charDECIMAL and \c \\char"HEX and \c \\char'OCTAL : draws a unicode character from its 32-bit codepoint \image html jkqtmathtext/jkqtmathtext_char.png (generated by <code>A: \\char65, circonflex: \\char\"109 accent: \\char\'351</code>)
- \c \\unicode{HEX} and \c \\usym{HEX} : draws a unicode character from its 32-bit codepoint \image html jkqtmathtext/jkqtmathtext_unicode.png (generated by <code>star: \\unicode{2605}, circonflex: \\unicode{109} emoticons: \\usym{1F440} \\usym{1F929}</code>)
- \c \\utfeight{HEX} : draws a unicode character from its UTF-8 encoding \image html jkqtmathtext/jkqtmathtext_utf8.png (generated by <code>star: \\utfeight{e29885} emoticons \\utfeight{F09F9881} \\utfeight{f09f98bb}</code>)
- \c ^{...} \c _{...} : display the contents of braces in superscript/subscript \image html jkqtmathtext/jkqtmathtext_supersub.png