2022-06-08 21:38:26 +08:00
|
|
|
/*
|
|
|
|
Copyright (c) 2008-2022 Jan W. Krieger (<jan@jkrieger.de>)
|
|
|
|
|
2022-08-02 18:16:10 +08:00
|
|
|
|
2022-06-08 21:38:26 +08:00
|
|
|
|
|
|
|
This software is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License (LGPL) as published by
|
|
|
|
the Free Software Foundation, either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License (LGPL) for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License (LGPL)
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "jkqtmathtext/nodes/jkqtmathtexttextnode.h"
|
|
|
|
#include "jkqtmathtext/jkqtmathtexttools.h"
|
|
|
|
#include "jkqtmathtext/nodes/jkqtmathtextnode.h"
|
|
|
|
#include "jkqtmathtext/jkqtmathtext.h"
|
|
|
|
#include "jkqtcommon/jkqtpcodestructuring.h"
|
|
|
|
#include "jkqtcommon/jkqtpstringtools.h"
|
2024-01-09 00:16:31 +08:00
|
|
|
#include "jkqtcommon/jkqtpdebuggingtools.h"
|
2022-06-08 21:38:26 +08:00
|
|
|
#include <cmath>
|
|
|
|
#include <QFontMetricsF>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QFontDatabase>
|
|
|
|
#include <QFontInfo>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QFont>
|
|
|
|
|
|
|
|
|
2022-08-03 21:23:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JKQTMathTextTextBaseNode::JKQTMathTextTextBaseNode(JKQTMathText *parent, const QString &text_):
|
|
|
|
JKQTMathTextNode(parent),
|
|
|
|
text(text_)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTMathTextTextBaseNode::~JKQTMathTextTextBaseNode()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QString JKQTMathTextTextBaseNode::getText() const
|
|
|
|
{
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-10 18:12:30 +08:00
|
|
|
|
2022-08-03 21:23:14 +08:00
|
|
|
|
|
|
|
QString JKQTMathTextTextBaseNode::textTransform(const QString &text, const JKQTMathTextEnvironment &/*currentEv*/) const
|
|
|
|
{
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-17 05:05:04 +08:00
|
|
|
bool JKQTMathTextTextBaseNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const {
|
2022-08-03 21:23:14 +08:00
|
|
|
html=html
|
|
|
|
+currentEv.toHtmlStart(defaultEv, parentMathText)
|
|
|
|
+textTransform(text, currentEv).toHtmlEscaped()
|
|
|
|
+currentEv.toHtmlAfter(defaultEv, parentMathText);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-01-06 06:26:47 +08:00
|
|
|
const QHash<QChar, uint32_t>& JKQTMathTextTextNode::blackboardUnicodeTable(){
|
|
|
|
static QHash<QChar, uint32_t> table=[]() {
|
|
|
|
QHash<QChar, uint32_t> blackboardUnicodeTable;
|
2022-08-10 18:12:30 +08:00
|
|
|
|
2024-01-06 06:26:47 +08:00
|
|
|
const QString ALPHA="ABDEFGIJKLMOSTUVWXYZ";
|
|
|
|
for (const QChar ch: ALPHA) {
|
|
|
|
blackboardUnicodeTable[ch]=0x1D538+(ch.unicode()-QChar('A').unicode());
|
|
|
|
}
|
|
|
|
const QString alpha="abcdefghijklmnopqrstuvwxyz";
|
|
|
|
for (const QChar ch: alpha) {
|
|
|
|
blackboardUnicodeTable[ch]=0x1D552+(ch.unicode()-QChar('a').unicode());
|
|
|
|
}
|
|
|
|
const QString nums="0123456789";
|
|
|
|
for (const QChar ch: nums) {
|
|
|
|
blackboardUnicodeTable[ch]=0x1D7D8+(ch.unicode()-QChar('0').unicode());
|
|
|
|
}
|
2023-06-30 19:52:17 +08:00
|
|
|
|
2024-01-06 06:26:47 +08:00
|
|
|
blackboardUnicodeTable['C']=0x2102;
|
|
|
|
blackboardUnicodeTable['H']=0x210D;
|
|
|
|
blackboardUnicodeTable['N']=0x2115;
|
|
|
|
blackboardUnicodeTable['P']=0x2119;
|
|
|
|
blackboardUnicodeTable['Q']=0x211A;
|
|
|
|
blackboardUnicodeTable['R']=0x211D;
|
|
|
|
blackboardUnicodeTable['Z']=0x2124;
|
|
|
|
|
|
|
|
return blackboardUnicodeTable;
|
|
|
|
}();
|
|
|
|
return table;
|
2022-08-10 18:12:30 +08:00
|
|
|
}
|
2022-08-03 21:23:14 +08:00
|
|
|
|
2022-06-08 21:38:26 +08:00
|
|
|
JKQTMathTextTextNode::JKQTMathTextTextNode(JKQTMathText* _parent, const QString& textIn, bool addWhitespace, bool stripInnerWhitepace):
|
2022-08-03 21:23:14 +08:00
|
|
|
JKQTMathTextTextBaseNode(_parent, "")
|
2022-06-08 21:38:26 +08:00
|
|
|
{
|
2022-08-03 21:23:14 +08:00
|
|
|
QString textTransformed=textIn;
|
2022-06-08 21:38:26 +08:00
|
|
|
|
|
|
|
if (stripInnerWhitepace) {
|
2022-08-03 21:23:14 +08:00
|
|
|
textTransformed="";
|
2022-06-08 21:38:26 +08:00
|
|
|
for (int i=0; i<textIn.size(); i++) {
|
2022-08-03 21:23:14 +08:00
|
|
|
if (!textIn[i].isSpace()) textTransformed+=textIn[i];
|
2022-06-08 21:38:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-03 21:23:14 +08:00
|
|
|
text=textTransformed;
|
2022-06-08 21:38:26 +08:00
|
|
|
// strip all whitespace from left
|
2022-08-03 21:23:14 +08:00
|
|
|
while (text.size()>1 && text[0].isSpace()) {
|
|
|
|
text=text.right(text.size()-1);
|
2022-06-08 21:38:26 +08:00
|
|
|
}
|
2022-08-03 21:23:14 +08:00
|
|
|
if (addWhitespace && (text.size()>0) && (!text[text.size()-1].isSpace())) text=text+" ";
|
2022-06-08 21:38:26 +08:00
|
|
|
//qDebug()<<"JKQTMathTextTextNode( text="<<text<<" addWhitespace="<<addWhitespace<<") [=> this->text="<<this->text<<"]";
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTMathTextTextNode::~JKQTMathTextTextNode() = default;
|
|
|
|
|
2022-08-17 05:05:04 +08:00
|
|
|
JKQTMathTextNodeSize JKQTMathTextTextNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
|
|
|
|
return calcLayout(painter, currentEv);
|
2022-08-02 18:16:10 +08:00
|
|
|
}
|
|
|
|
|
2022-08-17 05:05:04 +08:00
|
|
|
JKQTMathTextTextNode::LayoutInfo JKQTMathTextTextNode::calcLayout(QPainter &painter, JKQTMathTextEnvironment currentEv) const
|
2022-08-02 18:16:10 +08:00
|
|
|
{
|
2022-08-17 05:05:04 +08:00
|
|
|
LayoutInfo l;
|
|
|
|
|
2022-08-03 21:23:14 +08:00
|
|
|
const QString txt=textTransform(text, currentEv);
|
2022-08-17 05:05:04 +08:00
|
|
|
splitTextForLayout(painter, currentEv, txt, l.textpart, l.fontMode);
|
2022-08-02 18:16:10 +08:00
|
|
|
|
|
|
|
const QFont f=currentEv.getFont(parentMathText);
|
2022-08-10 18:12:30 +08:00
|
|
|
const QFont fUpright=JKQTMathTextGetNonItalic(f);
|
|
|
|
const QFont fFallbackSym=currentEv.exchangedFontFor(MTEFallbackSymbols).getFont(parentMathText);
|
|
|
|
const QFont fRoman=currentEv.exchangedFontForRoman().getFont(parentMathText);
|
2024-01-09 00:16:31 +08:00
|
|
|
const double sp=JKQTMathTextGetHorAdvance(f, " ", painter.device());
|
2022-08-17 05:05:04 +08:00
|
|
|
l.width=0;
|
2022-08-02 18:16:10 +08:00
|
|
|
double ascent=0;
|
|
|
|
double descent=0;
|
2022-08-17 05:05:04 +08:00
|
|
|
for (int i=0; i<l.textpart.size(); i++) {
|
2022-08-18 04:56:57 +08:00
|
|
|
l.baselineXCorrection=0;
|
|
|
|
l.topXCorrection=0;
|
2022-08-10 18:12:30 +08:00
|
|
|
QRectF br, tbr;
|
2022-08-17 05:05:04 +08:00
|
|
|
switch(l.fontMode[i]) {
|
2022-08-10 18:12:30 +08:00
|
|
|
case FMasDefined:
|
|
|
|
case FMasDefinedOutline:
|
2024-01-09 00:16:31 +08:00
|
|
|
br=JKQTMathTextGetBoundingRect(f, l.textpart[i], painter.device());
|
2022-08-17 05:05:04 +08:00
|
|
|
tbr=JKQTMathTextGetTightBoundingRect(f, l.textpart[i], painter.device());
|
2024-01-09 00:16:31 +08:00
|
|
|
if (f.italic() && l.textpart[i].size()>0) l.baselineXCorrection=JKQTMathTextGetRightBearing(f,l.textpart[i].operator[](l.textpart[i].size()-1),painter.device());
|
2022-08-10 18:12:30 +08:00
|
|
|
break;
|
|
|
|
case FMasDefinedForceUpright:
|
2024-01-09 00:16:31 +08:00
|
|
|
br=JKQTMathTextGetBoundingRect(fUpright, l.textpart[i], painter.device());
|
2022-08-17 05:05:04 +08:00
|
|
|
tbr=JKQTMathTextGetTightBoundingRect(fUpright, l.textpart[i], painter.device());
|
2022-08-10 18:12:30 +08:00
|
|
|
break;
|
|
|
|
case FMroman:
|
2024-01-09 00:16:31 +08:00
|
|
|
br=JKQTMathTextGetBoundingRect(fRoman, l.textpart[i], painter.device());
|
2022-08-17 05:05:04 +08:00
|
|
|
tbr=JKQTMathTextGetTightBoundingRect(fRoman, l.textpart[i], painter.device());
|
2024-01-09 00:16:31 +08:00
|
|
|
if (fRoman.italic() && l.textpart[i].size()>0) l.baselineXCorrection=JKQTMathTextGetRightBearing(fRoman,l.textpart[i].operator[](l.textpart[i].size()-1),painter.device());
|
2022-08-10 18:12:30 +08:00
|
|
|
break;
|
|
|
|
case FMfallbackSymbol:
|
2024-01-09 00:16:31 +08:00
|
|
|
br=JKQTMathTextGetBoundingRect(fFallbackSym, l.textpart[i], painter.device());
|
2022-08-17 05:05:04 +08:00
|
|
|
tbr=JKQTMathTextGetTightBoundingRect(fFallbackSym, l.textpart[i], painter.device());
|
2024-01-09 00:16:31 +08:00
|
|
|
if (fFallbackSym.italic() && l.textpart[i].size()>0) l.baselineXCorrection=JKQTMathTextGetRightBearing(fFallbackSym,l.textpart[i].operator[](l.textpart[i].size()-1),painter.device());
|
2022-08-10 18:12:30 +08:00
|
|
|
break;
|
|
|
|
}
|
2022-08-17 05:05:04 +08:00
|
|
|
l.textpartXPos.append(l.width);
|
2023-07-01 21:57:57 +08:00
|
|
|
if (i==l.textpart.size()-1) l.width+=tbr.width();
|
|
|
|
else l.width+=br.width();
|
2022-08-17 05:05:04 +08:00
|
|
|
if (l.textpart[i].size()>0 && l.textpart[i].at(l.textpart[i].size()-1).isSpace()) {
|
2022-08-03 21:23:14 +08:00
|
|
|
// this correction is necessary, because it seems that QFontMetricsF::boundingRect() ignores trailing spaces
|
2022-08-17 05:05:04 +08:00
|
|
|
l.width+=sp;
|
2022-08-03 21:23:14 +08:00
|
|
|
}
|
2022-08-02 18:16:10 +08:00
|
|
|
const double thisAscent=-tbr.top();
|
|
|
|
const double thisDescent=tbr.bottom();
|
|
|
|
ascent=qMax(ascent, thisAscent);
|
|
|
|
descent=qMax(descent, thisDescent);
|
2022-06-08 21:38:26 +08:00
|
|
|
}
|
2022-08-17 05:05:04 +08:00
|
|
|
l.overallHeight=(ascent+descent); //fm.height();
|
|
|
|
l.baselineHeight=ascent;
|
2024-01-09 00:16:31 +08:00
|
|
|
l.strikeoutPos=JKQTMathTextGetFontStrikoutPos(f, painter.device());
|
2022-08-17 05:05:04 +08:00
|
|
|
return l;
|
2022-08-02 18:16:10 +08:00
|
|
|
}
|
2022-06-08 21:38:26 +08:00
|
|
|
|
2022-08-10 18:12:30 +08:00
|
|
|
void JKQTMathTextTextNode::splitTextForLayout(QPainter &painter, JKQTMathTextEnvironment currentEv, const QString &txt, QStringList &textpart, QList<FontMode> &fontMode) const
|
2022-08-02 18:16:10 +08:00
|
|
|
{
|
|
|
|
auto isForcedUprightChar=[](const QChar& c) {
|
|
|
|
return c.isDigit()
|
|
|
|
|| c=='(' || c=='[' || c=='|' || c==']' || c==')' || c=='<' || c=='>'|| c=='{' || c=='}' || c=='|'
|
|
|
|
|| c==QChar(0x2329) || c==QChar(0x232A) || c==QChar(0x2308) || c==QChar(0x2309) || c==QChar(0x230A) || c==QChar(0x230B);
|
|
|
|
};
|
|
|
|
|
2022-08-10 18:12:30 +08:00
|
|
|
//const QFont f=currentEv.getFont(parentMathText);
|
|
|
|
//const QFont fUpright=JKQTMathTextGetNonItalic(f);
|
|
|
|
const QFont fFallbackSym=currentEv.exchangedFontFor(MTEFallbackSymbols).getFont(parentMathText);
|
|
|
|
const QFont fRoman=currentEv.exchangedFontForRoman().getFont(parentMathText);
|
|
|
|
//const QFontMetricsF fm(f, painter.device());
|
|
|
|
//const QFontMetricsF fmUpright(fUpright, painter.device());
|
|
|
|
const QFontMetricsF fmFallbackSym(fFallbackSym, painter.device());
|
|
|
|
const QFontMetricsF fmRoman(fRoman, painter.device());
|
|
|
|
const JKQTMathTextBlackboradDrawingMode bbMode=parentMathText->getFontBlackboradMode();
|
|
|
|
|
2022-08-02 18:16:10 +08:00
|
|
|
textpart.clear();
|
2022-08-10 18:12:30 +08:00
|
|
|
fontMode.clear();
|
2022-08-02 18:16:10 +08:00
|
|
|
QString currentSection="";
|
2022-08-10 18:12:30 +08:00
|
|
|
FontMode currentSectionFontMode=FMasDefined;
|
2022-08-02 18:16:10 +08:00
|
|
|
int i=0;
|
|
|
|
while (i<txt.size()) {
|
|
|
|
const QChar c=txt[i];
|
2022-08-10 18:12:30 +08:00
|
|
|
QString cs=c;
|
|
|
|
FontMode CFontMode=FMasDefined;
|
2022-08-02 18:16:10 +08:00
|
|
|
const bool CisForcedUprightChar=isForcedUprightChar(c);
|
|
|
|
const bool CisForcedUprightCharExt=CisForcedUprightChar||(c=='.')||(c==',');
|
2022-08-10 18:12:30 +08:00
|
|
|
if (currentEv.insideMath && currentEv.insideMathForceDigitsUpright && (currentEv.font==MTEroman || currentEv.font==MTEmathRoman)) {
|
|
|
|
if (currentSection.size()==0) {
|
|
|
|
if (CisForcedUprightChar) {
|
|
|
|
CFontMode=FMasDefinedForceUpright;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (CisForcedUprightCharExt) {
|
|
|
|
CFontMode=FMasDefinedForceUpright;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (currentEv.font==MTEblackboard) {
|
|
|
|
if (bbMode==MTBBDMfontDirectly) {
|
|
|
|
CFontMode=FMasDefined;
|
|
|
|
} else if (bbMode==MTBBDMsimulate) {
|
|
|
|
CFontMode=FMasDefinedOutline;
|
|
|
|
} else if (bbMode==MTBBDMunicodeCharactersOrSimulate || bbMode==MTBBDMunicodeCharactersOrFontDirectly) {
|
2024-01-06 06:26:47 +08:00
|
|
|
if (blackboardUnicodeTable().contains(c) && fmRoman.inFontUcs4(blackboardUnicodeTable().operator[](c))) {
|
|
|
|
cs=jkqtp_UnicodeToUTF8Q(blackboardUnicodeTable().operator[](c));
|
2022-08-10 18:12:30 +08:00
|
|
|
CFontMode=FMroman;
|
2024-01-06 06:26:47 +08:00
|
|
|
} else if (blackboardUnicodeTable().contains(c) && fmFallbackSym.inFontUcs4(blackboardUnicodeTable().operator[](c))) {
|
|
|
|
cs=jkqtp_UnicodeToUTF8Q(blackboardUnicodeTable().operator[](c));
|
2022-08-10 18:12:30 +08:00
|
|
|
CFontMode=FMfallbackSymbol;
|
|
|
|
} else {
|
|
|
|
if (bbMode==MTBBDMunicodeCharactersOrSimulate) {
|
|
|
|
CFontMode=FMasDefinedOutline;
|
|
|
|
} else if (bbMode==MTBBDMunicodeCharactersOrFontDirectly) {
|
|
|
|
CFontMode=FMasDefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-02 18:16:10 +08:00
|
|
|
if (currentSection.size()==0) {
|
|
|
|
// start new section
|
2022-08-10 18:12:30 +08:00
|
|
|
currentSectionFontMode=CFontMode;
|
|
|
|
currentSection+=cs;
|
2022-08-02 18:16:10 +08:00
|
|
|
} else {
|
|
|
|
// existing section
|
2022-08-10 18:12:30 +08:00
|
|
|
if (CFontMode==currentSectionFontMode) {
|
2022-08-02 18:16:10 +08:00
|
|
|
// continue current section
|
2022-08-10 18:12:30 +08:00
|
|
|
currentSection+=cs;
|
2022-08-02 18:16:10 +08:00
|
|
|
} else {
|
|
|
|
// start new section
|
|
|
|
textpart.append(currentSection);
|
2022-08-10 18:12:30 +08:00
|
|
|
fontMode.append(currentSectionFontMode);
|
|
|
|
currentSection=cs;
|
|
|
|
currentSectionFontMode=CFontMode;
|
2022-08-02 18:16:10 +08:00
|
|
|
}
|
|
|
|
}
|
2022-08-10 18:12:30 +08:00
|
|
|
|
2022-08-02 18:16:10 +08:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (currentSection.size()>0) {
|
|
|
|
textpart.append(currentSection);
|
2022-08-10 18:12:30 +08:00
|
|
|
fontMode.append(currentSectionFontMode);
|
2022-08-02 18:16:10 +08:00
|
|
|
}
|
2022-06-08 21:38:26 +08:00
|
|
|
}
|
|
|
|
|
2022-08-17 05:05:04 +08:00
|
|
|
double JKQTMathTextTextNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
|
2024-01-09 00:16:31 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
|
|
|
JKQTPAutoOutputTimer jkaat(QString("JKQTMathTextTextNode[]::draw()"));
|
|
|
|
#endif
|
2022-08-17 05:05:04 +08:00
|
|
|
const LayoutInfo l=calcLayout(painter, currentEv);
|
|
|
|
doDrawBoxes(painter, x, y, l);
|
2022-06-08 21:38:26 +08:00
|
|
|
|
|
|
|
|
2022-08-02 18:16:10 +08:00
|
|
|
const QFont f=currentEv.getFont(parentMathText);
|
2022-08-10 18:12:30 +08:00
|
|
|
const QFont fUpright=JKQTMathTextGetNonItalic(f);
|
|
|
|
const QFont fFallbackSym=currentEv.exchangedFontFor(MTEFallbackSymbols).getFont(parentMathText);
|
|
|
|
const QFont fRoman=currentEv.exchangedFontForRoman().getFont(parentMathText);
|
2024-01-06 06:26:47 +08:00
|
|
|
//const QFontMetricsF fm(f, painter.device());
|
|
|
|
//const QFontMetricsF fmUpright(fUpright, painter.device());
|
|
|
|
//const QFontMetricsF fmFallbackSym(fFallbackSym, painter.device());
|
|
|
|
//const QFontMetricsF fmRoman(fRoman, painter.device());
|
2022-06-08 21:38:26 +08:00
|
|
|
|
2022-08-02 18:16:10 +08:00
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
2022-06-08 21:38:26 +08:00
|
|
|
painter.setFont(f);
|
2022-08-10 18:12:30 +08:00
|
|
|
painter.setPen(currentEv.color);
|
2022-06-08 21:38:26 +08:00
|
|
|
|
|
|
|
//qDebug()<<"JKQTMathTextTextNode: text="<<text<<" font="<<f;
|
|
|
|
|
2022-08-13 21:32:31 +08:00
|
|
|
//std::cout<<" TEXT: currentEv.mathMode="<<currentEv.insideMath<<", currentEv.forceUpright="<<currentEv.insideMathForceDigitsUpright<<"\n";
|
2022-08-17 05:05:04 +08:00
|
|
|
for (int i=0; i<l.textpart.size(); i++) {
|
2022-08-13 21:32:31 +08:00
|
|
|
//std::cout<<" TEXT: mode="<<fontMode[i]<<", text='"<<textpart[i].toStdString()<<"'\n";
|
2022-08-17 05:05:04 +08:00
|
|
|
switch(l.fontMode[i]) {
|
2022-08-10 18:12:30 +08:00
|
|
|
case FMasDefined:
|
|
|
|
painter.setFont(f);
|
2022-08-17 05:05:04 +08:00
|
|
|
painter.drawText(QPointF(x+l.textpartXPos[i], y), l.textpart[i]);
|
2022-08-10 18:12:30 +08:00
|
|
|
break;
|
|
|
|
case FMasDefinedOutline:
|
2022-08-17 05:05:04 +08:00
|
|
|
JKQTMathTextDrawStringSimBlackboard(painter, f, currentEv.color, x+l.textpartXPos[i], y, l.textpart[i]);
|
2022-08-10 18:12:30 +08:00
|
|
|
break;
|
|
|
|
case FMasDefinedForceUpright:
|
|
|
|
painter.setFont(fUpright);
|
2022-08-17 05:05:04 +08:00
|
|
|
painter.drawText(QPointF(x+l.textpartXPos[i], y), l.textpart[i]);
|
2022-08-10 18:12:30 +08:00
|
|
|
break;
|
|
|
|
case FMroman:
|
|
|
|
painter.setFont(fRoman);
|
2022-08-17 05:05:04 +08:00
|
|
|
painter.drawText(QPointF(x+l.textpartXPos[i], y), l.textpart[i]);
|
2022-08-10 18:12:30 +08:00
|
|
|
break;
|
|
|
|
case FMfallbackSymbol:
|
|
|
|
painter.setFont(fFallbackSym);
|
2022-08-17 05:05:04 +08:00
|
|
|
painter.drawText(QPointF(x+l.textpartXPos[i], y), l.textpart[i]);
|
2022-08-10 18:12:30 +08:00
|
|
|
break;
|
|
|
|
}
|
2022-06-08 21:38:26 +08:00
|
|
|
}
|
|
|
|
|
2022-08-17 05:05:04 +08:00
|
|
|
return x+l.width;
|
2022-06-08 21:38:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString JKQTMathTextTextNode::getTypeName() const
|
|
|
|
{
|
|
|
|
return QLatin1String("JKQTMathTextTextNode(")+text+")";
|
|
|
|
}
|
|
|
|
|
2022-08-12 18:54:10 +08:00
|
|
|
void JKQTMathTextTextNode::removeTrailingWhitespace()
|
|
|
|
{
|
|
|
|
while (text.size()>0 && text[text.size()-1].isSpace()) text=text.left(text.size()-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTMathTextTextNode::removeLeadingWhitespace()
|
|
|
|
{
|
|
|
|
while (text.size()>0 && text[0].isSpace()) text=text.right(text.size()-1);
|
|
|
|
}
|
|
|
|
|
2022-08-03 21:23:14 +08:00
|
|
|
QString JKQTMathTextTextNode::textTransform(const QString &text, const JKQTMathTextEnvironment ¤tEv) const
|
2022-06-08 21:38:26 +08:00
|
|
|
{
|
|
|
|
QString txt=text;
|
2022-06-09 05:52:22 +08:00
|
|
|
auto fnt=parentMathText->getFontData(currentEv.font, currentEv.insideMath);
|
2022-08-03 21:23:14 +08:00
|
|
|
const QFontMetricsF fm(currentEv.getFont(parentMathText));
|
|
|
|
if (fnt.second==MTFELatin1 || fnt.second==MTFEUnicode) {
|
2022-06-08 21:38:26 +08:00
|
|
|
if (currentEv.insideMath) {
|
|
|
|
txt="";
|
|
|
|
for (int i=0; i<text.size(); i++) {
|
|
|
|
QChar c=text[i];
|
|
|
|
switch(c.unicode()) {
|
2022-08-03 21:23:14 +08:00
|
|
|
case '-':
|
|
|
|
if (fm.inFont(QChar(0x2212))) {
|
|
|
|
txt+=QString(QString(" ")+QChar(0x2212));
|
|
|
|
} else {
|
|
|
|
txt+=QString(QString(" -"));
|
|
|
|
}
|
|
|
|
break;
|
2022-06-08 21:38:26 +08:00
|
|
|
case '+': txt+=QString(QString(" +")); break;
|
|
|
|
case '<': txt+=QString(QString(" <")); break;
|
|
|
|
case '>': txt+=QString(QString(" >")); break;
|
|
|
|
case '=': txt+=QString(QString(" =")); break;
|
|
|
|
case ';': txt+=QString(QString("; ")); break;
|
|
|
|
case ',': txt+=QString(QString(", ")); break;
|
|
|
|
default: txt+=c; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
txt=txt.replace(" ", " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return txt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-08-10 18:12:30 +08:00
|
|
|
|
2022-08-17 05:05:04 +08:00
|
|
|
JKQTMathTextTextNode::LayoutInfo::LayoutInfo():
|
|
|
|
JKQTMathTextNodeSize(),
|
|
|
|
textpart(), fontMode(), textpartXPos()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTMathTextTextNode::LayoutInfo::LayoutInfo(const LayoutInfo &other):
|
|
|
|
LayoutInfo()
|
|
|
|
{
|
|
|
|
operator=(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTMathTextTextNode::LayoutInfo::LayoutInfo(const JKQTMathTextNodeSize &other):
|
|
|
|
LayoutInfo()
|
|
|
|
{
|
|
|
|
operator=(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTMathTextTextNode::LayoutInfo &JKQTMathTextTextNode::LayoutInfo::operator=(const LayoutInfo &other) {
|
|
|
|
JKQTMathTextNodeSize::operator=(other);
|
|
|
|
textpart=other.textpart;
|
|
|
|
fontMode=other.fontMode;
|
|
|
|
textpartXPos=other.textpartXPos;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTMathTextTextNode::LayoutInfo &JKQTMathTextTextNode::LayoutInfo::operator=(const JKQTMathTextNodeSize &other) {
|
|
|
|
JKQTMathTextNodeSize::operator=(other);
|
|
|
|
textpart.clear();
|
|
|
|
fontMode.clear();
|
|
|
|
textpartXPos.clear();
|
|
|
|
return *this;
|
|
|
|
}
|