JKQTMathText: fixed super-script sizing (using tightboundingbox around x instead of xHeight(), which caused some problems recently for several standard fonts

This commit is contained in:
jkriege2 2023-07-01 15:09:38 +02:00
parent 8719208acf
commit 4b4075c226

View File

@ -49,11 +49,15 @@ JKQTMathTextNodeSize JKQTMathTextSuperscriptNode::getSizeWithSpecialPlacement(QP
JKQTMathTextNodeSize s; JKQTMathTextNodeSize s;
JKQTMathTextEnvironment ev=currentEv; JKQTMathTextEnvironment ev=currentEv;
ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor(); ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor();
const QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device()); const QFont fnt=currentEv.getFont(parentMathText);
const QRectF tbr_of_letterM=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device()); 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 JKQTMathTextNodeSize cs=getChild()->getSize(painter, ev);
const double childDescent=cs.getDescent(); 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) { if (prevNodeSizeForSpecialPlacement!=nullptr) {
const double modifiedShift=prevNodeSizeForSpecialPlacement->baselineHeight-childDescent-parentMathText->getSpecialSuperShiftFactor()*cs.baselineHeight-childDescent; 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(); ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor();
const JKQTMathTextNodeSize cs=getChild()->getSize(painter, ev); const JKQTMathTextNodeSize cs=getChild()->getSize(painter, ev);
const QFont fnt=currentEv.getFont(parentMathText);
const QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device()); const QFontMetricsF fm(fnt, painter.device());
const QRectF tbr=JKQTMathTextGetTightBoundingRect(fnt, "x", painter.device());
const double xh=tbr.height();
//qDebug()<<"x="<<x<<" prevNodeSizeForSpecialPlacement="<<prevNodeSizeForSpecialPlacement<<" font="<<currentEv.getFont(parentMathText);
//QRectF tbr_of_letterM=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device()); //QRectF tbr_of_letterM=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
const double childDescent=cs.overallHeight-cs.baselineHeight; const double childDescent=cs.overallHeight-cs.baselineHeight;
double shiftToChildBottom=parentMathText->getSuperShiftFactor()*fm.xHeight(); double shiftToChildBottom=parentMathText->getSuperShiftFactor()*xh;//fm.xHeight();
if (prevNodeSizeForSpecialPlacement!=nullptr) { if (prevNodeSizeForSpecialPlacement!=nullptr) {
const double modifiedShift=prevNodeSizeForSpecialPlacement->baselineHeight-childDescent-parentMathText->getSpecialSuperShiftFactor()*cs.baselineHeight-childDescent; const double modifiedShift=prevNodeSizeForSpecialPlacement->baselineHeight-childDescent-parentMathText->getSpecialSuperShiftFactor()*cs.baselineHeight-childDescent;