diff options
-rw-r--r-- | src/gui/text/qtextlayout.cpp | 11 | ||||
-rw-r--r-- | tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp | 24 |
2 files changed, 34 insertions, 1 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 84ad9038d5..ede7426ffc 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1842,8 +1842,17 @@ void QTextLine::layout_helper(int maxGlyphs) addNextCluster(lbh.currentPosition, end, lbh.tmpData, lbh.glyphCount, current, lbh.logClusters, lbh.glyphs); + // This is a hack to fix a regression caused by the introduction of the + // whitespace flag to non-breakable spaces and will cause the non-breakable + // spaces to behave as in previous Qt versions in the line breaking algorithm. + // The line breaks do not currently follow the Unicode specs, but fixing this would + // require refactoring the code and would cause behavioral regressions. + bool isBreakableSpace = lbh.currentPosition < eng->layoutData->string.length() + && attributes[lbh.currentPosition].whiteSpace + && eng->layoutData->string.at(lbh.currentPosition).decompositionTag() != QChar::NoBreak; + if (lbh.currentPosition >= eng->layoutData->string.length() - || attributes[lbh.currentPosition].whiteSpace + || isBreakableSpace || attributes[lbh.currentPosition].lineBreak) { sb_or_ws = true; break; 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" |