diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 34788dc4dc..67dedca760 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -2057,7 +2057,7 @@ void QTextEngine::justify(const QScriptLine &line) // subtract one char more, as we can't justfy after the last character --line_length; - if (!line_length) + if (line_length <= 0) return; int firstItem = findItem(line.from); diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index d0482d77e2..26eaec0470 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -122,6 +122,7 @@ private slots: void boundingRectForUnsetLineWidth(); void boundingRectForSetLineWidth(); void glyphLessItems(); + void justifyTrailingSpaces(); // QTextLine stuff void setNumColumnsWrapAtWordBoundaryOrAnywhere(); @@ -1996,5 +1997,19 @@ void tst_QTextLayout::cursorInNonStopChars() QVERIFY(line.cursorToX(2) == line.cursorToX(3)); } +void tst_QTextLayout::justifyTrailingSpaces() +{ + QTextLayout layout(QStringLiteral(" t"), testFont); + layout.setTextOption(QTextOption(Qt::AlignJustify)); + layout.beginLayout(); + + QTextLine line = layout.createLine(); + line.setLineWidth(5); + + layout.endLayout(); + + QVERIFY(qFuzzyIsNull(layout.lineAt(0).cursorToX(0))); +} + QTEST_MAIN(tst_QTextLayout) #include "tst_qtextlayout.moc"