2022-06-08 21:38:26 +08:00
|
|
|
/*
|
|
|
|
Copyright (c) 2008-2022 Jan W. Krieger (<jan@jkrieger.de>)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/jkqtmathtextdecoratednode.h"
|
|
|
|
#include "jkqtmathtext/jkqtmathtexttools.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-06-10 02:32:16 +08:00
|
|
|
QString JKQTMathTextDecoratedNode::DecorationType2String(JKQTMathTextDecoratedNode::DecorationType mode)
|
|
|
|
{
|
|
|
|
switch(mode) {
|
|
|
|
case MTDvec:
|
|
|
|
return "vec";
|
2022-07-11 04:01:11 +08:00
|
|
|
case MTDgrave:
|
|
|
|
return "grave";
|
|
|
|
case MTDacute:
|
|
|
|
return "acute";
|
2022-06-10 02:32:16 +08:00
|
|
|
case MTDtilde:
|
|
|
|
return "tilde";
|
|
|
|
case MTDbreve:
|
|
|
|
return "breve";
|
|
|
|
case MTDwidetilde:
|
|
|
|
return "widetilde";
|
|
|
|
case MTDhat:
|
|
|
|
return "hat";
|
|
|
|
case MTDwidehat:
|
|
|
|
return "widehat";
|
|
|
|
case MTDcheck:
|
|
|
|
return "check";
|
|
|
|
case MTDwidecheck:
|
|
|
|
return "widecheck";
|
|
|
|
case MTDocirc:
|
|
|
|
return "ocirc";
|
|
|
|
case MTDdot:
|
|
|
|
return "dot";
|
|
|
|
case MTDddot:
|
|
|
|
return "ddot";
|
|
|
|
case MTDbar:
|
|
|
|
return "bar";
|
|
|
|
case MTDarrow:
|
|
|
|
return "arrow";
|
|
|
|
case MTDoverline:
|
|
|
|
return "overline";
|
|
|
|
case MTDdoubleoverline:
|
|
|
|
return "double overline";
|
|
|
|
case MTDunderline:
|
|
|
|
return "underline";
|
|
|
|
case MTDdoubleunderline:
|
|
|
|
return "double underline";
|
|
|
|
case MTDcancel:
|
|
|
|
return "cancel";
|
|
|
|
case MTDbcancel:
|
|
|
|
return "bcancel";
|
|
|
|
case MTDxcancel:
|
|
|
|
return "xcancel";
|
|
|
|
case MTDstrike:
|
|
|
|
return "strike";
|
2022-08-11 20:17:04 +08:00
|
|
|
case MTDoverleftarrow:
|
|
|
|
return "overleftarrow";
|
|
|
|
case MTDoverrightarrow:
|
|
|
|
return "overrightarrow";
|
|
|
|
case MTDoverleftrightarrow:
|
|
|
|
return "overleftrightarrow";
|
|
|
|
case MTDunderleftarrow:
|
|
|
|
return "underleftarrow";
|
|
|
|
case MTDunderrightarrow:
|
|
|
|
return "underrightarrow";
|
|
|
|
case MTDunderleftrightarrow:
|
|
|
|
return "underleftrightarrow";
|
|
|
|
case MTDunderlineDashed:
|
|
|
|
return "underlineDashed";
|
|
|
|
case MTDunderlineDotted:
|
|
|
|
return "MTDunderlineDotted";
|
2022-06-10 02:32:16 +08:00
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
2022-07-07 04:44:02 +08:00
|
|
|
JKQTMathTextDecoratedNode::DecorationType JKQTMathTextDecoratedNode::InstructionName2DecorationType(const QString &mode)
|
|
|
|
{
|
2024-01-06 06:26:47 +08:00
|
|
|
return instructions()[mode];
|
2022-07-07 04:44:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool JKQTMathTextDecoratedNode::supportsInstructionName(const QString &instructionName)
|
|
|
|
{
|
2024-01-06 06:26:47 +08:00
|
|
|
return instructions().contains(instructionName);
|
2022-07-07 04:44:02 +08:00
|
|
|
}
|
|
|
|
|
2022-06-10 02:32:16 +08:00
|
|
|
|
2022-06-08 21:38:26 +08:00
|
|
|
|
2022-06-10 02:32:16 +08:00
|
|
|
JKQTMathTextDecoratedNode::JKQTMathTextDecoratedNode(JKQTMathText* _parent, DecorationType decoration, JKQTMathTextNode* child):
|
2022-06-09 05:52:22 +08:00
|
|
|
JKQTMathTextSingleChildNode(child, _parent)
|
2022-06-08 21:38:26 +08:00
|
|
|
{
|
|
|
|
this->decoration=decoration;
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTMathTextDecoratedNode::~JKQTMathTextDecoratedNode() {
|
|
|
|
}
|
|
|
|
|
2022-08-17 05:05:04 +08:00
|
|
|
JKQTMathTextNodeSize JKQTMathTextDecoratedNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
|
|
|
|
JKQTMathTextNodeSize s;
|
2022-06-29 05:14:31 +08:00
|
|
|
JKQTMathTextEnvironment ev=currentEv;
|
2022-08-17 05:05:04 +08:00
|
|
|
JKQTMathTextNodeSize cs=getChild()->getSize(painter, ev);
|
|
|
|
const double cDescent=cs.getDescent();
|
2022-06-29 05:14:31 +08:00
|
|
|
const QFont font=ev.getFont(parentMathText);
|
2024-01-09 00:16:31 +08:00
|
|
|
const double fascent=JKQTMathTextGetFontAscent(font, painter.device());
|
|
|
|
const double decoSeparation=parentMathText->getDecorationSeparationFactor()*fascent;
|
|
|
|
const double deco_height=parentMathText->getDecorationHeightFactor()*fascent;
|
2022-08-17 05:05:04 +08:00
|
|
|
const double deco_ypos=cs.baselineHeight+decoSeparation;
|
2024-01-09 00:16:31 +08:00
|
|
|
const double decoAboveAscent_ypos=fascent+decoSeparation;
|
2022-06-29 05:14:31 +08:00
|
|
|
const double decobelow_ypos=cDescent+decoSeparation;
|
2022-08-17 05:05:04 +08:00
|
|
|
const double italic_xcorrection=getNonItalicXCorretion(painter, cs.width, ev, getChild());
|
2024-01-09 00:16:31 +08:00
|
|
|
const double deco_miniwidth=((decoration==MTDtilde||decoration==MTDbreve)?JKQTMathTextGetBoundingRect(font,"~",painter.device()).width():JKQTMathTextGetBoundingRect(font,"^",painter.device()).width())-italic_xcorrection;
|
|
|
|
const double linewidth=qMax(parentMathText->ABS_MIN_LINEWIDTH, JKQTMathTextGetFontLineWidth(font, painter.device()));
|
2022-06-08 21:38:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-08-17 05:05:04 +08:00
|
|
|
double descent=cs.getDescent();
|
|
|
|
double ascent=cs.baselineHeight;
|
2022-06-08 21:38:26 +08:00
|
|
|
if (decoration==MTDbar) {
|
2022-08-17 05:05:04 +08:00
|
|
|
ascent=std::max<double>(cs.baselineHeight+decoSeparation, decoAboveAscent_ypos)+linewidth/2.0;
|
2022-08-11 20:17:04 +08:00
|
|
|
} else if (decoration==MTDunderline || decoration==MTDunderlineDashed || decoration==MTDunderlineDotted) {
|
2022-06-29 05:14:31 +08:00
|
|
|
descent=std::max<double>(decobelow_ypos, cDescent)+linewidth/2.0;
|
|
|
|
} else if (decoration==MTDdoubleunderline) {
|
2022-08-11 20:17:04 +08:00
|
|
|
descent=std::max<double>(decobelow_ypos, cDescent)+3.5*linewidth;
|
|
|
|
} else if (decoration==MTDunderleftarrow || decoration==MTDunderrightarrow || decoration==MTDunderleftrightarrow) {
|
|
|
|
descent=std::max<double>(decobelow_ypos, cDescent)+0.5*linewidth+deco_height;
|
2022-06-29 05:14:31 +08:00
|
|
|
} else {
|
|
|
|
ascent=deco_ypos+deco_height;
|
2022-06-08 21:38:26 +08:00
|
|
|
}
|
2022-08-17 05:05:04 +08:00
|
|
|
s.overallHeight=ascent+descent;
|
|
|
|
s.baselineHeight=ascent;
|
|
|
|
s.strikeoutPos=cs.strikeoutPos;
|
|
|
|
s.width=std::max<double>(deco_miniwidth,cs.width);
|
2022-08-18 04:56:57 +08:00
|
|
|
s.baselineXCorrection=cs.baselineXCorrection;
|
2022-08-17 05:05:04 +08:00
|
|
|
return s;
|
2022-06-08 21:38:26 +08:00
|
|
|
}
|
|
|
|
|
2024-01-06 06:26:47 +08:00
|
|
|
const QHash<QString, JKQTMathTextDecoratedNode::DecorationType>& JKQTMathTextDecoratedNode::instructions() {
|
|
|
|
static QHash<QString, JKQTMathTextDecoratedNode::DecorationType> table =[](){
|
|
|
|
QHash<QString, JKQTMathTextDecoratedNode::DecorationType> instructions;
|
|
|
|
|
|
|
|
instructions["vec"]=MTDvec;
|
|
|
|
instructions["overline"]=MTDoverline;
|
|
|
|
instructions["oline"]=MTDoverline;
|
|
|
|
instructions["ol"]=MTDoverline;
|
|
|
|
instructions["underline"]=MTDunderline;
|
|
|
|
instructions["uline"]=MTDunderline;
|
|
|
|
instructions["ul"]=MTDunderline;
|
|
|
|
instructions["dashuline"]=MTDunderlineDashed;
|
|
|
|
instructions["dotuline"]=MTDunderlineDotted;
|
|
|
|
instructions["uuline"]=MTDdoubleunderline;
|
|
|
|
instructions["uul"]=MTDdoubleunderline;
|
|
|
|
instructions["ooline"]=MTDdoubleoverline;
|
|
|
|
instructions["ool"]=MTDdoubleoverline;
|
|
|
|
instructions["arrow"]=MTDarrow;
|
|
|
|
instructions["overrightarrow"]=MTDarrow;
|
|
|
|
instructions["overarrow"]=MTDarrow;
|
|
|
|
instructions["hat"]=MTDhat;
|
|
|
|
instructions["^"]=MTDhat;
|
|
|
|
instructions["widehat"]=MTDwidehat;
|
|
|
|
instructions["check"]=MTDcheck;
|
|
|
|
instructions["v"]=MTDcheck;
|
|
|
|
instructions["widecheck"]=MTDwidecheck;
|
|
|
|
instructions["bar"]=MTDbar;
|
|
|
|
instructions["="]=MTDbar;
|
|
|
|
instructions["dot"]=MTDdot;
|
|
|
|
instructions["."]=MTDdot;
|
|
|
|
instructions["ocirc"]=MTDocirc;
|
|
|
|
instructions["tilde"]=MTDtilde;
|
|
|
|
instructions["~"]=MTDtilde;
|
|
|
|
instructions["acute"]=MTDacute;
|
|
|
|
instructions["'"]=MTDacute;
|
|
|
|
instructions["grave"]=MTDgrave;
|
|
|
|
instructions["`"]=MTDgrave;
|
|
|
|
instructions["breve"]=MTDbreve;
|
|
|
|
instructions["u"]=MTDbreve;
|
|
|
|
instructions["widetilde"]=MTDwidetilde;
|
|
|
|
instructions["ddot"]=MTDddot;
|
|
|
|
instructions["cancel"]=MTDcancel;
|
|
|
|
instructions["xcancel"]=MTDxcancel;
|
|
|
|
instructions["bcancel"]=MTDbcancel;
|
|
|
|
instructions["strike"]=MTDstrike;
|
|
|
|
instructions["st"]=MTDstrike;
|
|
|
|
instructions["sout"]=MTDstrike;
|
|
|
|
instructions["overleftarrow"]=MTDoverleftarrow;
|
|
|
|
instructions["overrightarrow"]=MTDoverrightarrow;
|
|
|
|
instructions["overleftrightarrow"]=MTDoverleftrightarrow;
|
|
|
|
instructions["underleftarrow"]=MTDunderleftarrow;
|
|
|
|
instructions["underrightarrow"]=MTDunderrightarrow;
|
|
|
|
instructions["underleftrightarrow"]=MTDunderleftrightarrow;
|
|
|
|
|
|
|
|
return instructions;
|
|
|
|
|
|
|
|
}();
|
|
|
|
return table;
|
2022-07-07 04:44:02 +08:00
|
|
|
}
|
|
|
|
|
2022-08-17 05:05:04 +08:00
|
|
|
double JKQTMathTextDecoratedNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
|
2024-01-09 00:16:31 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
|
|
|
JKQTPAutoOutputTimer jkaat(QString("JKQTMathTextDecoratedNode[]::draw()"));
|
|
|
|
#endif
|
2022-06-08 21:38:26 +08:00
|
|
|
doDrawBoxes(painter, x, y, currentEv);
|
|
|
|
JKQTMathTextEnvironment ev=currentEv;
|
2022-08-17 05:05:04 +08:00
|
|
|
auto cs=getChild()->getSize(painter, ev);
|
|
|
|
const double cDescent=cs.overallHeight-cs.baselineHeight;
|
2022-06-09 05:52:22 +08:00
|
|
|
const QFont font=ev.getFont(parentMathText);
|
2022-06-08 21:38:26 +08:00
|
|
|
const QFontMetricsF fm(font, painter.device());
|
2024-01-09 00:16:31 +08:00
|
|
|
const double width_X=JKQTMathTextGetBoundingRect(font,"X",painter.device()).width();
|
|
|
|
const double width_x=JKQTMathTextGetBoundingRect(font,"x",painter.device()).width();
|
|
|
|
const double width_dot=JKQTMathTextGetBoundingRect(font,".",painter.device()).width()/2.0;
|
2024-01-09 04:11:32 +08:00
|
|
|
const double ascent=JKQTMathTextGetFontAscent(font, painter.device());
|
2024-01-09 00:16:31 +08:00
|
|
|
const double decoSeparation=parentMathText->getDecorationSeparationFactor()*ascent;
|
|
|
|
const double linewidth=qMax(parentMathText->ABS_MIN_LINEWIDTH, JKQTMathTextGetFontLineWidth(font, painter.device()));
|
2022-08-11 20:17:04 +08:00
|
|
|
const double linewidthArrow=linewidth*0.65;
|
2024-01-09 00:16:31 +08:00
|
|
|
const double deco_height=parentMathText->getDecorationHeightFactor()*ascent;
|
|
|
|
const double decoAboveAscent_ypos=y-ascent-decoSeparation;
|
2022-08-17 05:05:04 +08:00
|
|
|
const double strike_ypos=y-cs.baselineHeight/2.0;
|
2022-06-29 05:14:31 +08:00
|
|
|
const double decobelow_ypos=y+cDescent+decoSeparation;
|
2024-01-09 04:11:32 +08:00
|
|
|
const double italic_xcorrection=getNonItalicXCorretion(painter, cs.width, ev, getChild())*2.0;
|
2022-06-09 05:52:22 +08:00
|
|
|
const double deco_xoffset=parentMathText->getDecorationWidthReductionXFactor()*width_X/2.0;
|
2022-08-17 05:05:04 +08:00
|
|
|
const double deco_width=std::max<double>(width_x*0.5,cs.width-2.0*deco_xoffset-italic_xcorrection);
|
2022-08-19 18:16:00 +08:00
|
|
|
const double deco_vecwidth=width_x*0.25;
|
|
|
|
const double deco_vecheight=deco_height*0.5;
|
2022-07-11 04:01:11 +08:00
|
|
|
const double deco_accentwidth=deco_height/4.0;
|
2024-01-09 00:16:31 +08:00
|
|
|
const double deco_miniwidth=((decoration==MTDtilde||decoration==MTDbreve)?JKQTMathTextGetBoundingRect(font,"~",painter.device()).width():JKQTMathTextGetBoundingRect(font,"^",painter.device()).width())-italic_xcorrection;
|
2022-08-17 05:05:04 +08:00
|
|
|
const double decotop_xcenter=x+italic_xcorrection+(cs.width-italic_xcorrection)/2.0;
|
2022-06-29 05:14:31 +08:00
|
|
|
const double decotop_xstart=decotop_xcenter-deco_width/2.0+linewidth/2.0;
|
|
|
|
const double decotop_xend=decotop_xcenter+deco_width/2.0-linewidth/2.0;
|
|
|
|
const double decobot_xstart=x+linewidth/2.0;
|
2022-08-17 05:05:04 +08:00
|
|
|
const double decobot_xend=x+cs.width-italic_xcorrection-linewidth/2.0;
|
2022-07-22 04:17:37 +08:00
|
|
|
//const double decobot_xcenter=(decobot_xstart+decobot_xend)/2.0;
|
2022-08-17 05:05:04 +08:00
|
|
|
const double deco_ytopbot=y-cs.baselineHeight-decoSeparation-linewidth/2.0;
|
|
|
|
const double deco_ytoptop=y-cs.baselineHeight-decoSeparation-deco_height+linewidth/2.0;
|
|
|
|
const double deco_ytopcenter=y-cs.baselineHeight-decoSeparation-deco_height/2.0;
|
2022-06-08 21:38:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPen pold=painter.pen();
|
|
|
|
QPen p=pold;
|
|
|
|
p.setColor(ev.color);
|
2022-08-11 20:17:04 +08:00
|
|
|
p.setWidthF(linewidthArrow);
|
|
|
|
p.setCapStyle(Qt::SquareCap);
|
2022-06-29 05:14:31 +08:00
|
|
|
p.setJoinStyle(Qt::RoundJoin);
|
2022-06-08 21:38:26 +08:00
|
|
|
|
2022-08-11 20:17:04 +08:00
|
|
|
QPen pul=p;
|
|
|
|
pul.setWidthF(linewidth);
|
|
|
|
pul.setCapStyle(Qt::SquareCap);
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-06-20 04:36:38 +08:00
|
|
|
double xnew=getChild()->draw(painter, x, y, ev);
|
2022-06-08 21:38:26 +08:00
|
|
|
|
2022-07-11 04:01:11 +08:00
|
|
|
auto fDrawFontAccent=[&](QChar aDirect=QChar(), QChar aFallback=QChar()) -> bool {
|
|
|
|
if (!aDirect.isNull() && fm.inFont(aDirect)) {
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
2024-01-09 04:11:32 +08:00
|
|
|
const QRectF tbra=JKQTMathTextGetTightBoundingRect(font, aDirect, painter.device());
|
2022-08-11 18:26:14 +08:00
|
|
|
painter.translate(decotop_xcenter-tbra.width()/2.0, (deco_ytopcenter+deco_ytoptop)/2.0);
|
2022-07-11 04:01:11 +08:00
|
|
|
//painter.setPen("red");
|
|
|
|
//painter.drawEllipse(0-2,0-2,4,4);
|
|
|
|
painter.translate(-tbra.x(), -tbra.y());
|
|
|
|
//painter.setPen("magenta");
|
|
|
|
//painter.drawEllipse(0-2,0-2,4,4);
|
|
|
|
if (tbra.width()>0 && tbra.height()>0) {
|
|
|
|
painter.setFont(font);
|
|
|
|
painter.drawText(0,0,aDirect);
|
|
|
|
//painter.setPen("blue");
|
|
|
|
//painter.drawRect(tbra);
|
|
|
|
//painter.drawEllipse(0-2,0-2,4,4);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!aFallback.isNull() && fm.inFont(aFallback)) {
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
2024-01-09 04:11:32 +08:00
|
|
|
const QRectF tbra=JKQTMathTextGetTightBoundingRect(font, aFallback, painter.device());
|
2022-08-11 18:26:14 +08:00
|
|
|
painter.translate(decotop_xcenter-tbra.width()/2.0, (deco_ytopcenter+deco_ytoptop)/2.0);
|
2022-07-11 04:01:11 +08:00
|
|
|
//painter.setPen("yellow");
|
|
|
|
//painter.drawEllipse(0-2,0-2,4,4);
|
|
|
|
painter.translate(-tbra.x(), -tbra.y());
|
|
|
|
//painter.setPen("cyan");
|
|
|
|
//painter.drawEllipse(0-2,0-2,4,4);
|
|
|
|
if (tbra.width()>0 && tbra.height()>0) {
|
|
|
|
painter.setFont(font);
|
|
|
|
painter.drawText(0,0,aFallback);
|
|
|
|
//painter.setPen("green");
|
|
|
|
//painter.drawRect(tbra);
|
|
|
|
//painter.drawEllipse(0-2,0-2,4,4);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2022-06-08 21:38:26 +08:00
|
|
|
if (decoration==MTDvec) {
|
|
|
|
painter.setPen(p);
|
|
|
|
QPolygonF poly;
|
2022-07-11 04:01:11 +08:00
|
|
|
poly<<QPointF(decotop_xstart, deco_ytopbot)<<QPointF(decotop_xend, deco_ytopbot)<<QPointF(decotop_xend-deco_vecwidth, deco_ytopbot-deco_vecheight);
|
2022-06-08 21:38:26 +08:00
|
|
|
painter.drawPolyline(poly);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDoverline) {
|
2022-08-11 20:17:04 +08:00
|
|
|
painter.setPen(pul);
|
2022-07-11 04:01:11 +08:00
|
|
|
const QLineF l(decotop_xstart, deco_ytopbot, decotop_xend, deco_ytopbot);
|
2022-06-08 21:38:26 +08:00
|
|
|
if (l.length()>0) painter.drawLine(l);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDbar) {
|
2022-08-11 20:17:04 +08:00
|
|
|
painter.setPen(pul);
|
2022-06-08 21:38:26 +08:00
|
|
|
const QLineF l(decotop_xstart, decoAboveAscent_ypos, decotop_xend, decoAboveAscent_ypos);
|
|
|
|
if (l.length()>0) painter.drawLine(l);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDdoubleoverline) {
|
2022-08-11 20:17:04 +08:00
|
|
|
painter.setPen(pul);
|
2022-07-11 04:01:11 +08:00
|
|
|
const QLineF l(decotop_xstart, deco_ytopbot, decotop_xend, deco_ytopbot);
|
2022-06-08 21:38:26 +08:00
|
|
|
if (l.length()>0) painter.drawLine(l);
|
2022-08-11 20:17:04 +08:00
|
|
|
const QLineF l2(decotop_xstart, deco_ytopbot-2.5*pul.widthF(), decotop_xend, deco_ytopbot-2.5*pul.widthF());
|
2022-06-08 21:38:26 +08:00
|
|
|
if (l2.length()>0) painter.drawLine(l2);
|
|
|
|
painter.setPen(pold);
|
2022-08-11 20:17:04 +08:00
|
|
|
} else if (decoration==MTDunderline || decoration==MTDunderlineDashed || decoration==MTDunderlineDotted) {
|
|
|
|
if (decoration==MTDunderlineDashed) pul.setStyle(Qt::DashLine);
|
|
|
|
if (decoration==MTDunderlineDotted) pul.setStyle(Qt::DotLine);
|
|
|
|
painter.setPen(pul);
|
2022-06-08 21:38:26 +08:00
|
|
|
const QLineF l(decobot_xstart, decobelow_ypos, decobot_xend, decobelow_ypos);
|
|
|
|
if (l.length()>0) painter.drawLine(l);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDdoubleunderline) {
|
2022-08-11 20:17:04 +08:00
|
|
|
painter.setPen(pul);
|
2022-06-08 21:38:26 +08:00
|
|
|
const QLineF l(decobot_xstart, decobelow_ypos, decobot_xend, decobelow_ypos);
|
|
|
|
if (l.length()>0) painter.drawLine(l);
|
2022-08-11 20:17:04 +08:00
|
|
|
QLineF l2(decobot_xstart, decobelow_ypos+2.5*pul.widthF(), decobot_xend, decobelow_ypos+2.5*pul.widthF());
|
2022-06-08 21:38:26 +08:00
|
|
|
if (l2.length()>0) painter.drawLine(l2);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDarrow) {
|
|
|
|
painter.setPen(p);
|
2022-07-11 04:01:11 +08:00
|
|
|
const QLineF l(decotop_xstart, deco_ytopcenter, decotop_xend, deco_ytopcenter);
|
2022-06-08 21:38:26 +08:00
|
|
|
if (l.length()>0) painter.drawLine(l);
|
|
|
|
QPolygonF poly;
|
2022-07-11 04:01:11 +08:00
|
|
|
poly<<QPointF(decotop_xend-deco_vecwidth, deco_ytopbot)<<QPointF(decotop_xend, deco_ytopcenter)<<QPointF(decotop_xend-deco_vecwidth, deco_ytoptop);
|
2022-06-08 21:38:26 +08:00
|
|
|
painter.drawPolyline(poly);
|
|
|
|
painter.setPen(pold);
|
2022-08-11 20:17:04 +08:00
|
|
|
} else if (decoration==MTDoverrightarrow) {
|
|
|
|
painter.setPen(p);
|
|
|
|
const QPainterPath path=JKQTMathTextMakeArrow(decotop_xstart, deco_ytopcenter, deco_width, deco_height, false, true);
|
|
|
|
painter.drawPath(path);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDoverleftarrow) {
|
|
|
|
painter.setPen(p);
|
|
|
|
const QPainterPath path=JKQTMathTextMakeArrow(decotop_xstart, deco_ytopcenter, deco_width, deco_height, true, false);
|
|
|
|
painter.drawPath(path);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDoverleftrightarrow) {
|
|
|
|
painter.setPen(p);
|
|
|
|
const QPainterPath path=JKQTMathTextMakeArrow(decotop_xstart, deco_ytopcenter, deco_width, deco_height, true, true);
|
|
|
|
painter.drawPath(path);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDunderrightarrow) {
|
|
|
|
painter.setPen(p);
|
|
|
|
const QPainterPath path=JKQTMathTextMakeArrow(decobot_xstart, decobelow_ypos+deco_height/2.0, decobot_xend-decobot_xstart, deco_height, false, true);
|
|
|
|
painter.drawPath(path);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDunderleftarrow) {
|
|
|
|
painter.setPen(p);
|
|
|
|
const QPainterPath path=JKQTMathTextMakeArrow(decobot_xstart, decobelow_ypos+deco_height/2.0, decobot_xend-decobot_xstart, deco_height, true, false);
|
|
|
|
painter.drawPath(path);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDunderleftrightarrow) {
|
|
|
|
painter.setPen(p);
|
|
|
|
const QPainterPath path=JKQTMathTextMakeArrow(decobot_xstart, decobelow_ypos+deco_height/2.0, decobot_xend-decobot_xstart, deco_height, true, true);
|
|
|
|
painter.drawPath(path);
|
|
|
|
painter.setPen(pold);
|
2022-06-08 21:38:26 +08:00
|
|
|
} else if (decoration==MTDhat) {
|
2022-07-11 04:01:11 +08:00
|
|
|
if (!fDrawFontAccent(QChar(0x302), QChar(0x2c6))) {
|
|
|
|
painter.setPen(p);
|
|
|
|
QPolygonF poly;
|
|
|
|
poly<<QPointF(decotop_xcenter-0.5*deco_miniwidth, deco_ytopbot)<<QPointF(decotop_xcenter, deco_ytopcenter)<<QPointF(decotop_xcenter+0.5*deco_miniwidth, deco_ytopbot);
|
|
|
|
painter.drawPolyline(poly);
|
|
|
|
painter.setPen(pold);
|
|
|
|
}
|
2022-06-08 21:38:26 +08:00
|
|
|
} else if (decoration==MTDwidehat) {
|
|
|
|
painter.setPen(p);
|
|
|
|
QPolygonF poly;
|
2022-07-11 04:01:11 +08:00
|
|
|
poly<<QPointF(decotop_xstart, deco_ytopbot)<<QPointF(decotop_xcenter, deco_ytoptop)<<QPointF(decotop_xend, deco_ytopbot);
|
2022-06-08 21:38:26 +08:00
|
|
|
painter.drawPolyline(poly);
|
|
|
|
painter.setPen(pold);
|
|
|
|
|
|
|
|
} else if (decoration==MTDcheck) {
|
2022-07-11 04:01:11 +08:00
|
|
|
if (!fDrawFontAccent(QChar(0x30C), QChar(0x2C7))) {
|
|
|
|
painter.setPen(p);
|
|
|
|
QPolygonF poly;
|
|
|
|
poly<<QPointF(decotop_xcenter-0.5*deco_miniwidth, deco_ytopcenter)<<QPointF(decotop_xcenter, deco_ytopbot)<<QPointF(decotop_xcenter+0.5*deco_miniwidth, deco_ytopcenter);
|
|
|
|
painter.drawPolyline(poly);
|
|
|
|
painter.setPen(pold);
|
|
|
|
}
|
2022-06-08 21:38:26 +08:00
|
|
|
} else if (decoration==MTDwidecheck) {
|
|
|
|
painter.setPen(p);
|
|
|
|
QPolygonF poly;
|
2022-07-11 04:01:11 +08:00
|
|
|
poly<<QPointF(decotop_xstart, deco_ytoptop)<<QPointF(decotop_xcenter, deco_ytopbot)<<QPointF(decotop_xend, deco_ytoptop);
|
2022-06-08 21:38:26 +08:00
|
|
|
painter.drawPolyline(poly);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDbreve) {
|
2022-07-11 04:01:11 +08:00
|
|
|
if (!fDrawFontAccent(QChar(0x306), QChar(0x2D8))) {
|
|
|
|
painter.setPen(p);
|
|
|
|
QPainterPath path;
|
|
|
|
const double x0=decotop_xcenter-deco_miniwidth/2.0;
|
|
|
|
const double x1=decotop_xcenter+deco_miniwidth/2.0;
|
|
|
|
path.moveTo(x0, deco_ytopbot);
|
|
|
|
path.cubicTo(x0, deco_ytoptop, x1, deco_ytoptop , x1, deco_ytopbot);
|
|
|
|
painter.drawPath(path);
|
|
|
|
painter.setPen(pold);
|
|
|
|
}
|
2022-06-08 21:38:26 +08:00
|
|
|
} else if (decoration==MTDtilde) {
|
2022-07-11 04:01:11 +08:00
|
|
|
if (!fDrawFontAccent(QChar(0x2DC), QChar('~'))) {
|
|
|
|
painter.setPen(p);
|
|
|
|
QPainterPath path;
|
|
|
|
const double x0=decotop_xcenter-deco_miniwidth/2.0;
|
|
|
|
const double x1=decotop_xcenter+deco_miniwidth/2.0;
|
|
|
|
path.moveTo(x0, deco_ytopcenter);
|
|
|
|
path.cubicTo((x0+x1)/2.0, deco_ytopbot, (x0+x1)/2.0, deco_ytoptop , x1, deco_ytopcenter);
|
|
|
|
painter.drawPath(path);
|
|
|
|
painter.setPen(pold);
|
|
|
|
}
|
|
|
|
} else if (decoration==MTDacute) {
|
|
|
|
if (!fDrawFontAccent(QChar(0x301), QChar(0x2CA))) {
|
2022-08-11 20:17:04 +08:00
|
|
|
painter.setPen(pul);
|
2022-07-11 04:01:11 +08:00
|
|
|
painter.drawLine(QLineF(decotop_xcenter, deco_ytopbot, decotop_xcenter-deco_accentwidth, deco_ytopcenter));
|
|
|
|
painter.setPen(pold);
|
|
|
|
}
|
|
|
|
} else if (decoration==MTDgrave) {
|
|
|
|
if (!fDrawFontAccent(QChar(0x300), QChar(0x2CB))) {
|
2022-08-11 20:17:04 +08:00
|
|
|
painter.setPen(pul);
|
2022-07-11 04:01:11 +08:00
|
|
|
painter.drawLine(QLineF(decotop_xcenter, deco_ytopbot, decotop_xcenter+deco_accentwidth, deco_ytopcenter));
|
|
|
|
painter.setPen(pold);
|
|
|
|
}
|
2022-06-08 21:38:26 +08:00
|
|
|
|
|
|
|
} else if (decoration==MTDwidetilde) {
|
|
|
|
painter.setPen(p);
|
|
|
|
QPainterPath path;
|
|
|
|
const double x0=decotop_xstart;
|
|
|
|
const double x1=decotop_xend;
|
2022-07-11 04:01:11 +08:00
|
|
|
path.moveTo(x0, deco_ytopcenter);
|
|
|
|
path.cubicTo((x0+x1)/2.0, deco_ytopbot, (x0+x1)/2.0, deco_ytoptop , x1, deco_ytopcenter);
|
2022-06-08 21:38:26 +08:00
|
|
|
painter.drawPath(path);
|
|
|
|
painter.setPen(pold);
|
|
|
|
|
|
|
|
} else if (decoration==MTDocirc) {
|
2022-07-11 04:01:11 +08:00
|
|
|
if (!fDrawFontAccent(QChar(0x2DA), QChar(0xBA))) {
|
|
|
|
painter.setPen(p);
|
|
|
|
const QBrush bold=painter.brush();
|
|
|
|
painter.setBrush(Qt::NoBrush);
|
|
|
|
const double r=qMin(width_dot/1.5, deco_height/2.0-linewidth/2.0);
|
|
|
|
painter.drawEllipse(QPointF(decotop_xcenter, deco_ytopcenter), r, r);
|
|
|
|
painter.setBrush(bold);
|
|
|
|
painter.setPen(pold);
|
|
|
|
}
|
2022-06-08 21:38:26 +08:00
|
|
|
} else if (decoration==MTDdot) {
|
2022-07-11 04:01:11 +08:00
|
|
|
if (!fDrawFontAccent(QChar(0x2D9), QChar('.'))) {
|
|
|
|
p.setWidthF(0.01);
|
|
|
|
painter.setPen(p);
|
|
|
|
QBrush b=painter.brush();
|
|
|
|
const QBrush bold=b;
|
|
|
|
b.setColor(ev.color);
|
|
|
|
b.setStyle(Qt::SolidPattern);
|
|
|
|
painter.setBrush(b);
|
|
|
|
painter.drawEllipse(QPointF(decotop_xcenter, deco_ytopcenter), width_dot/2.0, width_dot/2.0);
|
|
|
|
painter.setBrush(bold);
|
|
|
|
painter.setPen(pold);
|
|
|
|
}
|
2022-06-08 21:38:26 +08:00
|
|
|
} else if (decoration==MTDddot) {
|
2022-07-11 04:01:11 +08:00
|
|
|
if (!fDrawFontAccent(QChar(0x308))) {
|
|
|
|
p.setWidthF(0.01);
|
|
|
|
painter.setPen(p);
|
|
|
|
QBrush b=painter.brush();
|
|
|
|
const QBrush bold=b;
|
|
|
|
b.setColor(ev.color);
|
|
|
|
b.setStyle(Qt::SolidPattern);
|
|
|
|
painter.setBrush(b);
|
|
|
|
painter.drawEllipse(QPointF(decotop_xcenter-width_dot, deco_ytopcenter), width_dot/2.0, width_dot/2.0);
|
|
|
|
painter.drawEllipse(QPointF(decotop_xcenter+width_dot, deco_ytopcenter), width_dot/2.0, width_dot/2.0);
|
|
|
|
painter.setBrush(bold);
|
|
|
|
painter.setPen(pold);
|
|
|
|
painter.setBrush(bold);
|
|
|
|
}
|
2022-06-08 21:38:26 +08:00
|
|
|
} else if (decoration==MTDstrike) {
|
2022-08-11 20:17:04 +08:00
|
|
|
painter.setPen(pul);
|
2022-06-08 21:38:26 +08:00
|
|
|
const QLineF l((decotop_xstart+decobot_xstart)/2.0, strike_ypos, (decotop_xend+decobot_xend)/2.0, strike_ypos);
|
|
|
|
if (l.length()>0) painter.drawLine(l);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDcancel) {
|
2022-08-11 20:17:04 +08:00
|
|
|
painter.setPen(pul);
|
2022-07-11 04:01:11 +08:00
|
|
|
const QLineF l(decobot_xstart, decobelow_ypos, decotop_xend, deco_ytopbot);
|
2022-06-08 21:38:26 +08:00
|
|
|
if (l.length()>0) painter.drawLine(l);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDbcancel) {
|
2022-08-11 20:17:04 +08:00
|
|
|
painter.setPen(pul);
|
2022-07-11 04:01:11 +08:00
|
|
|
const QLineF l(decobot_xstart, deco_ytopbot, decotop_xend, decobelow_ypos);
|
2022-06-08 21:38:26 +08:00
|
|
|
if (l.length()>0) painter.drawLine(l);
|
|
|
|
painter.setPen(pold);
|
|
|
|
} else if (decoration==MTDxcancel) {
|
2022-08-11 20:17:04 +08:00
|
|
|
painter.setPen(pul);
|
2022-07-11 04:01:11 +08:00
|
|
|
const QLineF l(decobot_xstart, deco_ytopbot, decotop_xend, decobelow_ypos);
|
2022-06-08 21:38:26 +08:00
|
|
|
if (l.length()>0) painter.drawLine(l);
|
2022-07-11 04:01:11 +08:00
|
|
|
const QLineF l1(decobot_xstart, decobelow_ypos, decotop_xend, deco_ytopbot);
|
2022-06-08 21:38:26 +08:00
|
|
|
if (l1.length()>0) painter.drawLine(l1);
|
|
|
|
painter.setPen(pold);
|
|
|
|
}
|
|
|
|
return xnew;
|
|
|
|
}
|
|
|
|
|
2022-08-17 05:05:04 +08:00
|
|
|
bool JKQTMathTextDecoratedNode::toHtml(QString &/*html*/, JKQTMathTextEnvironment /*currentEv*/, JKQTMathTextEnvironment /*defaultEv*/) const {
|
2022-06-08 21:38:26 +08:00
|
|
|
//QString f;
|
|
|
|
//JKQTMathTextEnvironment ev=currentEv;
|
|
|
|
|
|
|
|
//bool ok=child->toHtml(html, ev, defaultEv);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString JKQTMathTextDecoratedNode::getTypeName() const
|
|
|
|
{
|
|
|
|
return "MTdecoratedNode";
|
|
|
|
}
|
|
|
|
|
2022-06-10 02:32:16 +08:00
|
|
|
JKQTMathTextDecoratedNode::DecorationType JKQTMathTextDecoratedNode::getDecoration() const {
|
2022-06-08 21:38:26 +08:00
|
|
|
return this->decoration;
|
|
|
|
}
|
|
|
|
|
|
|
|
|