From 15414257b3719f2c302cca26efe40f2b3caa115b Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 4 Nov 2016 15:52:32 +0100 Subject: Don't count no-break spaces as trailing spaces No-break-spaces should not be counted in the space data, but rather be treated as any other non-breakable character. We were already taking care of this in the loop we reach if the item starts with a character which isn't whitespace, but there is a second loop for items that begin with whitespace characters. The result of this was that in certain circumstances where you gave the nbsp its own format and made the line wrap, the previous line would count an extra trailing space and it would swallow the first character in its following line. [ChangeLog][QtGui][Text] Fixed a bug where a no-break space would sometimes cause the first character of the containing line to not be displayed. Task-number: QTBUG-56714 Change-Id: Idd760a389052e6de70f6cc397122b217987fa5f2 Reviewed-by: Lars Knoll --- .../auto/gui/text/qtextlayout/tst_qtextlayout.cpp | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp') diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index 84d58191c0..22a4276b8e 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -142,6 +142,7 @@ private slots: void xToCursorForLigatures(); void cursorInNonStopChars(); void nbsp(); + void nbspWithFormat(); void noModificationOfInputString(); void superscriptCrash_qtbug53911(); @@ -2266,5 +2267,41 @@ void tst_QTextLayout::superscriptCrash_qtbug53911() qDeleteAll(textLayouts); } +void tst_QTextLayout::nbspWithFormat() +{ + QString s1 = QLatin1String("ABCDEF "); + QString s2 = QLatin1String("GHI"); + QChar nbsp(QChar::Nbsp); + QString s3 = QLatin1String("JKLMNOPQRSTUVWXYZ"); + + QTextLayout layout; + layout.setText(s1 + s2 + nbsp + s3); + + QTextLayout::FormatRange formatRange; + formatRange.start = s1.length() + s2.length(); + formatRange.length = 1; + formatRange.format.setFontUnderline(true); + + QList overrides; + overrides.append(formatRange); + + layout.setAdditionalFormats(overrides); + + layout.beginLayout(); + forever { + QTextLine line = layout.createLine(); + if (!line.isValid()) + break; + line.setLineWidth(1); + } + layout.endLayout(); + + QCOMPARE(layout.lineCount(), 2); + QCOMPARE(layout.lineAt(0).textStart(), 0); + QCOMPARE(layout.lineAt(0).textLength(), s1.length()); + QCOMPARE(layout.lineAt(1).textStart(), s1.length()); + QCOMPARE(layout.lineAt(1).textLength(), s2.length() + 1 + s3.length()); +} + QTEST_MAIN(tst_QTextLayout) #include "tst_qtextlayout.moc" -- cgit v1.2.3