summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextdocumentlayout.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-11-09 15:57:42 +0100
committerLiang Qi <liang.qi@qt.io>2018-11-19 11:45:09 +0000
commit199f9c54484b0dae3bc81f83c880a965192ecb24 (patch)
tree558d2d26da0ffcecd6485369535dad6b1da327be /src/gui/text/qtextdocumentlayout.cpp
parent4d180586cddbd71a67c83246db3bec1caa595e05 (diff)
Fix vertical alignment of inline images
Inline images can have 4 different alignments. Unfortunately, AlignTop and AlignBottom can only be set once we have laid out the whole line and know the total height of the line, as one could otherwise end up with lines that are too high. To fix this, position the images for these cases in a second loop after we have calculated the length of the line and the maximal image height in that line. Task-number: QTBUG-59310 Change-Id: I1fd4cd39e43a13d1967b9f5c9ce8270a99269cd9 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/gui/text/qtextdocumentlayout.cpp')
-rw-r--r--src/gui/text/qtextdocumentlayout.cpp18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp
index a9227f0171..9aeea44dd3 100644
--- a/src/gui/text/qtextdocumentlayout.cpp
+++ b/src/gui/text/qtextdocumentlayout.cpp
@@ -3049,18 +3049,12 @@ void QTextDocumentLayout::resizeInlineObject(QTextInlineObject item, int posInDo
QSizeF inlineSize = (pos == QTextFrameFormat::InFlow ? intrinsic : QSizeF(0, 0));
item.setWidth(inlineSize.width());
- QFontMetrics m(f.font());
- switch (f.verticalAlignment())
- {
- case QTextCharFormat::AlignMiddle:
- item.setDescent(inlineSize.height() / 2);
- item.setAscent(inlineSize.height() / 2);
- break;
- case QTextCharFormat::AlignBaseline:
- item.setDescent(m.descent());
- item.setAscent(inlineSize.height() - m.descent());
- break;
- default:
+ if (f.verticalAlignment() == QTextCharFormat::AlignMiddle) {
+ QFontMetrics m(f.font());
+ qreal halfX = m.xHeight()/2.;
+ item.setAscent((inlineSize.height() + halfX) / 2.);
+ item.setDescent((inlineSize.height() - halfX) / 2.);
+ } else {
item.setDescent(0);
item.setAscent(inlineSize.height());
}