summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/text/qtextengine.cpp2
-rw-r--r--src/gui/text/qtextengine_p.h3
-rw-r--r--src/gui/text/qtextlayout.cpp6
3 files changed, 6 insertions, 5 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 6f07131..a0e1751 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -2951,7 +2951,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 b1bd0c3..0a86886 100644
--- a/src/gui/text/qtextengine_p.h
+++ b/src/gui/text/qtextengine_p.h
@@ -376,7 +376,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;
@@ -388,6 +388,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 4fd6ddf..cf361a0 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -814,7 +814,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)
@@ -1931,7 +1931,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;
}
@@ -1995,7 +1995,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,