From f7eddcdcb12b9855e485e32924a41f3b2be6137a Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 18 Jul 2024 01:46:58 +0200 Subject: [PATCH] QTextDocument: repair AlignBaseline for inline objects The code from QTBUG-14414 (Qt4 commit ee9455ed2a83084692d969c398ecb91bcd4fc33a) was removed in commit 199f9c54484b0dae3bc81f83c880a965192ecb24, due to an oversight: that commit was only about images, while there's also the case of inline objects that contain actual text. Such objects are easy to overlook because they are not provided by Qt itself. They are however common in applications that implement word-processor-looking "variables", like a place-holder for "page number", for instance). Pick-to: 6.7 Change-Id: I2ff1476583bdfe24abcc523cffb65ce116b7faf9 Reviewed-by: Axel Spoerl (cherry picked from commit 99c1465215beac52fad4c6772c9bfef2209157e4) Reviewed-by: Qt Cherry-pick Bot --- src/gui/text/qtextdocumentlayout.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index 452f814231c..1eb0665dfdd 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -3896,14 +3896,25 @@ void QTextDocumentLayout::resizeInlineObject(QTextInlineObject item, int posInDo QSizeF inlineSize = (pos == QTextFrameFormat::InFlow ? intrinsic : QSizeF(0, 0)); item.setWidth(inlineSize.width()); - if (f.verticalAlignment() == QTextCharFormat::AlignMiddle) { + switch (f.verticalAlignment()) { + case QTextCharFormat::AlignMiddle: { QFontMetrics m(f.font()); qreal halfX = m.xHeight()/2.; item.setAscent((inlineSize.height() + halfX) / 2.); item.setDescent((inlineSize.height() - halfX) / 2.); - } else { + break; + } + case QTextCharFormat::AlignBaseline: { + QFontMetrics m(f.font()); + qreal descent = m.descent(); + item.setDescent(descent); + item.setAscent(inlineSize.height() - descent); + break; + } + default: item.setDescent(0); item.setAscent(inlineSize.height()); + break; } }