diff --git a/doc/dox/todo.dox b/doc/dox/todo.dox
index cad6088d0d..aac2ab7f7d 100644
--- a/doc/dox/todo.dox
+++ b/doc/dox/todo.dox
@@ -41,7 +41,7 @@ This page lists several todos and wishes for future version of JKQTPlotter
add instruction for unicode-characters \char"XXXX, \unicode{XXXX}, \utf8{XXXX}, \utf16{XXXX}, \utf32{XXXX} ...
check sub/superscript with italic text in math mode, possibly a correction is necessary
explore where QFontMetricsF::horizontalAdvance() can be used (for Qt >=5.15)
-
+ correction of frac-height (2*maxHeight or height1+height2) should be done by brace-node, not frac-node
diff --git a/doc/dox/whatsnew.dox b/doc/dox/whatsnew.dox
index 766adfcf4d..ba9bbd9f48 100644
--- a/doc/dox/whatsnew.dox
+++ b/doc/dox/whatsnew.dox
@@ -14,21 +14,29 @@ This page lists release notes for the different version of JKQTPlotter
\subsection page_whatsnew_TRUNK_OVERVIEW trunk: Overview
Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
- - fixed issue described in #62: Fix custom labels draw, because giving exactly two label-strings did not display all of them, thanks to user:FalsinSoft
- - fixed issue #70: Typo in jkqtplotter/CMakeLists.txt, thanks to user:tedlinlab
- - fixed: styling was not properly applied to coordinate axes of colorbars outside the plot
- - fixed: JKQTMathText added a little whitespace before and after the LaTeX-string. This was removed as it disturbed the layout of text in plots
- - fixes/improvements: JKQTMathText renders several LaTeX strings better (simple braces in math mode, +-*... as symbols with proper sizes in math mode, added some missing instruction aliases, improved size of \vec and \hat, corrrected fonts usage for mathrm
- - improved: high-dpr-support in JKQTMathText
- - improved: QT6-compatibility by removing deprecated warnings
- - NEW: JKQTPFilledCurveXGraph and JKQTPFilledCurveYGraph can now plot wiggle plots with different fill styles above and below the baseline (feature request #68 Wiggle Plots from user:xichaoqiang
- - NEW/BREAKING CHANGE: data tooltip can now also be shown when "just" moving the mouse (so far this was only possible when dragging the mouse with a button pressed). This also removes JKQtPlotter::getActMouseLeftAsToolTip() and adds JKQtPlotter::getActMouseMoveToolTip() instead! Also the default toolbars and context menus changed!
- - NEW: new "seaborn" style for plots
- - NEW/BREAKING CHANGE: changed JKQTPColorDerivationMode into a struct, which extends its capabilities above the previously available few enum-items
- - NEW: added debug-feature to show boxes around text in the plot
- - NEW: JKQTMathText: now supports new decoration instructions: \cancel, \xcancel, \bcancel, \sout, \ocirc, \widetilde, \widehat, \breve
- - NEW: JKQTMathText: reworked drawing of decorations: improved appearance and positioning!
- - NEW: JKQTMathText: reworked code structure: broke up large, single CPP-files into several smaller files!
+ - JKQtPlotter:
+ - fixed issue described in #62: Fix custom labels draw, because giving exactly two label-strings did not display all of them, thanks to user:FalsinSoft
+ - fixed issue #70: Typo in jkqtplotter/CMakeLists.txt, thanks to user:tedlinlab
+ - fixed: styling was not properly applied to coordinate axes of colorbars outside the plot
+ - improved: QT6-compatibility by removing deprecated warnings
+ - NEW: JKQTPFilledCurveXGraph and JKQTPFilledCurveYGraph can now plot wiggle plots with different fill styles above and below the baseline (feature request #68 Wiggle Plots from user:xichaoqiang
+ - NEW/BREAKING CHANGE: data tooltip can now also be shown when "just" moving the mouse (so far this was only possible when dragging the mouse with a button pressed). This also removes JKQtPlotter::getActMouseLeftAsToolTip() and adds JKQtPlotter::getActMouseMoveToolTip() instead! Also the default toolbars and context menus changed!
+ - NEW: new "seaborn" style for plots
+ - NEW/BREAKING CHANGE: changed JKQTPColorDerivationMode into a struct, which extends its capabilities above the previously available few enum-items
+ - NEW: added debug-feature to show boxes around text in the plot
+
+
+ - JKQTMathText:
+ - fixed: JKQTMathText added a little whitespace before and after the LaTeX-string. This was removed as it disturbed the layout of text in plots
+ - fixed: height-calculation of frac-like instructions: before the ascent and descent were equal, even if the numerator and denominator have different hieghts
+ - fixes/improvements: JKQTMathText renders several LaTeX strings better (simple braces in math mode, +-*... as symbols with proper sizes in math mode, added some missing instruction aliases, improved size of \vec and \hat, corrrected fonts usage for mathrm
+ - improved: high-dpr-support in JKQTMathText
+ - NEW: now supports new decoration instructions: \cancel, \xcancel, \bcancel, \sout, \ocirc, \widetilde, \widehat, \breve
+ - NEW: reworked drawing of decorations: improved appearance and positioning!
+ - NEW: reworked code structure: broke up large, single CPP-files into several smaller files!
+ - NEW: reworked node class tree: inserted base-class nodes for single-child, dual-child!
+ - NEW: improved frac-rendering: font-scaling takes nesting-level into account, overall-rendering, sizes, if a brace surrounds a frac, the heights are equal above and below to center the brace , ...
+
\subsection page_whatsnew_TRUNK_DOWNLOAD trunk: Download
diff --git a/doc/images/jkqtmathtext_fracnode_geo.cdr b/doc/images/jkqtmathtext_fracnode_geo.cdr
new file mode 100644
index 0000000000..8c0ba1869f
Binary files /dev/null and b/doc/images/jkqtmathtext_fracnode_geo.cdr differ
diff --git a/doc/images/jkqtmathtext_fracnode_geo.png b/doc/images/jkqtmathtext_fracnode_geo.png
new file mode 100644
index 0000000000..832d71ca33
Binary files /dev/null and b/doc/images/jkqtmathtext_fracnode_geo.png differ
diff --git a/doc/images/jkqtmathtext_node_geo.cdr b/doc/images/jkqtmathtext_node_geo.cdr
index 155eccd4ef..3a4faed601 100644
Binary files a/doc/images/jkqtmathtext_node_geo.cdr and b/doc/images/jkqtmathtext_node_geo.cdr differ
diff --git a/doc/images/jkqtmathtext_node_geo.png b/doc/images/jkqtmathtext_node_geo.png
index 925e9390a9..600e4e0ec3 100644
Binary files a/doc/images/jkqtmathtext_node_geo.png and b/doc/images/jkqtmathtext_node_geo.png differ
diff --git a/doc/images/jkqtmathtext_sfracnode_geo.cdr b/doc/images/jkqtmathtext_sfracnode_geo.cdr
new file mode 100644
index 0000000000..3f4a14bbcb
Binary files /dev/null and b/doc/images/jkqtmathtext_sfracnode_geo.cdr differ
diff --git a/doc/images/jkqtmathtext_sfracnode_geo.png b/doc/images/jkqtmathtext_sfracnode_geo.png
new file mode 100644
index 0000000000..e14823588e
Binary files /dev/null and b/doc/images/jkqtmathtext_sfracnode_geo.png differ
diff --git a/examples/jkqtmathtext_test/mathtest.pdf b/examples/jkqtmathtext_test/mathtest.pdf
index c5bcf39c6b..4795f7daf1 100644
Binary files a/examples/jkqtmathtext_test/mathtest.pdf and b/examples/jkqtmathtext_test/mathtest.pdf differ
diff --git a/examples/jkqtmathtext_test/mathtest.tex b/examples/jkqtmathtext_test/mathtest.tex
index a4480f6373..2bfd925168 100644
--- a/examples/jkqtmathtext_test/mathtest.tex
+++ b/examples/jkqtmathtext_test/mathtest.tex
@@ -130,5 +130,7 @@
\item\textbf{math: frac test:} \[\frac{a}{b}+\frac{g}{a}-\frac{a^2}{b^2}\cdot\frac{a^2}{b^{\frac{1}{2}}}\]
\end{itemize}
+
+
\end{document}
\ No newline at end of file
diff --git a/lib/jkqtmathtext/jkqtmathtext.cpp b/lib/jkqtmathtext/jkqtmathtext.cpp
index 492828c4f2..bf9373afd4 100644
--- a/lib/jkqtmathtext/jkqtmathtext.cpp
+++ b/lib/jkqtmathtext/jkqtmathtext.cpp
@@ -67,7 +67,8 @@ JKQTMathText::JKQTMathText(QObject* parent):
brace_shrink_factor=0.6;
fontColor=QColor("black");
- frac_factor=0.9;
+ frac_factor=1.0;
+ frac_nested_factor=0.7;
frac_shift_factor=0.4;
underbrace_factor=0.75;
undersetFactor=0.7;
@@ -733,6 +734,16 @@ double JKQTMathText::getFracFactor() const
return this->frac_factor;
}
+void JKQTMathText::setFracNestedFactor(double __value)
+{
+ frac_nested_factor=__value;
+}
+
+double JKQTMathText::getFracNestedFactor() const
+{
+ return frac_nested_factor;
+}
+
void JKQTMathText::setFracShiftFactor(double __value)
{
this->frac_shift_factor = __value;
@@ -962,7 +973,7 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, const QString& quitOn
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
if (n1 && n2) nl->addNode(new JKQTMathTextFracNode(this, n1, n2, MTFMfrac));
else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(name));
- } else if (name=="dfrac") {
+ } else if (name=="dfrac" || name=="cfrac") {
JKQTMathTextNode* n1=parseLatexString(true);
JKQTMathTextNode* n2=nullptr;
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
diff --git a/lib/jkqtmathtext/jkqtmathtext.h b/lib/jkqtmathtext/jkqtmathtext.h
index 801249bcdd..dc4975aa14 100644
--- a/lib/jkqtmathtext/jkqtmathtext.h
+++ b/lib/jkqtmathtext/jkqtmathtext.h
@@ -466,11 +466,17 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
void setUndersetFactor(double __value);
/** \copydoc undersetFactor */
double getUndersetFactor() const;
- /** \copydoc frac_factor */
+ /** \copydoc frac_factor */
void setFracFactor(double __value);
- /** \copydoc frac_factor */
+ /** \copydoc frac_factor */
double getFracFactor() const;
- /** \copydoc frac_shift_factor */
+ /** \copydoc frac_nested_factor */
+ void setFracNestedFactor(double __value);
+ /** \copydoc frac_nested_factor */
+ double getFracNestedFactor() const;
+
+
+ /** \copydoc frac_shift_factor */
void setFracShiftFactor(double __value);
/** \copydoc frac_shift_factor */
double getFracShiftFactor() const;
@@ -541,8 +547,10 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
double sub_shift_factor;
- /** \brief scaling factor for font of nominator and denominator of a fraction */
+ /** \brief scaling factor for font size of nominator and denominator of a fraction */
double frac_factor;
+ /** \brief scaling factor for font size of nominator and denominator of a nested fraction */
+ double frac_nested_factor;
/** \brief shift of denominator/nummerator away from central line of a frac */
double frac_shift_factor;
/** \brief scaling factor for font of underbrace/overbrace text */
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.cpp
index a52bcab1b0..de155962dd 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.cpp
@@ -37,30 +37,29 @@
JKQTMathTextBraceNode::JKQTMathTextBraceNode(JKQTMathText* _parent, const QString& openbrace, const QString& closebrace, JKQTMathTextNode* child, bool showRightBrace):
- JKQTMathTextNode(_parent)
+ JKQTMathTextSingleChildNode(child, _parent)
{
- this->child=child;
this->openbrace=openbrace;
this->closebrace=closebrace;
this->showRightBrace=showRightBrace;
}
+
JKQTMathTextBraceNode::~JKQTMathTextBraceNode() {
- if (child!=nullptr) delete child;
}
void JKQTMathTextBraceNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
- JKQTMathTextEnvironment ev=currentEv;
+ const JKQTMathTextEnvironment ev=currentEv;
child->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
double bracewidth=0, braceheight=0;
getBraceWidth(painter, ev, baselineHeight, overallHeight, bracewidth, braceheight);
- bracewidth=bracewidth/parent->getBraceShrinkFactor();
+ bracewidth=bracewidth/parentMathText->getBraceShrinkFactor();
- baselineHeight=/*qMin(baselineHeight, braceheight)*/ baselineHeight*parent->getBraceFactor();
- overallHeight=qMax(overallHeight, braceheight)*parent->getBraceFactor(); //fm.height();
+ baselineHeight=/*qMin(baselineHeight, braceheight)*/ baselineHeight*parentMathText->getBraceFactor();
+ overallHeight=qMax(overallHeight, braceheight)*parentMathText->getBraceFactor(); //fm.height();
width=width+bracewidth*2.0;
@@ -87,11 +86,11 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
getSize(painter, currentEv, cWidth, cBaselineHeight, cOverallHeight, cstrikeoutPos);
- double lw=qMax(0.25,ceil(currentEv.fontSize/16.0));//fm.lineWidth();
+ const double lw=qMax(0.25,ceil(currentEv.fontSize/16.0));//fm.lineWidth();
double xnew=x+lw;
- QPen pold=painter.pen();
+ const QPen pold=painter.pen();
QPen p=pold;
p.setWidthF(lw);
p.setColor(currentEv.color);
@@ -99,15 +98,15 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
double brace_fraction=0.85;
if (openbrace=="(") {
QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
path.moveTo(xnew+brace_fraction*bracewidth, y1);
path.cubicTo(xnew, (y1+y2)/2.0+fabs(y1-y2)/6.0, xnew, (y1+y2)/2.0-fabs(y1-y2)/6.0 , xnew+brace_fraction*bracewidth, y2);
painter.drawPath(path);
} else if (openbrace=="[") {
QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
path.moveTo(xnew+brace_fraction*bracewidth, y1);
path.lineTo(xnew+lw/2.0, y1);
path.lineTo(xnew+lw/2.0, y2);
@@ -122,39 +121,36 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
} else if (openbrace=="_") {
QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
path.moveTo(xnew+brace_fraction*bracewidth, y1);
path.lineTo(xnew, y1);
path.lineTo(xnew, y2);
painter.drawPath(path);
} else if (openbrace=="~") {
QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
path.moveTo(xnew, y1);
path.lineTo(xnew, y2);
path.lineTo(xnew+brace_fraction*bracewidth, y2);
painter.drawPath(path);
} else if (openbrace=="|") {
- QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
QLineF l(xnew+brace_fraction*bracewidth, y1, xnew+brace_fraction*bracewidth, y2);
if (l.length()>0) painter.drawLine(l);
- painter.drawPath(path);
} else if (openbrace=="#" || openbrace=="||") {
- QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
QLineF l(xnew+brace_fraction*bracewidth, y1, xnew+brace_fraction*bracewidth, y2);
if (l.length()>0) painter.drawLine(l);
l=QLineF(xnew+brace_fraction*bracewidth-1.5*lw, y1, xnew+brace_fraction*bracewidth-1.5*lw, y2);
if (l.length()>0) painter.drawLine(l);
} else if (openbrace=="<") {
QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
path.moveTo(xnew+brace_fraction*bracewidth, y1);
path.lineTo(xnew, (y2+y1)/2.0);
path.lineTo(xnew+brace_fraction*bracewidth, y2);
@@ -163,21 +159,21 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
painter.setPen(pold);
- xnew= child->draw(painter, xnew+bracewidth/parent->getBraceShrinkFactor()-lw, y, currentEv)+lw;
+ xnew= child->draw(painter, xnew+bracewidth/parentMathText->getBraceShrinkFactor()-lw, y, currentEv)+lw;
if (showRightBrace) {
painter.setPen(p);
if (closebrace==")") {
QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
path.moveTo(xnew+(1.0-brace_fraction)*bracewidth, y1);
path.cubicTo(xnew+bracewidth, (y1+y2)/2.0+fabs(y1-y2)/6.0, xnew+bracewidth, (y1+y2)/2.0-fabs(y1-y2)/6.0 , xnew+(1.0-brace_fraction)*bracewidth, y2);
painter.drawPath(path);
} else if (closebrace=="]") {
QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
path.moveTo(xnew+(1.0-brace_fraction)*bracewidth, y1);
path.lineTo(xnew+bracewidth-lw/2.0, y1);
path.lineTo(xnew+bracewidth-lw/2.0, y2);
@@ -192,39 +188,36 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
} else if (closebrace=="_") {
QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
path.moveTo(xnew+(1.0-brace_fraction)*bracewidth, y1);
path.lineTo(xnew+bracewidth, y1);
path.lineTo(xnew+bracewidth, y2);
painter.drawPath(path);
} else if (closebrace=="~") {
QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
path.moveTo(xnew+bracewidth, y1);
path.lineTo(xnew+bracewidth, y2);
path.lineTo(xnew+(1.0-brace_fraction)*bracewidth, y2);
painter.drawPath(path);
} else if (closebrace=="|") {
- QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
QLineF l(xnew+(1.0-brace_fraction)*bracewidth, y1, xnew+(1.0-brace_fraction)*bracewidth, y2);
if (l.length()>0) painter.drawLine(l);
- painter.drawPath(path);
} else if (closebrace=="#" || closebrace=="||") {
- QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
QLineF l(xnew+(1.0-brace_fraction)*bracewidth, y1, xnew+(1.0-brace_fraction)*bracewidth, y2);
if (l.length()>0) painter.drawLine(l);
l=QLineF(xnew+(1.0-brace_fraction)*bracewidth+1.5*lw, y1, xnew+(1.0-brace_fraction)*bracewidth+1.5*lw, y2);
if (l.length()>0) painter.drawLine(l);
} else if (closebrace==">") {
QPainterPath path;
- double y1=y+(cOverallHeight-cBaselineHeight);
- double y2=y-cBaselineHeight;
+ const double y1=y+(cOverallHeight-cBaselineHeight);
+ const double y2=y-cBaselineHeight;
path.moveTo(xnew+(1.0-brace_fraction)*bracewidth, y1);
path.lineTo(xnew+bracewidth, (y2+y1)/2.0);
path.lineTo(xnew+(1.0-brace_fraction)*bracewidth, y2);
@@ -234,7 +227,7 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
}
//qDebug()<<" ==> "<getBraceShrinkFactor()-lw;
+ return xnew+bracewidth/parentMathText->getBraceShrinkFactor()-lw;
}
bool JKQTMathTextBraceNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
@@ -259,19 +252,24 @@ bool JKQTMathTextBraceNode::toHtml(QString &html, JKQTMathTextEnvironment curren
return ok;
}
-void JKQTMathTextBraceNode::setDrawBoxes(bool draw)
-{
- this->drawBoxes=draw;
- child->setDrawBoxes(draw);
-
-}
-
QString JKQTMathTextBraceNode::getTypeName() const
{
return QLatin1String("MTbraceNode(")+openbrace+" "+closebrace+")";
}
-void JKQTMathTextBraceNode::getBraceWidth(QPainter &/*painter*/, JKQTMathTextEnvironment ev, double /*baselineHeight*/, double overallHeight, double &bracewidth, double &braceheight)
+QString JKQTMathTextBraceNode::getOpenbrace() const {
+ return this->openbrace;
+}
+
+QString JKQTMathTextBraceNode::getClosebrace() const {
+ return this->closebrace;
+}
+
+bool JKQTMathTextBraceNode::getShowRightBrace() const {
+ return this->showRightBrace;
+}
+
+void JKQTMathTextBraceNode::getBraceWidth(QPainter &/*painter*/, JKQTMathTextEnvironment ev, double /*baselineHeight*/, double overallHeight, double &bracewidth, double &braceheight) const
{
/*QFont evf=ev.getFont(parent);
if (ev.insideMath) evf.setItalic(false);
@@ -289,7 +287,7 @@ void JKQTMathTextBraceNode::getBraceWidth(QPainter &/*painter*/, JKQTMathTextEnv
bracewidth=fm.width("I")*parent->getBraceShrinkFactor();
braceheight=parent->getTBR(evf, bc, painter.device()).height();*/
double lw=qMax(0.25,ceil(ev.fontSize/12.0));
- braceheight=overallHeight*parent->getBraceFactor();
+ braceheight=overallHeight*parentMathText->getBraceFactor();
bracewidth=0.6*pow(braceheight, 0.6);
if (openbrace=="{" || closebrace=="}") bracewidth=qMax(bracewidth, lw*3.5);
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.h b/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.h
index ea1c60d609..a311a422ea 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.h
@@ -35,7 +35,7 @@ class JKQTMathText; // forward
/** \brief subclass representing a brace node
* \ingroup jkqtmathtext_items
*/
-class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceNode: public JKQTMathTextNode {
+class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceNode: public JKQTMathTextSingleChildNode {
public:
JKQTMathTextBraceNode(JKQTMathText* parent, const QString& openbrace, const QString& closebrace, JKQTMathTextNode* child, bool showRightBrace=true);
virtual ~JKQTMathTextBraceNode() override;
@@ -43,35 +43,25 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceNode: public JKQTMathTextNode {
virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
/** \copydoc JKQTMathTextNode::toHtml() */
virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
- /** \copydoc JKQTMathTextNode::setDrawBoxes() */
- virtual void setDrawBoxes(bool draw) override;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
- /** \brief returns the child node */
- inline JKQTMathTextNode* getChild() const {
- return this->child;
- }
- /** \copydoc openbrace */
- inline QString getOpenbrace() const {
- return this->openbrace;
- }
+ /** \copydoc openbrace */
+ QString getOpenbrace() const;
/** \copydoc closebrace */
- inline QString getClosebrace() const {
- return this->closebrace;
- }
+ QString getClosebrace() const;
/** \copydoc showRightBrace */
- inline bool getShowRightBrace() const {
- return this->showRightBrace;
- }
+ bool getShowRightBrace() const;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
- JKQTMathTextNode* child;
+ /**\brief opening brace */
QString openbrace;
+ /**\brief closing brace */
QString closebrace;
+ /**\brief if \c true, the right-hand-side brace is drawn */
bool showRightBrace;
-
- void getBraceWidth(QPainter& painter, JKQTMathTextEnvironment currentEv, double baselineHeight, double overallHeight, double& bracewidth, double& braceheight);
+ /** \brief calculate the width of the brace */
+ void getBraceWidth(QPainter& painter, JKQTMathTextEnvironment currentEv, double baselineHeight, double overallHeight, double& bracewidth, double& braceheight) const;
};
#endif // JKQTMATHTEXTBRACENODE_H
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.cpp
index 1865d1c7cb..6633820564 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.cpp
@@ -39,23 +39,21 @@
JKQTMathTextDecoratedNode::JKQTMathTextDecoratedNode(JKQTMathText* _parent, JKQTMathTextDecoration decoration, JKQTMathTextNode* child):
- JKQTMathTextNode(_parent)
+ JKQTMathTextSingleChildNode(child, _parent)
{
- this->child=child;
this->decoration=decoration;
}
JKQTMathTextDecoratedNode::~JKQTMathTextDecoratedNode() {
- if (child!=nullptr) delete child;
}
void JKQTMathTextDecoratedNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
- const QFontMetricsF fm(currentEv.getFont(parent), painter.device());
+ const QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
child->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
const double italic_xcorrection=getNonItalicXCorretion(painter, width, currentEv, child);
- const double decoheightfactor=parent->getDecorationHeightFactor();
+ const double decoheightfactor=parentMathText->getDecorationHeightFactor();
const double deco_miniwidth=((decoration==MTDtilde||decoration==MTDbreve)?fm.boundingRect("~").width():fm.boundingRect("^").width())-italic_xcorrection;
const double decoAboveAscent_yposdelta=fm.ascent()*(1.0+2.0*decoheightfactor);
@@ -76,19 +74,19 @@ double JKQTMathTextDecoratedNode::draw(QPainter& painter, double x, double y, JK
JKQTMathTextEnvironment ev=currentEv;
double width=0, baselineHeight=0, overallHeight=0, strikeoutPos=0;
child->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
- const QFont font=ev.getFont(parent);
+ const QFont font=ev.getFont(parentMathText);
const QFontMetricsF fm(font, painter.device());
const double width_X=fm.boundingRect("X").width();
const double width_x=fm.boundingRect("x").width();
const double width_dot=fm.boundingRect(".").width()/2.0;
- const double decoheightfactor=parent->getDecorationHeightFactor();
+ const double decoheightfactor=parentMathText->getDecorationHeightFactor();
const double deco_ypos=y-baselineHeight*(1.0+decoheightfactor);
const double decoAboveAscent_ypos=y-fm.ascent()*(1.0+decoheightfactor);
const double strike_ypos=y-baselineHeight/2.0;
const double decobelow_ypos=y+qMax((overallHeight-baselineHeight)*(1.0+decoheightfactor), fm.xHeight()*decoheightfactor);
const double deco_height=decoheightfactor*baselineHeight;
const double italic_xcorrection=getNonItalicXCorretion(painter, width, ev, child);
- const double deco_xoffset=parent->getDecorationWidthReductionXFactor()*width_X/2.0;
+ const double deco_xoffset=parentMathText->getDecorationWidthReductionXFactor()*width_X/2.0;
const double deco_width=std::max(width_x*0.5,width-2.0*deco_xoffset-italic_xcorrection);
const double deco_vecwidth=width_x*0.33;
const double deco_miniwidth=((decoration==MTDtilde||decoration==MTDbreve)?fm.boundingRect("~").width():fm.boundingRect("^").width())-italic_xcorrection;
@@ -104,7 +102,7 @@ double JKQTMathTextDecoratedNode::draw(QPainter& painter, double x, double y, JK
QPen pold=painter.pen();
QPen p=pold;
p.setColor(ev.color);
- p.setWidthF(qMax(parent->ABS_MIN_LINEWIDTH, fm.lineWidth()));//ceil(currentEv.fontSize/16.0));
+ p.setWidthF(qMax(parentMathText->ABS_MIN_LINEWIDTH, fm.lineWidth()));//ceil(currentEv.fontSize/16.0));
double xnew=child->draw(painter, x, y, ev);
@@ -279,22 +277,11 @@ bool JKQTMathTextDecoratedNode::toHtml(QString &/*html*/, JKQTMathTextEnvironmen
return false;
}
-void JKQTMathTextDecoratedNode::setDrawBoxes(bool draw)
-{
- this->drawBoxes=draw;
- child->setDrawBoxes(draw);
-
-}
-
QString JKQTMathTextDecoratedNode::getTypeName() const
{
return "MTdecoratedNode";
}
-JKQTMathTextNode *JKQTMathTextDecoratedNode::getChild() const {
- return this->child;
-}
-
JKQTMathTextDecoration JKQTMathTextDecoratedNode::getDecoration() const {
return this->decoration;
}
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.h b/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.h
index 0f4d7dd61c..23e2787c0c 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.h
@@ -38,7 +38,7 @@ class JKQTMathText; // forward
* \image html mathparser/decoration_sizing.png
*
*/
-class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextDecoratedNode: public JKQTMathTextNode {
+class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextDecoratedNode: public JKQTMathTextSingleChildNode {
public:
JKQTMathTextDecoratedNode(JKQTMathText* parent, JKQTMathTextDecoration decoration, JKQTMathTextNode* child);
virtual ~JKQTMathTextDecoratedNode() override;
@@ -46,19 +46,13 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextDecoratedNode: public JKQTMathTextNode
virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
/** \copydoc JKQTMathTextNode::toHtml() */
virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
- /** \copydoc JKQTMathTextNode::setDrawBoxes() */
- virtual void setDrawBoxes(bool draw) override;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override ;
- /** \brief returns the child node */
- JKQTMathTextNode* getChild() const;
/** \copydoc decoration */
JKQTMathTextDecoration getDecoration() const;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
- /** \brief child node that is decorated by this node */
- JKQTMathTextNode* child;
/** \brief type of decoration that is added to the child node */
JKQTMathTextDecoration decoration;
};
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.cpp
index 1c28b15242..eb2f065f5c 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.cpp
@@ -20,6 +20,7 @@
#include "jkqtmathtext/nodes/jkqtmathtextfracnode.h"
+#include "jkqtmathtext/nodes/jkqtmathtextbracenode.h"
#include "jkqtmathtext/jkqtmathtexttools.h"
#include "jkqtmathtext/jkqtmathtext.h"
#include "jkqtcommon/jkqtpcodestructuring.h"
@@ -39,16 +40,12 @@
JKQTMathTextFracNode::JKQTMathTextFracNode(JKQTMathText* _parent, JKQTMathTextNode* child_top, JKQTMathTextNode* child_bottom, JKQTMathTextFracMode mode):
- JKQTMathTextNode(_parent)
+ JKQTMathTextDualChildNode(child_top, child_bottom, _parent)
{
- this->child1=child_top;
- this->child2=child_bottom;
this->mode=mode;
}
JKQTMathTextFracNode::~JKQTMathTextFracNode() {
- if (child1!=nullptr) delete child1;
- if (child2!=nullptr) delete child2;
}
QString JKQTMathTextFracNode::getTypeName() const
@@ -57,25 +54,25 @@ QString JKQTMathTextFracNode::getTypeName() const
}
void JKQTMathTextFracNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
- QFontMetricsF fm(currentEv.getFont(parent), painter.device());
+ QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
JKQTMathTextEnvironment ev1=currentEv;
JKQTMathTextEnvironment ev2=currentEv;
- double xh=fm.xHeight(); //tightBoundingRect("x").height();
- double sp=xh;
- double Ah=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parent), "M", painter.device()).height();//fm.ascent();
- double xw=fm.boundingRect("x").width();
+ const double xheight=fm.xHeight(); //tightBoundingRect("x").height();
+ const double line_ascent=xheight/2.0;
+ const double Mheight=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device()).height();//fm.ascent();
+ const double xwidth=fm.boundingRect("x").width();
if (mode==MTFMunderbrace || mode==MTFMoverbrace) {
- ev2.fontSize=ev2.fontSize*parent->getUnderbraceFactor();
+ ev2.fontSize=ev2.fontSize*parentMathText->getUnderbraceFactor();
} else if (mode==MTFMunderset || mode==MTFMoverset) {
- ev2.fontSize=ev2.fontSize*parent->getUndersetFactor();
+ ev2.fontSize=ev2.fontSize*parentMathText->getUndersetFactor();
} else if (mode==MTFMfrac || mode==MTFMsfrac) {
- ev1.fontSize=ev1.fontSize*parent->getFracFactor();
- ev2.fontSize=ev2.fontSize*parent->getFracFactor();
+ ev1.fontSize=ev1.fontSize*getFracScalingFactor();
+ ev2.fontSize=ev2.fontSize*getFracScalingFactor();
} else if (mode==MTFMtfrac || mode==MTFMstfrac) {
- ev1.fontSize=ev1.fontSize*parent->getFracFactor()*0.7;
- ev2.fontSize=ev2.fontSize*parent->getFracFactor()*0.7;
+ ev1.fontSize=ev1.fontSize*getFracScalingFactor()*0.7;
+ ev2.fontSize=ev2.fontSize*getFracScalingFactor()*0.7;
}
@@ -84,59 +81,99 @@ void JKQTMathTextFracNode::getSizeInternal(QPainter& painter, JKQTMathTextEnviro
child1->getSize(painter, ev1, width1, baselineHeight1, overallHeight1, strikeoutPos1);
child2->getSize(painter, ev2, width2, baselineHeight2, overallHeight2, strikeoutPos2);
+
+ const double maxHeight=qMax(overallHeight1,overallHeight2);
+ const bool _isBraceParentNearerThanFrac=isBraceParentNearerThanFrac();
+ const double height1OrMaxHeight=(_isBraceParentNearerThanFrac)?maxHeight:overallHeight1;
+ const double height2OrMaxHeight=(_isBraceParentNearerThanFrac)?maxHeight:overallHeight2;
overallHeight=0;
baselineHeight=0;
width=0;
- if (mode==MTFMfrac || mode==MTFMdfrac || mode==MTFMtfrac) {
- //std::cout<<"\nxh="< baselineHeight="<addToErrorList(QObject::tr("unknown instruction '%1' found!").arg(name));
}
}
JKQTMathTextInstruction1Node::~JKQTMathTextInstruction1Node() {
- if (child!=nullptr) delete child;
}
QString JKQTMathTextInstruction1Node::getTypeName() const
@@ -65,7 +63,7 @@ void JKQTMathTextInstruction1Node::getSizeInternal(QPainter& painter, JKQTMathTe
child->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
if (name=="colorbox" || name=="fbox" || name=="boxed") {
- QFontMetricsF fm(ev.getFont(parent));
+ QFontMetricsF fm(ev.getFont(parentMathText));
double xw=fm.boundingRect("x").width();
width+=xw;
overallHeight+=xw;
@@ -88,7 +86,7 @@ double JKQTMathTextInstruction1Node::draw(QPainter& painter, double x, double y,
double width, baselineHeight, overallHeight, strikeoutPos;
child->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
QPen p=painter.pen();
- QFontMetricsF fm(currentEv.getFont(parent));
+ QFontMetricsF fm(currentEv.getFont(parentMathText));
double xw=fm.boundingRect("x").width();
p.setColor(fcol);
painter.setPen(p);
@@ -109,16 +107,6 @@ bool JKQTMathTextInstruction1Node::toHtml(QString &html, JKQTMathTextEnvironment
return child->toHtml(html, ev, defaultEv);
}
-void JKQTMathTextInstruction1Node::setDrawBoxes(bool draw)
-{
- drawBoxes=draw;
- child->setDrawBoxes(draw);
-}
-
-JKQTMathTextNode *JKQTMathTextInstruction1Node::getChild() const {
- return this->child;
-}
-
QString JKQTMathTextInstruction1Node::getName() const {
return this->name;
}
@@ -127,7 +115,7 @@ QStringList JKQTMathTextInstruction1Node::getParameters() const {
return this->parameters;
}
-bool JKQTMathTextInstruction1Node::setupMTenvironment(JKQTMathTextEnvironment &ev)
+bool JKQTMathTextInstruction1Node::setupMTenvironment(JKQTMathTextEnvironment &ev) const
{
if (name=="bf" || name=="textbf" || name=="mathbf") ev.bold=true;
else if (name=="em") ev.italic=!ev.italic;
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.h b/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.h
index 5839ee341a..39a8d00b38 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.h
@@ -34,7 +34,7 @@ class JKQTMathText; // forward
/** \brief subclass representing an instruction node with exactly one argument in the syntax tree
* \ingroup jkqtmathtext_items
*/
-class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextInstruction1Node: public JKQTMathTextNode {
+class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextInstruction1Node: public JKQTMathTextSingleChildNode {
public:
explicit JKQTMathTextInstruction1Node(JKQTMathText* parent, const QString& name, JKQTMathTextNode* child, const QStringList& parameters=QStringList());
virtual ~JKQTMathTextInstruction1Node() override;
@@ -45,10 +45,6 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextInstruction1Node: public JKQTMathTextN
/** \brief convert node to HTML and returns \c true on success */
/** \copydoc JKQTMathTextNode::toHtml() */
virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
- /** \copydoc JKQTMathTextNode::setDrawBoxes() */
- virtual void setDrawBoxes(bool draw) override;
- /** \brief returns the child node */
- JKQTMathTextNode* getChild() const;
/** \copydoc name */
QString getName() const;
/** \copydoc parameters */
@@ -56,10 +52,11 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextInstruction1Node: public JKQTMathTextN
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
- bool setupMTenvironment(JKQTMathTextEnvironment &ev);
-
- JKQTMathTextNode* child;
+ /** \brief set all properties in \a ev, as appropriate for the represented instruction */
+ bool setupMTenvironment(JKQTMathTextEnvironment &ev) const;
+ /** \brief instruction name */
QString name;
+ /** \brief additional string-parameters */
QStringList parameters;
};
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextlistnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextlistnode.cpp
index 4b12f081b8..5bd6fe1e39 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextlistnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextlistnode.cpp
@@ -36,18 +36,17 @@
#include
-
+QSet JKQTMathTextListNode::subsupOperations= (QSet()<<"sum"<<"prod"<<"coprod"
+ <<"bigcap"<<"bigcup"<<"bigvee"<<"bighat"
+ <<"int"<<"iint"<<"iiint"<<"oint"<<"oiint"<<"oiiint"
+ <<"mod"<<"median"<<"max"<<"min"<<"argmax"<<"argmin"<<"sup"<<"inf"
+ <<"liminf"<<"limsup"<<"lim"<<"max"<<"min");
JKQTMathTextListNode::JKQTMathTextListNode(JKQTMathText* _parent):
JKQTMathTextNode(_parent)
{
nodes.clear();
// these operations cause sub/sup script to be typeset over/under the operator, not right besides!
- subsupOperations<<"sum"<<"prod"<<"coprod"
- <<"bigcap"<<"bigcup"<<"bigvee"<<"bighat"
- <<"int"<<"iint"<<"iiint"<<"oint"<<"oiint"<<"oiiint"
- <<"mod"<<"median"<<"max"<<"min"<<"argmax"<<"argmin"<<"sup"<<"inf"
- <<"liminf"<<"limsup"<<"lim"<<"max"<<"min";
}
JKQTMathTextListNode::~JKQTMathTextListNode() {
@@ -67,7 +66,7 @@ void JKQTMathTextListNode::getSizeInternal(QPainter& painter, JKQTMathTextEnviro
overallHeight=0;
baselineHeight=0;
strikeoutPos=0;
- QFontMetricsF fm(currentEv.getFont(parent));
+ QFontMetricsF fm(currentEv.getFont(parentMathText));
//QRectF tbr=parent->getTightBoundingRect(currentEv.getFont(parent), "M", painter.device());
@@ -166,7 +165,7 @@ void JKQTMathTextListNode::getSizeInternal(QPainter& painter, JKQTMathTextEnviro
//std::cout<<"symbol ='"<getOperatorsubsuperSizeFactor();
+ ev.fontSize=ev.fontSize*parentMathText->getOperatorsubsuperSizeFactor();
double w1=0, w2=0, w3=0;
double oh1=0, oh2=0, oh3=0;
double bh1=0, bh2=0, bh3=0;
@@ -224,7 +223,7 @@ void JKQTMathTextListNode::getSizeInternal(QPainter& painter, JKQTMathTextEnviro
//qDebug()<<"### subsupop: sub+super";*/
} else if (subn) { // is this subscript?
JKQTMathTextEnvironment ev=currentEv;
- ev.fontSize=ev.fontSize*parent->getOperatorsubsuperSizeFactor();
+ ev.fontSize=ev.fontSize*parentMathText->getOperatorsubsuperSizeFactor();
double w1=0, w2=0;
double oh1=0, oh2=0;
double bh1=0, bh2=0;
@@ -280,7 +279,7 @@ double JKQTMathTextListNode::draw(QPainter& painter, double x, double y, JKQTMat
double ynew=y;
double xnew=x;
//qDebug()<<"listNode: "<getOperatorsubsuperSizeFactor();
+ ev.fontSize=ev.fontSize*parentMathText->getOperatorsubsuperSizeFactor();
double w1=0, w2=0, w3=0;
double oh1=0, oh2=0, oh3=0;
double bh1=0, bh2=0, bh3=0, sp;
@@ -364,7 +363,7 @@ double JKQTMathTextListNode::draw(QPainter& painter, double x, double y, JKQTMat
xnew=qMax(qMax(xn1, xn2), xn3)+fm.boundingRect(' ').width();
} else if (subn) { // is this subscript and not superscript?
JKQTMathTextEnvironment ev=currentEv;
- ev.fontSize=ev.fontSize*parent->getOperatorsubsuperSizeFactor();
+ ev.fontSize=ev.fontSize*parentMathText->getOperatorsubsuperSizeFactor();
double w1=0, w2=0;
double oh1=0, oh2=0;
double bh1=0, bh2=0, sp=0;
@@ -384,7 +383,7 @@ double JKQTMathTextListNode::draw(QPainter& painter, double x, double y, JKQTMat
xnew=qMax(xn1, xn2);
} else if (supn) { // is this subscript and superscript?
JKQTMathTextEnvironment ev=currentEv;
- ev.fontSize=ev.fontSize*parent->getOperatorsubsuperSizeFactor();
+ ev.fontSize=ev.fontSize*parentMathText->getOperatorsubsuperSizeFactor();
double w1=0, w3=0;
double oh1=0, oh3=0;
double bh1=0, bh3=0, sp;
@@ -415,6 +414,11 @@ double JKQTMathTextListNode::draw(QPainter& painter, double x, double y, JKQTMat
return xnew;
}
+void JKQTMathTextListNode::addNode(JKQTMathTextNode *n) {
+ n->setParentNode(this);
+ nodes.append(n);
+}
+
bool JKQTMathTextListNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
bool ok=true;
for (int i=0; i nodes;
- QSet subsupOperations;
+ /** \brief the instructions in this can have the sub-script/superscript set below/above, not besides the node */
+ static QSet subsupOperations;
};
#endif // JKQTMATHTEXTLISTNODE_H
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp
index 1df0126ecd..a35a5fa6c8 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp
@@ -43,10 +43,15 @@ JKQTMathTextMatrixNode::JKQTMathTextMatrixNode(JKQTMathText* _parent, QVectorlines=children.size();
this->columns=0;
- for (int i=0; ithis->columns) this->columns=children[i].size();
}
this->children=children;
+ for (int i=0; isetParentNode(this);
+ }
+ }
}
JKQTMathTextMatrixNode::~JKQTMathTextMatrixNode() {
@@ -64,7 +69,7 @@ QString JKQTMathTextMatrixNode::getTypeName() const
}
void JKQTMathTextMatrixNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
- QFontMetricsF fm(currentEv.getFont(parent), painter.device());
+ QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
JKQTMathTextEnvironment ev1=currentEv;
double xh=fm.strikeOutPos();//fm.xHeight();
@@ -108,7 +113,7 @@ void JKQTMathTextMatrixNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvi
double JKQTMathTextMatrixNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
doDrawBoxes(painter, x, y, currentEv);
- QFontMetricsF fm(currentEv.getFont(parent), painter.device());
+ QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
JKQTMathTextEnvironment ev1=currentEv;
double xh=fm.strikeOutPos();//fm.xHeight();
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.h b/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.h
index 682c4abeda..d26d6baa45 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.h
@@ -41,7 +41,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextMatrixNode: public JKQTMathTextNode {
virtual ~JKQTMathTextMatrixNode() override;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
+ /** \copydoc JKQTMathTextNode::draw() */
virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
+ /** \copydoc JKQTMathTextNode::toHtml() */
virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
/** \brief returns the child nodes */
QVector > getChildren() const;
@@ -54,8 +56,11 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextMatrixNode: public JKQTMathTextNode {
virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
/** \copydoc JKQTMathTextNode::setDrawBoxes() */
virtual void setDrawBoxes(bool draw) override;
+ /** \brief child nodes making up the matrix, vector of rows */
QVector > children;
+ /** \brief number of columns in the matrix */
int columns;
+ /** \brief number of rows in the matrix */
int lines;
};
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextnode.cpp
index 2a0790050c..026baec732 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextnode.cpp
@@ -36,9 +36,14 @@
// --------------------------------------------------------------------------------------------------
// -- implementation of the JKQTMathTextNode's methods
// --------------------------------------------------------------------------------------------------
-JKQTMathTextNode::JKQTMathTextNode(JKQTMathText* parent) {
- this->parent=parent;
- drawBoxes=false;
+
+
+JKQTMathTextNode::JKQTMathTextNode(JKQTMathText *_parent):
+ parentMathText(_parent),
+ parentNode(nullptr),
+ drawBoxes(false)
+{
+
}
JKQTMathTextNode::~JKQTMathTextNode()
@@ -113,3 +118,90 @@ QString JKQTMathTextNode::getTypeName() const
{
return "JKQTMathTextNode";
}
+
+void JKQTMathTextNode::setParentNode(JKQTMathTextNode *node)
+{
+ parentNode=node;
+ if (node) parentMathText=node->parentMathText;
+}
+
+JKQTMathTextNode *JKQTMathTextNode::getParentNode()
+{
+ return parentNode;
+}
+
+const JKQTMathTextNode *JKQTMathTextNode::getParentNode() const
+{
+ return parentNode;
+}
+
+JKQTMathTextSingleChildNode::JKQTMathTextSingleChildNode(JKQTMathTextNode *_child, JKQTMathText *parentMathText):
+ JKQTMathTextNode(parentMathText),
+ child(_child)
+{
+ if (child) child->setParentNode(this);
+}
+
+JKQTMathTextSingleChildNode::~JKQTMathTextSingleChildNode()
+{
+ if (child) delete child;
+}
+
+JKQTMathTextNode *JKQTMathTextSingleChildNode::getChild()
+{
+ return child;
+}
+
+const JKQTMathTextNode *JKQTMathTextSingleChildNode::getChild() const
+{
+ return child;
+}
+
+void JKQTMathTextSingleChildNode::setDrawBoxes(bool draw)
+{
+ JKQTMathTextNode::setDrawBoxes(draw);
+ if (child) child->setDrawBoxes(draw);
+}
+
+
+JKQTMathTextDualChildNode::JKQTMathTextDualChildNode(JKQTMathTextNode *_child1, JKQTMathTextNode *_child2, JKQTMathText *parentMathText):
+ JKQTMathTextNode(parentMathText),
+ child1(_child1),
+ child2(_child2)
+{
+ if (child1) child1->setParentNode(this);
+ if (child2) child2->setParentNode(this);
+}
+
+JKQTMathTextDualChildNode::~JKQTMathTextDualChildNode()
+{
+ if (child1) delete child1;
+ if (child2) delete child2;
+}
+
+JKQTMathTextNode *JKQTMathTextDualChildNode::getChild1()
+{
+ return child1;
+}
+
+const JKQTMathTextNode *JKQTMathTextDualChildNode::getChild1() const
+{
+ return child1;
+}
+
+JKQTMathTextNode *JKQTMathTextDualChildNode::getChild2()
+{
+ return child2;
+}
+
+const JKQTMathTextNode *JKQTMathTextDualChildNode::getChild2() const
+{
+ return child2;
+}
+
+void JKQTMathTextDualChildNode::setDrawBoxes(bool draw)
+{
+ JKQTMathTextNode::setDrawBoxes(draw);
+ if (child1) child1->setDrawBoxes(draw);
+ if (child2) child2->setDrawBoxes(draw);
+}
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextnode.h b/lib/jkqtmathtext/nodes/jkqtmathtextnode.h
index 30ce8df896..01a298187e 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextnode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextnode.h
@@ -36,7 +36,7 @@ class JKQTMathText; // forward
*/
class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNode {
public:
- explicit JKQTMathTextNode(JKQTMathText* parent);
+ explicit JKQTMathTextNode(JKQTMathText* parentMathText);
JKQTMathTextNode(const JKQTMathTextNode&)=delete;
JKQTMathTextNode& operator=(const JKQTMathTextNode&)=delete;
virtual ~JKQTMathTextNode();
@@ -78,6 +78,12 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNode {
virtual void setDrawBoxes(bool draw);
/** \brief return the name of this class as a string */
virtual QString getTypeName() const;
+ /** \copydoc parentNode */
+ void setParentNode(JKQTMathTextNode* node);
+ /** \copydoc parentNode */
+ JKQTMathTextNode* getParentNode();
+ /** \copydoc parentNode */
+ const JKQTMathTextNode* getParentNode() const;
protected:
/** \brief determine the size of the node, overwrite this function in derived classes
*
@@ -93,7 +99,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNode {
virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize=nullptr)=0;
/** \brief parent JKQTMathText object (required for several drawing operations */
- JKQTMathText* parent;
+ JKQTMathText* parentMathText;
+ /** \brief parent node of this node (i.e. one level up, ode \c nullptr ) */
+ JKQTMathTextNode* parentNode;
/** \brief enables the drawing of colored boxes (for DEBUGGING) around the actual output of the node */
bool drawBoxes;
/** \brief draws colored boxes (for DEBUGGING) around the actual output of the node
@@ -104,15 +112,80 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNode {
* \param currentEv JKQTMathTextEnvironment object describing the current drawing environment/settings
*/
void doDrawBoxes(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv);
+
+
+ /** \brief returns the list of parent, parent-of-parent, ... that can be cast to type \a T */
+ template
+ inline QList getParents() {
+ QList lst;
+ JKQTMathTextNode* p=getParentNode();
+ T* pT=dynamic_cast(p);
+ while (p!=nullptr) {
+ if (pT!=nullptr) lst.append(pT);
+ p=p->getParentNode();
+ pT=dynamic_cast(p);
+ }
+ return lst;
+ }
+
+ /** \brief returns the list of parent, parent-of-parent, ... that can be cast to type \a T */
+ template
+ inline QList getParents() const {
+ QList lst;
+ const JKQTMathTextNode* p=getParentNode();
+ const T* pT=dynamic_cast(p);
+ while (p!=nullptr) {
+ if (pT!=nullptr) lst.append(pT);
+ p=p->getParentNode();
+ pT=dynamic_cast(p);
+ }
+ return lst;
+ }
+};
+
+
+/** \brief subclass representing a node in the syntax tree, that has one child
+ * \ingroup jkqtmathtext_items
+ */
+class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSingleChildNode: public JKQTMathTextNode {
+ public:
+ explicit JKQTMathTextSingleChildNode(JKQTMathTextNode* _child, JKQTMathText* parentMathText);
+ virtual ~JKQTMathTextSingleChildNode() override;
+
+ /** \copydoc child */
+ JKQTMathTextNode* getChild();
+ /** \copydoc child */
+ const JKQTMathTextNode* getChild() const;
+ /** \copydoc JKQTMathTextNode::setDrawBoxes() */
+ virtual void setDrawBoxes(bool draw) override;
+ protected:
+ /** \brief child node of this node */
+ JKQTMathTextNode* child;
+};
+
+/** \brief subclass representing a node in the syntax tree, that has two children
+ * \ingroup jkqtmathtext_items
+ */
+class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextDualChildNode: public JKQTMathTextNode {
+ public:
+ explicit JKQTMathTextDualChildNode(JKQTMathTextNode* _child1, JKQTMathTextNode* _child2, JKQTMathText* parentMathText);
+ virtual ~JKQTMathTextDualChildNode() override;
+
+ /** \copydoc child1 */
+ JKQTMathTextNode* getChild1();
+ /** \copydoc child1 */
+ const JKQTMathTextNode* getChild1() const;
+ /** \copydoc child2 */
+ JKQTMathTextNode* getChild2();
+ /** \copydoc child2 */
+ const JKQTMathTextNode* getChild2() const;
+ /** \copydoc JKQTMathTextNode::setDrawBoxes() */
+ virtual void setDrawBoxes(bool draw) override;
+ protected:
+ /** \brief first child node of this node */
+ JKQTMathTextNode* child1;
+ /** \brief second child node of this node */
+ JKQTMathTextNode* child2;
};
#endif // JKQTMATHTEXTNODE_H
-
-
-
-
-
-
-
-
-
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.cpp
index 12d9a27e2b..201f280414 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.cpp
@@ -36,18 +36,16 @@
JKQTMathTextSqrtNode::JKQTMathTextSqrtNode(JKQTMathText* _parent, JKQTMathTextNode* child, int degree):
- JKQTMathTextNode(_parent)
+ JKQTMathTextSingleChildNode(child, _parent)
{
- this->child=child;
this->degree=degree;
}
JKQTMathTextSqrtNode::~JKQTMathTextSqrtNode() {
- if (child!=nullptr) delete child;
}
void JKQTMathTextSqrtNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
- QFontMetricsF fm(currentEv.getFont(parent), painter.device());
+ QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
child->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
@@ -60,7 +58,7 @@ double JKQTMathTextSqrtNode::draw(QPainter& painter, double x, double y, JKQTMat
doDrawBoxes(painter, x, y, currentEv);
double width=0, baselineHeight=0, overallHeight=0, sp=0;
child->getSize(painter, currentEv, width, baselineHeight, overallHeight, sp);
- QFont f=currentEv.getFont(parent);
+ QFont f=currentEv.getFont(parentMathText);
QFont fsmall=f;
QFontMetricsF fm(f, painter.device());
double w=fm.boundingRect("A").width();
@@ -104,22 +102,11 @@ bool JKQTMathTextSqrtNode::toHtml(QString &html, JKQTMathTextEnvironment current
return ok;
}
-void JKQTMathTextSqrtNode::setDrawBoxes(bool draw)
-{
- this->drawBoxes=draw;
- child->setDrawBoxes(draw);
-
-}
-
QString JKQTMathTextSqrtNode::getTypeName() const
{
return "MTsqrtNode";
}
-JKQTMathTextNode *JKQTMathTextSqrtNode::getChild() const {
- return this->child;
-}
-
int JKQTMathTextSqrtNode::getDegree() const {
return this->degree;
}
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.h b/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.h
index 6ca672ffc3..c9da40e0c5 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.h
@@ -36,7 +36,7 @@ class JKQTMathText; // forward
/** \brief subclass representing a sqrt node
* \ingroup jkqtmathtext_items
*/
-class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSqrtNode: public JKQTMathTextNode {
+class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSqrtNode: public JKQTMathTextSingleChildNode {
public:
JKQTMathTextSqrtNode(JKQTMathText* parent, JKQTMathTextNode* child, int degree=2);
virtual ~JKQTMathTextSqrtNode() override;
@@ -44,18 +44,14 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSqrtNode: public JKQTMathTextNode {
virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
/** \copydoc JKQTMathTextNode::toHtml() */
virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
- /** \copydoc JKQTMathTextNode::setDrawBoxes() */
- virtual void setDrawBoxes(bool draw) override;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override ;
- /** \brief returns the child node */
- JKQTMathTextNode *getChild() const;
- /** \copydoc degree */
+ /** \copydoc degree */
int getDegree() const;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
- JKQTMathTextNode* child;
+ /** \brief degree of the radical (shown of !=2) */
int degree;
};
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.cpp
index 7272a00cc5..2a134d2b6b 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.cpp
@@ -38,22 +38,20 @@
JKQTMathTextSuperscriptNode::JKQTMathTextSuperscriptNode(JKQTMathText* _parent, JKQTMathTextNode* child):
- JKQTMathTextNode(_parent)
+ JKQTMathTextSingleChildNode(child,_parent)
{
- this->child=child;
}
JKQTMathTextSuperscriptNode::~JKQTMathTextSuperscriptNode() {
- if (child!=nullptr) delete child;
}
void JKQTMathTextSuperscriptNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize) {
JKQTMathTextEnvironment ev=currentEv;
- ev.fontSize=ev.fontSize*parent->getSubsuperSizeFactor();
- QFontMetricsF fm(currentEv.getFont(parent), painter.device());
- QRectF tbr=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parent), "M", painter.device());
+ ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor();
+ QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
+ QRectF tbr=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
child->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
- double shift=parent->getSuperShiftFactor()*tbr.height();
+ double shift=parentMathText->getSuperShiftFactor()*tbr.height();
if (prevNodeSize!=nullptr && prevNodeSize->baselineHeight>tbr.height()) {
shift=prevNodeSize->baselineHeight-(overallHeight-baselineHeight)-shift;
@@ -62,20 +60,20 @@ void JKQTMathTextSuperscriptNode::getSizeInternal(QPainter& painter, JKQTMathTex
double yshift=shift+overallHeight-baselineHeight;
baselineHeight=overallHeight=overallHeight+shift;
strikeoutPos=strikeoutPos-yshift;
- if (currentEv.italic && prevNodeSize==nullptr) width=width+double(fm.boundingRect(' ').width())*parent->getItalicCorrectionFactor();
+ if (currentEv.italic && prevNodeSize==nullptr) width=width+double(fm.boundingRect(' ').width())*parentMathText->getItalicCorrectionFactor();
}
double JKQTMathTextSuperscriptNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize) {
doDrawBoxes(painter, x, y, currentEv);
JKQTMathTextEnvironment ev=currentEv;
- ev.fontSize=ev.fontSize*parent->getSubsuperSizeFactor();
+ ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor();
double cWidth, cBaselineHeight, cOverallHeight, cStrikeoutPos;
child->getSize(painter, ev, cWidth, cBaselineHeight, cOverallHeight, cStrikeoutPos);
- QFontMetricsF fm(currentEv.getFont(parent), painter.device());
- QRectF tbr=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parent), "M", painter.device());
- double shift=parent->getSuperShiftFactor()*tbr.height();
+ QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
+ QRectF tbr=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
+ double shift=parentMathText->getSuperShiftFactor()*tbr.height();
if (prevNodeSize!=nullptr && prevNodeSize->baselineHeight>tbr.height()) {
shift=prevNodeSize->baselineHeight-(cOverallHeight-cBaselineHeight)-shift;
@@ -83,15 +81,11 @@ double JKQTMathTextSuperscriptNode::draw(QPainter& painter, double x, double y,
double yshift=shift+cOverallHeight-cBaselineHeight;
double xx=x;
- if (currentEv.italic && prevNodeSize==nullptr) xx=xx+double(fm.boundingRect(' ').width())*parent->getItalicCorrectionFactor();
+ if (currentEv.italic && prevNodeSize==nullptr) xx=xx+double(fm.boundingRect(' ').width())*parentMathText->getItalicCorrectionFactor();
return child->draw(painter, xx, y-yshift, ev);//+0.5*fm.boundingRect("A").width();
}
-JKQTMathTextNode *JKQTMathTextSuperscriptNode::getChild() const {
- return this->child;
-}
-
QString JKQTMathTextSuperscriptNode::getTypeName() const
{
@@ -107,13 +101,6 @@ bool JKQTMathTextSuperscriptNode::toHtml(QString &html, JKQTMathTextEnvironment
return ok;
}
-void JKQTMathTextSuperscriptNode::setDrawBoxes(bool draw)
-{
- this->drawBoxes=draw;
- child->setDrawBoxes(draw);
-
-}
-
@@ -121,24 +108,23 @@ void JKQTMathTextSuperscriptNode::setDrawBoxes(bool draw)
JKQTMathTextSubscriptNode::JKQTMathTextSubscriptNode(JKQTMathText* _parent, JKQTMathTextNode* child):
- JKQTMathTextNode(_parent)
+ JKQTMathTextSingleChildNode(child, _parent)
{
- this->child=child;
}
JKQTMathTextSubscriptNode::~JKQTMathTextSubscriptNode() {
- if (child!=nullptr) delete child;
+
}
void JKQTMathTextSubscriptNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize) {
JKQTMathTextEnvironment ev=currentEv;
- ev.fontSize=ev.fontSize*parent->getSubsuperSizeFactor();
+ ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor();
child->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
- QFontMetricsF fm(ev.getFont(parent), painter.device());
- QRectF tbr=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parent), "M", painter.device());
- double shift=parent->getSubShiftFactor()*tbr.height();
+ QFontMetricsF fm(ev.getFont(parentMathText), painter.device());
+ QRectF tbr=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
+ double shift=parentMathText->getSubShiftFactor()*tbr.height();
if (prevNodeSize!=nullptr && prevNodeSize->overallHeight-prevNodeSize->baselineHeight>shift) {
shift=-1.0*(prevNodeSize->overallHeight-prevNodeSize->baselineHeight-shift);
@@ -147,19 +133,19 @@ void JKQTMathTextSubscriptNode::getSizeInternal(QPainter& painter, JKQTMathTextE
double yshift=baselineHeight-shift;
baselineHeight=shift;
strikeoutPos=fm.strikeOutPos()+yshift;
- if (currentEv.italic && prevNodeSize==nullptr) width=width-double(fm.boundingRect(' ').width())*parent->getItalicCorrectionFactor();
+ if (currentEv.italic && prevNodeSize==nullptr) width=width-double(fm.boundingRect(' ').width())*parentMathText->getItalicCorrectionFactor();
}
double JKQTMathTextSubscriptNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize) {
doDrawBoxes(painter, x, y, currentEv);
JKQTMathTextEnvironment ev=currentEv;
- ev.fontSize=ev.fontSize*parent->getSubsuperSizeFactor();
- QFontMetricsF fm(ev.getFont(parent), painter.device());
- QRectF tbr=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parent), "M", painter.device());
+ ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor();
+ QFontMetricsF fm(ev.getFont(parentMathText), painter.device());
+ QRectF tbr=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
double width=0, baselineHeight=0, overallHeight=0, strikeoutPos=0;
child->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
- double shift=parent->getSubShiftFactor()*tbr.height();
+ double shift=parentMathText->getSubShiftFactor()*tbr.height();
if (prevNodeSize!=nullptr && prevNodeSize->overallHeight-prevNodeSize->baselineHeight>shift) {
//qDebug()<<"oldshift="<overallHeight="<overallHeight<<", prevNodeSize->baselineHeight="<baselineHeight;
@@ -171,7 +157,7 @@ double JKQTMathTextSubscriptNode::draw(QPainter& painter, double x, double y, JK
//qDebug()<<"baselineHeight="<child;
-}
-
-
bool JKQTMathTextSubscriptNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
html=html+"";
bool ok=child->toHtml(html, currentEv, defaultEv);
html=html+"";
return ok;
}
-
-void JKQTMathTextSubscriptNode::setDrawBoxes(bool draw)
-{
- this->drawBoxes=draw;
- child->setDrawBoxes(draw);
-
-}
-
-
-
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.h b/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.h
index 7a65c933c6..2bc3802357 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.h
@@ -37,7 +37,7 @@ class JKQTMathText; // forward
*
* \image html jkqtmathtext_subscriptnode_getSizeInternal.png
*/
-class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSubscriptNode: public JKQTMathTextNode {
+class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSubscriptNode: public JKQTMathTextSingleChildNode {
public:
explicit JKQTMathTextSubscriptNode(JKQTMathText* parent, JKQTMathTextNode* child);
virtual ~JKQTMathTextSubscriptNode() override;
@@ -45,16 +45,11 @@ public:
virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override; /** \brief returns the child node */
- /** \brief returns the child node */
- JKQTMathTextNode *getChild() const;
/** \copydoc JKQTMathTextNode::toHtml() */
virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
- /** \copydoc JKQTMathTextNode::setDrawBoxes() */
- virtual void setDrawBoxes(bool draw) override;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
- JKQTMathTextNode* child;
};
/** \brief subclass representing an superscript node with exactly one argument in the syntax tree
@@ -64,24 +59,19 @@ protected:
*
* \note a MTlistNode might modify the positioning slightly for special cases (e.g. \c \\int , \c \\sum ... or after braces)
*/
-class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSuperscriptNode: public JKQTMathTextNode {
+class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSuperscriptNode: public JKQTMathTextSingleChildNode {
public:
explicit JKQTMathTextSuperscriptNode(JKQTMathText* parent, JKQTMathTextNode* child);
virtual ~JKQTMathTextSuperscriptNode() override;
/** \copydoc JKQTMathTextNode::draw() */
virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
- /** \brief returns the child node */
- JKQTMathTextNode* getChild() const;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::toHtml() */
virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
- /** \copydoc JKQTMathTextNode::setDrawBoxes() */
- virtual void setDrawBoxes(bool draw) override;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
- JKQTMathTextNode* child;
};
#endif // JKQTMATHTEXTSUBSUPERSCRIPTNODE_H
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp
index 28dffd91e3..d2e4fd3aac 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp
@@ -53,8 +53,8 @@ QString JKQTMathTextSymbolNode::getTypeName() const
bool JKQTMathTextSymbolNode::getWinSymbolProp(JKQTMathTextSymbolNode::SymbolProps& props, const QString &n, const JKQTMathTextEnvironment& currentEv, double mathFontFactor) const
{
- auto fnt=parent->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Text);
- auto fntSym=parent->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Symbols);
+ auto fnt=parentMathText->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Text);
+ auto fntSym=parentMathText->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Symbols);
//qDebug()<<" +--- getWinSymbolProp("<getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Text);
- auto fntGreek=parent->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Greek);
+ auto fnt=parentMathText->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Text);
+ auto fntGreek=parentMathText->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Greek);
//qDebug()<<" +--- getGreekSymbolProp("<getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Text);
- auto fntGreek=parent->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Greek);
- auto fntSym=parent->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Symbols);
+ auto fnt=parentMathText->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Text);
+ auto fntGreek=parentMathText->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Greek);
+ auto fntSym=parentMathText->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Symbols);
//qDebug()<<"--- getSymbolProp("<getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Text);
- auto fntSym=parent->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Symbols);
- auto fntGreek=parent->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Greek);
+ auto fnt=parentMathText->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Text);
+ auto fntSym=parentMathText->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Symbols);
+ auto fntGreek=parentMathText->getFontData(currentEv.font, currentEv.insideMath, JKQTMathText::FontSubclass::Greek);
JKQTMathTextSymbolNode::SymbolProps props;
double mathFontFactor=1.8;
@@ -869,7 +869,7 @@ JKQTMathTextSymbolNode::SymbolProps JKQTMathTextSymbolNode::getSymbolProp(const
}
if (props.symbol.simplified().isEmpty() && !extraSymbolName.contains(n)) {
- parent->addToErrorList(QObject::tr("unknown symbol '%1' found (%2)!").arg(n).arg(errorExplanation));
+ parentMathText->addToErrorList(QObject::tr("unknown symbol '%1' found (%2)!").arg(n).arg(errorExplanation));
}
//qDebug()<getMathoperatorWidthFactor();
+ if (props.extendWidthInMathmode && currentEv.insideMath) width=width*parentMathText->getMathoperatorWidthFactor();
}
@@ -938,7 +938,7 @@ double JKQTMathTextSymbolNode::draw(QPainter& painter, double x, double y, JKQTM
getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
QPen pold=painter.pen();
QFont fold=painter.font();
- QFont f=currentEv.getFont(parent);
+ QFont f=currentEv.getFont(parentMathText);
QFont f1=f;
auto props=getSymbolProp(symbolName, currentEv);
f.setFamily(props.font);
@@ -953,7 +953,7 @@ double JKQTMathTextSymbolNode::draw(QPainter& painter, double x, double y, JKQTM
double shift=0;
if (props.extendWidthInMathmode && currentEv.insideMath) {
- double origwidth=width/parent->getMathoperatorWidthFactor();
+ double origwidth=width/parentMathText->getMathoperatorWidthFactor();
shift=0.5*(width-origwidth);
//width=width*parent->getMathoperatorWidthFactor();
}
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp
index 237bb15d88..1452c7984a 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp
@@ -58,7 +58,7 @@ JKQTMathTextTextNode::JKQTMathTextTextNode(JKQTMathText* _parent, const QString&
JKQTMathTextTextNode::~JKQTMathTextTextNode() = default;
void JKQTMathTextTextNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
- QFont f=currentEv.getFont(parent);
+ QFont f=currentEv.getFont(parentMathText);
if (currentEv.insideMath && (text=="(" || text=="[" || text=="|" || text=="]" || text==")" || text=="<" || text==">" ||
text==QString(QChar(0x2329)) || text==QString(QChar(0x232A)) || text==QString(QChar(0x2308)) ||
text==QString(QChar(0x2309)) || text==QString(QChar(0x230A)) || text==QString(QChar(0x230B)))) {
@@ -111,7 +111,7 @@ double JKQTMathTextTextNode::draw(QPainter& painter, double x, double y, JKQTMat
QPen pold=painter.pen();
QFont fold=painter.font();
- QFont f=currentEv.getFont(parent);
+ QFont f=currentEv.getFont(parentMathText);
if (currentEv.insideMath && (text=="(" || text=="[" || text=="|" || text=="]" || text==")" || text=="<" || text==">" ||
text==QString(QChar(0x2329)) || text==QString(QChar(0x232A)) || text==QString(QChar(0x2308)) ||
text==QString(QChar(0x2309)) || text==QString(QChar(0x230A)) || text==QString(QChar(0x230B)))) {
@@ -138,7 +138,7 @@ double JKQTMathTextTextNode::draw(QPainter& painter, double x, double y, JKQTMat
}*/
if (!hasDigits || !f.italic()) {
- if (currentEv.font==MTEblackboard && parent->isFontBlackboardSimulated()) {
+ if (currentEv.font==MTEblackboard && parentMathText->isFontBlackboardSimulated()) {
QPainterPath path;
path.addText(QPointF(x+dx, y), f, txt);
painter.drawPath(path);
@@ -153,7 +153,7 @@ double JKQTMathTextTextNode::draw(QPainter& painter, double x, double y, JKQTMat
ff.setItalic(false);
while (iisFontBlackboardSimulated()) {
+ if (currentEv.font==MTEblackboard && parentMathText->isFontBlackboardSimulated()) {
QPainterPath path;
path.addText(QPointF(xx, y), ff, QString(txt[i]));
painter.drawPath(path);
@@ -163,7 +163,7 @@ double JKQTMathTextTextNode::draw(QPainter& painter, double x, double y, JKQTMat
}
xx=xx+fmff.boundingRect(txt[i]).width();
} else {
- if (currentEv.font==MTEblackboard && parent->isFontBlackboardSimulated()) {
+ if (currentEv.font==MTEblackboard && parentMathText->isFontBlackboardSimulated()) {
QPainterPath path;
path.addText(QPointF(xx, y), f, QString(txt[i]));
painter.drawPath(path);
@@ -199,7 +199,7 @@ QString JKQTMathTextTextNode::getTypeName() const
QString JKQTMathTextTextNode::textTransform(const QString &text, JKQTMathTextEnvironment currentEv, bool /*forSize*/)
{
QString txt=text;
- auto fnt=parent->getFontData(currentEv.font, currentEv.insideMath);
+ auto fnt=parentMathText->getFontData(currentEv.font, currentEv.insideMath);
if (fnt.second==MTFEunicode || fnt.second==MTFEunicodeLimited) {
if (currentEv.insideMath) {
txt="";