diff options
author | Dominik Holland <dominik.holland@qt.io> | 2020-06-12 13:50:18 +0200 |
---|---|---|
committer | Dominik Holland <dominik.holland@qt.io> | 2020-06-18 14:59:02 +0200 |
commit | e11939afee9b79127247d3b5ba0ce57b306a7dd6 (patch) | |
tree | 7656f7127c13de66aa67ec2ac9a0c635d605d383 /src/gui/text/qtextlayout.cpp | |
parent | c1e5044d22367d9088329b796d383a0ae72a47bb (diff) |
Fix the vertical alignment of images in a text document
Try to align with the HTML standard as much as possible.
AlignBottom is now really the bottom of the line (not the text).
AlignMiddle is between AlignTop and AlignBottom.
Change-Id: Ia067b96209c2ab0becbff99cf15bb8ab193ee2c6
Fixes: QTBUG-84981
Pick-to: 5.15
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/gui/text/qtextlayout.cpp')
-rw-r--r-- | src/gui/text/qtextlayout.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 72d409f638..53523f3abd 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -2097,6 +2097,10 @@ found: current.ascent = line.ascent; current.descent = height - line.ascent; break; + case QTextCharFormat::AlignMiddle: + current.ascent = (line.ascent + line.descent) / 2 - line.descent + height / 2; + current.descent = height - line.ascent; + break; case QTextCharFormat::AlignBottom: current.descent = line.descent; current.ascent = height - line.descent; @@ -2554,6 +2558,7 @@ void QTextLine::draw(QPainter *p, const QPointF &pos, const QTextLayout::FormatR QFont f = eng->font(si); QTextCharFormat format; + if (eng->hasFormats() || selection) { format = eng->format(&si); if (suppressColors) { @@ -2584,10 +2589,18 @@ void QTextLine::draw(QPainter *p, const QPointF &pos, const QTextLayout::FormatR p->save(); if (si.analysis.flags == QScriptAnalysis::Object && QTextDocumentPrivate::get(eng->block)) { QFixed itemY = y - si.ascent; - if (format.verticalAlignment() == QTextCharFormat::AlignTop) { + switch (format.verticalAlignment()) { + case QTextCharFormat::AlignTop: itemY = y - lineBase; - } else if (format.verticalAlignment() == QTextCharFormat::AlignBottom) { - itemY = y + line.descent - si.ascent - si.descent; + break; + case QTextCharFormat::AlignMiddle: + itemY = y - lineBase + (line.height() - si.height()) / 2; + break; + case QTextCharFormat::AlignBottom: + itemY = y - lineBase + line.height() - si.height(); + break; + default: + break; } QRectF itemRect(iterator.x.toReal(), itemY.toReal(), iterator.itemWidth.toReal(), si.height().toReal()); |