JKQTMathText: Code Cleanup: using JKQTMathTextNodeSize for all size-calculation functions and got rid of all functions that take the output parameters with call-by-reference

JKQTMathText: JKQTMathTextBraceNode now properly supports different opening and closing braces e.g. |...> for bra-vetors
This commit is contained in:
jkriege2 2022-08-16 23:05:04 +02:00
parent 74cf8046ce
commit 6fa5dd65ed
64 changed files with 861 additions and 755 deletions

View File

@ -58,6 +58,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>IMPROVED/REWORKED rendering of blackboard font: now several different rendering modes can be selected using JKQTMathText::setFontBlackboradMode()</li>
<li>BREAKING/REWORKED: The \\verb!...!-command now works the same as in LaTeX</li>
<li>BREAKING/CLEANUP: cleanup: Removed Parameter prevNodeSize from JKQTMathTextNode::draw() and JKQTMathTextNode::getSize()/JKQTMathTextNode::getSizeInternal(), since it is only really necessary for JKQTMathTextSubscriptNode and JKQTMathTextSuperscriptNode</li>
<li>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()</li>
<li>NEW: JKQTMathTextVerticalListNode allows to typeset a vertical list of lines</li>
<li>NEW: JKQTMathText::parse() by default allows linebreaks in the LaTeX string to be parsed. This can be switched off by a parameter</li>
<li>NEW: added functions to set the font-size in pixels (as alternative to the existing functions that set them in points), implements request <a href="https://github.com/jkriege2/JKQtPlotter/issues/76">#76</a> from <a href="https://github.com/igormironchik">user:igormironchik</a> </li>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@ -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

View File

@ -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},\\

View File

