diff options
author | Jiang Jiang <jiang.jiang@nokia.com> | 2011-09-08 16:31:53 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-17 03:20:28 +0200 |
commit | c298b0b153b91505b83d2a5f105194b18ae0d710 (patch) | |
tree | 49059eacabadd89782d39b55430ee4af50009385 /src | |
parent | 8dcb52df8e2e949232ccded9fad5a4f25ba6dda2 (diff) |
Fix trailing spaces problem by not adding it to QScriptLine.length
It seems to be the only sane way to fix it. Previous attempts to
fix it by compensating the trailing space width all failed in some
cases, one of the trickiest is when we are having embedded LTR text
that has trailing spaces in a RTL paragraph.
In this patch we leave line.length not including the trailing space
length, but saving it to a separated variable, so that we can always
add it back when needed (QTextLine::textLength() for instance).
It fixed all the problems in different alignments of both RTL and
LTR text. And no regression is found yet.
Reviewed-by: Eskil
(cherry picked from commit 80294c375eca9687d1c34e9ab048294373e7f00c)
Change-Id: Id248ab6f54f8cc25ba0e9d1626703463dfefbcea
Reviewed-on: http://codereview.qt-project.org/4778
Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qtextengine.cpp | 2 | ||||
-rw-r--r-- | src/gui/text/qtextengine_p.h | 3 | ||||
-rw-r--r-- | src/gui/text/qtextlayout.cpp | 7 |
3 files changed, 7 insertions, 5 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 97d5a3baaf..93c9e1e06f 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -2956,7 +2956,7 @@ int QTextEngine::lineNumberForTextPosition(int pos) return lines.size() - 1; for (int i = 0; i < lines.size(); ++i) { const QScriptLine& line = lines[i]; - if (line.from + line.length > pos) + if (line.from + line.length + line.trailingSpaces > pos) return i; } return -1; diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h index 325623fc63..fd11b9f658 100644 --- a/src/gui/text/qtextengine_p.h +++ b/src/gui/text/qtextengine_p.h @@ -378,7 +378,7 @@ struct Q_AUTOTEST_EXPORT QScriptLine { // created and filled in QTextLine::layout_helper QScriptLine() - : from(0), length(0), + : from(0), trailingSpaces(0), length(0), justified(0), gridfitted(0), hasTrailingSpaces(0), leadingIncluded(0) {} QFixed descent; @@ -390,6 +390,7 @@ struct Q_AUTOTEST_EXPORT QScriptLine QFixed textWidth; QFixed textAdvance; int from; + unsigned short trailingSpaces; signed int length : 28; mutable uint justified : 1; mutable uint gridfitted : 1; diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 5539acffd7..cd45d3ac5e 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -805,7 +805,7 @@ QTextLine QTextLayout::createLine() if (l && d->lines.at(l-1).length < 0) { QTextLine(l-1, d).setNumColumns(INT_MAX); } - int from = l > 0 ? d->lines.at(l-1).from + d->lines.at(l-1).length : 0; + int from = l > 0 ? d->lines.at(l-1).from + d->lines.at(l-1).length + d->lines.at(l-1).trailingSpaces : 0; int strlen = d->layoutData->string.length(); if (l && from >= strlen) { if (!d->lines.at(l-1).length || d->layoutData->string.at(strlen - 1) != QChar::LineSeparator) @@ -1728,6 +1728,7 @@ void QTextLine::layout_helper(int maxGlyphs) { QScriptLine &line = eng->lines[i]; line.length = 0; + line.trailingSpaces = 0; line.textWidth = 0; line.hasTrailingSpaces = false; @@ -1951,7 +1952,7 @@ found: if (eng->option.flags() & QTextOption::IncludeTrailingSpaces) line.textWidth += lbh.spaceData.textWidth; if (lbh.spaceData.length) { - line.length += lbh.spaceData.length; + line.trailingSpaces = lbh.spaceData.length; line.hasTrailingSpaces = true; } @@ -2015,7 +2016,7 @@ int QTextLine::textLength() const && eng->block.isValid() && i == eng->lines.count()-1) { return eng->lines[i].length - 1; } - return eng->lines[i].length; + return eng->lines[i].length + eng->lines[i].trailingSpaces; } static void drawMenuText(QPainter *p, QFixed x, QFixed y, const QScriptItem &si, QTextItemInt &gf, QTextEngine *eng, |