diff options
author | Dominik Holland <dominik.holland@qt.io> | 2020-06-12 10:36:08 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2020-06-17 19:35:27 +0000 |
commit | d1b1fa52a2fded9691f6be5ee864b30adab0db2b (patch) | |
tree | 1480d7334f1613a25d19dda736864ce9022588d6 | |
parent | d2471eb3ece7fee58dcb8819cc0ce953da832006 (diff) |
Fix the vertical alignment of images in a text document
Try to align with the HTML standard as much as possible.
AlignMiddle is between AlignTop and AlignBottom.
Fixes: QTBUG-84981
Change-Id: Ie99aef0d09a6ece751883492748630526c4a1195
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
(cherry picked from commit d28c625006c1b54fc3d39637a7b33e42fadb72a9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quick/items/qquicktextnodeengine.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp index a4d735d0e6..61a4529530 100644 --- a/src/quick/items/qquicktextnodeengine.cpp +++ b/src/quick/items/qquicktextnodeengine.cpp @@ -476,6 +476,9 @@ void QQuickTextNodeEngine::addTextObject(const QTextBlock &block, const QPointF } } + // Use https://developer.mozilla.org/de/docs/Web/CSS/vertical-align as a reference + // The top/bottom positions are supposed to be higher/lower than the text and reference + // the line height, not the text height (using QFontMetrics) qreal ascent; QTextLine line = block.layout()->lineForTextPosition(pos - block.position()); switch (format.verticalAlignment()) @@ -483,11 +486,10 @@ void QQuickTextNodeEngine::addTextObject(const QTextBlock &block, const QPointF case QTextCharFormat::AlignTop: ascent = line.ascent(); break; - case QTextCharFormat::AlignMiddle: { - QFontMetrics m(format.font()); - ascent = (size.height() - m.xHeight()) / 2; + case QTextCharFormat::AlignMiddle: + // Middlepoint of line (height - descent) + Half object height + ascent = (line.ascent() + line.descent()) / 2 - line.descent() + size.height() / 2; break; - } case QTextCharFormat::AlignBottom: ascent = size.height() - line.descent(); break; |