From 4085d3eef59763b91ae63818b5885e1027eef3c1 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 27 May 2010 12:04:19 +0200 Subject: Back port change d85b149a5c7f3532f8e1a593a79298c9ae38a95f Fixes right alignment of monospaced text, which was a regression in Qt 4.6.0. Initially it was fixed in Qt 4.7 only, but the regression was later deemed severe enough to fix in 4.6.x as well. Task-number: QTBUG-8864 Reviewed-by: thorbjorn --- src/gui/painting/qpainter.cpp | 5 +++-- src/gui/text/qtextengine_p.h | 1 + src/gui/text/qtextlayout.cpp | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 96981af..6055a04 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -7806,10 +7806,11 @@ start_lengthVariant: for (int i = 0; i < textLayout.lineCount(); i++) { QTextLine line = textLayout.lineAt(i); + qreal advance = textLayout.engine()->lines[i].textAdvance.toReal(); if (tf & Qt::AlignRight) - xoff = r.width() - line.naturalTextWidth(); + xoff = r.width() - advance; else if (tf & Qt::AlignHCenter) - xoff = (r.width() - line.naturalTextWidth())/2; + xoff = (r.width() - advance)/2; line.draw(painter, QPointF(r.x() + xoff + line.x(), r.y() + yoff)); } diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h index f36cbd2..5054b66 100644 --- a/src/gui/text/qtextengine_p.h +++ b/src/gui/text/qtextengine_p.h @@ -382,6 +382,7 @@ struct Q_AUTOTEST_EXPORT QScriptLine QFixed y; QFixed width; QFixed textWidth; + QFixed textAdvance; int from; signed int length : 29; mutable uint justified : 1; diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 3c0e85e..d4cb230 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1928,6 +1928,7 @@ void QTextLine::layout_helper(int maxGlyphs) found: if (lbh.rightBearing > 0) // If right bearing has not yet been adjusted lbh.adjustRightBearing(); + line.textAdvance = line.textWidth; line.textWidth -= qMin(QFixed(), lbh.rightBearing); if (line.length == 0) { -- cgit v0.12 From 3f74a095086f49be23f526a5adc7e65687a19c31 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 27 May 2010 13:14:20 +0200 Subject: Fix regression with Qt::AlignRight on monospaced text in QTextLayout For monospaced fonts, using the width (including the bearing) of the text to align it to the right hand side, will break alignment of columns of characters. To fix the problem, we go back to the old procedure, by using the advance of the text as basis of alignment instead. Done-by: thorbjorn Reviewed-by: Eskil --- src/gui/text/qtextlayout.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index d4cb230..c5dd854 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -89,9 +89,9 @@ static QFixed alignLine(QTextEngine *eng, const QScriptLine &line) if (align & Qt::AlignJustify && eng->option.textDirection() == Qt::RightToLeft) align = Qt::AlignRight; if (align & Qt::AlignRight) - x = line.width - (line.textWidth + leadingSpaceWidth(eng, line)); + x = line.width - (line.textAdvance + leadingSpaceWidth(eng, line)); else if (align & Qt::AlignHCenter) - x = (line.width - line.textWidth)/2; + x = (line.width - line.textAdvance)/2; } return x; } -- cgit v0.12