diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com> | 2014-04-29 09:06:08 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-30 18:23:33 +0200 |
commit | 7eae50a52d63b7f0434fdb75fc09b0901a0140cc (patch) | |
tree | d6bd759d980157ef5af158ece46c9ec67b826590 /tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp | |
parent | 12eb3b51c4c8c7ce90302d2c356fea09f2c42a5c (diff) |
Fix assert on justification of QTextLine with only spaces
In the justification code, we unconditionally subtracted one
from the line_length, but then compared the result to 0 afterwards,
so we did not support when the line_length is 0 initially, which
can happen if it only consists of spaces (in which case
trailingSpaces will be non-zero and line_length will be zero.)
The fix is to bail out for both strings of length 1 and length 0.
[ChangeLog][Text] Fixed an assert when justifying a QTextLine
which only contains spaces.
Task-number: QTBUG-38520
Change-Id: Ib04993f47eb2f9f7fc49c4a5400f18f9682a72f2
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp')
-rw-r--r-- | tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
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" |