From 4b4075c226b49a3bfce051389cd853893cdadd75 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Sat, 1 Jul 2023 15:09:38 +0200 Subject: [PATCH] JKQTMathText: fixed super-script sizing (using tightboundingbox around x instead of xHeight(), which caused some problems recently for several standard fonts --- .../nodes/jkqtmathtextsubsupernode.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.cpp index 3bfe701bb2..e47d7f9a60 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextsubsupernode.cpp @@ -49,11 +49,15 @@ JKQTMathTextNodeSize JKQTMathTextSuperscriptNode::getSizeWithSpecialPlacement(QP 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()); + const QFont fnt=currentEv.getFont(parentMathText); + const QFontMetricsF fm(fnt, painter.device()); + //const QRectF tbr_of_letterM=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device()); const JKQTMathTextNodeSize cs=getChild()->getSize(painter, ev); const double childDescent=cs.getDescent(); - double shiftToChildBottom=parentMathText->getSuperShiftFactor()*fm.xHeight(); + const QRectF tbr=JKQTMathTextGetTightBoundingRect(fnt, "x", painter.device()); + const double xh=tbr.height(); + + double shiftToChildBottom=parentMathText->getSuperShiftFactor()*xh;//fm.xHeight(); if (prevNodeSizeForSpecialPlacement!=nullptr) { const double modifiedShift=prevNodeSizeForSpecialPlacement->baselineHeight-childDescent-parentMathText->getSpecialSuperShiftFactor()*cs.baselineHeight-childDescent; @@ -78,11 +82,14 @@ double JKQTMathTextSuperscriptNode::drawWithSpecialPlacement(QPainter& painter, ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor(); const JKQTMathTextNodeSize cs=getChild()->getSize(painter, ev); - - const QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device()); + const QFont fnt=currentEv.getFont(parentMathText); + const QFontMetricsF fm(fnt, painter.device()); + const QRectF tbr=JKQTMathTextGetTightBoundingRect(fnt, "x", painter.device()); + const double xh=tbr.height(); + //qDebug()<<"x="<getSuperShiftFactor()*fm.xHeight(); + double shiftToChildBottom=parentMathText->getSuperShiftFactor()*xh;//fm.xHeight(); if (prevNodeSizeForSpecialPlacement!=nullptr) { const double modifiedShift=prevNodeSizeForSpecialPlacement->baselineHeight-childDescent-parentMathText->getSpecialSuperShiftFactor()*cs.baselineHeight-childDescent;