diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com> | 2012-12-11 13:33:04 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-19 12:28:14 (GMT) |
commit | 99288633373ecc8ba808cf0ecf18f4a81d62ac84 (patch) | |
tree | dd54685ab5724c9db57bf08326e230bb02de1e4d /src | |
parent | 0deddff9c8ca7e1a1e9288a09bc015fd7ea0fd03 (diff) | |
download | Qt-99288633373ecc8ba808cf0ecf18f4a81d62ac84.zip Qt-99288633373ecc8ba808cf0ecf18f4a81d62ac84.tar.gz Qt-99288633373ecc8ba808cf0ecf18f4a81d62ac84.tar.bz2 |
Backport adjusting cursorToX for trailing spaces from Qt 5
This is a backport of d07982b104de5dc2b54bef09c071500ce22cf539
from Qt 5 which fixes cursorToX() in some cases, e.g. when
a line filled with spaces is ended by a soft line break.
Task-number: QTBUG-27354
Change-Id: Ia88873aeb3c0620044fefe24fc6bb1310e3aa339
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Reviewed-by: Andrew den Exter <andrew.den.exter@qinetic.com.au>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qtextengine.cpp | 14 | ||||
-rw-r--r-- | src/gui/text/qtextlayout.cpp | 11 |
2 files changed, 10 insertions, 15 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index b368fd9..319829d 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -2826,13 +2826,7 @@ QFixed QTextEngine::leadingSpaceWidth(const QScriptLine &line) || !isRightToLeft()) return QFixed(); - int pos = line.length; - const HB_CharAttributes *attributes = this->attributes(); - if (!attributes) - return QFixed(); - while (pos > 0 && attributes[line.from + pos - 1].whiteSpace) - --pos; - return width(line.from + pos, line.length - pos); + return width(line.from + line.length, line.trailingSpaces); } QFixed QTextEngine::alignLine(const QScriptLine &line) @@ -2842,14 +2836,12 @@ 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)); + x = line.width - (line.textAdvance); else if (align & Qt::AlignHCenter) - x = (line.width - line.textAdvance)/2 - leadingSpaceWidth(line); + x = (line.width - line.textAdvance)/2; } return x; } diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 4b26eb5..bb216e9 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -2498,13 +2498,14 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const bool lastLine = i >= eng->lines.size() - 1; QFixed x = line.x; - x += eng->alignLine(line); + x += eng->alignLine(line) - eng->leadingSpaceWidth(line); if (!i && !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(); @@ -2512,9 +2513,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); } @@ -2546,7 +2547,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 @@ -2619,6 +2619,9 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const if (eng->option.wrapMode() != QTextOption::NoWrap && x > line.x + line.width) x = line.x + line.width; + if (eng->option.wrapMode() != QTextOption::NoWrap && x < 0) + x = 0; + *cursorPos = pos + si->position; return x.toReal(); } |