Fix finding cursor position in words with accents

In positionInLigature() we were mixing indexes into the script item with
indexes into the entire string. The getClusterLength() function would expect
an attributes array for the current script item and it thus needs to be
adjusted by si->position. In addition, when looking for the next grapheme
boundary, we were comparing pos (which indexed the string) with end (which
indexed the script item). This has also now been fixed by adjusting for
si->position as well.

Task-number: QTBUG-30123
Change-Id: Id02e2eddcc5b7888eacb34bd1e39cc6911880ca1
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
bb10
Joshua Grauman 2013-10-26 15:25:03 -07:00 committed by The Qt Project
parent 43002e2572
commit f18fd0450c
1 changed files with 3 additions and 3 deletions

View File

@ -3100,7 +3100,7 @@ int QTextEngine::positionInLigature(const QScriptItem *si, int end,
glyph_pos--;
}
const QCharAttributes *attrs = attributes();
const QCharAttributes *attrs = attributes() + si->position;
logClusters = this->logClusters(si);
clusterLength = getClusterLength(logClusters, attrs, 0, end, glyph_pos, &clusterStart);
@ -3117,11 +3117,11 @@ int QTextEngine::positionInLigature(const QScriptItem *si, int end,
int closestItem = dist > (perItemWidth / 2) ? n + 1 : n;
if (cursorOnCharacter && closestItem > 0)
closestItem--;
int pos = si->position + clusterStart + closestItem;
int pos = clusterStart + closestItem;
// Jump to the next grapheme boundary
while (pos < end && !attrs[pos].graphemeBoundary)
pos++;
return pos;
return si->position + pos;
}
return si->position + end;
}