diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2009-09-22 12:12:25 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2009-09-22 12:13:31 (GMT) |
commit | 0d830dc5b0716bdb4fa7130f724ba5c9593411fa (patch) | |
tree | d409e211a8aa3e339946b290f0ad0cf6718c4358 /tests | |
parent | 6e6dcc1575188751a730cdc3376b036b3df1f08e (diff) | |
download | Qt-0d830dc5b0716bdb4fa7130f724ba5c9593411fa.zip Qt-0d830dc5b0716bdb4fa7130f724ba5c9593411fa.tar.gz Qt-0d830dc5b0716bdb4fa7130f724ba5c9593411fa.tar.bz2 |
Fix breaking on fixed column width when text has tabs
When a text in QTextLayout contained tabs, these would be counted as
single glyphs when breaking the text on a fixed number of columns,
rather than the number of characters they span.
The patch calculates the number of characters represented by a tab by
using the average character width of the font engine.
Task-number: QTBUG-4468
Reviewed-by: Simon Hausmann
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qtextlayout/tst_qtextlayout.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/qtextlayout/tst_qtextlayout.cpp b/tests/auto/qtextlayout/tst_qtextlayout.cpp index 9f23ece..5ccae94 100644 --- a/tests/auto/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/qtextlayout/tst_qtextlayout.cpp @@ -109,6 +109,7 @@ private slots: void capitalization_capitalize(); void longText(); void widthOfTabs(); + void columnWrapWithTabs(); // QTextLine stuff void setNumColumnsWrapAtWordBoundaryOrAnywhere(); @@ -1275,5 +1276,40 @@ void tst_QTextLayout::widthOfTabs() QCOMPARE(qRound(engine.width(0, 5)), qRound(engine.boundingBox(0, 5).width)); } +void tst_QTextLayout::columnWrapWithTabs() +{ + QTextLayout textLayout; + { + QTextOption textOption; + textOption.setWrapMode(QTextOption::WordWrap); + textLayout.setTextOption(textOption); + } + + // Make sure string with spaces does not break + { + QString text = "Foo bar foo bar foo bar"; + textLayout.setText(text); + + textLayout.beginLayout(); + QTextLine line = textLayout.createLine(); + line.setNumColumns(30); + QCOMPARE(line.textLength(), text.length()); + textLayout.endLayout(); + } + + // Make sure string with tabs breaks + { + QString text = "Foo\tbar\tfoo\tbar\tfoo\tbar"; + textLayout.setText(text); + textLayout.beginLayout(); + QTextLine line = textLayout.createLine(); + line.setNumColumns(30); + QVERIFY(line.textLength() < text.length()); + textLayout.endLayout(); + } + +} + + QTEST_MAIN(tst_QTextLayout) #include "tst_qtextlayout.moc" |