diff options
author | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-08-14 15:49:31 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-08-14 15:55:12 (GMT) |
commit | ca89fd9ee95511a7fe1e8cdb2317e7c8388ec220 (patch) | |
tree | c38656404ad29cc5f668359decbc1b964311d0ad | |
parent | a7b24170890aad476345a5d7a56ded8d62c53df0 (diff) | |
download | Qt-ca89fd9ee95511a7fe1e8cdb2317e7c8388ec220.zip Qt-ca89fd9ee95511a7fe1e8cdb2317e7c8388ec220.tar.gz Qt-ca89fd9ee95511a7fe1e8cdb2317e7c8388ec220.tar.bz2 |
Autotest for correct word wrapping on text next to floating object
We set the document's page size to be large enough to contain an
image which is 100 pixels wide and one, but not two, instances of the
word 'Foobar'. We then render HTML which contains a string with repeated
occurrences of the word 'Foobar' next to a floating, right-aligned image
which is 100 pixels wide. The layout should break on word boundaries,
since this is the default in QTextDocument, and thus each text line
should contain one instance of the word 'Foobar'.
Task-number: 240325
-rw-r--r-- | tests/auto/qtextdocument/tst_qtextdocument.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/qtextdocument/tst_qtextdocument.cpp b/tests/auto/qtextdocument/tst_qtextdocument.cpp index 72f3ea8..4643df0 100644 --- a/tests/auto/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/qtextdocument/tst_qtextdocument.cpp @@ -55,8 +55,13 @@ #include <qtextlist.h> #include <qtextcodec.h> #include <qurl.h> +#include <qpainter.h> +#include <qfontmetrics.h> +#include <qimage.h> +#include <qtextlayout.h> #include "common.h" + QT_FORWARD_DECLARE_CLASS(QTextDocument) //TESTED_CLASS= @@ -93,6 +98,8 @@ private slots: void noundo_isModified3(); void mightBeRichText(); + void task240325(); + void toHtml_data(); void toHtml(); void toHtml2(); @@ -532,6 +539,38 @@ void tst_QTextDocument::noundo_basicIsModifiedChecks() QCOMPARE(spy.count(), 0); } +void tst_QTextDocument::task240325() +{ + doc->setHtml("<html><img width=\"100\" height=\"100\" align=\"right\"/>Foobar Foobar Foobar Foobar</html>"); + + QImage img(1000, 7000, QImage::Format_ARGB32_Premultiplied); + QPainter p(&img); + QFontMetrics fm(p.font()); + + // Set page size to contain image and one "Foobar" + doc->setPageSize(QSize(100 + fm.width("Foobar")*2, 1000)); + + // Force layout + doc->drawContents(&p); + + QCOMPARE(doc->blockCount(), 1); + for (QTextBlock block = doc->begin() ; block!=doc->end() ; block = block.next()) { + QTextLayout *layout = block.layout(); + QCOMPARE(layout->lineCount(), 4); + for (int lineIdx=0;lineIdx<layout->lineCount();++lineIdx) { + QTextLine line = layout->lineAt(lineIdx); + + QString text = block.text().mid(line.textStart(), line.textLength()).trimmed(); + + // Remove start token + if (lineIdx == 0) + text = text.mid(1); + + QCOMPARE(text, QString::fromLatin1("Foobar")); + } + } +} + void tst_QTextDocument::noundo_moreIsModified() { doc->setUndoRedoEnabled(false); |