From 57993ba7a181c92acfa8a0213ed1260c3b85fbd4 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Mon, 4 Jul 2011 11:14:42 +0200 Subject: Fix horizontal center alignment with trailing space Text drawn with horizontal center alignment (AlignHCenter) and QTextOption::IncludeTrailingSpaces flag as off should consider the trailing space width (leading space width for RTL lines), because textAdvance here ignores the space. Disregard that space width here in alignLine will make RTL lines aligned a bit to the right. In short, for something like this: |w1|space|text|w2| |<- totalWidth ->| we want to have w1 + spaceWidth = w2 = (totalWidth - textWidth)/2, so that the actual rendered text will appear at the center of the bounding rect. Task-number: QTBUG-18303 Reviewed-by: Eskil --- src/gui/text/qtextlayout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 4b3c9e7..0fbf838 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -76,7 +76,7 @@ static QFixed alignLine(QTextEngine *eng, const QScriptLine &line) if (align & Qt::AlignRight) x = line.width - (line.textAdvance + eng->leadingSpaceWidth(line)); else if (align & Qt::AlignHCenter) - x = (line.width - line.textAdvance)/2; + x = (line.width - (line.textAdvance))/2 - eng->leadingSpaceWidth(line); } return x; } -- cgit v0.12