MTinstruction1Node: Move repeated code to a function

This commit is contained in:
Razi Alavizadeh 2018-12-08 16:49:52 +03:30
parent 1cca87d759
commit ed8c136185
2 changed files with 21 additions and 49 deletions

View File

@ -458,26 +458,8 @@ QString JKQTmathText::MTinstruction1Node::getTypeName() const
void JKQTmathText::MTinstruction1Node::getSizeInternal(QPainter& painter, JKQTmathText::MTenvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) { void JKQTmathText::MTinstruction1Node::getSizeInternal(QPainter& painter, JKQTmathText::MTenvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) {
JKQTmathText::MTenvironment ev=currentEv; JKQTmathText::MTenvironment ev=currentEv;
if (name=="bf" || name=="textbf" || name=="mathbf") ev.bold=true;
else if (name=="em") ev.italic=!ev.italic; setupMTenvironment(ev);
else if (name=="it" || name=="textit" || name=="mathit") ev.italic=true;
else if (name=="textcolor" || name=="mathcolor" || name=="color") ev.color=QColor(parameters.value(0, ev.color.name()));
else if (name=="equation") { ev.italic=true; ev.insideMath=true; }
else if (name=="sc" || name=="textsc" || name=="mathsc") ev.smallCaps=true;
else if (name=="ul" || name=="underline" || name=="underlined") ev.underlined=true;
else if (name=="ol" || name=="overline" || name=="overlined") ev.overline=true;
else if (name=="strike") ev.strike=true;
else if (name=="rm" || name=="textrm") { ev.font=JKQTmathText::MTEroman; }
else if (name=="mathrm" || name=="text" || name=="mbox" || name=="operatorname") { ev.font=JKQTmathText::MTEroman; ev.italic=false; }
else if (name=="mat") { ev.font=JKQTmathText::MTEroman; ev.italic=false; ev.bold=true; }
else if (name=="cal" || name=="textcal" || name=="mathcal") { ev.font=JKQTmathText::MTEcaligraphic; }
else if (name=="bb" || name=="textbb" || name=="mathbb") { ev.font=JKQTmathText::MTEblackboard; }
else if (name=="tt" || name=="texttt" || name=="mathtt") { ev.font=JKQTmathText::MTEtypewriter; }
else if (name=="sf" || name=="textsf" || name=="mathsf") { ev.font=JKQTmathText::MTEsans; }
else if (name=="script" || name=="textscript" || name=="mathscript") { ev.font=JKQTmathText::MTEscript; }
else if (name=="displaystyle") { ev.fontSize=ev.fontSize/0.8; }
else if (name=="scriptstyle") { ev.fontSize=ev.fontSize*0.8; }
else if (name=="scriptscriptstyle") { ev.fontSize=ev.fontSize*0.8*0.8; }
child->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos); child->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
if (name=="colorbox" || name=="fbox" || name=="boxed") { if (name=="colorbox" || name=="fbox" || name=="boxed") {
@ -491,27 +473,9 @@ void JKQTmathText::MTinstruction1Node::getSizeInternal(QPainter& painter, JKQTma
double JKQTmathText::MTinstruction1Node::draw(QPainter& painter, double x, double y, JKQTmathText::MTenvironment currentEv) { double JKQTmathText::MTinstruction1Node::draw(QPainter& painter, double x, double y, JKQTmathText::MTenvironment currentEv) {
doDrawBoxes(painter, x, y, currentEv); doDrawBoxes(painter, x, y, currentEv);
JKQTmathText::MTenvironment ev=currentEv; JKQTmathText::MTenvironment ev=currentEv;
if (name=="bf" || name=="textbf" || name=="mathbf") ev.bold=true;
else if (name=="em") ev.italic=!ev.italic; setupMTenvironment(ev);
else if (name=="it" || name=="textit" || name=="mathit") ev.italic=true;
else if (name=="textcolor" || name=="mathcolor" || name=="color") ev.color=QColor(parameters.value(0, ev.color.name()));
else if (name=="equation") { ev.italic=true; ev.insideMath=true; }
else if (name=="sc" || name=="textsc" || name=="mathsc") ev.smallCaps=true;
else if (name=="ul" || name=="underline" || name=="underlined") ev.underlined=true;
else if (name=="ol" || name=="overline" || name=="overlined") ev.overline=true;
else if (name=="strike") ev.strike=true;
else if (name=="rm" || name=="textrm") { ev.font=JKQTmathText::MTEroman; }
else if (name=="mathrm" || name=="text" || name=="mbox" || name=="operatorname") { ev.font=JKQTmathText::MTEroman; ev.italic=false; }
else if (name=="mat") { ev.font=JKQTmathText::MTEroman; ev.italic=false; ev.bold=true; }
else if (name=="cal" || name=="textcal" || name=="mathcal") { ev.font=JKQTmathText::MTEcaligraphic; }
else if (name=="bb" || name=="textbb" || name=="mathbb") { ev.font=JKQTmathText::MTEblackboard; }
else if (name=="tt" || name=="texttt" || name=="mathtt") { ev.font=JKQTmathText::MTEtypewriter; }
else if (name=="sf" || name=="textsf" || name=="mathsf") { ev.font=JKQTmathText::MTEsans; }
else if (name=="script" || name=="textscript" || name=="mathscript") { ev.font=JKQTmathText::MTEscript; }
else if (name=="displaystyle") { ev.fontSize=ev.fontSize/0.8; }
else if (name=="scriptstyle") { ev.fontSize=ev.fontSize*0.8; }
else if (name=="scriptscriptstyle") { ev.fontSize=ev.fontSize*0.8*0.8; }
QPen oldPen=painter.pen(); QPen oldPen=painter.pen();
double shiftX=0; double shiftX=0;
@ -537,6 +501,20 @@ double JKQTmathText::MTinstruction1Node::draw(QPainter& painter, double x, doubl
bool JKQTmathText::MTinstruction1Node::toHtml(QString &html, JKQTmathText::MTenvironment currentEv, JKQTmathText::MTenvironment defaultEv) { bool JKQTmathText::MTinstruction1Node::toHtml(QString &html, JKQTmathText::MTenvironment currentEv, JKQTmathText::MTenvironment defaultEv) {
JKQTmathText::MTenvironment ev=currentEv; JKQTmathText::MTenvironment ev=currentEv;
setupMTenvironment(ev);
return child->toHtml(html, ev, defaultEv);
}
void JKQTmathText::MTinstruction1Node::set_drawBoxes(bool draw)
{
drawBoxes=draw;
child->set_drawBoxes(draw);
}
void JKQTmathText::MTinstruction1Node::setupMTenvironment(JKQTmathText::MTenvironment &ev)
{
if (name=="bf" || name=="textbf" || name=="mathbf") ev.bold=true; if (name=="bf" || name=="textbf" || name=="mathbf") ev.bold=true;
else if (name=="em") ev.italic=!ev.italic; else if (name=="em") ev.italic=!ev.italic;
else if (name=="it" || name=="textit" || name=="mathit") ev.italic=true; else if (name=="it" || name=="textit" || name=="mathit") ev.italic=true;
@ -557,14 +535,6 @@ bool JKQTmathText::MTinstruction1Node::toHtml(QString &html, JKQTmathText::MTenv
else if (name=="displaystyle") { ev.fontSize=ev.fontSize/0.8; } else if (name=="displaystyle") { ev.fontSize=ev.fontSize/0.8; }
else if (name=="scriptstyle") { ev.fontSize=ev.fontSize*0.8; } else if (name=="scriptstyle") { ev.fontSize=ev.fontSize*0.8; }
else if (name=="scriptscriptstyle") { ev.fontSize=ev.fontSize*0.8*0.8; } else if (name=="scriptscriptstyle") { ev.fontSize=ev.fontSize*0.8*0.8; }
return child->toHtml(html, ev, defaultEv);
}
void JKQTmathText::MTinstruction1Node::set_drawBoxes(bool draw)
{
drawBoxes=draw;
child->set_drawBoxes(draw);
} }

View File

@ -388,6 +388,8 @@ class LIB_EXPORT JKQTmathText : public QObject {
JKQTPGET_MACRO(QString, name) JKQTPGET_MACRO(QString, name)
JKQTPGET_MACRO(QStringList, parameters) JKQTPGET_MACRO(QStringList, parameters)
protected: protected:
void setupMTenvironment(JKQTmathText::MTenvironment &ev);
MTnode* child; MTnode* child;
QString name; QString name;
QStringList parameters; QStringList parameters;