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)
This commit is contained in:
Jiang Jiang 2011-04-19 14:40:19 +02:00
parent d623257584
commit 044e7602ae
2 changed files with 4 additions and 1 deletions

View File

@ -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;
}

View File

@ -1060,6 +1060,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVector<FormatRang
QRectF lineRect(tl.naturalTextRect());
lineRect.translate(position);
lineRect.adjust(0, 0, d->leadingSpaceWidth(sl).toReal(), 0);
bool isLastLineInBlock = (line == d->lines.size()-1);
int sl_length = sl.length + (isLastLineInBlock? 1 : 0); // the infamous newline