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 <axel.spoerl@qt.io>
(cherry picked from commit 99c1465215beac52fad4c6772c9bfef2209157e4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
David Faure 2024-07-18 01:46:58 +02:00 committed by Qt Cherry-pick Bot
parent abb231a2f0
commit f7eddcdcb1

View File

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