summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-03-09 13:13:58 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2010-03-09 14:04:09 (GMT)
commitd85b149a5c7f3532f8e1a593a79298c9ae38a95f (patch)
tree61446d8e6a65ccc2fa0c30c2b2a345a47895b77d
parent6396e7a15079cb157caef319348a0bcd0b95a6a7 (diff)
downloadQt-d85b149a5c7f3532f8e1a593a79298c9ae38a95f.zip
Qt-d85b149a5c7f3532f8e1a593a79298c9ae38a95f.tar.gz
Qt-d85b149a5c7f3532f8e1a593a79298c9ae38a95f.tar.bz2
Fix alignment of text with negative right bearing
In change 5364fd96a72c89b281f0540da909fe64d0575ccf and some related changes, we made sure that the natural text width used for calculating bounding rects and line breaks in the text, takes the right bearing of the last glyph into consideration. As a side-effect, this broke alignment of text, as we want to align based on the accumulated advance of the glyphs, not based on the actual width. This is in particular important when aligning monospaced text, since the text can become misaligned if the glyphs extend beyond their advance. The bug was visible e.g. in line numbers ending with 2 in Qt Creator on X11, which would be shifted one pixel to the left compared to other line numbers. Task-number: QTBUG-8864 Reviewed-by: Thorbjørn
-rw-r--r--src/gui/painting/qpainter.cpp5
-rw-r--r--src/gui/text/qtextengine_p.h1
-rw-r--r--src/gui/text/qtextlayout.cpp2
3 files changed, 6 insertions, 2 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index dc96c17..9e2fc82 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -7994,10 +7994,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 af91603..cc6793d 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -1875,6 +1875,7 @@ void QTextLine::layout_helper(int maxGlyphs)
line.textWidth += lbh.softHyphenWidth;
}
+ line.textAdvance = line.textWidth;
line.textWidth += lbh.rightBearing;
goto found;
@@ -1885,6 +1886,7 @@ void QTextLine::layout_helper(int maxGlyphs)
}
LB_DEBUG("reached end of line");
lbh.checkFullOtherwiseExtend(line);
+ line.textAdvance = line.textWidth;
line.textWidth += lbh.rightBearing;
found: