summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextlayout.cpp
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-05-09 16:14:34 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-17 04:47:32 +0200
commitd07982b104de5dc2b54bef09c071500ce22cf539 (patch)
treef72110e14aabe4b21adf6298f0fc2f630ccaa4c1 /src/gui/text/qtextlayout.cpp
parent438787b0ca18b08993bfa640ddf0ad5e6d2340e8 (diff)
Fix cursorToX for right to left text with trailing whitespace.
QTextLine::cursorToX returned the line width for cursor positions outside the width of a wrapped right to left line because the leading space width was always calculated as 0. Returning a non-zero width for the leading space does cause problems for other uses of QTextEngine::alignLine() though as the textAdvance already doesn't include the leading/trailing space so subtracting it there double accounts for it. Task-number: QTBUG-24801 Change-Id: I56cbb139814c32813bebb49de8c045b29154a958 Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
Diffstat (limited to 'src/gui/text/qtextlayout.cpp')
-rw-r--r--src/gui/text/qtextlayout.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index 0ab964778a..43d212f394 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -2584,13 +2584,14 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const
bool lastLine = index >= eng->lines.size() - 1;
QFixed x = line.x;
- x += eng->alignLine(line);
+ x += eng->alignLine(line) - eng->leadingSpaceWidth(line);
if (!index && !eng->layoutData->items.size()) {
*cursorPos = 0;
return x.toReal();
}
+ int lineEnd = line.from + line.length + line.trailingSpaces;
int pos = *cursorPos;
int itm;
const HB_CharAttributes *attributes = eng->attributes();
@@ -2598,9 +2599,9 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const
*cursorPos = 0;
return x.toReal();
}
- while (pos < line.from + line.length && !attributes[pos].charStop)
+ while (pos < lineEnd && !attributes[pos].charStop)
pos++;
- if (pos == line.from + (int)line.length) {
+ if (pos == lineEnd) {
// end of line ensure we have the last item on the line
itm = eng->findItem(pos-1);
}
@@ -2633,7 +2634,6 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const
bool reverse = eng->layoutData->items[itm].analysis.bidiLevel % 2;
- int lineEnd = line.from + line.length;
// add the items left of the cursor
@@ -2705,6 +2705,8 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const
if (eng->option.wrapMode() != QTextOption::NoWrap && x > line.width)
x = line.width;
+ if (eng->option.wrapMode() != QTextOption::NoWrap && x < 0)
+ x = 0;
*cursorPos = pos + si->position;
return x.toReal();