@ -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) {

View File

@ -301,7 +301,7 @@ struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEnvironment {
/** \brief build a <a href="https://doc.qt.io/qt-5/qfont.html">QFont</a> 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 */

View File

@ -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="<<showOpeningBrace<<", openbrace="<<openbrace<<", showClosingBrace="<<showClosingBrace<<", closebrace="<<closebrace;
//qDebug()<<"getSizeInternalAndBrace(): child: baselineHeight="<<baselineHeight<<", strikeoutPos="<<strikeoutPos<<", overallHeight="<<overallHeight;
@ -73,29 +69,25 @@ void JKQTMathTextBraceNode::getSizeInternalAndBrace(QPainter &painter, JKQTMathT
const double heightAboveBelowStrike=qMax(cAscentAboveStrike, cDescentBelowStrike);
baselineHeight=strikeoutPos+heightAboveBelowStrike*parentMathText->getBraceFactor();
overallHeight=2.0*heightAboveBelowStrike*parentMathText->getBraceFactor(); //fm.height();
s.width=childSize.width;
s.strikeoutPos=childSize.strikeoutPos;
s.baselineHeight=childSize.strikeoutPos+heightAboveBelowStrike*parentMathText->getBraceFactor();
s.overallHeight=2.0*heightAboveBelowStrike*parentMathText->getBraceFactor(); //fm.height();
//qDebug()<<"getSizeInternalAndBrace(): heightAboveBelowStrike="<<heightAboveBelowStrike<<", baselineHeight="<<baselineHeight<<", overallHeight="<<overallHeight;
bracewidth=0;
braceheight=0;
getBraceSize(painter, currentEv, baselineHeight, overallHeight, bracewidth, braceheight);
calcBraceSizes(s, painter, currentEv, childSize);
if (openbrace!=MTBTNone && openbrace!=MTBTAny) width+=bracewidth;
if (closebrace!=MTBTNone && closebrace!=MTBTAny) width+=bracewidth;
if (openbrace!=MTBTNone && openbrace!=MTBTAny) s.width+=s.openBraceWidth;
if (closebrace!=MTBTNone && closebrace!=MTBTAny) s.width+=s.closeBraceWidth;
return s;
}
double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) {
double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
//std::cout<<"drawing brace-node: '"<<openbrace.toStdString()<<"' ... '"<<closebrace.toStdString()<<"'\n";
doDrawBoxes(painter, x, y, currentEv);
double nodeWidth=0;
double nodeBaselineHeight=0;
double nodeOverallHeight=0, nodeStrikeoutPos=0;
double bracewidth=0, braceheight=0;
getSizeInternalAndBrace(painter, currentEv, nodeWidth, nodeBaselineHeight, nodeOverallHeight, nodeStrikeoutPos, bracewidth, braceheight);
const NodeSize nodesize=getSizeInternalAndBrace(painter, currentEv);
doDrawBoxes(painter, x, y, nodesize);
const QFontMetricsF fm(currentEv.getFont(parentMathText));
const double lw=fm.lineWidth();
@ -117,12 +109,12 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
{
bool showOpeningBrace=true;
const double xbrace1=xnew+lw;
const double xbrace2=xnew+qMin(paren_fraction*bracewidth, bracewidth-lw/2.0);
const double xbraceC=xnew+bracewidth/2.0;
const double xbrace2=xnew+qMin(paren_fraction*nodesize.openBraceWidth, nodesize.openBraceWidth-lw/2.0);
const double xbraceC=xnew+nodesize.openBraceWidth/2.0;
if (openbrace==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(xbrace2-paren_topwidth/2.0, y1);
const QPointF pbc1(xbrace1-paren_centerwidth/2.0, (y1+y2)/2.0+fabs(y1-y2)/6.0);
const QPointF ptc1(xbrace1-paren_centerwidth/2.0, (y1+y2)/2.0-fabs(y1-y2)/6.0);
@ -144,8 +136,8 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
painter.drawLine(pt2,ptc2);*/
} else if (openbrace==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(xbrace2-paren_topwidth/2.0, y1);
const QPointF pc1(xbrace1-angle_centerwidth/2.0, yc);
@ -163,8 +155,8 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
painter.fillPath(path, QBrush(currentEv.color, Qt::SolidPattern));
} else if (openbrace==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(xbrace2, y1);
path.lineTo(xbrace1, y1);
path.lineTo(xbrace1, y2);
@ -173,7 +165,7 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
} else if (openbrace==MTBTTopCorner) {
QPainterPath path;
const double dx=fabs(xbrace2-xbrace1);
const double y1=y-nodeBaselineHeight+lw/2.0;
const double y1=y-nodesize.baselineHeight+lw/2.0;
path.moveTo(xbrace2, y1);
path.lineTo(xbrace1, y1);
path.lineTo(xbrace1, y1+dx);
@ -181,38 +173,38 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
} else if (openbrace==MTBTBottomCorner) {
QPainterPath path;
const double dx=fabs(xbrace2-xbrace1);
const double y1=y+(nodeOverallHeight-nodeBaselineHeight)-lw/2.0;
const double y1=y+(nodesize.overallHeight-nodesize.baselineHeight)-lw/2.0;
path.moveTo(xbrace2, y1);
path.lineTo(xbrace1, y1);
path.lineTo(xbrace1, y1-dx);
painter.drawPath(path);
} else if (openbrace==MTBTCurlyBracket) {
const QPainterPath path=JKQTMathTextMakeHBracePath(0,0,nodeOverallHeight, bracewidth*paren_fraction, p.widthF());
const QPainterPath path=JKQTMathTextMakeHBracePath(0,0,nodesize.overallHeight, nodesize.openBraceWidth*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(90);
QPen plocal=p;
plocal.setWidthF(0.0001);
painter.fillPath(path, QBrush(currentEv.color));
} else if (openbrace==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(xbrace2, y1);
path.lineTo(xbrace1, y1);
path.lineTo(xbrace1, y2);
painter.drawPath(path);
} else if (openbrace==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(xbrace1, y1);
path.lineTo(xbrace1, y2);
path.lineTo(xbrace2, y2);
painter.drawPath(path);
} else if (openbrace==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);
@ -220,8 +212,8 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
if (l.length()>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="&lang;";
@ -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<const JKQTMathTextNodeSize&>(other));
openBraceWidth=other.openBraceWidth;
openBraceHeight=other.openBraceHeight;
closeBraceWidth=other.closeBraceWidth;
closeBraceHeight=other.closeBraceHeight;
return *this;
}
JKQTMathTextBraceNode::NodeSize::NodeSize(const NodeSize &other):
JKQTMathTextNodeSize(dynamic_cast<const JKQTMathTextNodeSize&>(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);
}

View File

@ -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

View File

@ -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<double>(baselineHeight+decoSeparation, decoAboveAscent_ypos)+linewidth/2.0;
ascent=std::max<double>(cs.baselineHeight+decoSeparation, decoAboveAscent_ypos)+linewidth/2.0;
} else if (decoration==MTDunderline || decoration==MTDunderlineDashed || decoration==MTDunderlineDotted) {
descent=std::max<double>(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<double>(deco_miniwidth,cwidth);
s.overallHeight=ascent+descent;
s.baselineHeight=ascent;
s.strikeoutPos=cs.strikeoutPos;
s.width=std::max<double>(deco_miniwidth,cs.width);
return s;
}
QHash<QString, JKQTMathTextDecoratedNode::DecorationType> 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<double>(width_x*0.5,cwidth-2.0*deco_xoffset-italic_xcorrection);
const double deco_width=std::max<double>(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;

View File

@ -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 */

View File

@ -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;
}

View File

@ -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) */

View File

@ -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<QString, JKQTMathTextSimpleInstructionNode::InstructionProperties> 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());

View File

@ -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 &params=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;

View File

@ -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.size()) { // is there one mor node behind?
JKQTMathTextSubscriptNode* nodeISucc_SubScript=dynamic_cast<JKQTMathTextSubscriptNode*>(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: "<<nodes[i]->getTypeName()<<" w2="<<w2<<" bh"<<bh<<" oh="<<oh<<" sp="<<sp;
if (bh>baselineHeight) {
overallHeight=overallHeight+bh-baselineHeight;
baselineHeight=bh;
strikeoutPos=sp;
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.getDescent()>outSize.overallHeight) {
outSize.overallHeight=outSize.baselineHeight+ns2.getDescent();
outSize.strikeoutPos=ns2.strikeoutPos;
}
xnew+=qMax(w1+spaceWidth, w2+prevNodeSize.subBesidesXCorrection);
xnew+=qMax(ns.width+spaceWidth, ns2.width+prevNodeSize.subBesidesXCorrection);
doDraw=false;
//qDebug()<<"### super+sub";
@ -131,30 +127,29 @@ void JKQTMathTextHorizontalListNode::getSizeInternal(QPainter& painter, JKQTMath
if (i+1<nodes.size()) { // is there one mor node behind?
JKQTMathTextSuperscriptNode* nodeISucc_SuperScript=dynamic_cast<JKQTMathTextSuperscriptNode*>(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="<<overallHeight<<" baselineHeight="<<baselineHeight;
}
} else {
double w1=0, oh=0, bh=0, sp=0;
nodes[i]->getSize(painter, currentEv, w1, bh, oh, sp);
if (bh>baselineHeight) {
overallHeight=overallHeight+bh-baselineHeight;
baselineHeight=bh;
strikeoutPos=sp;
const JKQTMathTextNodeSize ns=nodes[i]->getSize(painter, currentEv);
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;
}
xnew+=w1-prevNodeSize.subBesidesXCorrection;
xnew+=ns.width-prevNodeSize.subBesidesXCorrection;
doDraw=false;
}
@ -197,31 +191,27 @@ void JKQTMathTextHorizontalListNode::getSizeInternal(QPainter& painter, JKQTMath
if (!supn) supn=supn2;
JKQTMathTextEnvironment ev=currentEv;
ev.fontSize=ev.fontSize*parentMathText->getOperatorsubsuperSizeFactor();
double w1=0, wsub=0, wsup=0;
double oh1=0, ohsub=0, ohsup=0;
double bh1=0, bhsub=0, bhsup=0;
double sp1=0, spsub=0, spsup=0;
nodes[i]->getSize(painter, currentEv, w1, bh1, oh1, sp1);
//qDebug()<<"sub_super: node: "<<nodes[i]->getTypeName()<<" w1="<<w1<<" bh"<<bh1<<" oh="<<oh1<<" sp="<<sp1;
subn->getChild()->getSize(painter, ev, wsub, bhsub, ohsub, spsub);
const JKQTMathTextNodeSize ns=nodes[i]->getSize(painter, currentEv);
//qDebug()<<"sub_super: node: "<<nodes[i]->getTypeName()<<" ns.width="<<ns.width<<" bh"<<ns.baselineHeight<<" oh="<<ns.overallHeight<<" sp="<<ns.strikeoutPos;
const JKQTMathTextNodeSize sub=subn->getChild()->getSize(painter, ev);
//qDebug()<<"sub_super: node: "<<subn->getTypeName()<<" w2="<<w2<<" bh2"<<bh2<<" oh2="<<oh2<<" sp2="<<sp2;
supn->getChild()->getSize(painter, ev, wsup, bhsup, ohsup, spsup);
const JKQTMathTextNodeSize sup=supn->getChild()->getSize(painter, ev);
//qDebug()<<"sub_super: node: "<<supn->getTypeName()<<" w3="<<w3<<" bh3"<<bh3<<" oh3="<<oh3<<" sp3="<<sp3;
const double descent1=oh1-bh1;
//double d1=oh1-bh1;
const double descent1=ns.overallHeight-ns.baselineHeight;
//double d1=ns.overallHeight-ns.baselineHeight;
//double d2=oh2-bh2;
//double d3=oh3-bh3;
const double neww=qMax(qMax(w1, wsub+prevNodeSize.subSuperXCorrection), wsup+prevNodeSize.subSuperXCorrection)+subsuperextrawidth;
const double newBaselineHeight=bh1+ohsup+subsupershift;
if (newBaselineHeight>baselineHeight) {
const double extraBaselineHeight=newBaselineHeight-baselineHeight;
baselineHeight=newBaselineHeight;
overallHeight=overallHeight+extraBaselineHeight;
const double neww=qMax(qMax(ns.width, sub.width+prevNodeSize.subSuperXCorrection), sup.width+prevNodeSize.subSuperXCorrection)+subsuperextrawidth;
const double newBaselineHeight=ns.baselineHeight+sup.overallHeight+subsupershift;
if (newBaselineHeight>outSize.baselineHeight) {
const double extraBaselineHeight=newBaselineHeight-outSize.baselineHeight;
outSize.baselineHeight=newBaselineHeight;
outSize.overallHeight=outSize.overallHeight+extraBaselineHeight;
}
const double newDescent=descent1+ohsub+subsupershift;
if (newDescent>overallHeight-baselineHeight) {
const double extraDescent=newDescent-(overallHeight-baselineHeight);
overallHeight=overallHeight+extraDescent;
const double newDescent=descent1+sub.overallHeight+subsupershift;
if (newDescent>outSize.overallHeight-outSize.baselineHeight) {
const double extraDescent=newDescent-(outSize.overallHeight-outSize.baselineHeight);
outSize.overallHeight=outSize.overallHeight+extraDescent;
}
i++;
@ -233,10 +223,6 @@ void JKQTMathTextHorizontalListNode::getSizeInternal(QPainter& painter, JKQTMath
} else if (subn) { // is this subscript?
JKQTMathTextEnvironment ev=currentEv;
ev.fontSize=ev.fontSize*parentMathText->getOperatorsubsuperSizeFactor();
double wsub=0;
double ohsub=0;
double bhsub=0;
double spsub=0;//, sp3=0;
JKQTMathTextSymbolNode* symbN=dynamic_cast<JKQTMathTextSymbolNode*>(nodes[i]);
JKQTMathTextSymbolNode::NodeSize nodeSize;
if (symbN) {
@ -244,21 +230,21 @@ void JKQTMathTextHorizontalListNode::getSizeInternal(QPainter& painter, JKQTMath
} 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 d1=oh1-bh1;
//double d1=ns.overallHeight-ns.baselineHeight;
//double d2=oh2-bh2;
const double newDescent=descent1+ohsub+subsupershift;
if (newDescent>overallHeight-baselineHeight) {
const double extraDescent=newDescent-(overallHeight-baselineHeight);
overallHeight=overallHeight+extraDescent;
const double newDescent=descent1+sub.overallHeight+subsupershift;
if (newDescent>outSize.overallHeight-outSize.baselineHeight) {
const double extraDescent=newDescent-(outSize.overallHeight-outSize.baselineHeight);
outSize.overallHeight=outSize.overallHeight+extraDescent;
}
if (nodeSize.baselineHeight>baselineHeight) {
overallHeight=overallHeight+(nodeSize.baselineHeight-baselineHeight);
baselineHeight=nodeSize.baselineHeight;
if (nodeSize.baselineHeight>outSize.baselineHeight) {
outSize.overallHeight=outSize.overallHeight+(nodeSize.baselineHeight-outSize.baselineHeight);
outSize.baselineHeight=nodeSize.baselineHeight;
}
const double neww=qMax(nodeSize.width, wsub+nodeSize.subSuperXCorrection)+subsuperextrawidth;
const double neww=qMax(nodeSize.width, sub.width+nodeSize.subSuperXCorrection)+subsuperextrawidth;
i++;
doDraw=false;
xnew+=neww;
@ -266,10 +252,6 @@ void JKQTMathTextHorizontalListNode::getSizeInternal(QPainter& painter, JKQTMath
} else if (supn) { // is this superscript?
JKQTMathTextEnvironment ev=currentEv;
ev.fontSize=ev.fontSize*parentMathText->getOperatorsubsuperSizeFactor();
double wsup=0;
double ohsup=0;
double bhsup=0;
double spsup=0;//, sp3=0;
JKQTMathTextSymbolNode::NodeSize nodeSize;
JKQTMathTextSymbolNode* symbN=dynamic_cast<JKQTMathTextSymbolNode*>(nodes[i]);
if (symbN) {
@ -278,21 +260,21 @@ void JKQTMathTextHorizontalListNode::getSizeInternal(QPainter& painter, JKQTMath
nodeSize=nodes[i]->getSize(painter, currentEv);
}
const double descent1=nodeSize.getDescent();
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 newBaselineHeight=nodeSize.baselineHeight+ohsup+subsupershift;
if (newBaselineHeight>baselineHeight) {
const double extraBaselineHeight=newBaselineHeight-baselineHeight;
baselineHeight=newBaselineHeight;
overallHeight=overallHeight+extraBaselineHeight;
const double newBaselineHeight=nodeSize.baselineHeight+sup.overallHeight+subsupershift;
if (newBaselineHeight>outSize.baselineHeight) {
const double extraBaselineHeight=newBaselineHeight-outSize.baselineHeight;
outSize.baselineHeight=newBaselineHeight;
outSize.overallHeight=outSize.overallHeight+extraBaselineHeight;
}
if (descent1>overallHeight-baselineHeight) {
overallHeight=baselineHeight+descent1;
if (descent1>outSize.overallHeight-outSize.baselineHeight) {
outSize.overallHeight=outSize.baselineHeight+descent1;
}
const double neww=qMax(nodeSize.width, wsup+nodeSize.subSuperXCorrection)+subsuperextrawidth;
const double neww=qMax(nodeSize.width, sup.width+nodeSize.subSuperXCorrection)+subsuperextrawidth;
i++;
doDraw=false;
xnew+=neww;
@ -302,33 +284,35 @@ void JKQTMathTextHorizontalListNode::getSizeInternal(QPainter& painter, JKQTMath
}
if (i<nodes.size() && doDraw) {
double w=0, oh=0, bh=0, sp=0;
if (nodeI_SubScript) nodeI_SubScript->getSizeWithSpecialPlacement(painter, currentEv, w, bh, oh, sp, prevNodeSizePtrForSubscript);
else if (nodeI_SuperScript) nodeI_SuperScript->getSizeWithSpecialPlacement(painter, currentEv, w, bh, oh, sp, prevNodeSizePtrForSuperscript);
else nodes[i]->getSize(painter, currentEv, w, bh, oh, sp);
const double cDescent=oh-bh;
JKQTMathTextNodeSize ns;
if (nodeI_SubScript) ns=nodeI_SubScript->getSizeWithSpecialPlacement(painter, currentEv, prevNodeSizePtrForSubscript);
else if (nodeI_SuperScript) ns=nodeI_SuperScript->getSizeWithSpecialPlacement(painter, currentEv, prevNodeSizePtrForSuperscript);
else ns=nodes[i]->getSize(painter, currentEv);
const double cDescent=ns.getDescent();
//qDebug()<<"### else: bh="<<bh<<" baselineHeight="<<baselineHeight<<" oh="<<oh<<" overallHeight="<<overallHeight;
if (bh>baselineHeight) {
overallHeight=overallHeight-baselineHeight+bh;
baselineHeight=bh;
strikeoutPos=sp;
//qDebug()<<"### else: ns.baselineHeight="<<ns.baselineHeight<<" baselineHeight="<<baselineHeight<<" oh="<<oh<<" overallHeight="<<overallHeight;
if (ns.baselineHeight>outSize.baselineHeight) {
outSize.overallHeight=outSize.overallHeight-outSize.baselineHeight+ns.baselineHeight;
outSize.baselineHeight=ns.baselineHeight;
outSize.strikeoutPos=ns.strikeoutPos;
}
if (baselineHeight+cDescent>overallHeight) {
overallHeight=baselineHeight+cDescent;
strikeoutPos=sp;
if (outSize.baselineHeight+cDescent>outSize.overallHeight) {
outSize.overallHeight=outSize.baselineHeight+cDescent;
outSize.strikeoutPos=ns.strikeoutPos;
}
//qDebug()<<"### subsupop: else overallHeight="<<overallHeight<<" baselineHeight="<<baselineHeight;
xnew+=w;
xnew+=ns.width;
//qDebug()<<i<<xnew;
}
//wasBrace=dynamic_cast<JKQTMathTextBraceNode*>(nodes[i]);
}
width=xnew;
outSize.width=xnew;
return outSize;
}
double JKQTMathTextHorizontalListNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) {
double JKQTMathTextHorizontalListNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
doDrawBoxes(painter, x, y, currentEv);
double ynew=y;
double xnew=x;
@ -373,13 +357,13 @@ double JKQTMathTextHorizontalListNode::draw(QPainter& painter, double x, double
//painter.setPen(QPen("red"));
//painter.drawEllipse(xnew-4,ynew+shift-(ccOverallHeight-ccBaselineHeight)-4,8,8);
double xnew1=nodeI_SuperScript->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<JKQTMathTextSymbolNode*>(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<JKQTMathTextSymbolNode*>(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<JKQTMathTextSymbolNode*>(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<nodes.size(); i++) {
QString h="";
@ -605,12 +580,8 @@ QString JKQTMathTextVerticalListNode::getTypeName() const
return "MTVerticalListNode";
}
void JKQTMathTextVerticalListNode::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 JKQTMathTextVerticalListNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const {
return calcLayout(painter, currentEv);
}
JKQTMathTextVerticalListNode::LayoutInfo JKQTMathTextVerticalListNode::calcLayout(QPainter &painter, JKQTMathTextEnvironment currentEv) const
@ -633,27 +604,26 @@ JKQTMathTextVerticalListNode::LayoutInfo JKQTMathTextVerticalListNode::calcLayou
QList<double> 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; i<nodes.size(); i++) {
double locWidth=0, locOverallHeight=0, locBaselineHeight=0, locStrikeoutPos=0;
nodes[i]->getSize(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<<locWidth;
l.width=qMax(l.width, locWidth);
heights<<locOverallHeight;
ascents<<locBaselineHeight;
descents<<(locOverallHeight-locBaselineHeight);
strikeouts<<locStrikeoutPos;
widths<<loc.width;
l.width=qMax(l.width, loc.width);
heights<<loc.overallHeight;
ascents<<loc.baselineHeight;
descents<<(loc.overallHeight-loc.baselineHeight);
strikeouts<<loc.strikeoutPos;
ysFromFirstLine<<y;
}
heightSum+=descents.last();
@ -690,7 +660,7 @@ JKQTMathTextVerticalListNode::LayoutInfo JKQTMathTextVerticalListNode::calcLayou
return l;
}
double JKQTMathTextVerticalListNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) {
double JKQTMathTextVerticalListNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const {
doDrawBoxes(painter, x, y, currentEv);
const LayoutInfo l=calcLayout(painter, currentEv);
for (int i=0; i<nodes.size(); i++) {
@ -704,7 +674,7 @@ void JKQTMathTextVerticalListNode::addChild(JKQTMathTextNode *n) {
nodes.append(n);
}
bool JKQTMathTextVerticalListNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
bool JKQTMathTextVerticalListNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const {
bool ok=true;
if (alignment==MTHALeft) {
html+="<div align=\"left\">";
@ -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<const JKQTMathTextNodeSize&>(other));
X=other.X;
return *this;
}
JKQTMathTextVerticalListNode::LayoutInfo::LayoutInfo(const LayoutInfo &other):
JKQTMathTextNodeSize(dynamic_cast<const JKQTMathTextNodeSize&>(other)),
X(other.X)
{
}

View File

@ -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<JKQTMathTextNode*> 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<QPointF> X;
};

View File

@ -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;

View File

@ -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<QVector<JKQTMathTextNode*> > 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 */

View File

@ -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();
}

View File

@ -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

View File

@ -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;

View File

@ -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) */

View File

@ -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+"<sup>";
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="<<shift<<", prevNodeSize->overallHeight="<<prevNodeSize->overallHeight<<", prevNodeSize->baselineHeight="<<prevNodeSize->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="<<shift;
}
baselineHeight=cBaselineHeight-shift_to_childBaseline;
overallHeight=cOverallHeight;
if (prevNodeSizeForSpecialPlacement!=nullptr) strikeoutPos=prevNodeSizeForSpecialPlacement->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="<<shift<<", prevNodeSize->overallHeight="<<prevNodeSize->overallHeight<<", prevNodeSize->baselineHeight="<<prevNodeSize->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="<<shift;
}
@ -188,13 +188,13 @@ double JKQTMathTextSubscriptNode::drawWithSpecialPlacement(QPainter& painter, do
//qDebug()<<"shift="<<shift<<", yshift="<<yshift;
double xx=x;
if (currentEv.italic && prevNodeSizeForSpecialPlacement==nullptr) {
std::cout<<"italic_xshift="<<italic_xshift<<"\n";
//std::cout<<"italic_xshift="<<italic_xshift<<"\n";
xx=xx-italic_xshift;
}
return getChild()->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+"<sub>";
bool ok=getChild()->toHtml(html, currentEv, defaultEv);
html=html+"</sub>";

View File

@ -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

View File

@ -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;
}

View File

@ -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 */

View File

@ -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> fontMode;
QList<double> 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> &fontMode, QList<double> &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; i<textpart.size(); i++) {
for (int i=0; i<l.textpart.size(); i++) {
QRectF br, tbr;
switch(fontMode[i]) {
switch(l.fontMode[i]) {
case FMasDefined:
case FMasDefinedOutline:
br=fm.boundingRect(textpart[i]);
tbr=JKQTMathTextGetTightBoundingRect(f, textpart[i], painter.device());
br=fm.boundingRect(l.textpart[i]);
tbr=JKQTMathTextGetTightBoundingRect(f, l.textpart[i], painter.device());
break;
case FMasDefinedForceUpright:
br=fmUpright.boundingRect(textpart[i]);
tbr=JKQTMathTextGetTightBoundingRect(fUpright, textpart[i], painter.device());
br=fmUpright.boundingRect(l.textpart[i]);
tbr=JKQTMathTextGetTightBoundingRect(fUpright, l.textpart[i], painter.device());
break;
case FMroman:
br=fmRoman.boundingRect(textpart[i]);
tbr=JKQTMathTextGetTightBoundingRect(fRoman, textpart[i], painter.device());
br=fmRoman.boundingRect(l.textpart[i]);
tbr=JKQTMathTextGetTightBoundingRect(fRoman, l.textpart[i], painter.device());
break;
case FMfallbackSymbol:
br=fmFallbackSym.boundingRect(textpart[i]);
tbr=JKQTMathTextGetTightBoundingRect(fFallbackSym, textpart[i], painter.device());
br=fmFallbackSym.boundingRect(l.textpart[i]);
tbr=JKQTMathTextGetTightBoundingRect(fFallbackSym, l.textpart[i], painter.device());
break;
}
textpartXPos.append(width);
width+=br.width();
if (textpart[i].size()>0 && 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> &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<double> textpartXPos;
QList<FontMode> 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="<<text<<" font="<<f;
//std::cout<<" TEXT: currentEv.mathMode="<<currentEv.insideMath<<", currentEv.forceUpright="<<currentEv.insideMathForceDigitsUpright<<"\n";
for (int i=0; i<textpart.size(); i++) {
for (int i=0; i<l.textpart.size(); i++) {
//std::cout<<" TEXT: mode="<<fontMode[i]<<", text='"<<textpart[i].toStdString()<<"'\n";
switch(fontMode[i]) {
switch(l.fontMode[i]) {
case FMasDefined:
painter.setFont(f);
painter.drawText(QPointF(x+textpartXPos[i], y), textpart[i]);
painter.drawText(QPointF(x+l.textpartXPos[i], y), l.textpart[i]);
break;
case FMasDefinedOutline:
JKQTMathTextDrawStringSimBlackboard(painter, f, currentEv.color, x+textpartXPos[i], y, textpart[i]);
JKQTMathTextDrawStringSimBlackboard(painter, f, currentEv.color, x+l.textpartXPos[i], y, l.textpart[i]);
break;
case FMasDefinedForceUpright:
painter.setFont(fUpright);
painter.drawText(QPointF(x+textpartXPos[i], y), textpart[i]);
painter.drawText(QPointF(x+l.textpartXPos[i], y), l.textpart[i]);
break;
case FMroman:
painter.setFont(fRoman);
painter.drawText(QPointF(x+textpartXPos[i], y), textpart[i]);
painter.drawText(QPointF(x+l.textpartXPos[i], y), l.textpart[i]);
break;
case FMfallbackSymbol:
painter.setFont(fFallbackSym);
painter.drawText(QPointF(x+textpartXPos[i], y), textpart[i]);
painter.drawText(QPointF(x+l.textpartXPos[i], y), l.textpart[i]);
break;
}
}
return x+width;
return x+l.width;
}
@ -430,11 +421,11 @@ size_t JKQTMathTextVerbatimNode::getTabSize() const
return tabSize;
}
double JKQTMathTextVerbatimNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv)
double JKQTMathTextVerbatimNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const
{
doDrawBoxes(painter, x, y, currentEv);
transformEnvironment(currentEv);
const LayoutInfo l=calcLayout(painter, currentEv);
doDrawBoxes(painter, x, y, l);
QFont f=currentEv.getFont(parentMathText);
f.setStyleStrategy(QFont::PreferDefault);
f.setFixedPitch(true);
@ -446,7 +437,7 @@ double JKQTMathTextVerbatimNode::draw(QPainter &painter, double x, double y, JKQ
return x+l.width;
}
bool JKQTMathTextVerbatimNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv)
bool JKQTMathTextVerbatimNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const
{
transformEnvironment(currentEv);
const bool isMultiLine=text.count('\n')>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 &currentEv) 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;
}

View File

@ -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> fontMode;
/** \brief drawing x-position for each entry in textpart */
QList<double> 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>& fontMode, QList<double>& 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;

View File

@ -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; i++) {
html=html+Type2HTML(whitespace.type);
}
@ -115,22 +115,23 @@ size_t JKQTMathTextWhitespaceNode::getWhitespaceCount() const
return whitespace.count;
}
double JKQTMathTextWhitespaceNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv)
double JKQTMathTextWhitespaceNode::draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const
{
doDrawBoxes(painter, x,y,currentEv);
double width=0, bh=0, oh=0, sp=0;
getSize(painter, currentEv, width, bh, oh, sp);
return x+width;
const JKQTMathTextNodeSize s=getSize(painter, currentEv);
doDrawBoxes(painter, x,y,s);
return x+s.width;
}
void JKQTMathTextWhitespaceNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos)
JKQTMathTextNodeSize JKQTMathTextWhitespaceNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const
{
JKQTMathTextNodeSize s;
const double singelWidthPIX=Type2PixelWidth(whitespace.type, currentEv, painter.device());
const QFontMetricsF fm(currentEv.getFont(parentMathText));
width=singelWidthPIX*static_cast<double>(whitespace.count);
baselineHeight=0;
overallHeight=0;
strikeoutPos=fm.strikeOutPos();
s.width=singelWidthPIX*static_cast<double>(whitespace.count);
s.baselineHeight=0;
s.overallHeight=0;
s.strikeoutPos=fm.strikeOutPos();
return s;
}
QHash<QString, JKQTMathTextWhitespaceNode::WhitespaceProps> 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 "&nbsp;";

View File

@ -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!