From: Jiang Jiang Date: Fri, 20 May 2011 08:26:54 +0000 (+0200) Subject: Fix ligature offset in multi-line text X-Git-Tag: qt-v5.0.0-alpha1~4230 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=37f20ea8e64afa2d29d9fb56ac34ff405367a2b8;p=profile%2Fivi%2Fqtbase.git Fix ligature offset in multi-line text Reviewed-by: Eskil (cherry picked from commit 278cf1f37945050c4a46d5acab0659f3a7546a43) Change-Id: Ice20aa38a49ea16cf56bd3705c7d400ee165a9c2 Reviewed-on: http://codereview.qt.nokia.com/195 Reviewed-by: Jiang Jiang --- diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 9e067d7..2e2a623 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -2609,8 +2609,8 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const } else { bool rtl = eng->isRightToLeft(); bool visual = eng->visualCursorMovement(); + int end = qMin(lineEnd, si->position + l) - si->position; if (reverse) { - int end = qMin(lineEnd, si->position + l) - si->position; int glyph_end = end == l ? si->num_glyphs : logClusters[end]; int glyph_start = glyph_pos; if (visual && !rtl && !(lastLine && itm == (visualOrder[nItems - 1] + firstItem))) @@ -2626,7 +2626,7 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const for (int i = glyph_start; i <= glyph_end; i++) x += glyphs.effectiveAdvance(i); } - x += eng->offsetInLigature(si, pos, line.length, glyph_pos); + x += eng->offsetInLigature(si, pos, end, glyph_pos); } *cursorPos = pos + si->position; diff --git a/tests/auto/qtextlayout/tst_qtextlayout.cpp b/tests/auto/qtextlayout/tst_qtextlayout.cpp index b6adc2b..be0a83f 100644 --- a/tests/auto/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/qtextlayout/tst_qtextlayout.cpp @@ -127,6 +127,7 @@ private slots: void textWithSurrogates_qtbug15679(); void textWidthWithStackedTextEngine(); void textWidthWithLineSeparator(); + void cursorInLigatureWithMultipleLines(); private: QFont testFont; @@ -1460,5 +1461,21 @@ void tst_QTextLayout::textWidthWithLineSeparator() QCOMPARE(line1.naturalTextWidth(), line2.naturalTextWidth()); } +void tst_QTextLayout::cursorInLigatureWithMultipleLines() +{ +#if !defined(Q_WS_MAC) + QSKIP("This test can not be run on Mac", SkipAll); +#endif + QTextLayout layout("first line finish", QFont("Times", 20)); + layout.beginLayout(); + QTextLine line = layout.createLine(); + line.setLineWidth(70); + line = layout.createLine(); + layout.endLayout(); + + // The second line will be "finish", with "fi" as a ligature + QVERIFY(line.cursorToX(0) != line.cursorToX(1)); +} + QTEST_MAIN(tst_QTextLayout) #include "tst_qtextlayout.moc"