From 24914b1acbfc5e45768dd1465b9e3f3e61185829 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 18 Mar 2016 15:49:58 +0100 Subject: Qt Quick: Fix bug for selections with line wraps and breaks This fixes yet another bug where the selection spans both line wraps and explicit line breaks. Offsetting the log clusters by the text position in 342c909b340cb1bfbb95480fc79dcea21a470c83 was not entirely correct, because in some cases the script item will refer to a specific part of the string, as indicated by si.position, while iterator.itemStart is in the context of the full string. In this case, the log cluster array pointer we use refers to the script item's part of the array, i.e. it is already offset by si.position. Therefore, we must offset the logClusters pointer by the text position *relative* to the current script item. Previously we would actually offset by si.position twice in cases where si.position != 0. We want the text range to refer to the full string, though, so it can be compared to other text ranges later. However, in some cases when we are requesting only part of a script item, then iterator.itemStart does not correspond to relativeFrom, so in order for the text range search to work, we must pass in the text positions we are using [relativeFrom, relativeTo], though offset by si.position so that it refers to the full string and not just the part addressed by the script item. Task-number: QTBUG-51759 Change-Id: Ib69856d6d3bc1dd501db94c9d295623f436d122c Reviewed-by: Konstantin Ritt Reviewed-by: Simon Hausmann --- src/gui/text/qtextlayout.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/gui/text/qtextlayout.cpp') diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index bc9c452ff7..aca475a581 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -2141,7 +2141,6 @@ static QGlyphRun glyphRunWithInfo(QFontEngine *fontEngine, QGlyphRunPrivate *d = QGlyphRunPrivate::get(glyphRun); int rangeStart = textPosition; - logClusters += textPosition; while (*logClusters != glyphsStart && rangeStart < textPosition + textLength) { ++logClusters; ++rangeStart; @@ -2350,9 +2349,9 @@ QList QTextLine::glyphRuns(int from, int length) const width, glyphsStart + start, glyphsStart + end, - logClusters, - iterator.itemStart, - iterator.itemLength)); + logClusters + relativeFrom, + relativeFrom + si.position, + relativeTo - relativeFrom + 1)); for (int i = 0; i < subLayout.numGlyphs; ++i) { QFixed justification = QFixed::fromFixed(subLayout.justifications[i].space_18d6); pos.rx() += (subLayout.advances[i] + justification).toReal(); @@ -2380,9 +2379,9 @@ QList QTextLine::glyphRuns(int from, int length) const width, glyphsStart + start, glyphsStart + end, - logClusters, - iterator.itemStart, - iterator.itemLength); + logClusters + relativeFrom, + relativeFrom + si.position, + relativeTo - relativeFrom + 1); if (!glyphRun.isEmpty()) glyphRuns.append(glyphRun); } else { @@ -2396,9 +2395,9 @@ QList QTextLine::glyphRuns(int from, int length) const width, glyphsStart, glyphsEnd, - logClusters, - iterator.itemStart, - iterator.itemLength); + logClusters + relativeFrom, + relativeFrom + si.position, + relativeTo - relativeFrom + 1); if (!glyphRun.isEmpty()) glyphRuns.append(glyphRun); } -- cgit v1.2.3