From 044e7602ae72889f363d688dbe0d73cec5f0636a Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Tue, 19 Apr 2011 14:40:19 +0200 Subject: [PATCH] Take leading space width into account for painting and selection When painting horizontally centered RTL text and selection with trailing spaces, we need to take that space width into account because line.textAdvance doesn't include it. Task-number: QTBUG-18612 Reviewed-by: Eskil (cherry picked from commit 224226727f07e8940e0d3131fe7587b11cc4a6ca) --- src/gui/text/qtextengine.cpp | 4 +++- src/gui/text/qtextlayout.cpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index dab4bb7..ce012a8 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -2777,12 +2777,14 @@ QFixed QTextEngine::alignLine(const QScriptLine &line) // if width is QFIXED_MAX that means we used setNumColumns() and that implicitly makes this line left aligned. if (!line.justified && line.width != QFIXED_MAX) { int align = option.alignment(); + if (align & Qt::AlignLeft) + x -= leadingSpaceWidth(line); if (align & Qt::AlignJustify && isRightToLeft()) align = Qt::AlignRight; if (align & Qt::AlignRight) x = line.width - (line.textAdvance + leadingSpaceWidth(line)); else if (align & Qt::AlignHCenter) - x = (line.width - line.textAdvance)/2; + x = (line.width - (line.textAdvance + leadingSpaceWidth(line)))/2; } return x; } diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 9fc4e7f..cb5ba0e 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1060,6 +1060,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVectorleadingSpaceWidth(sl).toReal(), 0); bool isLastLineInBlock = (line == d->lines.size()-1); int sl_length = sl.length + (isLastLineInBlock? 1 : 0); // the infamous newline -- 2.7.4