diff options
author | Dominik Holland <dominik.holland@qt.io> | 2020-06-12 10:36:08 +0200 |
---|---|---|
committer | Dominik Holland <dominik.holland@qt.io> | 2020-06-17 16:39:54 +0200 |
commit | d28c625006c1b54fc3d39637a7b33e42fadb72a9 (patch) | |
tree | fea04608247301695a9e0691c88a325abfebe5f0 /src/quick/items/qquicktextnodeengine.cpp | |
parent | 899e69d0407d7b2206e1308d96960934880469cb (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
Pick-to: 5.15
Change-Id: Ie99aef0d09a6ece751883492748630526c4a1195
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/quick/items/qquicktextnodeengine.cpp')
-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 82bd9cd4ec..19df175115 100644 --- a/src/quick/items/qquicktextnodeengine.cpp +++ b/src/quick/items/qquicktextnodeengine.cpp @@ -477,6 +477,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()) @@ -484,11 +487,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; |