diff -r 5dc02b23752f -r 3e2da88830cd tests/benchmarks/gui/text/qtext/main.cpp --- a/tests/benchmarks/gui/text/qtext/main.cpp Tue Jul 06 15:10:48 2010 +0300 +++ b/tests/benchmarks/gui/text/qtext/main.cpp Wed Aug 18 10:37:55 2010 +0300 @@ -82,7 +82,13 @@ void constructControl(); void constructDocument(); + void newLineReplacement(); + void formatManipulation(); + void fontResolution(); + + void layout_data(); void layout(); + void formattedLayout(); void paintLayoutToPixmap(); void paintLayoutToPixmap_painterFill(); @@ -95,7 +101,7 @@ void paintControlToPixmap_painterFill(); private: - QSize setupTextLayout(QTextLayout *layout); + QSize setupTextLayout(QTextLayout *layout, bool wrap = true, int wrapWidth = 100); QString m_lorem; QString m_shortLorem; @@ -227,10 +233,8 @@ delete doc; } -QSize tst_QText::setupTextLayout(QTextLayout *layout) +QSize tst_QText::setupTextLayout(QTextLayout *layout, bool wrap, int wrapWidth) { - bool wrap = true; - int wrapWidth = 300; layout->setCacheEnabled(true); int height = 0; @@ -242,7 +246,6 @@ lineWidth = wrapWidth; layout->beginLayout(); - while (1) { QTextLine line = layout->createLine(); if (!line.isValid()) @@ -284,13 +287,95 @@ } } +//this step is needed before giving the string to a QTextLayout +void tst_QText::newLineReplacement() +{ + QString text = QString::fromLatin1("H\ne\nl\nl\no\n\nW\no\nr\nl\nd"); + + QBENCHMARK { + QString tmp = text; + tmp.replace(QLatin1Char('\n'), QChar::LineSeparator); + } +} + +void tst_QText::formatManipulation() +{ + QFont font; + + QBENCHMARK { + QTextCharFormat format; + format.setFont(font); + } +} + +void tst_QText::fontResolution() +{ + QFont font; + QFont font2; + font.setFamily("DejaVu"); + font2.setBold(true); + + QBENCHMARK { + QFont res = font.resolve(font2); + } +} + +void tst_QText::layout_data() +{ + QTest::addColumn("wrap"); + QTest::newRow("wrap") << true; + QTest::newRow("nowrap") << false; +} + void tst_QText::layout() { + QFETCH(bool,wrap); QTextLayout layout(m_shortLorem); + setupTextLayout(&layout, wrap); + + QBENCHMARK { + QTextLayout layout(m_shortLorem); + setupTextLayout(&layout, wrap); + } +} + +//### requires tst_QText to be a friend of QTextLayout +/*void tst_QText::stackTextLayout() +{ + QStackTextEngine engine(m_shortLorem, qApp->font()); + QTextLayout layout(&engine); + setupTextLayout(&layout); + + QBENCHMARK { + QStackTextEngine engine(m_shortLorem, qApp->font()); + QTextLayout layout(&engine); + setupTextLayout(&layout); + } +}*/ + +void tst_QText::formattedLayout() +{ + //set up formatting + QList ranges; + { + QTextCharFormat format; + format.setForeground(QColor("steelblue")); + + QTextLayout::FormatRange formatRange; + formatRange.format = format; + formatRange.start = 0; + formatRange.length = 50; + + ranges.append(formatRange); + } + + QTextLayout layout(m_shortLorem); + layout.setAdditionalFormats(ranges); setupTextLayout(&layout); QBENCHMARK { QTextLayout layout(m_shortLorem); + layout.setAdditionalFormats(ranges); setupTextLayout(&layout); } }