diff --git a/doc/dox/whatsnew.dox b/doc/dox/whatsnew.dox index b4d2b2f204..6485321c9e 100644 --- a/doc/dox/whatsnew.dox +++ b/doc/dox/whatsnew.dox @@ -38,6 +38,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
$\\sqrt{1+\\sqrt{1+x}}$
\image html jkqtmathtext/jkqtmathtext_sqrt.png
+ - $\\sqrt[3]{1+\\sqrt[3]{1+x}}$
\image html jkqtmathtext/jkqtmathtext_cbrt.png
+ .
+
\subsection JKQTMathTextSuppoertedLaTeXUnderOver Undersetting, Oversetting, Underbraces, Overbraces ...
There are also instructions that allow to under/overset braces, arrows, ...:
- $\\underbrace{x+x+...+x}{k\\ \\mathrm{times}}$
\image html jkqtmathtext/jkqtmathtext_brace_underbrace.png
@@ -535,6 +541,23 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
void setDecorationWidthReductionXFactor(double __value);
/** \copydoc decoration_width_reduction_Xfactor */
double getDecorationWidthReductionXFactor() const;
+
+
+ /** \copydoc sqrt_width_Xfactor */
+ void setSqrtWidthXFactor(double __value);
+ /** \copydoc sqrt_width_Xfactor */
+ double getSqrtWidthXFactor() const;
+ /** \copydoc sqrt_height_factor */
+ void setSqrtHeightFactor(double __value);
+ /** \copydoc sqrt_height_factor */
+ double getSqrtHeightFactor() const;
+ /** \copydoc sqrt_smallfont_factor */
+ void setSqrtSmallFontFactor(double __value);
+ /** \copydoc sqrt_smallfont_factor */
+ double getSqrtSmallFontFactor() const;
+
+
+
/** \copydoc useUnparsed */
void setUseUnparsed(bool __value);
/** \copydoc useUnparsed */
@@ -692,6 +715,12 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
* \image html jkqtmathtext/decoration_sizing.png
*/
double decoration_width_reduction_Xfactor;
+ /** \brief scaling factor for the small font used to indicate the degree of the sqrt */
+ double sqrt_smallfont_factor;
+ /** \brief width of the sqrt-symbol, as factor to width("X") */
+ double sqrt_width_Xfactor;
+ /** \brief height-increase of the sqrt-symbol, as factor of the child's height */
+ double sqrt_height_factor;
/** \brief a list that will be filled with error messages while parsing, if any error occur */
QStringList error_list;
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.cpp
index 0f00a79bfc..66d072e981 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.cpp
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.cpp
@@ -45,54 +45,92 @@ JKQTMathTextSqrtNode::~JKQTMathTextSqrtNode() {
}
void JKQTMathTextSqrtNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
- QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
+ const QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
+ QFont fsmall=currentEv.getFont(parentMathText);
+ fsmall.setPointSizeF(fsmall.pointSizeF()*parentMathText->getSqrtSmallFontFactor());
+ fsmall.setItalic(false);
+ const QFontMetricsF fmsmall(fsmall, painter.device());
getChild()->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
+ const double descent=overallHeight-baselineHeight;
+ const double sqrtwidth=fm.boundingRect("X").width()*parentMathText->getSqrtWidthXFactor();
+ const double newAscent=qMax(baselineHeight*parentMathText->getSqrtHeightFactor(), fm.ascent());
+ const double newDescent=qMax(descent*parentMathText->getSqrtHeightFactor(), fm.descent());
- overallHeight=overallHeight*1.2;//+fm.ascent()*0.1;
- baselineHeight=baselineHeight*1.2;//+fm.ascent()*0.1;
- width=width+fm.boundingRect("A").width()*2; // 1.53
+ overallHeight=newAscent+newDescent;;
+ baselineHeight=newAscent;
+ width=width+sqrtwidth;
+ if (degree!=2) {
+ const QString degreetext=QLocale::c().toString(degree);
+ const double degwidth=fmsmall.width(degreetext);
+ const double smalltextIndent=0.6*sqrtwidth;
+ if (degwidth>smalltextIndent) width=width+(degwidth-smalltextIndent);
+ }
}
double JKQTMathTextSqrtNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
doDrawBoxes(painter, x, y, currentEv);
- double width=0, baselineHeight=0, overallHeight=0, sp=0;
- getChild()->getSize(painter, currentEv, width, baselineHeight, overallHeight, sp);
- QFont f=currentEv.getFont(parentMathText);
+
+ const QFont f=currentEv.getFont(parentMathText);
QFont fsmall=f;
- QFontMetricsF fm(f, painter.device());
- double w=fm.boundingRect("A").width();
- double a=baselineHeight*1.15;
- double d=overallHeight-baselineHeight;
+ const QFontMetricsF fm(f, painter.device());
+ fsmall.setPointSizeF(fsmall.pointSizeF()*parentMathText->getSqrtSmallFontFactor());
+ fsmall.setItalic(false);
+ const QFontMetricsF fmsmall(fsmall, painter.device());
+
+ double width=0, baselineHeight=0, overallHeight=0, strikeoutPos=0;
+ getChild()->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
+ const double descent=overallHeight-baselineHeight;
+ const double sqrtwidth=fm.boundingRect("X").width()*parentMathText->getSqrtWidthXFactor();
+ const double newAscent=qMax(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;
+ const QString degreetext=(degree!=2)?QLocale::c().toString(degree):"";
+ const double degwidth=fmsmall.width(degreetext);
+ const double degheight=fmsmall.boundingRect(degreetext).height();
+ const double degree_overwidth=(degwidth>smalltextIndent)?(degwidth-smalltextIndent):0.0;
+
//painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
QPen p=painter.pen();
p.setColor(currentEv.color);
- p.setWidthF(fm.lineWidth());
+ p.setWidthF(linewidth);
+ p.setCapStyle(Qt::RoundCap);
+ p.setJoinStyle(Qt::RoundJoin);
//painter.setPen(p);
- QPainterPath path;
- if (w>0) {
- path.moveTo(x+0.1*w, y-0.4*a);
- path.lineTo(x+0.33*w, y-0.4*a);
- path.lineTo( x+0.66*w, y+0.5*d);
- path.lineTo(x+w, y-a);
- }
- if (degree!=2) {
- fsmall.setPointSizeF(fsmall.pointSizeF()/2.0);
- fsmall.setItalic(false);
- painter.setFont(fsmall);
- painter.drawText(QPointF(x+0.33*w, y-0.55*a), QLocale::c().toString(degree));
- }
- //painter.restore();
- double xnew=getChild()->draw(painter, x+1.2*w, y, currentEv);
- painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
- painter.setPen(p);
- if (w>0) {
- path.lineTo( xnew+0.2*w, y-a);
- path.lineTo(xnew+0.2*w, y-0.8*a);
+
+ 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 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;
+ const double x_tinyhooktop=x_start+tinyhookSize;
+ 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+fmsmall.ascent()+(fabs(y_top-(y_tinyhooktop-linewidth))-degheight)/2.0;
+ if (sqrtwidth>0) {
+ QPainterPath path;
+ path.moveTo(x_start, y_tinyhooktop+tinyhookSize);
+ path.lineTo(x_tinyhooktop, y_tinyhooktop);
+ path.lineTo(x_hookbottom, y_bottom);
+ path.lineTo(x_hooktop, y_top);
+ path.lineTo(xnew-linewidth/2.0, y_top);
+ path.moveTo(x_tinyhooktop,y_tinyhooktop);
+ path.lineTo(x_tinyhooktop+linewidth*0.8, y_tinyhooktop-linewidth*0.8);
+ path.lineTo(x_hookbottom, y_bottom-2.0*linewidth);
+ painter.setPen(p);
painter.drawPath(path);
}
+ if (degree!=2) {
+ painter.setFont(fsmall);
+ painter.drawText(QPointF(x_smalltextend-degwidth, y_smalltext), degreetext);
+ }
- return xnew+0.33*w;
+ return xnew;
}
bool JKQTMathTextSqrtNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.h b/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.h
index c9da40e0c5..a14da4087d 100644
--- a/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.h
+++ b/lib/jkqtmathtext/nodes/jkqtmathtextsqrtnode.h
@@ -35,6 +35,10 @@ class JKQTMathText; // forward
/** \brief subclass representing a sqrt node
* \ingroup jkqtmathtext_items
+ *
+ * This node renders square roots without and with an explicitly shown degree:
+ * \image html jkqtmathtext/jkqtmathtext_sqrt.png
+ * \image html jkqtmathtext/jkqtmathtext_cbrt.png
*/
class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSqrtNode: public JKQTMathTextSingleChildNode {
public: