From b56a42be1476d7b3330968d81329a5e29b5fb819 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 24 Jun 2014 12:40:03 +0200 Subject: REG: Fix nbsp in QTextLayout At some point since Qt 4.8, the nbsp character has acquired the whitespace attribute, causing it to be treated exactly like an ordinary space. To account for this, we add an extra check in the layout code to avoid breaking on non-breaking spaces even if they have the whiteSpace flag set. This is a temporary fix for the regression. The line breaking algorithm needs to be refactored and support Unicode tr14 properly, which it currently doesn't. [ChangeLog][Text] Fixed lines breaking on non-breaking spaces. Task-number: QTBUG-39832 Change-Id: Ibd7e1a11ce4b82c611ecda1542c8638a67bf3cae Reviewed-by: Konstantin Ritt --- .../auto/gui/text/qtextlayout/tst_qtextlayout.cpp | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/auto/gui/text') diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index 26eaec0470..ec698e5db4 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -139,6 +139,7 @@ private slots: void cursorInLigatureWithMultipleLines(); void xToCursorForLigatures(); void cursorInNonStopChars(); + void nbsp(); private: QFont testFont; @@ -2011,5 +2012,28 @@ void tst_QTextLayout::justifyTrailingSpaces() QVERIFY(qFuzzyIsNull(layout.lineAt(0).cursorToX(0))); } +void tst_QTextLayout::nbsp() +{ + QString s = QString() + QChar(' ') + QChar('a') + QString(10, QChar::Nbsp) + QChar('a') + QChar(' ') + QChar('A'); + QString text = s + s + s + s + s + s + s + s + s + s + s + s + s + s; + QTextLayout layout(text); + layout.setCacheEnabled(true); + layout.beginLayout(); + layout.createLine(); + layout.endLayout(); + + int naturalWidth = qCeil(layout.lineAt(0).naturalTextWidth()); + int lineWidth = naturalWidth; + + layout.beginLayout(); + QTextLine line = layout.createLine(); + while (lineWidth-- > naturalWidth / 2) { + line.setLineWidth(lineWidth); + QVERIFY(text.at(line.textLength()-1).unicode() != QChar::Nbsp); + } + + layout.endLayout(); +} + QTEST_MAIN(tst_QTextLayout) #include "tst_qtextlayout.moc" -- cgit v1.2.3