diff --git a/doc/dox/whatsnew.dox b/doc/dox/whatsnew.dox
index 8fe3535374..58601921d8 100644
--- a/doc/dox/whatsnew.dox
+++ b/doc/dox/whatsnew.dox
@@ -58,6 +58,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
IMPROVED/REWORKED rendering of blackboard font: now several different rendering modes can be selected using JKQTMathText::setFontBlackboradMode()
BREAKING/REWORKED: The \\verb!...!-command now works the same as in LaTeX
BREAKING/CLEANUP: cleanup: Removed Parameter prevNodeSize from JKQTMathTextNode::draw() and JKQTMathTextNode::getSize()/JKQTMathTextNode::getSizeInternal(), since it is only really necessary for JKQTMathTextSubscriptNode and JKQTMathTextSuperscriptNode
+ BREAKING/CLEANUP: using JKQTMathTextNodeSize for all size-calculation functions and got rid of all functions that take the output parameters with call-by-reference, additional information can be outut by local size-classes that derive from JKQTMathTextNodeSize, see e.g. JKQTMathTextSymbolNode::NodeSize and JKQTMathTextSymbolNode::getSymbolSize()
NEW: JKQTMathTextVerticalListNode allows to typeset a vertical list of lines
NEW: JKQTMathText::parse() by default allows linebreaks in the LaTeX string to be parsed. This can be switched off by a parameter
NEW: added functions to set the font-size in pixels (as alternative to the existing functions that set them in points), implements request #76 from user:igormironchik
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_DejaVuSans.png b/doc/images/jkqtmathtext/jkqtmathtext_DejaVuSans.png
index e662bcc806..6c5b093039 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_DejaVuSans.png and b/doc/images/jkqtmathtext/jkqtmathtext_DejaVuSans.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_DejaVuSerif.png b/doc/images/jkqtmathtext/jkqtmathtext_DejaVuSerif.png
index f0af95478d..94ad6fec32 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_DejaVuSerif.png and b/doc/images/jkqtmathtext/jkqtmathtext_DejaVuSerif.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_OldEnglish.png b/doc/images/jkqtmathtext/jkqtmathtext_OldEnglish.png
index 89334b3d1e..dc0170b103 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_OldEnglish.png and b/doc/images/jkqtmathtext/jkqtmathtext_OldEnglish.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_arial.png b/doc/images/jkqtmathtext/jkqtmathtext_arial.png
index fe6ddf5b82..257fda5647 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_arial.png and b/doc/images/jkqtmathtext/jkqtmathtext_arial.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_array.png b/doc/images/jkqtmathtext/jkqtmathtext_array.png
index c14fdf7e55..7c7c96911d 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_array.png and b/doc/images/jkqtmathtext/jkqtmathtext_array.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_asana.png b/doc/images/jkqtmathtext/jkqtmathtext_asana.png
index dcfe66e8e3..f9c01db21f 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_asana.png and b/doc/images/jkqtmathtext/jkqtmathtext_asana.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_bbmatrix.png b/doc/images/jkqtmathtext/jkqtmathtext_bbmatrix.png
index 2d462c2f7f..cedcab7cb6 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_bbmatrix.png and b/doc/images/jkqtmathtext/jkqtmathtext_bbmatrix.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_bmatrix.png b/doc/images/jkqtmathtext/jkqtmathtext_bmatrix.png
index 641bcdb22f..ab2088d331 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_bmatrix.png and b/doc/images/jkqtmathtext/jkqtmathtext_bmatrix.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_brace_bbig.png b/doc/images/jkqtmathtext/jkqtmathtext_brace_bbig.png
index e0e35cecfb..038092fbf9 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_brace_bbig.png and b/doc/images/jkqtmathtext/jkqtmathtext_brace_bbig.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_brace_bbigg.png b/doc/images/jkqtmathtext/jkqtmathtext_brace_bbigg.png
index a4a82b5e74..b15380cdb9 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_brace_bbigg.png and b/doc/images/jkqtmathtext/jkqtmathtext_brace_bbigg.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_brace_begincases.png b/doc/images/jkqtmathtext/jkqtmathtext_brace_begincases.png
index ead065311d..57824a2121 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_brace_begincases.png and b/doc/images/jkqtmathtext/jkqtmathtext_brace_begincases.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_brace_big.png b/doc/images/jkqtmathtext/jkqtmathtext_brace_big.png
index 95c7a55ba7..12d978f1cf 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_brace_big.png and b/doc/images/jkqtmathtext/jkqtmathtext_brace_big.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_brace_bigfamily.png b/doc/images/jkqtmathtext/jkqtmathtext_brace_bigfamily.png
index cbefb2dfdc..65c085710a 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_brace_bigfamily.png and b/doc/images/jkqtmathtext/jkqtmathtext_brace_bigfamily.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_brace_bigg.png b/doc/images/jkqtmathtext/jkqtmathtext_brace_bigg.png
index c081ccf5b9..2538d094a7 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_brace_bigg.png and b/doc/images/jkqtmathtext/jkqtmathtext_brace_bigg.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_brace_stackrel.png b/doc/images/jkqtmathtext/jkqtmathtext_brace_stackrel.png
index 732e3073bd..9bc8122868 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_brace_stackrel.png and b/doc/images/jkqtmathtext/jkqtmathtext_brace_stackrel.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_comicsans.png b/doc/images/jkqtmathtext/jkqtmathtext_comicsans.png
index f603aa35aa..6b3f46d386 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_comicsans.png and b/doc/images/jkqtmathtext/jkqtmathtext_comicsans.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_comicsans_textonly.png b/doc/images/jkqtmathtext/jkqtmathtext_comicsans_textonly.png
index 0f4b1f2933..2b5c24a2c1 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_comicsans_textonly.png and b/doc/images/jkqtmathtext/jkqtmathtext_comicsans_textonly.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_computermodern.png b/doc/images/jkqtmathtext/jkqtmathtext_computermodern.png
index 2d3563f065..6d9bd496df 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_computermodern.png and b/doc/images/jkqtmathtext/jkqtmathtext_computermodern.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_couriernew.png b/doc/images/jkqtmathtext/jkqtmathtext_couriernew.png
index c1ceb9b01e..d1800b19f2 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_couriernew.png and b/doc/images/jkqtmathtext/jkqtmathtext_couriernew.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_doc_subsuper_italiccorrection.png b/doc/images/jkqtmathtext/jkqtmathtext_doc_subsuper_italiccorrection.png
index 4d37d255d8..5ea543f2d6 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_doc_subsuper_italiccorrection.png and b/doc/images/jkqtmathtext/jkqtmathtext_doc_subsuper_italiccorrection.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_doc_subsuper_italiccorrection_boxes.png b/doc/images/jkqtmathtext/jkqtmathtext_doc_subsuper_italiccorrection_boxes.png
index fd1815a12d..9a71108ce2 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_doc_subsuper_italiccorrection_boxes.png and b/doc/images/jkqtmathtext/jkqtmathtext_doc_subsuper_italiccorrection_boxes.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_doc_subsupershift_integral.png b/doc/images/jkqtmathtext/jkqtmathtext_doc_subsupershift_integral.png
index 8ef2998254..0dee9aac6f 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_doc_subsupershift_integral.png and b/doc/images/jkqtmathtext/jkqtmathtext_doc_subsupershift_integral.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_doc_subsupershift_integral_boxes.png b/doc/images/jkqtmathtext/jkqtmathtext_doc_subsupershift_integral_boxes.png
index 1ae786695f..c42099d8c0 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_doc_subsupershift_integral_boxes.png and b/doc/images/jkqtmathtext/jkqtmathtext_doc_subsupershift_integral_boxes.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_fira.png b/doc/images/jkqtmathtext/jkqtmathtext_fira.png
index 1bd68866a6..2df8980402 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_fira.png and b/doc/images/jkqtmathtext/jkqtmathtext_fira.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_matrix.png b/doc/images/jkqtmathtext/jkqtmathtext_matrix.png
index b9ed13924c..cec94125f4 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_matrix.png and b/doc/images/jkqtmathtext/jkqtmathtext_matrix.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_mssegoeui.png b/doc/images/jkqtmathtext/jkqtmathtext_mssegoeui.png
index f3038d7882..bbbcda5b89 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_mssegoeui.png and b/doc/images/jkqtmathtext/jkqtmathtext_mssegoeui.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_pmatrix.png b/doc/images/jkqtmathtext/jkqtmathtext_pmatrix.png
index ad752bd583..b045b1e703 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_pmatrix.png and b/doc/images/jkqtmathtext/jkqtmathtext_pmatrix.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_timesnewroman.png b/doc/images/jkqtmathtext/jkqtmathtext_timesnewroman.png
index 98ed2f0ae8..b451351b9c 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_timesnewroman.png and b/doc/images/jkqtmathtext/jkqtmathtext_timesnewroman.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_vmatrix.png b/doc/images/jkqtmathtext/jkqtmathtext_vmatrix.png
index 28519adc4a..f25d555ce7 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_vmatrix.png and b/doc/images/jkqtmathtext/jkqtmathtext_vmatrix.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_vvmatrix.png b/doc/images/jkqtmathtext/jkqtmathtext_vvmatrix.png
index cb5d78d27b..0c5e81b726 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_vvmatrix.png and b/doc/images/jkqtmathtext/jkqtmathtext_vvmatrix.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_xits.png b/doc/images/jkqtmathtext/jkqtmathtext_xits.png
index 6c3183beed..5442443ab6 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_xits.png and b/doc/images/jkqtmathtext/jkqtmathtext_xits.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_xits_all.png b/doc/images/jkqtmathtext/jkqtmathtext_xits_all.png
index 6c3183beed..5442443ab6 100644
Binary files a/doc/images/jkqtmathtext/jkqtmathtext_xits_all.png and b/doc/images/jkqtmathtext/jkqtmathtext_xits_all.png differ
diff --git a/doc/images/jkqtmathtext/schreq_mathmode.png b/doc/images/jkqtmathtext/schreq_mathmode.png
index 7f4ca81d53..b30eccbdb6 100644
Binary files a/doc/images/jkqtmathtext/schreq_mathmode.png and b/doc/images/jkqtmathtext/schreq_mathmode.png differ
diff --git a/doc/images/jkqtmathtext/schreq_normalmode.png b/doc/images/jkqtmathtext/schreq_normalmode.png
index 384b34b0c1..38dbf7359b 100644
Binary files a/doc/images/jkqtmathtext/schreq_normalmode.png and b/doc/images/jkqtmathtext/schreq_normalmode.png differ
diff --git a/doc/jkqtmathtext_docimages_math.jkmt b/doc/jkqtmathtext_docimages_math.jkmt
index 764a0f7486..a957451e5d 100644
--- a/doc/jkqtmathtext_docimages_math.jkmt
+++ b/doc/jkqtmathtext_docimages_math.jkmt
@@ -38,7 +38,7 @@ jkqtmathtext_limits.png
no specifier: $\sum_{i=0}^\infty k_i^2\ \ \lim_{x\rightarrow0}f(x)\ \ \nabla_{x}f(x)$ \ \ \ \ \ {\backslash}limits: $\sum\limits_{i=0}^\infty k_i^2\ \ \lim\limits_{x\rightarrow0}f(x)\ \ \nabla\limits_{x}f(x)$ \ \ \ \ \ {\backslash}nolimits: $\sum\nolimits_{i=0}^\infty k_i^2\ \ \lim\nolimits_{x\rightarrow0}f(x)\ \ \nabla\nolimits_{x}f(x)$
---
jkqtmathtext_doc_subsupershift_integral.png
---fontsoze=30
+--fontsize=30
sub-/superscript:\\
\begin{tabular}{c:c|c:c}
shifted & subs. shifted & unshifted & unshifted\\\hdashline
@@ -46,7 +46,7 @@ $\int\limits_{\textcolor{blue}{\leftarrow}}^{\textcolor{blue}{\rightarrow}}$ & $
\end{tabular}
---
jkqtmathtext_doc_subsupershift_integral_boxes.png
---drawboxes --fontsoze=30
+--drawboxes --fontsize=30
sub-/superscript:\\
\begin{tabular}{c:c|c:c}
shifted & subs. shifted & unshifted & unshifted\\\hdashline
@@ -54,7 +54,7 @@ $\int\limits_{\textcolor{blue}{\leftarrow}}^{\textcolor{blue}{\rightarrow}}$ & $
\end{tabular}
---
jkqtmathtext_doc_subsuper_italiccorrection.png
---fontsoze=30
+--fontsize=30
sub-/superscript:\\
\begin{tabular}{c|c}
italic-correction & no correction\\\hdashline
@@ -62,7 +62,7 @@ $x_\textcolor{blue}{\leftarrow}^\textcolor{red}{0}$ & $\mathrm{M}_\textcolor{red
\end{tabular}
---
jkqtmathtext_doc_subsuper_italiccorrection_boxes.png
---drawboxes --fontsoze=30
+--drawboxes --fontsize=30
sub-/superscript:\\
\begin{tabular}{c|c}
italic-correction & no correction\\\hdashline
diff --git a/examples/jkqtmathtext_test/mathtest.pdf b/examples/jkqtmathtext_test/mathtest.pdf
index a0a35300c3..44876c9af4 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 40dc9193a8..908bb8675f 100644
--- a/examples/jkqtmathtext_test/mathtest.tex
+++ b/examples/jkqtmathtext_test/mathtest.tex
@@ -49,6 +49,7 @@
\begin{document}
\begin{itemize}
+ \item \sout{x \fbox{\ } \fbox{\hspace*{1cm}} \fbox{\vspace*{2cm}}}
\item $x_1^2 X_1^2 q_1^2$
\item\textbf{Text: Umlaute \& fonts: }\\ rm: \textrm{\"Aq{\"u}\"{a}t{\oe}r abcABC00, 123-45+6.0\%\S},\\
it: \textit{\"Aq{\"u}\"{a}t{\oe}r abcABC00, 123-45+6.0\%\S},\\
diff --git a/lib/jkqtmathtext/jkqtmathtexttools.cpp b/lib/jkqtmathtext/jkqtmathtexttools.cpp
index 79072b0b9d..e6938a21a2 100644
--- a/lib/jkqtmathtext/jkqtmathtexttools.cpp
+++ b/lib/jkqtmathtext/jkqtmathtexttools.cpp
@@ -509,7 +509,7 @@ JKQTMathTextFontEncoding JKQTMathTextEnvironment::getFontEncoding(JKQTMathText*
return MTFEStandard;
}
-QFont JKQTMathTextEnvironment::getFont(JKQTMathText* parent) const {
+QFont JKQTMathTextEnvironment::getFont(const JKQTMathText* parent) const {
QFont f;
switch (font) {
case MTEsans: if (insideMath) {
diff --git a/lib/jkqtmathtext/jkqtmathtexttools.h b/lib/jkqtmathtext/jkqtmathtexttools.h
index bb488c5a18..e1ddf20ad1 100644
--- a/lib/jkqtmathtext/jkqtmathtexttools.h
+++ b/lib/jkqtmathtext/jkqtmathtexttools.h
@@ -301,7 +301,7 @@ struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEnvironment {
/** \brief build a QFont object from the settings in this object */
- QFont getFont(JKQTMathText* parent) const;
+ QFont getFont(const JKQTMathText *parent) const;
/** \brief return a copy of this object with the font exchanged for \a font */
JKQTMathTextEnvironment exchangedFontFor(JKQTMathTextEnvironmentFont font) const;
/** \brief return a copy of this object with the font exchanged for the matching roman font */
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.cpp
index d6219b74c4..644e070ae8 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.cpp
@@ -47,25 +47,21 @@ JKQTMathTextBraceNode::JKQTMathTextBraceNode(JKQTMathText* _parent, JKQTMathText
JKQTMathTextBraceNode::~JKQTMathTextBraceNode() {
}
-void JKQTMathTextBraceNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) {
- double braceWidth=0, braceHeight=0;
- getSizeInternalAndBrace(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos, braceWidth, braceHeight);
+JKQTMathTextNodeSize JKQTMathTextBraceNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
+ return getSizeInternalAndBrace(painter, currentEv);
}
-void JKQTMathTextBraceNode::getSizeInternalAndBrace(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos, double &bracewidth, double &braceheight)
+JKQTMathTextBraceNode::NodeSize JKQTMathTextBraceNode::getSizeInternalAndBrace(QPainter &painter, JKQTMathTextEnvironment currentEv) const
{
- width=0;
- baselineHeight=0;
- overallHeight=0;
- strikeoutPos=0;
- getChild()->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
+ NodeSize s;
+ const NodeSize childSize=getChild()->getSize(painter, currentEv);
const QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
const double minChildHeight=fm.tightBoundingRect("l").height();
double cAscentAboveStrike=0;
double cDescentBelowStrike=0;
- cAscentAboveStrike=qMax(minChildHeight-strikeoutPos, baselineHeight-strikeoutPos);
- cDescentBelowStrike=qMax(strikeoutPos, overallHeight-baselineHeight+strikeoutPos);
+ cAscentAboveStrike=qMax(minChildHeight-childSize.strikeoutPos, childSize.baselineHeight-childSize.strikeoutPos);
+ cDescentBelowStrike=qMax(childSize.strikeoutPos, childSize.getDescent()+childSize.strikeoutPos);
//qDebug()<<"getSizeInternalAndBrace(): showOpeningBrace="<0) painter.drawLine(l);
painter.setPen(p);
} else if (openbrace==MTBTDoubleLine) {
- const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
- const double y2=y-nodeBaselineHeight;
+ const double y1=y+(nodesize.overallHeight-nodesize.baselineHeight);
+ const double y2=y-nodesize.baselineHeight;
QPen plocal=p;
plocal.setWidthF(plocal.widthF()*absnorm_linewidth_factor);
painter.setPen(plocal);
@@ -234,7 +226,7 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
showOpeningBrace=false;
}
if (showOpeningBrace) {
- xnew=xnew+bracewidth;
+ xnew=xnew+nodesize.openBraceWidth;
}
}
@@ -244,14 +236,14 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
{
bool showClosingBrace=true;
- const double xbrace1=qMax(xnew+bracewidth-paren_fraction*bracewidth, xnew+lw/2.0);
- const double xbrace2=xnew+bracewidth-lw;
- const double xbraceC=xnew+bracewidth/2.0;
+ const double xbrace1=qMax(xnew+nodesize.closeBraceWidth-paren_fraction*nodesize.closeBraceWidth, xnew+lw/2.0);
+ const double xbrace2=xnew+nodesize.closeBraceWidth-lw;
+ const double xbraceC=xnew+nodesize.closeBraceWidth/2.0;
painter.setPen(p);
if (closebrace==MTBTParenthesis) {
QPainterPath path;
- const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
- const double y2=y-nodeBaselineHeight;
+ const double y1=y+(nodesize.overallHeight-nodesize.baselineHeight);
+ const double y2=y-nodesize.baselineHeight;
const QPointF pb1(xbrace1-paren_topwidth/2.0, y1);
const QPointF pbc1(xbrace2-paren_centerwidth/2.0, (y1+y2)/2.0+fabs(y1-y2)/6.0);
const QPointF ptc1(xbrace2-paren_centerwidth/2.0, (y1+y2)/2.0-fabs(y1-y2)/6.0);
@@ -273,8 +265,8 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
painter.drawLine(pt2,ptc2);*/
} else if (closebrace==MTBTAngleBracket) {
QPainterPath path;
- const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
- const double y2=y-nodeBaselineHeight;
+ const double y1=y+(nodesize.overallHeight-nodesize.baselineHeight);
+ const double y2=y-nodesize.baselineHeight;
const double yc=(y1+y2)/2.0;
const QPointF pb1(xbrace1-paren_topwidth/2.0, y1);
const QPointF pc1(xbrace2-angle_centerwidth/2.0, yc);
@@ -292,8 +284,8 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
painter.fillPath(path, QBrush(currentEv.color, Qt::SolidPattern));
} else if (closebrace==MTBTSquareBracket) {
QPainterPath path;
- const double y1=y+(nodeOverallHeight-nodeBaselineHeight)-lw/2.0;
- const double y2=y-nodeBaselineHeight+lw/2.0;
+ const double y1=y+(nodesize.overallHeight-nodesize.baselineHeight)-lw/2.0;
+ const double y2=y-nodesize.baselineHeight+lw/2.0;
path.moveTo(xbrace1, y1);
path.lineTo(xbrace2, y1);
path.lineTo(xbrace2, y2);
@@ -302,7 +294,7 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
} else if (closebrace==MTBTBottomCorner) {
QPainterPath path;
const double dx=fabs(xbrace1-xbrace2);
- const double y1=y+(nodeOverallHeight-nodeBaselineHeight)-lw/2.0;
+ const double y1=y+(nodesize.overallHeight-nodesize.baselineHeight)-lw/2.0;
path.moveTo(xbrace1, y1);
path.lineTo(xbrace2, y1);
path.lineTo(xbrace2, y1-dx);
@@ -310,38 +302,38 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
} else if (closebrace==MTBTTopCorner) {
QPainterPath path;
const double dx=fabs(xbrace1-xbrace2);
- const double y1=y-nodeBaselineHeight+lw/2.0;
+ const double y1=y-nodesize.baselineHeight+lw/2.0;
path.moveTo(xbrace1, y1);
path.lineTo(xbrace2, y1);
path.lineTo(xbrace2, y1+dx);
painter.drawPath(path);
} else if (closebrace==MTBTCurlyBracket) {
- const QPainterPath path=JKQTMathTextMakeHBracePath(0,0,nodeOverallHeight, bracewidth*paren_fraction, p.widthF());
+ const QPainterPath path=JKQTMathTextMakeHBracePath(0,0,nodesize.overallHeight, nodesize.closeBraceWidth*paren_fraction, p.widthF());
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
- painter.translate(xbraceC, y-nodeBaselineHeight+nodeOverallHeight/2.0);
+ painter.translate(xbraceC, y-nodesize.baselineHeight+nodesize.overallHeight/2.0);
painter.rotate(270);
QPen plocal=p;
plocal.setWidthF(0.0001);
painter.fillPath(path, QBrush(currentEv.color));
} else if (closebrace==MTBTFloorBracket) {
QPainterPath path;
- const double y1=y+(nodeOverallHeight-nodeBaselineHeight)-lw/2.0;
- const double y2=y-nodeBaselineHeight;
+ const double y1=y+(nodesize.overallHeight-nodesize.baselineHeight)-lw/2.0;
+ const double y2=y-nodesize.baselineHeight;
path.moveTo(xbrace1, y1);
path.lineTo(xbrace2, y1);
path.lineTo(xbrace2, y2);
painter.drawPath(path);
} else if (closebrace==MTBTCeilBracket) {
QPainterPath path;
- const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
- const double y2=y-nodeBaselineHeight+lw/2.0;
+ const double y1=y+(nodesize.overallHeight-nodesize.baselineHeight);
+ const double y2=y-nodesize.baselineHeight+lw/2.0;
path.moveTo(xbrace2, y1);
path.lineTo(xbrace2, y2);
path.lineTo(xbrace1, y2);
painter.drawPath(path);
} else if (closebrace==MTBTSingleLine) {
- const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
- const double y2=y-nodeBaselineHeight;
+ const double y1=y+(nodesize.overallHeight-nodesize.baselineHeight);
+ const double y2=y-nodesize.baselineHeight;
const QLineF l(xbraceC, y1, xbraceC, y2);
QPen plocal=p;
plocal.setWidthF(plocal.widthF()*absnorm_linewidth_factor);
@@ -349,8 +341,8 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
if (l.length()>0) painter.drawLine(l);
painter.setPen(p);
} else if (closebrace==MTBTDoubleLine) {
- const double y1=y+(nodeOverallHeight-nodeBaselineHeight);
- const double y2=y-nodeBaselineHeight;
+ const double y1=y+(nodesize.overallHeight-nodesize.baselineHeight);
+ const double y2=y-nodesize.baselineHeight;
const QLineF l(xbraceC-lw, y1, xbraceC-lw, y2);
QPen plocal=p;
plocal.setWidthF(plocal.widthF()*absnorm_linewidth_factor);
@@ -364,7 +356,7 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
}
painter.setPen(pold);
if (showClosingBrace) {
- xnew=xnew+bracewidth;
+ xnew=xnew+nodesize.closeBraceWidth;
}
}
@@ -372,7 +364,7 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
return xnew;
}
-bool JKQTMathTextBraceNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
+bool JKQTMathTextBraceNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const {
QString ob;
QString cb;
if (openbrace==MTBTAngleBracket) ob="〈";
@@ -419,19 +411,85 @@ JKQTMathTextBraceType JKQTMathTextBraceNode::getClosebrace() const {
return this->closebrace;
}
-void JKQTMathTextBraceNode::getBraceSize(QPainter &painter, JKQTMathTextEnvironment ev, double /*baselineHeight*/, double overallHeight, double &bracewidth, double &braceheight) const
-{
- const QFontMetricsF fm(ev.getFont(parentMathText), painter.device());
- const double lw=fm.lineWidth();
- const double dblline_distance=2.0*lw;
- braceheight=overallHeight*parentMathText->getBraceFactor();
- bracewidth=lw*5.0;
- if (openbrace==MTBTCurlyBracket || closebrace==MTBTCurlyBracket) bracewidth=lw*6.5;
- if (openbrace==MTBTParenthesis || closebrace==MTBTParenthesis) bracewidth=lw*6.0;
- if (openbrace==MTBTDoubleLine || closebrace==MTBTDoubleLine) bracewidth=dblline_distance+3.0*lw;
- if (openbrace==MTBTSingleLine || closebrace==MTBTSingleLine) bracewidth=3.0*lw;
- const double overSizeFactor=braceheight/fm.height();
- if (overSizeFactor>1.2) bracewidth=bracewidth*sqrt(overSizeFactor);
+
+JKQTMathTextBraceNode::NodeSize::NodeSize():
+ JKQTMathTextNodeSize(),
+ openBraceWidth(0.0),
+ openBraceHeight(0.0),
+ closeBraceWidth(0.0),
+ closeBraceHeight(0.0)
+{
+
}
+JKQTMathTextBraceNode::NodeSize::NodeSize(const JKQTMathTextNodeSize &other):
+ JKQTMathTextNodeSize(other),
+ openBraceWidth(0.0),
+ openBraceHeight(0.0),
+ closeBraceWidth(0.0),
+ closeBraceHeight(0.0)
+{
+
+}
+
+JKQTMathTextBraceNode::NodeSize &JKQTMathTextBraceNode::NodeSize::operator=(const JKQTMathTextNodeSize &other)
+{
+ JKQTMathTextNodeSize::operator=(other);
+ openBraceWidth=0.0;
+ openBraceHeight=0.0;
+ closeBraceWidth=0.0;
+ closeBraceHeight=0.0;
+ return *this;
+}
+
+JKQTMathTextBraceNode::NodeSize &JKQTMathTextBraceNode::NodeSize::operator=(const NodeSize &other)
+{
+ JKQTMathTextNodeSize::operator=(dynamic_cast(other));
+ openBraceWidth=other.openBraceWidth;
+ openBraceHeight=other.openBraceHeight;
+ closeBraceWidth=other.closeBraceWidth;
+ closeBraceHeight=other.closeBraceHeight;
+ return *this;
+}
+
+JKQTMathTextBraceNode::NodeSize::NodeSize(const NodeSize &other):
+ JKQTMathTextNodeSize(dynamic_cast(other)),
+ openBraceWidth(other.openBraceWidth),
+ openBraceHeight(other.openBraceHeight),
+ closeBraceWidth(other.closeBraceWidth),
+ closeBraceHeight(other.closeBraceHeight)
+{
+
+}
+
+
+void JKQTMathTextBraceNode::calcBraceSizes(NodeSize& out, QPainter &painter, const JKQTMathTextEnvironment &ev, const JKQTMathTextNodeSize &childSize) const
+{
+ const QFontMetricsF fm(ev.getFont(parentMathText), painter.device());
+ const QSizeF openBraceS=calcBraceSize(fm, openbrace, childSize);
+ const QSizeF closeBraceS=calcBraceSize(fm, closebrace, childSize);
+ out.openBraceWidth=openBraceS.width();
+ out.openBraceHeight=openBraceS.width();
+ out.closeBraceWidth=closeBraceS.width();
+ out.closeBraceHeight=closeBraceS.width();
+}
+
+QSizeF JKQTMathTextBraceNode::calcBraceSize(const QFontMetricsF &fm, JKQTMathTextBraceType bracetype, const JKQTMathTextNodeSize &childSize) const
+{
+ double braceWidth=0.0;
+ double braceHeight=0.0;
+ const double lw=fm.lineWidth();
+ const double dblline_distance=2.0*lw;
+ braceHeight=childSize.overallHeight*parentMathText->getBraceFactor();
+ braceWidth=lw*5.0;
+ if (bracetype==MTBTCurlyBracket) braceWidth=lw*6.5;
+ if (bracetype==MTBTParenthesis) braceWidth=lw*6.0;
+ if (bracetype==MTBTDoubleLine) braceWidth=dblline_distance+3.0*lw;
+ if (bracetype==MTBTSingleLine) braceWidth=3.0*lw;
+
+ const double overSizeFactor=braceHeight/fm.height();
+ if (overSizeFactor>1.2) braceWidth=braceWidth*sqrt(overSizeFactor);
+
+ return QSizeF(braceWidth, braceHeight);
+}
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.h b/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.h
index aba8346fc4..17d4126981 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextbracenode.h
@@ -48,9 +48,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceNode: public JKQTMathTextSingleCh
JKQTMathTextBraceNode(JKQTMathText* parent, JKQTMathTextBraceType openbrace, JKQTMathTextBraceType closebrace, JKQTMathTextNode* child);
virtual ~JKQTMathTextBraceNode() override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc openbrace */
@@ -58,19 +58,50 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceNode: public JKQTMathTextSingleCh
/** \copydoc closebrace */
JKQTMathTextBraceType getClosebrace() const;
protected:
+ /** \brief defines the size of the node (JKQTMathTextNodeSize) and additional information */
+ struct NodeSize: public JKQTMathTextNodeSize {
+ NodeSize();
+ NodeSize(const NodeSize& other);
+ NodeSize(const JKQTMathTextNodeSize& other);
+ NodeSize& operator=(const NodeSize& other);
+ NodeSize& operator=(const JKQTMathTextNodeSize& other);
+ /** \brief width of the opening brace */
+ double openBraceWidth;
+ /** \brief height of the opening brace */
+ double openBraceHeight;
+ /** \brief width of the closing brace */
+ double closeBraceWidth;
+ /** \brief height of the closing brace */
+ double closeBraceHeight;
+ };
/** \copydoc JKQTMathTextNode::getSizeInternal()
*
* \note This function internally calls getSizeInternalAndBrace() and returns part of its results.
*/
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** calculates the size of this node (also returned by getSizeInternal() ) and of the brace */
- void getSizeInternalAndBrace(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, double& bracewidth, double&braceheight);
+ NodeSize getSizeInternalAndBrace(QPainter& painter, JKQTMathTextEnvironment currentEv) const;
/**\brief opening brace */
JKQTMathTextBraceType openbrace;
/**\brief closing brace */
JKQTMathTextBraceType closebrace;
- /** \brief calculate the width of the brace */
- void getBraceSize(QPainter& painter, JKQTMathTextEnvironment currentEv, double baselineHeight, double overallHeight, double& bracewidth, double& braceheight) const;
+ /** \brief calculate the width of the braces, fills NodeSize::openbracewidth/NodeSize::closebracewidth and NodeSize::braceheight/NodeSize::closeheight in \a out, based on \a childSize
+ *
+ * \param[out] out this function fills NodeSize::openbracewidth/NodeSize::closebracewidth and NodeSize::braceheight/NodeSize::closeheight in \a out
+ * \param painter a QPainter used for size-calculation/drawing
+ * \param currentEv font environment
+ * \param childSize size of the child node surrounded by the node
+ */
+ void calcBraceSizes(NodeSize& out, QPainter& painter, const JKQTMathTextEnvironment& currentEv, const JKQTMathTextNodeSize &childSize) const;
+ /** \brief calculate the width and height of a brace, based on \a childSize
+ *
+ * \param fm QFontMetricsF object describing the font of the current environment
+ * \param bracetype brace type
+ * \param childSize size of the child node surrounded by the node
+ *
+ * \return width and hieght of the brace
+ */
+ QSizeF calcBraceSize(const QFontMetricsF& fm, JKQTMathTextBraceType bracetype, const JKQTMathTextNodeSize &childSize) const;
};
#endif // JKQTMATHTEXTBRACENODE_H
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.cpp
index 0f412dd4d1..f6ce642154 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.cpp
@@ -129,28 +129,28 @@ JKQTMathTextDecoratedNode::JKQTMathTextDecoratedNode(JKQTMathText* _parent, Deco
JKQTMathTextDecoratedNode::~JKQTMathTextDecoratedNode() {
}
-void JKQTMathTextDecoratedNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) {
+JKQTMathTextNodeSize JKQTMathTextDecoratedNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
+ JKQTMathTextNodeSize s;
JKQTMathTextEnvironment ev=currentEv;
- double cwidth=0, cbaselineHeight=0, coverallHeight=0, cstrikeoutPos=0;
- getChild()->getSize(painter, ev, cwidth, cbaselineHeight, coverallHeight, cstrikeoutPos);
- const double cDescent=coverallHeight-cbaselineHeight;
+ JKQTMathTextNodeSize cs=getChild()->getSize(painter, ev);
+ const double cDescent=cs.getDescent();
const QFont font=ev.getFont(parentMathText);
const QFontMetricsF fm(font, painter.device());
const double decoSeparation=parentMathText->getDecorationSeparationFactor()*fm.ascent();
const double deco_height=parentMathText->getDecorationHeightFactor()*fm.ascent();
- const double deco_ypos=cbaselineHeight+decoSeparation;
+ const double deco_ypos=cs.baselineHeight+decoSeparation;
const double decoAboveAscent_ypos=fm.ascent()+decoSeparation;
const double decobelow_ypos=cDescent+decoSeparation;
- const double italic_xcorrection=getNonItalicXCorretion(painter, cwidth, ev, getChild());
+ const double italic_xcorrection=getNonItalicXCorretion(painter, cs.width, ev, getChild());
const double deco_miniwidth=((decoration==MTDtilde||decoration==MTDbreve)?fm.boundingRect("~").width():fm.boundingRect("^").width())-italic_xcorrection;
const double linewidth=qMax(parentMathText->ABS_MIN_LINEWIDTH, fm.lineWidth());
- double descent=coverallHeight-cbaselineHeight;
- double ascent=cbaselineHeight;
+ double descent=cs.getDescent();
+ double ascent=cs.baselineHeight;
if (decoration==MTDbar) {
- ascent=std::max(baselineHeight+decoSeparation, decoAboveAscent_ypos)+linewidth/2.0;
+ ascent=std::max(cs.baselineHeight+decoSeparation, decoAboveAscent_ypos)+linewidth/2.0;
} else if (decoration==MTDunderline || decoration==MTDunderlineDashed || decoration==MTDunderlineDotted) {
descent=std::max(decobelow_ypos, cDescent)+linewidth/2.0;
} else if (decoration==MTDdoubleunderline) {
@@ -160,10 +160,11 @@ void JKQTMathTextDecoratedNode::getSizeInternal(QPainter& painter, JKQTMathTextE
} else {
ascent=deco_ypos+deco_height;
}
- overallHeight=ascent+descent;
- baselineHeight=ascent;
- strikeoutPos=cstrikeoutPos;
- width=std::max(deco_miniwidth,cwidth);
+ s.overallHeight=ascent+descent;
+ s.baselineHeight=ascent;
+ s.strikeoutPos=cs.strikeoutPos;
+ s.width=std::max(deco_miniwidth,cs.width);
+ return s;
}
QHash JKQTMathTextDecoratedNode::instructions;
@@ -224,12 +225,11 @@ void JKQTMathTextDecoratedNode::fillInstructions()
}
-double JKQTMathTextDecoratedNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) {
+double JKQTMathTextDecoratedNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
doDrawBoxes(painter, x, y, currentEv);
JKQTMathTextEnvironment ev=currentEv;
- double cwidth=0, cbaselineHeight=0, coverallHeight=0, cstrikeoutPos=0;
- getChild()->getSize(painter, ev, cwidth, cbaselineHeight, coverallHeight, cstrikeoutPos);
- const double cDescent=coverallHeight-cbaselineHeight;
+ auto cs=getChild()->getSize(painter, ev);
+ const double cDescent=cs.overallHeight-cs.baselineHeight;
const QFont font=ev.getFont(parentMathText);
const QFontMetricsF fm(font, painter.device());
const double width_X=fm.boundingRect("X").width();
@@ -240,24 +240,24 @@ double JKQTMathTextDecoratedNode::draw(QPainter& painter, double x, double y, JK
const double linewidthArrow=linewidth*0.65;
const double deco_height=parentMathText->getDecorationHeightFactor()*fm.ascent();
const double decoAboveAscent_ypos=y-fm.ascent()-decoSeparation;
- const double strike_ypos=y-cbaselineHeight/2.0;
+ const double strike_ypos=y-cs.baselineHeight/2.0;
const double decobelow_ypos=y+cDescent+decoSeparation;
- const double italic_xcorrection=getNonItalicXCorretion(painter, cwidth, ev, getChild());
+ const double italic_xcorrection=getNonItalicXCorretion(painter, cs.width, ev, getChild());
const double deco_xoffset=parentMathText->getDecorationWidthReductionXFactor()*width_X/2.0;
- const double deco_width=std::max(width_x*0.5,cwidth-2.0*deco_xoffset-italic_xcorrection);
+ const double deco_width=std::max(width_x*0.5,cs.width-2.0*deco_xoffset-italic_xcorrection);
const double deco_vecwidth=width_x*0.18;
const double deco_vecheight=deco_height*0.25;
const double deco_accentwidth=deco_height/4.0;
const double deco_miniwidth=((decoration==MTDtilde||decoration==MTDbreve)?fm.boundingRect("j").width():fm.boundingRect("^").width())-italic_xcorrection;
- const double decotop_xcenter=x+italic_xcorrection+(cwidth-italic_xcorrection)/2.0;
+ const double decotop_xcenter=x+italic_xcorrection+(cs.width-italic_xcorrection)/2.0;
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;
- const double decobot_xend=x+cwidth-italic_xcorrection-linewidth/2.0;
+ const double decobot_xend=x+cs.width-italic_xcorrection-linewidth/2.0;
//const double decobot_xcenter=(decobot_xstart+decobot_xend)/2.0;
- const double deco_ytopbot=y-cbaselineHeight-decoSeparation-linewidth/2.0;
- const double deco_ytoptop=y-cbaselineHeight-decoSeparation-deco_height+linewidth/2.0;
- const double deco_ytopcenter=y-cbaselineHeight-decoSeparation-deco_height/2.0;
+ 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;
@@ -529,7 +529,7 @@ double JKQTMathTextDecoratedNode::draw(QPainter& painter, double x, double y, JK
return xnew;
}
-bool JKQTMathTextDecoratedNode::toHtml(QString &/*html*/, JKQTMathTextEnvironment /*currentEv*/, JKQTMathTextEnvironment /*defaultEv*/) {
+bool JKQTMathTextDecoratedNode::toHtml(QString &/*html*/, JKQTMathTextEnvironment /*currentEv*/, JKQTMathTextEnvironment /*defaultEv*/) const {
//QString f;
//JKQTMathTextEnvironment ev=currentEv;
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.h b/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.h
index 2242c2fdd4..cf6ea52086 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextdecoratednode.h
@@ -91,16 +91,16 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextDecoratedNode: public JKQTMathTextSing
JKQTMathTextDecoratedNode(JKQTMathText* parent, DecorationType decoration, JKQTMathTextNode* child);
virtual ~JKQTMathTextDecoratedNode() override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override ;
/** \copydoc decoration */
DecorationType getDecoration() const;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** \brief type of decoration that is added to the child node */
DecorationType decoration;
/** \brief lists all supported instructions */
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.cpp
index 442b7a06af..be45c3e203 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.cpp
@@ -123,7 +123,7 @@ QString JKQTMathTextFracNode::getTypeName() const
return "MTfracNode";
}
-void JKQTMathTextFracNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) {
+JKQTMathTextNodeSize JKQTMathTextFracNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
const QFont f=currentEv.getFont(parentMathText);
const QFontMetricsF fm(f, painter.device());
JKQTMathTextEnvironment ev1=currentEv;
@@ -156,69 +156,68 @@ void JKQTMathTextFracNode::getSizeInternal(QPainter& painter, JKQTMathTextEnviro
const QRectF AeTBR2=fmev2.tightBoundingRect("A");
const double asc2=AeTBR2.height();
- double width1=0, baselineHeight1=0, overallHeight1=0, strikeoutPos1=0;
- double width2=0, baselineHeight2=0, overallHeight2=0, strikeoutPos2=0;
- child1->getSize(painter, ev1, width1, baselineHeight1, overallHeight1, strikeoutPos1);
- child2->getSize(painter, ev2, width2, baselineHeight2, overallHeight2, strikeoutPos2);
- if (asc1>baselineHeight1) {
- const double oldDescent=overallHeight1-baselineHeight1;
- baselineHeight1=asc1;
- overallHeight1=baselineHeight1+oldDescent;
+ JKQTMathTextNodeSize size1=child1->getSize(painter, ev1);
+ JKQTMathTextNodeSize size2=child2->getSize(painter, ev2);
+ if (asc1>size1.baselineHeight) {
+ const double oldDescent=size1.overallHeight-size1.baselineHeight;
+ size1.baselineHeight=asc1;
+ size1.overallHeight=size1.baselineHeight+oldDescent;
}
- if (asc2>baselineHeight2) {
- const double oldDescent=overallHeight2-baselineHeight2;
- baselineHeight2=asc2;
- overallHeight2=baselineHeight2+oldDescent;
+ if (asc2>size2.baselineHeight) {
+ const double oldDescent=size2.overallHeight-size2.baselineHeight;
+ size2.baselineHeight=asc2;
+ size2.overallHeight=size2.baselineHeight+oldDescent;
}
- const double descent1=overallHeight1-baselineHeight1;
+ const double descent1=size1.overallHeight-size1.baselineHeight;
-
- overallHeight=0;
- baselineHeight=0;
- width=0;
+ JKQTMathTextNodeSize size;
+ size.overallHeight=0;
+ size.baselineHeight=0;
+ size.width=0;
if (mode==JKQTMathTextFracNode::MTFMfrac || mode==JKQTMathTextFracNode::MTFMdfrac || mode==JKQTMathTextFracNode::MTFMtfrac || mode==JKQTMathTextFracNode::MTFMstackrel) {
const double top_ascent=line_ascent+xheight*parentMathText->getFracShiftFactor();
const double bot_ascent=line_ascent-xheight*parentMathText->getFracShiftFactor();
- const double newascent=overallHeight1+top_ascent;
- const double newdescent=overallHeight2-bot_ascent;
- width=qMax(width1, width2);
- if (mode!=JKQTMathTextFracNode::MTFMstackrel) width+=xwidth/2.0;
- strikeoutPos=line_ascent;
+ const double newascent=size1.overallHeight+top_ascent;
+ const double newdescent=size2.overallHeight-bot_ascent;
+ size.width=qMax(size1.width, size2.width);
+ if (mode!=JKQTMathTextFracNode::MTFMstackrel) size.width+=xwidth/2.0;
+ size.strikeoutPos=line_ascent;
- overallHeight=newascent+newdescent;
- baselineHeight=newascent;
+ size.overallHeight=newascent+newdescent;
+ size.baselineHeight=newascent;
} else if (mode==JKQTMathTextFracNode::MTFMstfrac || mode==JKQTMathTextFracNode::MTFMsfrac) {
const double top_ascent=line_ascent;
- const double newascent=overallHeight1+top_ascent;
- const double newdescent=qMax(overallHeight2-baselineHeight2, qheight-xheight);
- width=width1+width2+xwidth*0.666;
- strikeoutPos=line_ascent;
+ const double newascent=size1.overallHeight+top_ascent;
+ const double newdescent=qMax(size2.overallHeight-size2.baselineHeight, qheight-xheight);
+ size.width=size1.width+size2.width+xwidth*0.666;
+ size.strikeoutPos=line_ascent;
- overallHeight=newascent+newdescent;
- baselineHeight=newascent;
+ size.overallHeight=newascent+newdescent;
+ size.baselineHeight=newascent;
} else if (mode==JKQTMathTextFracNode::MTFMunderbrace || mode==JKQTMathTextFracNode::MTFMunderbracket) {
- const double newdescent=descent1+overallHeight2+braceheight+2.0*braceseparation;
- overallHeight=newdescent+baselineHeight1;
- baselineHeight=baselineHeight1;
- width=qMax(width1, width2)+xwidth;
- strikeoutPos=line_ascent;
+ const double newdescent=descent1+size2.overallHeight+braceheight+2.0*braceseparation;
+ size.overallHeight=newdescent+size1.baselineHeight;
+ size.baselineHeight=size1.baselineHeight;
+ size.width=qMax(size1.width, size2.width)+xwidth;
+ size.strikeoutPos=line_ascent;
} else if (mode==JKQTMathTextFracNode::MTFMoverbrace || mode==JKQTMathTextFracNode::MTFMoverbracket) {
- overallHeight=overallHeight1+overallHeight2+braceheight+2.0*braceseparation;
- baselineHeight=baselineHeight1+overallHeight2+braceheight+2.0*braceseparation;
- width=qMax(width1, width2)+xwidth;
- strikeoutPos=line_ascent;
+ size.overallHeight=size1.overallHeight+size2.overallHeight+braceheight+2.0*braceseparation;
+ size.baselineHeight=size1.baselineHeight+size2.overallHeight+braceheight+2.0*braceseparation;
+ size.width=qMax(size1.width, size2.width)+xwidth;
+ size.strikeoutPos=line_ascent;
} else if (mode==JKQTMathTextFracNode::MTFMunderset) {
- overallHeight=overallHeight1+overallHeight2+xheight/6.0;
- baselineHeight=baselineHeight1;
- width=qMax(width1, width2)+xwidth;
- strikeoutPos=line_ascent;
+ size.overallHeight=size1.overallHeight+size2.overallHeight+xheight/6.0;
+ size.baselineHeight=size1.baselineHeight;
+ size.width=qMax(size1.width, size2.width)+xwidth;
+ size.strikeoutPos=line_ascent;
} else if (mode==JKQTMathTextFracNode::MTFMoverset) {
- overallHeight=overallHeight1+overallHeight2+xheight/6.0;
- baselineHeight=baselineHeight1+overallHeight2+xheight/6.0;
- width=qMax(width1, width2)+xwidth;
- strikeoutPos=line_ascent;
+ size.overallHeight=size1.overallHeight+size1.overallHeight+xheight/6.0;
+ size.baselineHeight=size1.baselineHeight+size2.overallHeight+xheight/6.0;
+ size.width=qMax(size1.width, size2.width)+xwidth;
+ size.strikeoutPos=line_ascent;
}
+ return size;
}
int JKQTMathTextFracNode::getNestingLevel(bool /*sameType*/) const
@@ -240,7 +239,7 @@ double JKQTMathTextFracNode::getFracScalingFactor() const
return parentMathText->getFracFactor();
}
-double JKQTMathTextFracNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) {
+double JKQTMathTextFracNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
doDrawBoxes(painter, x, y, currentEv);
const QFont f=currentEv.getFont(parentMathText);
const QFontMetricsF fm(f, painter.device());
@@ -276,31 +275,29 @@ double JKQTMathTextFracNode::draw(QPainter& painter, double x, double y, JKQTMat
const QRectF AeTBR2=fmev2.tightBoundingRect("A");
const double asc2=AeTBR2.height();
- double width1=0, baselineHeight1=0, overallHeight1=0;//, strikeoutPos1=0;
- double width2=0, baselineHeight2=0, overallHeight2=0, strikeoutPos=0;
- child1->getSize(painter, ev1, width1, baselineHeight1, overallHeight1, strikeoutPos);
- child2->getSize(painter, ev2, width2, baselineHeight2, overallHeight2, strikeoutPos);
- if (asc1>baselineHeight1) {
- const double oldDescent=overallHeight1-baselineHeight1;
- baselineHeight1=asc1;
- overallHeight1=baselineHeight1+oldDescent;
+ JKQTMathTextNodeSize size1=child1->getSize(painter, ev1);
+ JKQTMathTextNodeSize size2=child2->getSize(painter, ev2);
+ if (asc1>size1.baselineHeight) {
+ const double oldDescent=size1.overallHeight-size1.baselineHeight;
+ size1.baselineHeight=asc1;
+ size1.overallHeight=size1.baselineHeight+oldDescent;
}
- if (asc2>baselineHeight2) {
- const double oldDescent=overallHeight2-baselineHeight2;
- baselineHeight2=asc2;
- overallHeight2=baselineHeight2+oldDescent;
+ if (asc2>size2.baselineHeight) {
+ const double oldDescent=size2.overallHeight-size2.baselineHeight;
+ size2.baselineHeight=asc2;
+ size2.overallHeight=size2.baselineHeight+oldDescent;
}
- const double ascent1=baselineHeight1;
- const double descent1=overallHeight1-baselineHeight1;
- const double ascent2=baselineHeight2;
- const double descent2=overallHeight2-baselineHeight2;
+ const double ascent1=size1.baselineHeight;
+ const double descent1=size1.overallHeight-size1.baselineHeight;
+ const double ascent2=size2.baselineHeight;
+ const double descent2=size2.overallHeight-size2.baselineHeight;
const double yline=y-xheight*0.5;
- //double overallHeight=overallHeight1+overallHeight2+xh;
- //double baselineHeight=3.0*xh/2.0+overallHeight1;
- const double maxWidth=qMax(width1, width2);
+ //double overallHeight=size1.overallHeight+size2.overallHeight+xh;
+ //double baselineHeight=3.0*xh/2.0+size1.overallHeight;
+ const double maxWidth=qMax(size1.width, size2.width);
double deltaWidth=0;
QPen p=painter.pen();
@@ -313,32 +310,32 @@ double JKQTMathTextFracNode::draw(QPainter& painter, double x, double y, JKQTMat
deltaWidth=xwidth/2.0;
const QLineF l(x+p.widthF()*2.0, yline, x+maxWidth+deltaWidth-p.widthF()*2.0, yline);
if (l.length()>0) painter.drawLine(l);
- child1->draw(painter, x+deltaWidth/2.0+(maxWidth-width1)/2.0, yline-xheight*(parentMathText->getFracShiftFactor())-descent1, ev1);
- child2->draw(painter, x+deltaWidth/2.0+(maxWidth-width2)/2.0, yline+xheight*(parentMathText->getFracShiftFactor())+ascent2, ev2);
+ child1->draw(painter, x+deltaWidth/2.0+(maxWidth-size1.width)/2.0, yline-xheight*(parentMathText->getFracShiftFactor())-descent1, ev1);
+ child2->draw(painter, x+deltaWidth/2.0+(maxWidth-size2.width)/2.0, yline+xheight*(parentMathText->getFracShiftFactor())+ascent2, ev2);
} else if (mode==JKQTMathTextFracNode::MTFMstackrel) {
- child1->draw(painter, x+(maxWidth-width1)/2.0, yline-xheight*(parentMathText->getFracShiftFactor())-descent1, ev1);
- child2->draw(painter, x+(maxWidth-width2)/2.0, yline+xheight*(parentMathText->getFracShiftFactor())+ascent2, ev2);
+ child1->draw(painter, x+(maxWidth-size1.width)/2.0, yline-xheight*(parentMathText->getFracShiftFactor())-descent1, ev1);
+ child2->draw(painter, x+(maxWidth-size2.width)/2.0, yline+xheight*(parentMathText->getFracShiftFactor())+ascent2, ev2);
} else if (mode==JKQTMathTextFracNode::MTFMstfrac || mode==JKQTMathTextFracNode::MTFMsfrac) {
deltaWidth=xwidth*0.666;
child1->draw(painter, x, yline, ev1);
- child2->draw(painter, x+width1+deltaWidth, y, ev2);
- const QLineF l(x+width1+deltaWidth, y-Mheight, x+width1, y+(qheight-xheight));
+ child2->draw(painter, x+size1.width+deltaWidth, y, ev2);
+ const QLineF l(x+size1.width+deltaWidth, y-Mheight, x+size1.width, y+(qheight-xheight));
if (l.length()>0) painter.drawLine(l);
} else if (mode==JKQTMathTextFracNode::MTFMunderset) {
- child1->draw(painter, x+xwidth/2.0+(maxWidth-width1)/2.0, y, ev1);
- child2->draw(painter, x+xwidth/2.0+(maxWidth-width2)/2.0, y+descent1+xheight/6.0+ascent2, ev2);
+ child1->draw(painter, x+xwidth/2.0+(maxWidth-size1.width)/2.0, y, ev1);
+ child2->draw(painter, x+xwidth/2.0+(maxWidth-size2.width)/2.0, y+descent1+xheight/6.0+ascent2, ev2);
deltaWidth=xwidth;
} else if (mode==JKQTMathTextFracNode::MTFMunderbrace) {
const double ybrace=y+descent1+braceseparation+braceheight/2.0;
const double ybot=y+descent1+2.0*braceseparation+braceheight+ascent2;
{
- const QPainterPath path=JKQTMathTextMakeHBracePath(x+xwidth/2.0+(width1)/2.0, ybrace, maxWidth, braceheight, p.width());
+ const QPainterPath path=JKQTMathTextMakeHBracePath(x+xwidth/2.0+(size1.width)/2.0, ybrace, maxWidth, braceheight, p.width());
QPen plocal=p;
plocal.setWidthF(0.0001);
painter.fillPath(path, QBrush(ev1.color));
}
- child1->draw(painter, x+xwidth/2.0+(maxWidth-width1)/2.0, y, ev1);
- child2->draw(painter, x+xwidth/2.0+(maxWidth-width2)/2.0, ybot, ev2);
+ child1->draw(painter, x+xwidth/2.0+(maxWidth-size1.width)/2.0, y, ev1);
+ child2->draw(painter, x+xwidth/2.0+(maxWidth-size2.width)/2.0, ybot, ev2);
deltaWidth=xwidth;
} else if (mode==JKQTMathTextFracNode::MTFMunderbracket) {
const double ybrace=y+descent1+braceseparation+braceheight/2.0;
@@ -355,19 +352,19 @@ double JKQTMathTextFracNode::draw(QPainter& painter, double x, double y, JKQTMat
path.lineTo(x2, y1);
painter.drawPath(path);
}
- child1->draw(painter, x+xwidth/2.0+(maxWidth-width1)/2.0, y, ev1);
- child2->draw(painter, x+xwidth/2.0+(maxWidth-width2)/2.0, ybot, ev2);
+ child1->draw(painter, x+xwidth/2.0+(maxWidth-size1.width)/2.0, y, ev1);
+ child2->draw(painter, x+xwidth/2.0+(maxWidth-size2.width)/2.0, ybot, ev2);
deltaWidth=xwidth;
} else if (mode==JKQTMathTextFracNode::MTFMoverset) {
- child1->draw(painter, x+xwidth/2.0+(maxWidth-width1)/2.0, y, ev1);
- child2->draw(painter, x+xwidth/2.0+(maxWidth-width2)/2.0, y-ascent1-xheight/6.0-descent2, ev2);
+ child1->draw(painter, x+xwidth/2.0+(maxWidth-size1.width)/2.0, y, ev1);
+ child2->draw(painter, x+xwidth/2.0+(maxWidth-size2.width)/2.0, y-ascent1-xheight/6.0-descent2, ev2);
deltaWidth=xwidth;
} else if (mode==JKQTMathTextFracNode::MTFMoverbrace) {
const double ybrace=y-ascent1-braceheight/2.0-braceseparation;
const double ytop=y-ascent1-2.0*braceseparation-braceheight-descent2;
{
painter.save(); auto __finalpaintinner=JKQTPFinally([&painter]() {painter.restore();});
- painter.translate(x+xwidth/2.0+(width1)/2.0, ybrace);
+ painter.translate(x+xwidth/2.0+(size1.width)/2.0, ybrace);
painter.rotate(180);
const QPainterPath path=JKQTMathTextMakeHBracePath(0,0, maxWidth, braceheight, p.widthF());
QPen plocal=p;
@@ -375,8 +372,8 @@ double JKQTMathTextFracNode::draw(QPainter& painter, double x, double y, JKQTMat
painter.fillPath(path, QBrush(ev1.color));
}
- child1->draw(painter, x+xwidth/2.0+(maxWidth-width1)/2.0, y, ev1);
- child2->draw(painter, x+xwidth/2.0+(maxWidth-width2)/2.0, ytop, ev2);
+ child1->draw(painter, x+xwidth/2.0+(maxWidth-size1.width)/2.0, y, ev1);
+ child2->draw(painter, x+xwidth/2.0+(maxWidth-size2.width)/2.0, ytop, ev2);
deltaWidth=xwidth;
} else if (mode==JKQTMathTextFracNode::MTFMoverbracket) {
const double ybrace=y-ascent1-braceheight/2.0-braceseparation;
@@ -393,22 +390,21 @@ double JKQTMathTextFracNode::draw(QPainter& painter, double x, double y, JKQTMat
path.lineTo(x2, y1);
painter.drawPath(path);
}
- child1->draw(painter, x+xwidth/2.0+(maxWidth-width1)/2.0, y, ev1);
- child2->draw(painter, x+xwidth/2.0+(maxWidth-width2)/2.0, ytop, ev2);
+ child1->draw(painter, x+xwidth/2.0+(maxWidth-size1.width)/2.0, y, ev1);
+ child2->draw(painter, x+xwidth/2.0+(maxWidth-size2.width)/2.0, ytop, ev2);
deltaWidth=xwidth;
}
- if (mode==JKQTMathTextFracNode::MTFMstfrac || mode==JKQTMathTextFracNode::MTFMsfrac) return x+width1+width2+deltaWidth;
+ if (mode==JKQTMathTextFracNode::MTFMstfrac || mode==JKQTMathTextFracNode::MTFMsfrac) return x+size1.width+size2.width+deltaWidth;
else return x+maxWidth+deltaWidth;
}
-bool JKQTMathTextFracNode::toHtml(QString &/*html*/, JKQTMathTextEnvironment /*currentEv*/, JKQTMathTextEnvironment /*defaultEv*/) {
+bool JKQTMathTextFracNode::toHtml(QString &/*html*/, JKQTMathTextEnvironment /*currentEv*/, JKQTMathTextEnvironment /*defaultEv*/) const {
bool ok=false;
-
return ok;
}
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.h b/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.h
index d1708eb489..aff8c56c47 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextfracnode.h
@@ -83,9 +83,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextFracNode: public JKQTMathTextDualChild
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \copydoc mode */
JKQTMathTextFracNode::FracType getMode() const;
protected:
@@ -94,7 +94,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextFracNode: public JKQTMathTextDualChild
/** \brief fills instructions */
static void fillInstructions();
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** \brief actual display type of fraction object */
JKQTMathTextFracNode::FracType mode;
/** \brief returns the nesting level of the node (of same type of \a sameType \c ==true) */
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp
index 45ed2eb81d..1503241810 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.cpp
@@ -78,7 +78,7 @@ QString JKQTMathTextSimpleInstructionNode::getTypeName() const
return QLatin1String("JKQTMathTextSimpleInstructionNode(")+instructionName+")";
}
-double JKQTMathTextSimpleInstructionNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv)
+double JKQTMathTextSimpleInstructionNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const
{
doDrawBoxes(painter, x, y, currentEv);
fillInstructions();
@@ -93,7 +93,7 @@ double JKQTMathTextSimpleInstructionNode::draw(QPainter &painter, double x, doub
return x+bb.width();
}
-bool JKQTMathTextSimpleInstructionNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv)
+bool JKQTMathTextSimpleInstructionNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const
{
fillInstructions();
const QString txt=executeInstruction();
@@ -124,7 +124,7 @@ size_t JKQTMathTextSimpleInstructionNode::countParametersOfInstruction(const QSt
return 0;
}
-void JKQTMathTextSimpleInstructionNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos)
+JKQTMathTextNodeSize JKQTMathTextSimpleInstructionNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const
{
fillInstructions();
QFont f=currentEv.getFont(parentMathText);
@@ -132,10 +132,12 @@ void JKQTMathTextSimpleInstructionNode::getSizeInternal(QPainter &painter, JKQTM
const QFontMetricsF fm(f);
const QString txt=executeInstruction();
const QRectF bb=fm.boundingRect(txt);
- width=bb.width();
- baselineHeight=-bb.y();
- overallHeight=bb.height();
- strikeoutPos=fm.strikeOutPos();
+ JKQTMathTextNodeSize s;
+ s.width=bb.width();
+ s.baselineHeight=-bb.y();
+ s.overallHeight=bb.height();
+ s.strikeoutPos=fm.strikeOutPos();
+ return s;
}
QHash JKQTMathTextSimpleInstructionNode::instructions;
@@ -215,16 +217,16 @@ QString JKQTMathTextModifiedTextPropsInstructionNode::getTypeName() const
return QLatin1String("JKQTMathTextModifiedTextPropsInstructionNode(")+instructionName+")";
}
-void JKQTMathTextModifiedTextPropsInstructionNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) {
+JKQTMathTextNodeSize JKQTMathTextModifiedTextPropsInstructionNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
fillInstructions();
JKQTMathTextEnvironment ev=currentEv;
executeInstruction(ev);
- getChild()->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
+ return getChild()->getSize(painter, ev);
}
-double JKQTMathTextModifiedTextPropsInstructionNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) {
+double JKQTMathTextModifiedTextPropsInstructionNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
fillInstructions();
doDrawBoxes(painter, x, y, currentEv);
JKQTMathTextEnvironment ev=currentEv;
@@ -234,7 +236,7 @@ double JKQTMathTextModifiedTextPropsInstructionNode::draw(QPainter& painter, dou
return getChild()->draw(painter, x, y, ev);
}
-bool JKQTMathTextModifiedTextPropsInstructionNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
+bool JKQTMathTextModifiedTextPropsInstructionNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const {
JKQTMathTextEnvironment ev=currentEv;
fillInstructions();
executeInstruction(ev);
@@ -665,7 +667,7 @@ QString JKQTMathTextBoxInstructionNode::getTypeName() const
return QLatin1String("JKQTMathTextBoxInstructionNode(")+instructionName+")";
}
-void JKQTMathTextBoxInstructionNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) {
+JKQTMathTextNodeSize JKQTMathTextBoxInstructionNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
JKQTMathTextEnvironment ev=currentEv;
const auto& inst=instructions.value(getInstructionName());
@@ -676,13 +678,16 @@ void JKQTMathTextBoxInstructionNode::getSizeInternal(QPainter& painter, JKQTMath
const double lw=p.widthF();
const double padding=inst.paddingFactor*fmNonItalic.tightBoundingRect("x").width();
- getChild()->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
- width=width+2.0*(padding+lw/2.0);
- baselineHeight=baselineHeight+padding+lw/2.0;
- overallHeight=overallHeight+2.0*(padding+lw/2.0);
+ const JKQTMathTextNodeSize cs=getChild()->getSize(painter, ev);
+ JKQTMathTextNodeSize s;
+ s.width=cs.width+2.0*(padding+lw/2.0);
+ s.baselineHeight=cs.baselineHeight+padding+lw/2.0;
+ s.overallHeight=cs.overallHeight+2.0*(padding+lw/2.0);
+ s.strikeoutPos=cs.strikeoutPos;
+ return s;
}
-double JKQTMathTextBoxInstructionNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) {
+double JKQTMathTextBoxInstructionNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
doDrawBoxes(painter, x, y, currentEv);
JKQTMathTextEnvironment ev=currentEv;
@@ -694,21 +699,20 @@ double JKQTMathTextBoxInstructionNode::draw(QPainter& painter, double x, double
const double lw=p.widthF();
const double padding=inst.paddingFactor*fmNonItalic.tightBoundingRect("x").width();
const double rr=inst.roundingFactor*fmNonItalic.tightBoundingRect("x").width();
- double width=0, baselineHeight=0, overallHeight=0, strikeoutPos=0;
- getChild()->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
+ const JKQTMathTextNodeSize cs=getChild()->getSize(painter, ev);
{
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
painter.setBrush(b);
painter.setPen(p);
- const QRectF rect(x+lw/2.0, y-baselineHeight-padding-lw/2.0, width+2.0*padding, overallHeight+2.0*padding);
+ const QRectF rect(x+lw/2.0, y-cs.baselineHeight-padding-lw/2.0, cs.width+2.0*padding, cs.overallHeight+2.0*padding);
if (rr>0) painter.drawRoundedRect(rect, rr, rr, Qt::AbsoluteSize);
else painter.drawRect(rect);
if (inst.doubleLine) {
painter.setBrush(Qt::NoBrush);
QPen p2=p;
p2.setWidthF(p.widthF()*0.6);
- const QRectF recti(x+lw*2.5, y-baselineHeight-lw/2.0-padding+2.0*lw, width+2.0*padding-4.0*lw, overallHeight+2.0*padding-4.0*lw);
+ const QRectF recti(x+lw*2.5, y-cs.baselineHeight-lw/2.0-padding+2.0*lw, cs.width+2.0*padding-4.0*lw, cs.overallHeight+2.0*padding-4.0*lw);
if (rr>0) painter.drawRoundedRect(recti, rr, rr, Qt::AbsoluteSize);
else painter.drawRect(recti);
}
@@ -719,7 +723,7 @@ double JKQTMathTextBoxInstructionNode::draw(QPainter& painter, double x, double
return xnew+padding+lw/2.0;
}
-bool JKQTMathTextBoxInstructionNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
+bool JKQTMathTextBoxInstructionNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const {
JKQTMathTextEnvironment ev=currentEv;
fillInstructions();
const auto& inst=instructions.value(getInstructionName());
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.h b/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.h
index 664f69dae0..ae29543a47 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextinstructionnode.h
@@ -70,9 +70,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSimpleInstructionNode: public JKQTMath
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \copydoc instructionName */
const QString& getInstructionName() const;
/** \copydoc parameters */
@@ -89,7 +89,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSimpleInstructionNode: public JKQTMath
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** \brief defines the implementation of an instruction represented by JKQTMathTextModifiedTextPropsInstructionNode */
struct InstructionProperties {
/** \brief this functor implements the instruction */
@@ -131,9 +131,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextModifiedTextPropsInstructionNode: publ
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \brief returns true, if the given \a instructionName can be represented by this node
* \see instructions
@@ -150,7 +150,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextModifiedTextPropsInstructionNode: publ
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** \brief defines the implementation of an instruction represented by JKQTMathTextModifiedTextPropsInstructionNode */
struct InstructionProperties {
/** \brief this functor implements the instruction */
@@ -188,9 +188,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBoxInstructionNode: public JKQTMathTex
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \brief returns true, if the given \a instructionName can be represented by this node
* \see instructions
@@ -210,7 +210,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBoxInstructionNode: public JKQTMathTex
static void modifyInMathEnvironment(const QString& instructionName, bool& insideMath, const QStringList ¶ms=QStringList());
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** \brief set all properties in \a ev, as appropriate for the represented instruction */
bool setupMTenvironment(JKQTMathTextEnvironment &ev) const;
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextlistnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextlistnode.cpp
index 76acf7dea7..0eca47d8c1 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextlistnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextlistnode.cpp
@@ -52,11 +52,8 @@ QString JKQTMathTextHorizontalListNode::getTypeName() const
return "MTHorizontalListNode";
}
-void JKQTMathTextHorizontalListNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) {
- width=0;
- overallHeight=0;
- baselineHeight=0;
- strikeoutPos=0;
+JKQTMathTextNodeSize JKQTMathTextHorizontalListNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
+ JKQTMathTextNodeSize outSize;
const QFontMetricsF fm(currentEv.getFont(parentMathText));
const double subsupershift=fm.xHeight()*parentMathText->getOperatorsubsuperDistanceFactor();
const double subsuperextrawidth=fm.boundingRect('x').width()*parentMathText->getOperatorsubsuperExtraSpaceFactor();
@@ -95,32 +92,31 @@ void JKQTMathTextHorizontalListNode::getSizeInternal(QPainter& painter, JKQTMath
if (i+1(nodes[i+1]);
if (nodeISucc_SubScript) { // is this subscript?
- double w1=0, w2=0, oh=0, bh=0, sp=0;
- nodeI_SuperScript->getSizeWithSpecialPlacement(painter, currentEv, w1, bh, oh, sp, prevNodeSizePtrForSuperscript);
+ const JKQTMathTextNodeSize ns=nodeI_SuperScript->getSizeWithSpecialPlacement(painter, currentEv, prevNodeSizePtrForSuperscript);
- if (bh>baselineHeight) {
- overallHeight=overallHeight+bh-baselineHeight;
- baselineHeight=bh;
- strikeoutPos=sp;
+ if (ns.baselineHeight>outSize.baselineHeight) {
+ outSize.overallHeight=outSize.overallHeight+ns.baselineHeight-outSize.baselineHeight;
+ outSize.baselineHeight=ns.baselineHeight;
+ outSize.strikeoutPos=ns.strikeoutPos;
}
- if (baselineHeight+oh-bh>overallHeight) {
- overallHeight=baselineHeight+oh-bh;
- strikeoutPos=sp;
+ if (outSize.baselineHeight+ns.getDescent()>outSize.overallHeight) {
+ outSize.overallHeight=outSize.baselineHeight+ns.getDescent();
+ outSize.strikeoutPos=ns.strikeoutPos;
}
i++;
- nodeISucc_SubScript->getSizeWithSpecialPlacement(painter, currentEv, w2, bh, oh, sp, prevNodeSizePtrForSubscript);
+ const JKQTMathTextNodeSize ns2=nodeISucc_SubScript->getSizeWithSpecialPlacement(painter, currentEv, prevNodeSizePtrForSubscript);
//qDebug()<<"super_sub: sub: "<getTypeName()<<" w2="<(nodes[i+1]);
if (nodeISucc_SuperScript) { // is this subscript?
- double w1=0, w2=0, oh=0, bh=0, sp=0;
- nodeI_SubScript->getSizeWithSpecialPlacement(painter, currentEv, w1, bh, oh, sp, prevNodeSizePtrForSubscript);
- if (bh>baselineHeight) {
- overallHeight=overallHeight+bh-baselineHeight;
- baselineHeight=bh;
- strikeoutPos=sp;
+ const JKQTMathTextNodeSize ns=nodeI_SubScript->getSizeWithSpecialPlacement(painter, currentEv, prevNodeSizePtrForSubscript);
+ if (ns.baselineHeight>outSize.baselineHeight) {
+ outSize.overallHeight=outSize.overallHeight+ns.baselineHeight-outSize.baselineHeight;
+ outSize.baselineHeight=ns.baselineHeight;
+ outSize.strikeoutPos=ns.strikeoutPos;
}
- if (baselineHeight+oh-bh>overallHeight) {
- overallHeight=baselineHeight+oh-bh;
- strikeoutPos=sp;
+ if (outSize.baselineHeight+ns.overallHeight-ns.baselineHeight>outSize.overallHeight) {
+ outSize.overallHeight=outSize.baselineHeight+ns.overallHeight-ns.baselineHeight;
+ outSize.strikeoutPos=ns.strikeoutPos;
}
i++;
- nodeISucc_SuperScript->getSizeWithSpecialPlacement(painter, currentEv, w2, bh, oh, sp, prevNodeSizePtrForSuperscript);
- if (bh>baselineHeight) {
- overallHeight=overallHeight+bh-baselineHeight;
- baselineHeight=bh;
- strikeoutPos=sp;
+ const JKQTMathTextNodeSize ns2=nodeISucc_SuperScript->getSizeWithSpecialPlacement(painter, currentEv, prevNodeSizePtrForSuperscript);
+ if (ns2.baselineHeight>outSize.baselineHeight) {
+ outSize.overallHeight=outSize.overallHeight+ns2.baselineHeight-outSize.baselineHeight;
+ outSize.baselineHeight=ns2.baselineHeight;
+ outSize.strikeoutPos=ns2.strikeoutPos;
}
- if (baselineHeight+oh-bh>overallHeight) {
- overallHeight=baselineHeight+oh-bh;
- strikeoutPos=sp;
+ if (outSize.baselineHeight+ns2.overallHeight-ns2.baselineHeight>outSize.overallHeight) {
+ outSize.overallHeight=outSize.baselineHeight+ns2.overallHeight-ns2.baselineHeight;
+ outSize.strikeoutPos=ns2.strikeoutPos;
}
- xnew+=qMax(w1+prevNodeSize.subBesidesXCorrection, w2+spaceWidth);
+ xnew+=qMax(ns.width+prevNodeSize.subBesidesXCorrection, ns2.width+spaceWidth);
doDraw=false;
@@ -162,18 +157,17 @@ void JKQTMathTextHorizontalListNode::getSizeInternal(QPainter& painter, JKQTMath
//qDebug()<<"### subsupop: sub+super1 overallHeight="<getTypeName()<<" w1="<getTypeName()<<" ns.width="<getTypeName()<<" w2="<getTypeName()<<" w3="<drawWithSpecialPlacement(painter, xnew, ynew, currentEv, prevNodeSizePtrForSuperscript);
+ const double xnewidth=nodeI_SuperScript->drawWithSpecialPlacement(painter, xnew, ynew, currentEv, prevNodeSizePtrForSuperscript);
i++;
//painter.setPen(QPen("magenta"));
//painter.drawEllipse(xnew-4,ynew-4,8,8);
- double xnew2=nodeISucc_SubScript->drawWithSpecialPlacement(painter, xnew-prevNodeSize.subSuperXCorrection, ynew, currentEv, prevNodeSizePtrForSubscript);
+ const double xnew2=nodeISucc_SubScript->drawWithSpecialPlacement(painter, xnew-prevNodeSize.subSuperXCorrection, ynew, currentEv, prevNodeSizePtrForSubscript);
//i++;
- xnew=qMax(xnew1, xnew2);
+ xnew=qMax(xnewidth, xnew2);
doDraw=false;
}
}
@@ -389,13 +373,13 @@ double JKQTMathTextHorizontalListNode::draw(QPainter& painter, double x, double
if (nodeISucc_SuperScript) { // is this subscript?
//painter.setPen(QPen("red"));
//painter.drawEllipse(xnew-4,ynew+shift-(ccOverallHeight-ccBaselineHeight)-4,8,8);
- double xnew1=nodeI_SubScript->drawWithSpecialPlacement(painter, xnew-prevNodeSize.subSuperXCorrection, ynew, currentEv, prevNodeSizePtrForSubscript);
+ double xnewidth=nodeI_SubScript->drawWithSpecialPlacement(painter, xnew-prevNodeSize.subSuperXCorrection, ynew, currentEv, prevNodeSizePtrForSubscript);
i++;
//painter.setPen(QPen("magenta"));
//painter.drawEllipse(xnew-4,ynew-4,8,8);
double xnew2=nodeISucc_SuperScript->drawWithSpecialPlacement(painter, xnew, ynew, currentEv, prevNodeSizePtrForSuperscript);
//i++;
- xnew=qMax(xnew1, xnew2);
+ xnew=qMax(xnewidth, xnew2);
doDraw=false;
}
} else {
@@ -423,9 +407,6 @@ double JKQTMathTextHorizontalListNode::draw(QPainter& painter, double x, double
if (!supn) supn=supn2;
JKQTMathTextEnvironment ev=currentEv;
ev.fontSize=ev.fontSize*parentMathText->getOperatorsubsuperSizeFactor();
- double wsub=0, wsup=0;
- double ohsub=0, ohsup=0;
- double bhsub=0, bhsup=0, spsub, spsup, sp;
JKQTMathTextSymbolNode::NodeSize nodeSize;
JKQTMathTextSymbolNode* symbN=dynamic_cast(nodes[i]);
if (symbN) {
@@ -435,29 +416,26 @@ double JKQTMathTextHorizontalListNode::draw(QPainter& painter, double x, double
}
- subn->getChild()->getSize(painter, ev, wsub, bhsub, ohsub, spsub);
- supn->getChild()->getSize(painter, ev, wsup, bhsup, ohsup, spsup);
+ const JKQTMathTextNodeSize sub=subn->getChild()->getSize(painter, ev);
+ const JKQTMathTextNodeSize sup=supn->getChild()->getSize(painter, ev);
const double descent1=nodeSize.getDescent();
//double d2=oh2-bh2;
- const double descent3=ohsup-bhsup;
+ const double descent3=sup.getDescent();
- const double neww=qMax(qMax(nodeSize.width, wsub), wsup)+subsuperextrawidth;
- //double xnew1=
+ const double neww=qMax(qMax(nodeSize.width, sub.width), sup.width)+subsuperextrawidth;
+ //double xnewidth=
const double xn1=nodes[i]->draw(painter, xnew+(neww-nodeSize.width)/2.0, ynew, currentEv);
i++;
//double xnew2=
- const double xnsub=subn->getChild()->draw(painter, xnew+(neww-wsub)/2.0-nodeSize.subSuperXCorrection, ynew+bhsub+descent1+subsupershift, ev);
+ const double xnsub=subn->getChild()->draw(painter, xnew+(neww-sub.width)/2.0-nodeSize.subSuperXCorrection, ynew+sub.baselineHeight+descent1+subsupershift, ev);
i++;
//double xnew3=
- const double xnsup=supn->getChild()->draw(painter, xnew+(neww-wsup)/2.0+nodeSize.subSuperXCorrection, ynew-nodeSize.baselineHeight-descent3-subsupershift, ev);
+ const double xnsup=supn->getChild()->draw(painter, xnew+(neww-sup.width)/2.0+nodeSize.subSuperXCorrection, ynew-nodeSize.baselineHeight-descent3-subsupershift, ev);
doDraw=false;
xnew=qMax(qMax(xn1, xnsub), xnsup)+subsuperextrawidth/2.0;
} else if (subn) { // is this subscript and no following superscript?
JKQTMathTextEnvironment ev=currentEv;
ev.fontSize=ev.fontSize*parentMathText->getOperatorsubsuperSizeFactor();
- double wsub=0;
- double ohsub=0;
- double bhsub=0, sp=0, spsub=0;
JKQTMathTextSymbolNode::NodeSize nodeSize;
JKQTMathTextSymbolNode* symbN=dynamic_cast(nodes[i]);
if (symbN) {
@@ -465,25 +443,22 @@ double JKQTMathTextHorizontalListNode::draw(QPainter& painter, double x, double
} else {
nodeSize=nodes[i]->getSize(painter, currentEv);
}
- subn->getChild()->getSize(painter, ev, wsub, bhsub, ohsub, spsub);
+ const JKQTMathTextNodeSize sub=subn->getChild()->getSize(painter, ev);
const double descent1=nodeSize.getDescent();
//double d2=oh2-bh2;
- const double neww=qMax(nodeSize.width, wsub)+subsuperextrawidth;
- //double xnew1=
+ const double neww=qMax(nodeSize.width, sub.width)+subsuperextrawidth;
+ //double xnewidth=
const double xn1=nodes[i]->draw(painter, xnew+(neww-nodeSize.width)/2.0, ynew, currentEv);
i++;
//double xnew2=
- const double xnsub=subn->getChild()->draw(painter, xnew+(neww-wsub)/2.0-nodeSize.subSuperXCorrection, ynew+bhsub+descent1+subsupershift, ev)+subsupershift;
+ const double xnsub=subn->getChild()->draw(painter, xnew+(neww-sub.width)/2.0-nodeSize.subSuperXCorrection, ynew+sub.baselineHeight+descent1+subsupershift, ev)+subsupershift;
doDraw=false;
//xnew+=w;
xnew=qMax(xnsub, xn1)+subsuperextrawidth/2.0;
} else if (supn) { // is this superscript and no following subscript?
JKQTMathTextEnvironment ev=currentEv;
ev.fontSize=ev.fontSize*parentMathText->getOperatorsubsuperSizeFactor();
- double wsup=0;
- double ohsup=0;
- double bhsup=0, sp, spsup;
JKQTMathTextSymbolNode::NodeSize nodeSize;
JKQTMathTextSymbolNode* symbN=dynamic_cast(nodes[i]);
if (symbN) {
@@ -491,17 +466,17 @@ double JKQTMathTextHorizontalListNode::draw(QPainter& painter, double x, double
} else {
nodeSize=nodes[i]->getSize(painter, currentEv);
}
- supn->getChild()->getSize(painter, ev, wsup, bhsup, ohsup, spsup);
- //double d1=oh1-bh1;
+ const JKQTMathTextNodeSize sup=supn->getChild()->getSize(painter, ev);
+ //double d1=ns.overallHeight-ns.baselineHeight;
//double d2=oh2-bh2;
- const double descent3=ohsup-bhsup;
+ const double descent3=sup.getDescent();
- const double neww=qMax(nodeSize.width, wsup)+subsuperextrawidth;
- //double xnew1=
+ const double neww=qMax(nodeSize.width, sup.width)+subsuperextrawidth;
+ //double xnewidth=
const double xn1=nodes[i]->draw(painter, xnew+(neww-nodeSize.width)/2.0, ynew, currentEv);
i++;
//double xnew3=
- const double xnsup=supn->getChild()->draw(painter, xnew+(neww-wsup)/2.0+nodeSize.subSuperXCorrection, ynew-nodeSize.baselineHeight-descent3-subsupershift, ev);
+ const double xnsup=supn->getChild()->draw(painter, xnew+(neww-sup.width)/2.0+nodeSize.subSuperXCorrection, ynew-nodeSize.baselineHeight-descent3-subsupershift, ev);
doDraw=false;
xnew=qMax(xn1, xnsup)+subsuperextrawidth/2.0;
}
@@ -522,7 +497,7 @@ void JKQTMathTextHorizontalListNode::addChild(JKQTMathTextNode *n) {
nodes.append(n);
}
-bool JKQTMathTextHorizontalListNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
+bool JKQTMathTextHorizontalListNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const {
bool ok=true;
for (int i=0; i ysFromFirstLine; // y-position of each line, where the first line is always at y=0 (i.e. ysFromFirstLine[0]==0)
double y=0;
for (int i=0; igetSize(painter, currentEv, locWidth, locBaselineHeight, locOverallHeight, locStrikeoutPos);
+ const JKQTMathTextNodeSize loc=nodes[i]->getSize(painter, currentEv);
if (i==0) {
- heightSum=locBaselineHeight;
+ heightSum=loc.baselineHeight;
} else if (i>0) {
double deltaLine=0;
if (spacingMode==MTSMMinimalSpacing) {
- deltaLine=descents.last()+lineLeading+locBaselineHeight;
+ deltaLine=descents.last()+lineLeading+loc.baselineHeight;
} else if (spacingMode==MTSMDefaultSpacing) {
- deltaLine=qMax(linespacing, descents.last()+lineLeading+locBaselineHeight);
+ deltaLine=qMax(linespacing, descents.last()+lineLeading+loc.baselineHeight);
}
heightSum=heightSum+deltaLine;
y=y+deltaLine;
}
- widths<";
@@ -817,3 +787,33 @@ void JKQTMathTextVerticalListNode::setSpacingMode(JKQTMathTextLineSpacingMode va
JKQTMathTextVerticalListNode::LayoutInfo::LayoutInfo():
JKQTMathTextNodeSize(), X()
{}
+
+
+
+JKQTMathTextVerticalListNode::LayoutInfo::LayoutInfo(const JKQTMathTextNodeSize &other):
+ JKQTMathTextNodeSize(other),
+ X()
+{
+
+}
+
+JKQTMathTextVerticalListNode::LayoutInfo &JKQTMathTextVerticalListNode::LayoutInfo::operator=(const JKQTMathTextNodeSize &other)
+{
+ JKQTMathTextNodeSize::operator=(other);
+ X.clear();
+ return *this;
+}
+
+JKQTMathTextVerticalListNode::LayoutInfo &JKQTMathTextVerticalListNode::LayoutInfo::operator=(const LayoutInfo &other)
+{
+ JKQTMathTextNodeSize::operator=(dynamic_cast(other));
+ X=other.X;
+ return *this;
+}
+
+JKQTMathTextVerticalListNode::LayoutInfo::LayoutInfo(const LayoutInfo &other):
+ JKQTMathTextNodeSize(dynamic_cast(other)),
+ X(other.X)
+{
+
+}
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextlistnode.h b/lib/jkqtmathtext/nodes/jkqtmathtextlistnode.h
index cd8df0aabb..bc6af49d23 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextlistnode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextlistnode.h
@@ -49,9 +49,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextHorizontalListNode: public JKQTMathTex
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \brief add a child node */
void addChild(JKQTMathTextNode* n);
/** \copydoc JKQTMathTextMultiChildNode::getChildren() */
@@ -70,7 +70,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextHorizontalListNode: public JKQTMathTex
virtual JKQTMathTextNode* replaceChild(int i, JKQTMathTextNode* newChild) override;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
QList nodes;
private:
/** \brief internal implementation of clearChildren() that is non-virtual, so can be used in the destructor */
@@ -101,9 +101,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextVerticalListNode: public JKQTMathTextM
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \brief add a child node */
void addChild(JKQTMathTextNode* n);
/** \copydoc JKQTMathTextMultiChildNode::getChildren() */
@@ -138,11 +138,15 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextVerticalListNode: public JKQTMathTextM
void setSpacingMode(JKQTMathTextLineSpacingMode value) ;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** \brief describes the layout of the whole node */
struct LayoutInfo: public JKQTMathTextNodeSize {
LayoutInfo();
+ LayoutInfo(const LayoutInfo& other);
+ LayoutInfo(const JKQTMathTextNodeSize& other);
+ LayoutInfo& operator=(const LayoutInfo& other);
+ LayoutInfo& operator=(const JKQTMathTextNodeSize& other);
/** \brief drawing position for each line */
QList X;
};
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp
index d27d88751b..d096a2d52c 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.cpp
@@ -98,7 +98,7 @@ QString JKQTMathTextMatrixNode::getTypeName() const
}
-bool JKQTMathTextMatrixNode::toHtml(QString &/*html*/, JKQTMathTextEnvironment /*currentEv*/, JKQTMathTextEnvironment /*defaultEv*/)
+bool JKQTMathTextMatrixNode::toHtml(QString &/*html*/, JKQTMathTextEnvironment /*currentEv*/, JKQTMathTextEnvironment /*defaultEv*/) const
{
return false;
}
@@ -362,21 +362,17 @@ JKQTMathTextMatrixNode::LayoutInfo JKQTMathTextMatrixNode::calcLayout(QPainter &
return l;
}
-void JKQTMathTextMatrixNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) {
- const LayoutInfo l=calcLayout(painter, currentEv);
- width=l.width;
- overallHeight=l.overallHeight;
- baselineHeight=l.baselineHeight;
- strikeoutPos=l.strikeoutPos;
+JKQTMathTextNodeSize JKQTMathTextMatrixNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
+ return calcLayout(painter, currentEv);
}
-double JKQTMathTextMatrixNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) {
- doDrawBoxes(painter, x, y, currentEv);
+double JKQTMathTextMatrixNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
const QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
JKQTMathTextEnvironment ev1=currentEv;
const LayoutInfo l=calcLayout(painter, currentEv);
+ doDrawBoxes(painter, x, y, l);
const double xwidth=fm.boundingRect("x").width();
const double XSeparation=parentMathText->getMatrixXSeparationFactor()*xwidth;
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.h b/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.h
index 71a50d2001..db0bce7cf8 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextmatrixnode.h
@@ -68,9 +68,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextMatrixNode: public JKQTMathTextMultiCh
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \brief returns the child nodes */
QVector > getChildrenMatrix() const;
/** \copydoc columns */
@@ -122,7 +122,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextMatrixNode: public JKQTMathTextMultiCh
*/
LayoutInfo calcLayout(QPainter& painter, const JKQTMathTextEnvironment& currentEv) const;
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::setDrawBoxes() */
virtual void setDrawBoxes(bool draw) override;
/** \brief child nodes making up the matrix, vector of rows */
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextnode.cpp
index 2b3289260f..d6360c1f36 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextnode.cpp
@@ -50,33 +50,26 @@ JKQTMathTextNode::JKQTMathTextNode(JKQTMathText *_parent):
JKQTMathTextNode::~JKQTMathTextNode()
= default;
-void JKQTMathTextNode::getSize(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos)
+JKQTMathTextNodeSize JKQTMathTextNode::getSize(QPainter &painter, JKQTMathTextEnvironment currentEv) const
{
- double w=width, b=baselineHeight, o=overallHeight, s=strikeoutPos;
- getSizeInternal(painter, currentEv, w, b, o, s);
-
- if (w<1e5) width=w;
- if (b<1e5) baselineHeight=b;
- if (o<1e5) overallHeight=o;
- if (s<1e5) strikeoutPos=s;
+ return getSizeInternal(painter, currentEv);
}
-double JKQTMathTextNode::getNonItalicXCorretion(QPainter &painter, double width_potentiallyitalic, const JKQTMathTextEnvironment &ev_potentiallyitalic, JKQTMathTextNode* child) const
+double JKQTMathTextNode::getNonItalicXCorretion(QPainter &painter, double width_potentiallyitalic, const JKQTMathTextEnvironment &ev_potentiallyitalic, const JKQTMathTextNode* child)
{
double italic_xcorrection=0.0;
if (ev_potentiallyitalic.italic) {
JKQTMathTextEnvironment ev_nonitalic=ev_potentiallyitalic;
ev_nonitalic.italic=false;
- double width_nonitalic=0, baselineHeight_nonitalic=0, overallHeight_nonitalic=0, strikeoutPos_nonitalic=0;
- child->getSize(painter, ev_nonitalic, width_nonitalic, baselineHeight_nonitalic, overallHeight_nonitalic, strikeoutPos_nonitalic);
- italic_xcorrection=width_potentiallyitalic-width_nonitalic;
+ JKQTMathTextNodeSize s_nonitalic=child->getSize(painter, ev_nonitalic);
+ italic_xcorrection=width_potentiallyitalic-s_nonitalic.width;
}
return italic_xcorrection;
}
-bool JKQTMathTextNode::toHtml(QString &/*html*/, JKQTMathTextEnvironment /*currentEv*/, JKQTMathTextEnvironment /*defaultEv*/) {
+bool JKQTMathTextNode::toHtml(QString &/*html*/, JKQTMathTextEnvironment /*currentEv*/, JKQTMathTextEnvironment /*defaultEv*/) const {
return false;
}
@@ -85,24 +78,23 @@ bool JKQTMathTextNode::getDrawBoxes() const {
}
-void JKQTMathTextNode::doDrawBoxes(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) {
+void JKQTMathTextNode::doDrawBoxes(QPainter &painter, double x, double y, const JKQTMathTextNodeSize &size) const
+{
if (drawBoxes) {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
- double w, oh, bh, sp;
- getSize(painter, currentEv, w, bh, oh, sp);
QPen p=painter.pen();
p.setColor("lightcoral");
p.setWidthF(0.5);
painter.setPen(p);
- QRectF r(x, y-bh, w, oh);
+ QRectF r(x, y-size.baselineHeight, size.width, size.overallHeight );
painter.drawRect(r);
p.setColor("lightblue");
painter.setPen(p);
- if (w>0) painter.drawLine(QLineF(x, y, x+w, y));
+ if (size.width>0) painter.drawLine(QLineF(x, y, x+size.width, y));
p.setColor("pink");
p.setStyle(Qt::DashLine);
painter.setPen(p);
- if (w>0) painter.drawLine(QLineF(x, y-sp, x+w, y-sp));
+ if (size.width>0) painter.drawLine(QLineF(x, y-size.strikeoutPos, x+size.width, y-size.strikeoutPos));
p.setColor("green");
p.setStyle(Qt::SolidLine);
painter.setPen(p);
@@ -113,6 +105,13 @@ void JKQTMathTextNode::doDrawBoxes(QPainter& painter, double x, double y, JKQTMa
painter.drawLine(QLineF(x, y-2, x, y+2.0));
}
+
+}
+
+void JKQTMathTextNode::doDrawBoxes(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
+ if (drawBoxes) {
+ doDrawBoxes(painter, x, y, getSize(painter, currentEv));
+ }
}
void JKQTMathTextNode::setDrawBoxes(bool draw)
@@ -151,6 +150,7 @@ void JKQTMathTextNode::setSubSuperscriptAboveBelowNode(bool __value)
subSuperscriptAboveBelowNode=__value;
}
+
JKQTMathTextSingleChildNode::JKQTMathTextSingleChildNode(JKQTMathTextNode *_child, JKQTMathText *parentMathText):
JKQTMathTextNode(parentMathText),
child(_child)
@@ -374,13 +374,6 @@ void JKQTMathTextMultiChildNode::setDrawBoxes(bool draw)
}
-JKQTMathTextNodeSize JKQTMathTextNode::getSize(QPainter &painter, JKQTMathTextEnvironment currentEv)
-{
- JKQTMathTextNodeSize s;
- getSize(painter, currentEv, s.width, s.baselineHeight, s.overallHeight, s.strikeoutPos);
- return s;
-}
-
JKQTMathTextNoopNode::JKQTMathTextNoopNode(JKQTMathText *parent):
JKQTMathTextNode(parent)
{
@@ -397,20 +390,17 @@ QString JKQTMathTextNoopNode::getTypeName() const
return "MTNoopNode";
}
-bool JKQTMathTextNoopNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv)
+bool JKQTMathTextNoopNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const
{
return true;
}
-double JKQTMathTextNoopNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv)
+double JKQTMathTextNoopNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const
{
return x;
}
-void JKQTMathTextNoopNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos)
+JKQTMathTextNodeSize JKQTMathTextNoopNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const
{
- width=0;
- baselineHeight=0;
- overallHeight=0;
- strikeoutPos=0;
+ return JKQTMathTextNodeSize();
}
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextnode.h b/lib/jkqtmathtext/nodes/jkqtmathtextnode.h
index 7c869d6fdc..7ee94ba9dd 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextnode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextnode.h
@@ -40,17 +40,6 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNode {
JKQTMathTextNode(const JKQTMathTextNode&)=delete;
JKQTMathTextNode& operator=(const JKQTMathTextNode&)=delete;
virtual ~JKQTMathTextNode();
- /** \brief determine the size of the node, calls getSizeInternal() implementation of the actual type \see getSizeInternal()
- *
- * \param painter painter to use for determining the size
- * \param currentEv current environment object
- * \param[out] width width of the block/node
- * \param[out] baselineHeight distance from the bottom of the block/node-box to the baseline
- * \param[out] overallHeight overall height (bottom to top) of the node, the ascent is \c overallHeight-baselineHeight
- * \param[out] strikeoutPos position of the strikeout-line
- *
- */
- void getSize(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos);
/** \brief determine the size of the node, calls getSizeInternal() implementation of the actual type \see getSizeInternal()
*
* \param painter painter to use for determining the size
@@ -59,9 +48,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNode {
* \return all important box size parameters packed as JKQTMathTextNodeSize
*
*/
- JKQTMathTextNodeSize getSize(QPainter& painter, JKQTMathTextEnvironment currentEv);
+ JKQTMathTextNodeSize getSize(QPainter& painter, JKQTMathTextEnvironment currentEv) const;
/** \brief calculates the x-size-difference between the given (probably) italic (width externally calculated: \a width_potentiallyitalic, \a ev_potentiallyitalic) and the non-italic version of \a child */
- double getNonItalicXCorretion(QPainter &painter, double width_potentiallyitalic, const JKQTMathTextEnvironment &ev_potentiallyitalic, JKQTMathTextNode* child) const;
+ static double getNonItalicXCorretion(QPainter &painter, double width_potentiallyitalic, const JKQTMathTextEnvironment &ev_potentiallyitalic, const JKQTMathTextNode* child) ;
/** \brief draw the contents at the designated position
*
* \param painter QPainter to use
@@ -71,14 +60,14 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNode {
*
* \return the x position which to use for the next part of the text
*/
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv)=0;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const=0;
/** \brief convert node to HTML and returns \c true on success
* \param[out] html new HTML code is APPENDED to this string
* \param currentEv JKQTMathTextEnvironment object describing the current drawing environment/settings
* \param defaultEv JKQTMathTextEnvironment object describing the default drawing environment/settings when starting to interpret a node tree
* \return \c true on success
*/
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv);
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const;
/** \brief returns the drawing of colored boxes (for DEBUGGING) around the actual output of the node is enabled */
bool getDrawBoxes() const;
@@ -108,7 +97,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNode {
* \param[out] strikeoutPos position of the strikeout-line
*
*/
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos)=0;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const =0;
/** \brief parent JKQTMathText object (required for several drawing operations */
JKQTMathText* parentMathText;
@@ -127,9 +116,21 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNode {
* \param painter QPainter to use
* \param x x-position, where the drawing starts [Pixel]
* \param y Y-position of the baseline, where the drawing starts [Pixel]
- * \param currentEv JKQTMathTextEnvironment object describing the current drawing environment/settings
+ * \param size size of the node, result of getSize(), see JKQTMathTextNodeSize
*/
- void doDrawBoxes(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv);
+ void doDrawBoxes(QPainter& painter, double x, double y, const JKQTMathTextNodeSize& size) const;
+ /** \brief draws colored boxes (for DEBUGGING) around the actual output of the node
+ *
+ * \param painter QPainter to use
+ * \param x x-position, where the drawing starts [Pixel]
+ * \param y Y-position of the baseline, where the drawing starts [Pixel]
+ * \param currentEv JKQTMathTextEnvironment object describing the current drawing environment/settings
+ *
+ * \note This version of the function calls getSize() internally. There is a second variant that
+ * skips this call and expects the node size info as parameter. This can be used in
+ * draw() implementations that call getSize() themselves to speed up drawing.
+ */
+ void doDrawBoxes(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const;
/** \brief returns the list of parent, parent-of-parent, ... that can be cast to type \a T */
@@ -292,12 +293,12 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNoopNode: public JKQTMathTextNode {
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
};
#endif // JKQTMATHTEXTNODE_H
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.cpp
index d73512cfbd..675c955e12 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.cpp
@@ -50,30 +50,32 @@ JKQTMathTextSqrtNode::~JKQTMathTextSqrtNode() {
childDegree=nullptr;
}
-void JKQTMathTextSqrtNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) {
+JKQTMathTextNodeSize JKQTMathTextSqrtNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
+ JKQTMathTextNodeSize s;
const QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
JKQTMathTextEnvironment evSmall=currentEv;
evSmall.fontSize=currentEv.fontSize*parentMathText->getSqrtSmallFontFactor();
evSmall.italic=false;
- getChild()->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
- const double descent=overallHeight-baselineHeight;
+ const JKQTMathTextNodeSize cs=getChild()->getSize(painter, currentEv);
+ const double descent=cs.getDescent();
const double sqrtwidth=fm.boundingRect("X").width()*parentMathText->getSqrtWidthXFactor();
- const double newAscent=qMax(baselineHeight*parentMathText->getSqrtHeightFactor(), fm.ascent());
+ const double newAscent=qMax(cs.baselineHeight*parentMathText->getSqrtHeightFactor(), fm.ascent());
const double newDescent=qMax(descent*parentMathText->getSqrtHeightFactor(), fm.descent());
- overallHeight=newAscent+newDescent;;
- baselineHeight=newAscent;
- width=width+sqrtwidth;
+ s.overallHeight=newAscent+newDescent;
+ s.baselineHeight=newAscent;
+ s.width=cs.width+sqrtwidth;
+ s.strikeoutPos=cs.strikeoutPos;
if (childDegree) {
- double degwidth=0, degBH=0, degOH=0, degSP=0;
- childDegree->getSize(painter, evSmall, degwidth, degBH, degOH, degSP);
+ const JKQTMathTextNodeSize ds=childDegree->getSize(painter, evSmall);
const double smalltextIndent=0.6*sqrtwidth;
- if (degwidth>smalltextIndent) width=width+(degwidth-smalltextIndent);
+ if (ds.width>smalltextIndent) s.width=s.width+(ds.width-smalltextIndent);
}
+ return s;
}
-double JKQTMathTextSqrtNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) {
+double JKQTMathTextSqrtNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
doDrawBoxes(painter, x, y, currentEv);
const QFont f=currentEv.getFont(parentMathText);
@@ -82,20 +84,19 @@ double JKQTMathTextSqrtNode::draw(QPainter& painter, double x, double y, JKQTMat
evSmall.fontSize=currentEv.fontSize*parentMathText->getSqrtSmallFontFactor();
evSmall.italic=false;
- double width=0, baselineHeight=0, overallHeight=0, strikeoutPos=0;
- getChild()->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
- const double descent=overallHeight-baselineHeight;
+ const JKQTMathTextNodeSize cs=getChild()->getSize(painter, currentEv);
+ const double descent=cs.overallHeight-cs.baselineHeight;
const double sqrtwidth=fm.boundingRect("X").width()*parentMathText->getSqrtWidthXFactor();
- const double newAscent=qMax(baselineHeight*parentMathText->getSqrtHeightFactor(), fm.ascent());
+ const double newAscent=qMax(cs.baselineHeight*parentMathText->getSqrtHeightFactor(), fm.ascent());
const double newDescent=qMax(descent*parentMathText->getSqrtHeightFactor(), fm.descent());
const double linewidth=fm.lineWidth();
const double tinyhookSize=sqrtwidth*0.1;
const double smalltextIndent=0.6*sqrtwidth;
- double degwidth=0, degBH=0, degOH=0, degSP=0;
- if (childDegree) childDegree->getSize(painter, evSmall, degwidth, degBH, degOH, degSP);
- const double degheight=degOH;
- const double degree_overwidth=(degwidth>smalltextIndent)?(degwidth-smalltextIndent):0.0;
+ JKQTMathTextNodeSize ds;
+ if (childDegree) ds=childDegree->getSize(painter, evSmall);
+ const double degheight=ds.overallHeight;
+ const double degree_overwidth=(ds.width>smalltextIndent)?(ds.width-smalltextIndent):0.0;
//painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
QPen p=painter.pen();
@@ -107,8 +108,8 @@ double JKQTMathTextSqrtNode::draw(QPainter& painter, double x, double y, JKQTMat
double xnew=getChild()->draw(painter, x+sqrtwidth+degree_overwidth, y, currentEv);
- const bool useAltForm=overallHeight>4.0*sqrtwidth;
- const double y_tinyhooktop=y-strikeoutPos;
+ const bool useAltForm=cs.overallHeight>4.0*sqrtwidth;
+ const double y_tinyhooktop=y-cs.strikeoutPos;
const double y_bottom=y+newDescent-linewidth/2.0;
const double y_top=y-newAscent+linewidth/2.0;
const double x_start=x+degree_overwidth+linewidth/2.0;
@@ -116,7 +117,7 @@ double JKQTMathTextSqrtNode::draw(QPainter& painter, double x, double y, JKQTMat
const double x_hookbottom=(!useAltForm)?(x_start+0.33*sqrtwidth):(x_start+0.66*sqrtwidth);
const double x_hooktop=(!useAltForm)?(x_start+sqrtwidth):x_hookbottom;
const double x_smalltextend=x_start+smalltextIndent;
- const double y_smalltext=y_top+degBH+(fabs(y_top-(y_tinyhooktop-linewidth))-degheight)/2.0;
+ const double y_smalltext=y_top+ds.baselineHeight+(fabs(y_top-(y_tinyhooktop-linewidth))-degheight)/2.0;
if (sqrtwidth>0) {
QPainterPath path;
path.moveTo(x_start, y_tinyhooktop+tinyhookSize);
@@ -131,13 +132,13 @@ double JKQTMathTextSqrtNode::draw(QPainter& painter, double x, double y, JKQTMat
painter.drawPath(path);
}
if (childDegree) {
- childDegree->draw(painter, x_smalltextend-degwidth, y_smalltext, evSmall);
+ childDegree->draw(painter, x_smalltextend-ds.width, y_smalltext, evSmall);
}
return xnew;
}
-bool JKQTMathTextSqrtNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
+bool JKQTMathTextSqrtNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const {
bool ok=true;
if (childDegree) {
JKQTMathTextEnvironment evSmall=currentEv;
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.h b/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.h
index 1a93536836..23a253f0ee 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.h
@@ -45,9 +45,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSqrtNode: public JKQTMathTextMultiChil
JKQTMathTextSqrtNode(JKQTMathText* parent, JKQTMathTextNode* child__, JKQTMathTextNode* childDegree__=nullptr);
virtual ~JKQTMathTextSqrtNode() override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override ;
@@ -75,7 +75,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSqrtNode: public JKQTMathTextMultiChil
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** \brief child node for the part under the root */
JKQTMathTextNode* child;
/** \brief second child node for the degree of the root (or nullptr if nothing) */
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.cpp
index e4537ddddd..8faa32abe9 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.cpp
@@ -45,48 +45,48 @@ JKQTMathTextSuperscriptNode::JKQTMathTextSuperscriptNode(JKQTMathText* _parent,
JKQTMathTextSuperscriptNode::~JKQTMathTextSuperscriptNode() {
}
-void JKQTMathTextSuperscriptNode::getSizeWithSpecialPlacement(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement) {
+JKQTMathTextNodeSize JKQTMathTextSuperscriptNode::getSizeWithSpecialPlacement(QPainter& painter, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement) const{
+ JKQTMathTextNodeSize s;
JKQTMathTextEnvironment ev=currentEv;
ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor();
const QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
const QRectF tbr_of_letterM=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
- double cStrikeoutPos=0, cWidth=0, cBaselineHeight=0, cOverallHeight=0;
- getChild()->getSize(painter, ev, cWidth, cBaselineHeight, cOverallHeight, cStrikeoutPos);
- const double childDescent=cOverallHeight-cBaselineHeight;
+ const JKQTMathTextNodeSize cs=getChild()->getSize(painter, ev);
+ const double childDescent=cs.getDescent();
double shiftToChildBottom=parentMathText->getSuperShiftFactor()*fm.xHeight();
if (prevNodeSizeForSpecialPlacement!=nullptr) {
- const double modifiedShift=prevNodeSizeForSpecialPlacement->baselineHeight-childDescent-parentMathText->getSpecialSuperShiftFactor()*cBaselineHeight-childDescent;
+ const double modifiedShift=prevNodeSizeForSpecialPlacement->baselineHeight-childDescent-parentMathText->getSpecialSuperShiftFactor()*cs.baselineHeight-childDescent;
if (modifiedShift>shiftToChildBottom) shiftToChildBottom=modifiedShift;
}
- baselineHeight=overallHeight=cOverallHeight+shiftToChildBottom;
- width=cWidth;
- if (prevNodeSizeForSpecialPlacement!=nullptr) strikeoutPos=prevNodeSizeForSpecialPlacement->strikeoutPos;
- else strikeoutPos=fm.strikeOutPos();
- if (currentEv.italic && prevNodeSizeForSpecialPlacement==nullptr) width=width+double(fm.boundingRect(' ').width())*parentMathText->getItalicCorrectionFactor();
+ s.baselineHeight=s.overallHeight=cs.overallHeight+shiftToChildBottom;
+ s.width=cs.width;
+ if (prevNodeSizeForSpecialPlacement!=nullptr) s.strikeoutPos=prevNodeSizeForSpecialPlacement->strikeoutPos;
+ else s.strikeoutPos=fm.strikeOutPos();
+ if (currentEv.italic && prevNodeSizeForSpecialPlacement==nullptr) s.width=s.width+double(fm.boundingRect(' ').width())*parentMathText->getItalicCorrectionFactor();
+ return s;
}
-void JKQTMathTextSuperscriptNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos)
+JKQTMathTextNodeSize JKQTMathTextSuperscriptNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const
{
- getSizeWithSpecialPlacement(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos, nullptr);
+ return getSizeWithSpecialPlacement(painter, currentEv, nullptr);
}
-double JKQTMathTextSuperscriptNode::drawWithSpecialPlacement(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement) {
+double JKQTMathTextSuperscriptNode::drawWithSpecialPlacement(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement) const {
doDrawBoxes(painter, x, y, currentEv);
JKQTMathTextEnvironment ev=currentEv;
ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor();
- double cWidth, cBaselineHeight, cOverallHeight, cStrikeoutPos;
- getChild()->getSize(painter, ev, cWidth, cBaselineHeight, cOverallHeight, cStrikeoutPos);
+ const JKQTMathTextNodeSize cs=getChild()->getSize(painter, ev);
const QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
- QRectF tbr_of_letterM=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
- const double childDescent=cOverallHeight-cBaselineHeight;
+ //QRectF tbr_of_letterM=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
+ const double childDescent=cs.overallHeight-cs.baselineHeight;
double shiftToChildBottom=parentMathText->getSuperShiftFactor()*fm.xHeight();
if (prevNodeSizeForSpecialPlacement!=nullptr) {
- const double modifiedShift=prevNodeSizeForSpecialPlacement->baselineHeight-childDescent-parentMathText->getSpecialSuperShiftFactor()*cBaselineHeight-childDescent;
+ const double modifiedShift=prevNodeSizeForSpecialPlacement->baselineHeight-childDescent-parentMathText->getSpecialSuperShiftFactor()*cs.baselineHeight-childDescent;
if (modifiedShift>shiftToChildBottom) shiftToChildBottom=modifiedShift;
}
@@ -96,7 +96,7 @@ double JKQTMathTextSuperscriptNode::drawWithSpecialPlacement(QPainter& painter,
return getChild()->draw(painter, xx, y-(shiftToChildBottom+childDescent), ev);//+0.5*fm.boundingRect("A").width();
}
-double JKQTMathTextSuperscriptNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv)
+double JKQTMathTextSuperscriptNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const
{
return drawWithSpecialPlacement(painter, x, y, currentEv, nullptr);
}
@@ -108,7 +108,7 @@ QString JKQTMathTextSuperscriptNode::getTypeName() const
}
-bool JKQTMathTextSuperscriptNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv)
+bool JKQTMathTextSuperscriptNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const
{
html=html+"";
bool ok=getChild()->toHtml(html, currentEv, defaultEv);
@@ -131,55 +131,55 @@ JKQTMathTextSubscriptNode::~JKQTMathTextSubscriptNode() {
}
-void JKQTMathTextSubscriptNode::getSizeWithSpecialPlacement(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement) {
+JKQTMathTextNodeSize JKQTMathTextSubscriptNode::getSizeWithSpecialPlacement(QPainter& painter, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement) const {
+ JKQTMathTextNodeSize s;
JKQTMathTextEnvironment ev=currentEv;
ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor();
const QFontMetricsF fm(ev.getFont(parentMathText), painter.device());
//const QRectF tbr_of_letterM=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
const double italic_xshift=qMax(0.0,-fm.rightBearing('x'));// double(fm.boundingRect('x').width())*parentMathText->getItalicCorrectionFactor();
- double cWidth=0, cBaselineHeight=0, cOverallHeight=0, cStrikeoutPos=0;
- getChild()->getSize(painter, ev, cWidth, cBaselineHeight, cOverallHeight, cStrikeoutPos);
- //const double childDescent=cOverallHeight-cBaselineHeight;
- double shift_to_childBaseline=cBaselineHeight-parentMathText->getSubShiftFactor()*fm.xHeight();
+ const JKQTMathTextNodeSize cs=getChild()->getSize(painter, ev);
+ //const double childDescent=cs.overallHeight-cs.baselineHeight;
+ double shift_to_childBaseline=cs.baselineHeight-parentMathText->getSubShiftFactor()*fm.xHeight();
if (prevNodeSizeForSpecialPlacement!=nullptr) {
//qDebug()<<"oldshift="<overallHeight="<overallHeight<<", prevNodeSize->baselineHeight="<baselineHeight;
const double parentDescent=prevNodeSizeForSpecialPlacement->overallHeight-prevNodeSizeForSpecialPlacement->baselineHeight;
- const double newShift=parentDescent+parentMathText->getSpecialSubShiftFactor()*cBaselineHeight;
+ const double newShift=parentDescent+parentMathText->getSpecialSubShiftFactor()*cs.baselineHeight;
if (newShift>shift_to_childBaseline) shift_to_childBaseline=newShift;
//qDebug()<<"newshift="<strikeoutPos;
- else strikeoutPos=fm.strikeOutPos();
- width=cWidth;
- if (currentEv.italic && prevNodeSizeForSpecialPlacement==nullptr) width=width-italic_xshift;
+ s.baselineHeight=cs.baselineHeight-shift_to_childBaseline;
+ s.overallHeight=cs.overallHeight;
+ if (prevNodeSizeForSpecialPlacement!=nullptr) s.strikeoutPos=prevNodeSizeForSpecialPlacement->strikeoutPos;
+ else s.strikeoutPos=fm.strikeOutPos();
+ s.width=cs.width;
+ if (currentEv.italic && prevNodeSizeForSpecialPlacement==nullptr) s.width=s.width-italic_xshift;
+ return s;
}
-void JKQTMathTextSubscriptNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos)
+JKQTMathTextNodeSize JKQTMathTextSubscriptNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const
{
- getSizeWithSpecialPlacement(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos, nullptr);
+ return getSizeWithSpecialPlacement(painter, currentEv, nullptr);
}
-double JKQTMathTextSubscriptNode::drawWithSpecialPlacement(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement) {
+double JKQTMathTextSubscriptNode::drawWithSpecialPlacement(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement) const {
doDrawBoxes(painter, x, y, currentEv);
JKQTMathTextEnvironment ev=currentEv;
ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor();
const QFontMetricsF fm(ev.getFont(parentMathText), painter.device());
//const QRectF tbr_of_letterM=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
- double cWidth=0, cBaselineHeight=0, cOverallHeight=0, cStrikeoutPos=0;
- getChild()->getSize(painter, ev, cWidth, cBaselineHeight, cOverallHeight, cStrikeoutPos);
- double shift_to_childBaseline=cBaselineHeight-parentMathText->getSubShiftFactor()*fm.xHeight();
+ const JKQTMathTextNodeSize cs=getChild()->getSize(painter, ev);
+ double shift_to_childBaseline=cs.baselineHeight-parentMathText->getSubShiftFactor()*fm.xHeight();
const double italic_xshift=qMax(0.0,-fm.rightBearing('x'));// double(fm.boundingRect('x').width())*parentMathText->getItalicCorrectionFactor();
if (prevNodeSizeForSpecialPlacement!=nullptr) {
//qDebug()<<"oldshift="<overallHeight="<overallHeight<<", prevNodeSize->baselineHeight="<baselineHeight;
const double parentDescent=prevNodeSizeForSpecialPlacement->overallHeight-prevNodeSizeForSpecialPlacement->baselineHeight;
- const double newShift=parentDescent+parentMathText->getSpecialSubShiftFactor()*cBaselineHeight;
+ const double newShift=parentDescent+parentMathText->getSpecialSubShiftFactor()*cs.baselineHeight;
if (newShift>shift_to_childBaseline) shift_to_childBaseline=newShift;
//qDebug()<<"newshift="<draw(painter, xx, y+shift_to_childBaseline, ev);//+0.5*fm.boundingRect("A").width();
}
-double JKQTMathTextSubscriptNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv)
+double JKQTMathTextSubscriptNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const
{
return drawWithSpecialPlacement(painter, x, y, currentEv, nullptr);
}
@@ -204,7 +204,7 @@ QString JKQTMathTextSubscriptNode::getTypeName() const
return "MTsubscriptNode";
}
-bool JKQTMathTextSubscriptNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
+bool JKQTMathTextSubscriptNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const {
html=html+"";
bool ok=getChild()->toHtml(html, currentEv, defaultEv);
html=html+"";
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.h b/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.h
index 1602bce325..2d6a706107 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.h
@@ -51,30 +51,30 @@ public:
*
* \return the x position which to use for the next part of the text
*/
- double drawWithSpecialPlacement(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement);
+ double drawWithSpecialPlacement(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement) const;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override; /** \brief returns the child node */
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \brief like getSize(), i.e. determine the size of the node, but cares for subscript with special placement rules after large blocks (e.g. braces), when \a prevNodeSizeForSpecialPlacement is not \c nullptr
*
* \param painter painter to use for determining the size
* \param currentEv current environment object
- * \param[out] width width of the block/node
- * \param[out] baselineHeight distance from the bottom of the block/node-box to the baseline
- * \param[out] overallHeight overall height (bottom to top) of the node, the ascent is \c overallHeight-baselineHeight
- * \param[out] strikeoutPos position of the strikeout-line
* \param[in] prevNodeSizeForSpecialPlacement optional parameter, describing the size of the previous node (on the left). This may be used for layout of some nodes (e.g. sub/super to move correctly next to large parantheses ...)
*
*/
- void getSizeWithSpecialPlacement(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement);
+ JKQTMathTextNodeSize getSizeWithSpecialPlacement(QPainter& painter, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement) const;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
};
+
+
+
+
/** \brief subclass representing an superscript node with exactly one argument in the syntax tree
* \ingroup jkqtmathtext_items
*
@@ -96,28 +96,24 @@ public:
*
* \return the x position which to use for the next part of the text
*/
- double drawWithSpecialPlacement(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement);
+ double drawWithSpecialPlacement(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement) const;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \brief like getSize(), i.e. determine the size of the node, but cares for superscript with special placement rules after large blocks (e.g. braces), when \a prevNodeSizeForSpecialPlacement is not \c nullptr
*
* \param painter painter to use for determining the size
* \param currentEv current environment object
- * \param[out] width width of the block/node
- * \param[out] baselineHeight distance from the bottom of the block/node-box to the baseline
- * \param[out] overallHeight overall height (bottom to top) of the node, the ascent is \c overallHeight-baselineHeight
- * \param[out] strikeoutPos position of the strikeout-line
* \param[in] prevNodeSizeForSpecialPlacement optional parameter, describing the size of the previous node (on the left). This may be used for layout of some nodes (e.g. sub/super to move correctly next to large parantheses ...)
*
*/
- void getSizeWithSpecialPlacement(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement) ;
+ JKQTMathTextNodeSize getSizeWithSpecialPlacement(QPainter& painter, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSizeForSpecialPlacement) const;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
};
#endif // JKQTMATHTEXTSUBSUPERSCRIPTNODE_H
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp
index b9b95869a3..d0b3f46189 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp
@@ -51,63 +51,8 @@ QString JKQTMathTextSymbolNode::getTypeName() const
}
-void JKQTMathTextSymbolNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) {
- double dummy1, dummy2;
- getSymbolSizeInternal(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos, dummy1, dummy2);
-}
-
-void JKQTMathTextSymbolNode::getSymbolSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos, double &subSuperXCorrection, double &subBesidesXCorrection)
-{
- const auto fullProps=symbols.value(symbolName, SymbolFullProps());
- const GlobalSymbolFlags globalFlags=fullProps.globalFlags;
- const auto drawProps=fullProps.getDrawingData(currentEv, parentMathText);
- const QFont f=drawProps.first;
- const QFontMetricsF fm(f);
- const JKQTMathTextSymbolNode::SymbolProps symprops=drawProps.second;
- const SymbolFlags symflags=symprops.flags;
- const QString sym=symprops.symbol;
- const QRectF tbr=getTightBoundingRect(fm, sym, globalFlags);
- const QRectF br=getBoundingRect(fm, sym, globalFlags);
- const QRectF tbrNoSymbol=JKQTMathTextGetTightBoundingRect(f, "X", painter.device());
- const QRectF mintbr=JKQTMathTextGetTightBoundingRect(f, "(", painter.device());
- //const double yShift=symprops.yShiftFactor*tbr.height();
-
-
- if (currentEv.insideMath) {
- width=qMax(br.width(), mintbr.width());
- if (has(globalFlags, SmallExtendWidthInMathmode)) {
- if (!symprops.getSymbolSingleChar().isNull()) width=width*(1.0+(parentMathText->getMathoperatorWidthFactor()-1.0)/5.0);
- else width=width+mintbr.width()*0.15;
- } else if (has(globalFlags, ExtendWidthInMathmode)) {
- if (!symprops.getSymbolSingleChar().isNull()) width=width*parentMathText->getMathoperatorWidthFactor();
- else width=width+mintbr.width()*0.5;
- }
- } else {
- width=br.width();
- }
- if (!sym.isEmpty()) {
- overallHeight=tbr.height();
- baselineHeight=tbr.height()-tbr.bottom();
- } else {
- overallHeight=tbrNoSymbol.height();
- baselineHeight=tbrNoSymbol.height()-tbrNoSymbol.bottom();
- width=tbrNoSymbol.width();
- }
- const double oldDescent=overallHeight-baselineHeight;
-
- if (has(symflags, HeightIsAscent)) {
- baselineHeight=fm.ascent();
- overallHeight=baselineHeight+oldDescent;
- }
- if (has(symflags, RotateSymbol90)) {
- width=qMax(overallHeight, width);
- }
- strikeoutPos=fm.strikeOutPos();
-
- if (has(globalFlags, IntLikeSymbolCorrection)) {
- subSuperXCorrection=parentMathText->getIntSubSuperXCorrectionFactor()*tbr.width();
- subBesidesXCorrection=parentMathText->getIntSubBesidesXCorrectionXFactor()*JKQTMathTextGetTightBoundingRect(f, "X", painter.device()).width();
- }
+JKQTMathTextNodeSize JKQTMathTextSymbolNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
+ return getSymbolSize(painter, currentEv);
}
QRectF JKQTMathTextSymbolNode::getBoundingRect(const QFontMetricsF &fm, const QString &text, GlobalSymbolFlags globalFlags)
@@ -193,12 +138,9 @@ void JKQTMathTextSymbolNode::drawText(QPainter &p, const QString &text, GlobalSy
}
-double JKQTMathTextSymbolNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) {
- doDrawBoxes(painter, x, y, currentEv);
- double width=0;
- double baselineHeight=0;
- double overallHeight=0, strikeoutPos=0;
- getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
+double JKQTMathTextSymbolNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
+ const NodeSize s=getSymbolSize(painter, currentEv);
+ doDrawBoxes(painter, x, y, s);
const auto fullProps=symbols.value(symbolName, SymbolFullProps());
const GlobalSymbolFlags globalFlags=fullProps.globalFlags;
@@ -215,7 +157,7 @@ double JKQTMathTextSymbolNode::draw(QPainter& painter, double x, double y, JKQTM
//const QRectF br=getBoundingRect(fm, sym, globalFlags);
const QRectF tbrNoSymbol=JKQTMathTextGetTightBoundingRect(f, "X", painter.device());
const double yShift=symprops.yShiftFactor*tbr.height();
- const double xShift=(width-tbr.width())/2.0;
+ const double xShift=(s.width-tbr.width())/2.0;
const QPointF x0(x+xShift-tbr.x(), y+yShift);
double italic_xcorrection=fabs(tbr.width()-tbrNonItalic.width());
if (fabs(italic_xcorrection)<1e-6) italic_xcorrection=double(fm.boundingRect(' ').width())*parentMathText->getItalicCorrectionFactor();
@@ -250,11 +192,11 @@ double JKQTMathTextSymbolNode::draw(QPainter& painter, double x, double y, JKQTM
}
if (has(symflags, DrawSlash)) {
//qDebug()<<" -> DrawSlash";
- painter.drawText(QPointF((width-fm.boundingRect('/').width())/2.0,0),"/");
+ painter.drawText(QPointF((s.width-fm.boundingRect('/').width())/2.0,0),"/");
}
if (has(symflags, DrawBackSlash)) {
//qDebug()<<" -> DrawBackSlash";
- painter.drawText(QPointF((width-fm.boundingRect('\\').width())/2.0,0),"\\");
+ painter.drawText(QPointF((s.width-fm.boundingRect('\\').width())/2.0,0),"\\");
}
/*painter.save();
painter.setPen(QPen(QColor("red"), 0.5, Qt::DotLine));
@@ -269,10 +211,10 @@ double JKQTMathTextSymbolNode::draw(QPainter& painter, double x, double y, JKQTM
painter.drawRect(QRectF(x0.x(), x0.y()-tbrNoSymbol.height(), tbrNoSymbol.width(), tbrNoSymbol.height()));
}
- return x+width;
+ return x+s.width;
}
-bool JKQTMathTextSymbolNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
+bool JKQTMathTextSymbolNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const {
bool ok=true;
const auto props=symbols.value(symbolName, SymbolFullProps());
QString s=props.html.symbol;
@@ -288,10 +230,60 @@ QString JKQTMathTextSymbolNode::getSymbolName() const {
return this->symbolName;
}
-JKQTMathTextSymbolNode::NodeSize JKQTMathTextSymbolNode::getSymbolSize(QPainter &painter, JKQTMathTextEnvironment currentEv)
+JKQTMathTextSymbolNode::NodeSize JKQTMathTextSymbolNode::getSymbolSize(QPainter &painter, JKQTMathTextEnvironment currentEv) const
{
NodeSize s;
- getSymbolSizeInternal(painter, currentEv, s.width, s.baselineHeight, s.overallHeight, s.strikeoutPos, s.subSuperXCorrection, s.subBesidesXCorrection);
+
+ const auto fullProps=symbols.value(symbolName, SymbolFullProps());
+ const GlobalSymbolFlags globalFlags=fullProps.globalFlags;
+ const auto drawProps=fullProps.getDrawingData(currentEv, parentMathText);
+ const QFont f=drawProps.first;
+ const QFontMetricsF fm(f);
+ const JKQTMathTextSymbolNode::SymbolProps symprops=drawProps.second;
+ const SymbolFlags symflags=symprops.flags;
+ const QString sym=symprops.symbol;
+ const QRectF tbr=getTightBoundingRect(fm, sym, globalFlags);
+ const QRectF br=getBoundingRect(fm, sym, globalFlags);
+ const QRectF tbrNoSymbol=JKQTMathTextGetTightBoundingRect(f, "X", painter.device());
+ const QRectF mintbr=JKQTMathTextGetTightBoundingRect(f, "(", painter.device());
+ //const double yShift=symprops.yShiftFactor*tbr.height();
+
+ if (currentEv.insideMath) {
+ s.width=qMax(br.width(), mintbr.width());
+ if (has(globalFlags, SmallExtendWidthInMathmode)) {
+ if (!symprops.getSymbolSingleChar().isNull()) s.width=s.width*(1.0+(parentMathText->getMathoperatorWidthFactor()-1.0)/5.0);
+ else s.width=s.width+mintbr.width()*0.15;
+ } else if (has(globalFlags, ExtendWidthInMathmode)) {
+ if (!symprops.getSymbolSingleChar().isNull()) s.width=s.width*parentMathText->getMathoperatorWidthFactor();
+ else s.width=s.width+mintbr.width()*0.5;
+ }
+ } else {
+ s.width=br.width();
+ }
+ if (!sym.isEmpty()) {
+ s.overallHeight=tbr.height();
+ s.baselineHeight=tbr.height()-tbr.bottom();
+ } else {
+ s.overallHeight=tbrNoSymbol.height();
+ s.baselineHeight=tbrNoSymbol.height()-tbrNoSymbol.bottom();
+ s.width=tbrNoSymbol.width();
+ }
+ const double oldDescent=s.overallHeight-s.baselineHeight;
+
+ if (has(symflags, HeightIsAscent)) {
+ s.baselineHeight=fm.ascent();
+ s.overallHeight=s.baselineHeight+oldDescent;
+ }
+ if (has(symflags, RotateSymbol90)) {
+ s.width=qMax(s.overallHeight, s.width);
+ }
+ s.strikeoutPos=fm.strikeOutPos();
+
+ if (has(globalFlags, IntLikeSymbolCorrection)) {
+ s.subSuperXCorrection=parentMathText->getIntSubSuperXCorrectionFactor()*tbr.width();
+ s.subBesidesXCorrection=parentMathText->getIntSubBesidesXCorrectionXFactor()*JKQTMathTextGetTightBoundingRect(f, "X", painter.device()).width();
+ }
+
return s;
}
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.h b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.h
index 07c60ab0ad..2cd68cb5d3 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.h
@@ -62,9 +62,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSymbolNode: public JKQTMathTextNode {
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \copydoc symbolName */
QString getSymbolName() const;
/** \brief return type for getSymbolSize(), extends JKQTMathTextNodeSize with information about x-correction for sub- and superscript */
@@ -88,7 +88,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSymbolNode: public JKQTMathTextNode {
*
* \return all important size properties, packed into a NodeSize struct
*/
- NodeSize getSymbolSize(QPainter& painter, JKQTMathTextEnvironment currentEv);
+ NodeSize getSymbolSize(QPainter& painter, JKQTMathTextEnvironment currentEv) const;
/** \brief checks whether the given symbol name can be prepresented by this type of node */
static bool hasSymbol(const QString& symbolName);
/** \brief return a list of all defined symbols */
@@ -101,9 +101,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSymbolNode: public JKQTMathTextNode {
static int getSymbolLength(const QString& symbolName);
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
- /** \copydoc JKQTMathTextSymbolNode::getSymbolSize() */
- virtual void getSymbolSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, double& subSuperXCorrection, double& subBesidesXCorrection) ;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** \brief this string will be sent to the drawText method with properly set fonts */
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp
index 1db3fbe250..40c6dce208 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp
@@ -63,7 +63,7 @@ QString JKQTMathTextTextBaseNode::textTransform(const QString &text, const JKQTM
}
-bool JKQTMathTextTextBaseNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
+bool JKQTMathTextTextBaseNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const {
html=html
+currentEv.toHtmlStart(defaultEv, parentMathText)
+textTransform(text, currentEv).toHtmlEscaped()
@@ -121,19 +121,16 @@ JKQTMathTextTextNode::JKQTMathTextTextNode(JKQTMathText* _parent, const QString&
JKQTMathTextTextNode::~JKQTMathTextTextNode() = default;
-void JKQTMathTextTextNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) {
- QStringList textpart;
- QList fontMode;
- QList textpartXPos;
- getSizeInternalAndData(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos,textpart, fontMode, textpartXPos);
+JKQTMathTextNodeSize JKQTMathTextTextNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
+ return calcLayout(painter, currentEv);
}
-void JKQTMathTextTextNode::getSizeInternalAndData(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos, QStringList &textpart, QList &fontMode, QList &textpartXPos)
+JKQTMathTextTextNode::LayoutInfo JKQTMathTextTextNode::calcLayout(QPainter &painter, JKQTMathTextEnvironment currentEv) const
{
- textpart.clear();
- fontMode.clear();
+ LayoutInfo l;
+
const QString txt=textTransform(text, currentEv);
- splitTextForLayout(painter, currentEv, txt, textpart, fontMode);
+ splitTextForLayout(painter, currentEv, txt, l.textpart, l.fontMode);
const QFont f=currentEv.getFont(parentMathText);
const QFont fUpright=JKQTMathTextGetNonItalic(f);
@@ -148,44 +145,45 @@ void JKQTMathTextTextNode::getSizeInternalAndData(QPainter &painter, JKQTMathTex
#else
const double sp=fm.width(' ');
#endif
- width=0;
+ l.width=0;
double ascent=0;
double descent=0;
- for (int i=0; i0 && textpart[i].at(textpart[i].size()-1).isSpace()) {
+ l.textpartXPos.append(l.width);
+ l.width+=br.width();
+ if (l.textpart[i].size()>0 && l.textpart[i].at(l.textpart[i].size()-1).isSpace()) {
// this correction is necessary, because it seems that QFontMetricsF::boundingRect() ignores trailing spaces
- width+=sp;
+ l.width+=sp;
}
const double thisAscent=-tbr.top();
const double thisDescent=tbr.bottom();
ascent=qMax(ascent, thisAscent);
descent=qMax(descent, thisDescent);
}
- overallHeight=(ascent+descent); //fm.height();
- baselineHeight=ascent;
- strikeoutPos=fm.strikeOutPos();
+ l.overallHeight=(ascent+descent); //fm.height();
+ l.baselineHeight=ascent;
+ l.strikeoutPos=fm.strikeOutPos();
+ return l;
}
void JKQTMathTextTextNode::splitTextForLayout(QPainter &painter, JKQTMathTextEnvironment currentEv, const QString &txt, QStringList &textpart, QList &fontMode) const
@@ -275,16 +273,9 @@ void JKQTMathTextTextNode::splitTextForLayout(QPainter &painter, JKQTMathTextEnv
}
}
-double JKQTMathTextTextNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) {
- doDrawBoxes(painter, x, y, currentEv);
- double width=0;
- double baselineHeight=0;
- double overallHeight=0;
- double sp=0;
- QStringList textpart;
- QList textpartXPos;
- QList fontMode;
- getSizeInternalAndData(painter, currentEv, width, baselineHeight, overallHeight, sp, textpart, fontMode, textpartXPos);
+double JKQTMathTextTextNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
+ const LayoutInfo l=calcLayout(painter, currentEv);
+ doDrawBoxes(painter, x, y, l);
const QFont f=currentEv.getFont(parentMathText);
@@ -303,32 +294,32 @@ double JKQTMathTextTextNode::draw(QPainter& painter, double x, double y, JKQTMat
//qDebug()<<"JKQTMathTextTextNode: text="<0;
@@ -468,14 +459,10 @@ bool JKQTMathTextVerbatimNode::toHtml(QString &html, JKQTMathTextEnvironment cur
return true;
}
-void JKQTMathTextVerbatimNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos)
+JKQTMathTextNodeSize JKQTMathTextVerbatimNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const
{
transformEnvironment(currentEv);
- const LayoutInfo l=calcLayout(painter, currentEv);
- width=l.width;
- overallHeight=l.overallHeight;
- baselineHeight=l.baselineHeight;
- strikeoutPos=l.strikeoutPos;
+ return calcLayout(painter, currentEv);
}
void JKQTMathTextVerbatimNode::transformEnvironment(JKQTMathTextEnvironment ¤tEv) const
@@ -592,3 +579,38 @@ JKQTMathTextVerbatimNode::LayoutInfo::LayoutInfo():
{
}
+
+JKQTMathTextTextNode::LayoutInfo::LayoutInfo():
+ JKQTMathTextNodeSize(),
+ textpart(), fontMode(), textpartXPos()
+{
+
+}
+
+JKQTMathTextTextNode::LayoutInfo::LayoutInfo(const LayoutInfo &other):
+ LayoutInfo()
+{
+ operator=(other);
+}
+
+JKQTMathTextTextNode::LayoutInfo::LayoutInfo(const JKQTMathTextNodeSize &other):
+ LayoutInfo()
+{
+ operator=(other);
+}
+
+JKQTMathTextTextNode::LayoutInfo &JKQTMathTextTextNode::LayoutInfo::operator=(const LayoutInfo &other) {
+ JKQTMathTextNodeSize::operator=(other);
+ textpart=other.textpart;
+ fontMode=other.fontMode;
+ textpartXPos=other.textpartXPos;
+ return *this;
+}
+
+JKQTMathTextTextNode::LayoutInfo &JKQTMathTextTextNode::LayoutInfo::operator=(const JKQTMathTextNodeSize &other) {
+ JKQTMathTextNodeSize::operator=(other);
+ textpart.clear();
+ fontMode.clear();
+ textpartXPos.clear();
+ return *this;
+}
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.h b/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.h
index bf491ad6e7..75a81fafa4 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.h
@@ -46,7 +46,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextTextBaseNode: public JKQTMathTextNode
explicit JKQTMathTextTextBaseNode(JKQTMathText* parent, const QString& text);
virtual ~JKQTMathTextTextBaseNode() override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \copydoc text */
QString getText() const;
protected:
@@ -65,7 +65,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextTextNode: public JKQTMathTextTextBaseN
explicit JKQTMathTextTextNode(JKQTMathText* parent, const QString& text, bool addWhitespace, bool stripInnerWhitepace=false);
virtual ~JKQTMathTextTextNode() override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override ;
/** \brief remove trailing whitespace, is used by simplifyJKQTMathTextNode() */
@@ -82,9 +82,24 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextTextNode: public JKQTMathTextTextBaseN
FMfallbackSymbol, /*!< \brief use JKQTMathText::getFallbackFontSymbols() */
};
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
+
+ /** \brief describes the layout of the whole node */
+ struct LayoutInfo: public JKQTMathTextNodeSize {
+ LayoutInfo();
+ LayoutInfo(const LayoutInfo& other);
+ LayoutInfo(const JKQTMathTextNodeSize& other);
+ LayoutInfo& operator=(const JKQTMathTextNodeSize& other);
+ LayoutInfo& operator=(const LayoutInfo& other);
+ /** \brief the text that shall be printed is split up into different parts (with different formatting each) */
+ QStringList textpart;
+ /** \brief formatting for each entry in textpart */
+ QList fontMode;
+ /** \brief drawing x-position for each entry in textpart */
+ QList textpartXPos;
+ };
/** \brief calculates the size of the node, much like JKQTMathTextNode::getSizeInternal(), but returns additional properties that can be reused for drawing */
- void getSizeInternalAndData(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, QStringList& textpart, QList& fontMode, QList& textpartXPos) ;
+ LayoutInfo calcLayout(QPainter& painter, JKQTMathTextEnvironment currentEv) const ;
/** \brief split text for Math-Modelayout into sections, where each section has a defined way of output
*
* \param painter the QPainter to use for sizing/drawing
@@ -130,9 +145,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextVerbatimNode: public JKQTMathTextTextB
/** \copydoc tabSize */
size_t getTabSize() const;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
protected:
/** \brief alignment scheme used to lay out all lines
*
@@ -157,7 +172,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextVerbatimNode: public JKQTMathTextTextB
size_t tabSize;
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** \brief sets all necessary settings in \a currentEv for drawing this node */
virtual void transformEnvironment(JKQTMathTextEnvironment& currentEv) const;
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextwhitespacenode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextwhitespacenode.cpp
index f1837423b0..b7d779c2d2 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextwhitespacenode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextwhitespacenode.cpp
@@ -79,7 +79,7 @@ QString JKQTMathTextWhitespaceNode::getTypeName() const
return QLatin1String("JKQTMathTextWhitespaceNode(")+Type2String(whitespace.type)+", count="+QString::number(whitespace.count)+")";
}
-bool JKQTMathTextWhitespaceNode::toHtml(QString &html, JKQTMathTextEnvironment /*currentEv*/, JKQTMathTextEnvironment /*defaultEv*/) {
+bool JKQTMathTextWhitespaceNode::toHtml(QString &html, JKQTMathTextEnvironment /*currentEv*/, JKQTMathTextEnvironment /*defaultEv*/) const {
for (size_t i=0; i(whitespace.count);
- baselineHeight=0;
- overallHeight=0;
- strikeoutPos=fm.strikeOutPos();
+ s.width=singelWidthPIX*static_cast(whitespace.count);
+ s.baselineHeight=0;
+ s.overallHeight=0;
+ s.strikeoutPos=fm.strikeOutPos();
+ return s;
}
QHash JKQTMathTextWhitespaceNode::supportedInstructions;
@@ -294,9 +295,9 @@ QString JKQTMathTextEmptyBoxNode::getTypeName() const
return QString("JKQTMathTextEmptyBoxNode(%1%2 x %3%4)").arg(getWidth()).arg(JKQTMathTextEmptyBoxNode::Units2String(getWidthUnit())).arg(getHeight()).arg(JKQTMathTextEmptyBoxNode::Units2String(getHeightUnit()));
}
-bool JKQTMathTextEmptyBoxNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv)
+bool JKQTMathTextEmptyBoxNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const
{
- return true;
+ return false;
}
JKQTMathTextEmptyBoxNode::Units JKQTMathTextEmptyBoxNode::getWidthUnit() const
@@ -319,24 +320,26 @@ double JKQTMathTextEmptyBoxNode::getHeight() const
return height;
}
-double JKQTMathTextEmptyBoxNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv)
+double JKQTMathTextEmptyBoxNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const
{
- doDrawBoxes(painter, x,y,currentEv);
const auto s=getSize(painter, currentEv);
+ doDrawBoxes(painter, x,y,s);
return x+s.width;
}
-void JKQTMathTextEmptyBoxNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos)
+JKQTMathTextNodeSize JKQTMathTextEmptyBoxNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const
{
+ JKQTMathTextNodeSize s;
const QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
- width=Units2PixelWidth(this->width, widthUnit, currentEv, painter.device());
- overallHeight=Units2PixelWidth(height, heightUnit, currentEv, painter.device());
+ s.width=Units2PixelWidth(width, widthUnit, currentEv, painter.device());
+ s.overallHeight=Units2PixelWidth(height, heightUnit, currentEv, painter.device());
if (height>0) {
- baselineHeight=overallHeight;
+ s.baselineHeight=s.overallHeight;
} else {
- baselineHeight=0;
+ s.baselineHeight=0;
}
- strikeoutPos=fm.strikeOutPos();
+ s.strikeoutPos=fm.strikeOutPos();
+ return s;
}
@@ -383,35 +386,32 @@ QString JKQTMathTextPhantomNode::getTypeName() const
return QLatin1String("JKQTMathTextPhantomNode(")+instructionName+")";
}
-void JKQTMathTextPhantomNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) {
+JKQTMathTextNodeSize JKQTMathTextPhantomNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
fillInstructions();
- JKQTMathTextEnvironment ev=currentEv;
-
- getChild()->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
+ JKQTMathTextNodeSize s=getChild()->getSize(painter, currentEv);
switch(instructions[getInstructionName()]) {
case FMwidth:
- overallHeight=0;
- baselineHeight=0;
- strikeoutPos=0;
+ s.overallHeight=0;
+ s.baselineHeight=0;
+ s.strikeoutPos=0;
break;
case FMwidthAndHeight:
break;
case FMheight:
- width=0;
+ s.width=0;
break;
}
+ return s;
}
-double JKQTMathTextPhantomNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) {
- doDrawBoxes(painter, x, y, currentEv);
- JKQTMathTextEnvironment ev=currentEv;
-
+double JKQTMathTextPhantomNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
const JKQTMathTextNodeSize s=getSize(painter, currentEv);
+ doDrawBoxes(painter, x, y, s);
return x+s.width;
}
-bool JKQTMathTextPhantomNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
+bool JKQTMathTextPhantomNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const {
JKQTMathTextEnvironment ev=currentEv;
fillInstructions();
return " ";
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextwhitespacenode.h b/lib/jkqtmathtext/nodes/jkqtmathtextwhitespacenode.h
index 0dee62671d..071537e48c 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextwhitespacenode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextwhitespacenode.h
@@ -76,16 +76,16 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextWhitespaceNode: public JKQTMathTextNod
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \copydoc WhitespaceProps::type */
Types getWhitespaceType() const;
/** \copydoc WhitespaceProps::count */
size_t getWhitespaceCount() const;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** \brief describes a whitespace */
struct WhitespaceProps {
WhitespaceProps(Types type=WSTNormal, size_t count=1);
@@ -129,7 +129,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEmptyBoxNode: public JKQTMathTextNode
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \copydoc widthUnit */
Units getWidthUnit() const;
/** \copydoc width */
@@ -139,10 +139,10 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEmptyBoxNode: public JKQTMathTextNode
/** \copydoc height */
double getHeight() const;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** \brief width of the (empty) box, units of this value defined in widthUnit */
double width;
/** \brief units to interpret width */
@@ -175,9 +175,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextPhantomNode: public JKQTMathTextInstru
/** \copydoc JKQTMathTextNode::getTypeName() */
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::draw() */
- virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) override;
+ virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
/** \copydoc JKQTMathTextNode::toHtml() */
- virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
+ virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
/** \brief returns true, if the given \a instructionName can be represented by this node
* \see instructions
@@ -186,7 +186,7 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextPhantomNode: public JKQTMathTextInstru
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
- virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos) override;
+ virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
/** \brief fills instructions
*
* \note this is the customization point for new instructions!