summaryrefslogtreecommitdiffstats
path: root/tests/manual/textrendering
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/textrendering')
-rw-r--r--tests/manual/textrendering/glyphshaping/glyphshaping.pro5
-rw-r--r--tests/manual/textrendering/glyphshaping/glyphshaping_data.xml251
-rw-r--r--tests/manual/textrendering/glyphshaping/main.cpp269
-rw-r--r--tests/manual/textrendering/textperformance/main.cpp231
-rw-r--r--tests/manual/textrendering/textperformance/textperformance.pro1
5 files changed, 757 insertions, 0 deletions
diff --git a/tests/manual/textrendering/glyphshaping/glyphshaping.pro b/tests/manual/textrendering/glyphshaping/glyphshaping.pro
new file mode 100644
index 0000000000..1d78aa3351
--- /dev/null
+++ b/tests/manual/textrendering/glyphshaping/glyphshaping.pro
@@ -0,0 +1,5 @@
+SOURCES = main.cpp
+OTHER_FILES = glyphshaping_data.xml
+glyphshaping_data.path = .
+glyphshaping_data.files = $$PWD/glyphshaping_data.xml
+DEPLOYMENT += glyphshaping_data
diff --git a/tests/manual/textrendering/glyphshaping/glyphshaping_data.xml b/tests/manual/textrendering/glyphshaping/glyphshaping_data.xml
new file mode 100644
index 0000000000..040804e838
--- /dev/null
+++ b/tests/manual/textrendering/glyphshaping/glyphshaping_data.xml
@@ -0,0 +1,251 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<shapingtests>
+
+ <language name="Vietnamese">
+ <test
+ name="capital U, combining horn"
+ inpututf16="0x0055, 0x031B"
+ outpututf16="0x01AF"
+ />
+ <test
+ name="capital U, apostrophe"
+ inpututf16="0x0055, 0x0027"
+ outpututf16="0x0055"
+ />
+ <test
+ name="capital U, modifier prime"
+ inpututf16="0x0055, 0x02B9"
+ outpututf16="0x0055"
+ />
+ <test
+ name="capital U, modifier apostrophe"
+ inpututf16="0x0055, 0x02BC"
+ outpututf16="0x0055"
+ />
+ <test
+ name="capital U, combining comma above right"
+ inpututf16="0x0055, 0x0315"
+ outpututf16="0x0055, 0x0315"
+ />
+ <test
+ name="capital U, right single quote mark"
+ inpututf16="0x0055, 0x2019"
+ outpututf16="0x0055"
+ />
+ <test
+ name="capital U with horn, space"
+ inpututf16="0x01AF, 0x0020"
+ outpututf16="0x01AF"
+ />
+ <test
+ name="capital E, combining horn"
+ inpututf16="0x0045, 0x031B"
+ outpututf16="0x0045, 0x031B"
+ />
+ <test
+ name="capital A, combining breve, combining acute"
+ inpututf16="0x0041, 0x0306, 0x0301"
+ outpututf16="0x1EAE"
+ />
+ <test
+ name="capital A with breve, combining acute"
+ inpututf16="0x0102, 0x0301"
+ outpututf16="0x1EAE"
+ />
+ <test
+ name="capital A, combining acute, combining breve"
+ inpututf16="0x0041, 0x0301, 0x0306"
+ outpututf16="0x0041, 0x0301, 0x0306"
+ />
+ <test
+ name="capital A, combining dot below, combining breve"
+ inpututf16="0x0041, 0x0323"
+ outpututf16="0x0306"
+ />
+ <test
+ name="capital A with dot below, combining breve"
+ inpututf16="0x1EA0, 0x0306"
+ outpututf16="0x1EB6"
+ />
+ <test
+ name="capital A with breve, combining dot below"
+ inpututf16="0x0102, 0x0323"
+ outpututf16="0x0102, 0x0323"
+ />
+ <test
+ name="capital E, combining circumflex, combining acute"
+ inpututf16="0x0045, 0x0302, 0x0301"
+ outpututf16="0x1EBE"
+ />
+ <test
+ name="capital E with circumflex, combining acute"
+ inpututf16="0x00CA, 0x0301"
+ outpututf16="0x1EBE"
+ />
+ <test
+ name="capital O, combining horn, combining hook above"
+ inpututf16="0x004F, 0x031B, 0x0309"
+ outpututf16="0x1EDE"
+ />
+ <test
+ name="capital O with horn, combining hook above"
+ inpututf16="0x01A0, 0x0309"
+ outpututf16="0x1EDE"
+ />
+ </language>
+
+ <language name="Tamil">
+ <test
+ name="Tamil Ka"
+ inpututf16="0x0B95"
+ outputglyphids="0x0bf6"
+ />
+ <test
+ name="Tamil e"
+ inpututf16="0x0B8E"
+ outputglyphids="0x0bf0"
+ />
+ <test
+ name="Latin A"
+ inpututf16="0x0061"
+ outpututf16="0x0061"
+ />
+ <test
+ name="Hindi Ka"
+ inpututf16="0x0905"
+ outputglyphids="0x0528"
+ />
+ <test
+ name="03 - 1: Latin 06"
+ inpututf16="0x0036"
+ outputglyphids="0x077A"
+ />
+ <test
+ name="03 - 2: Tamil 06"
+ inpututf16="0x0BEC"
+ outputglyphids="0x0c20"
+ />
+ <test
+ name="10 1.3.6 - 1: Pa, Virama, Ka, Virama, Tta, -e"
+ inpututf16="0x0BAA, 0x0BCD, 0x0B95, 0x0BCD, 0x0B9F, 0x0BC7"
+ outputglyphids="0x0c3a, 0x0c30, 0x0c13, 0x0bfb"
+ />
+ <test
+ name="10 1.3.6 - 2: Pa, Virama, Ka, AU"
+ inpututf16="0x0BAA, 0x0BCD, 0x0B95, 0x0BCC"
+ outputglyphids="0x0c3a, 0x0c12, 0x0bf6, 0x0c19"
+ />
+ <test
+ name="10 1.3.6 - 3: Ka, Virama, Ssa, OO"
+ inpututf16="0x0B95, 0x0BCD, 0x0BB7, 0x0BCB"
+ outputglyphids="0x0c13, 0x0c2f, 0x0c0d"
+ />
+ <test
+ name="11: Ka, -e"
+ inpututf16="0x0B95, 0x0BC7"
+ outputglyphids="0x0c13, 0x0bf6"
+ />
+ <test
+ name="12 1.3.5.2: Ka, O"
+ inpututf16="0x0B95, 0x0BCA"
+ outputglyphids="0x0c12, 0x0bf6, 0x0c0d"
+ />
+ <test
+ name="13 - 1: Ka"
+ inpututf16="0x0B95"
+ outputglyphids="0x0bf6"
+ />
+ <test
+ name="13 - 2: Aythem, A"
+ inpututf16="0x0B83, 0x0B85"
+ />
+ <test
+ name="14 - 1: Ka, Anusvara"
+ inpututf16="0x0B95, 0x0B82"
+ outputglyphids="0x0bf6, 0x0be8"
+ />
+ <test
+ name="14 - 2: Ka"
+ inpututf16="0x0B95"
+ outputglyphids="0x0bf6"
+ />
+ <test
+ name="15 - 1: Ra, Virama"
+ inpututf16="0x0BB0, 0x0BCD"
+ outputglyphids="0x0c03"
+ />
+ <test
+ name="15 - 2: ZWJ"
+ inpututf16="0x8205"
+ />
+ <test
+ name="16: Ka, Anusvara"
+ inpututf16="0x0B95, 0x0B82"
+ outputglyphids="0x0bf6"
+ />
+ <test
+ name="17 1.3.11 - 1: Tta, I"
+ inpututf16="0x0B9F, 0x0BBF"
+ outputglyphids="0x0c51"
+ />
+ <test
+ name="17 1.3.11 - 2: Tta, Ii"
+ inpututf16="0x0B9F, 0x0BC0"
+ outputglyphids="0x0c52"
+ />
+ <test
+ name="18 - 1: Ra, I"
+ inpututf16="0x0BB0, 0x0BBF"
+ outputglyphids="0x0c0d, 0x0c0e"
+ />
+ <test
+ name="18 - 2: Ra, Ii"
+ inpututf16="0x0BB0, 0x0BC0"
+ outputglyphids="0x0c0d, 0x0c0f"
+ />
+ <test
+ name="19 - 1: Nga, I"
+ inpututf16="0x0B99, 0x0BBF"
+ outputglyphids="0x0bf7, 0x0c0e"
+ />
+ <test
+ name="19 - 2: Nga, Ii"
+ inpututf16="0x0B99, 0x0BC0"
+ outputglyphids="0x0c4a"
+ />
+ <test
+ name="20 - 1: Ja, U"
+ inpututf16="0x0B9C, 0x0BC1"
+ outputglyphids="0x0bf9, 0x0c10"
+ />
+ <test
+ name="20 - 2: Ja, Uu"
+ inpututf16="0x0B9C, 0x0BC2"
+ outputglyphids="0x0bf9, 0x0c11"
+ />
+ <test
+ name="21 1.3.15: Ka, Ai"
+ inpututf16="0x0B95, 0x0BC8"
+ outputglyphids="0x0c14, 0x0bf6"
+ />
+ <test
+ name="22: Ka, Virama, Ssa"
+ inpututf16="0x0B95, 0x0BCD, 0x0BB7"
+ outputglyphids="0x0c2f"
+ />
+ <test
+ name="23 1.3.17: Sa, Virama, Ra, Matra I"
+ inpututf16="0x0BB8, 0x0BCD, 0x0BB0, 0x0BC0"
+ outputglyphids="0x0c79"
+ />
+ <test
+ name="24 1.3.18 - 1: Ka"
+ inpututf16="0x0B95"
+ outputglyphids="0x0bf6"
+ />
+ <test
+ name="24 1.3.18 - 2: Virama, ZWJ"
+ inpututf16="0x0BCD, 0x8205"
+ />
+ </language>
+</shapingtests>
diff --git a/tests/manual/textrendering/glyphshaping/main.cpp b/tests/manual/textrendering/glyphshaping/main.cpp
new file mode 100644
index 0000000000..d29f5ad79d
--- /dev/null
+++ b/tests/manual/textrendering/glyphshaping/main.cpp
@@ -0,0 +1,269 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+static const int fontPixelSize = 25;
+static const QLatin1String fontFamily("Series 60 Sans");
+
+struct testDataSet
+{
+ QString language;
+ QString name;
+ QString input;
+ QString inputOriginal;
+ QString output;
+ QString outputOriginal;
+ QVector<uint> outputGlyphIDs;
+ QString outputGlyphIDsOriginal;
+};
+
+QString charHexCsv2String(const QString &csv)
+{
+ QString result;
+ foreach (const QString &charString, csv.split(QLatin1Char(','), QString::SkipEmptyParts)) {
+ bool isOk;
+ const uint charUInt = charString.toUInt(&isOk, 16);
+ Q_ASSERT(isOk);
+ const int size = charUInt >= SHRT_MAX ? 2:1;
+ result.append(QString::fromUtf16((const ushort*)&charUInt, size));
+ }
+ return result;
+}
+
+QList<testDataSet> testDataSetList()
+{
+ QList<testDataSet> result;
+ QFile file("glyphshaping_data.xml");
+ const bool success = file.open(QIODevice::ReadOnly);
+ Q_ASSERT(success);
+
+ const QLatin1String language("language");
+ const QLatin1String test("test");
+ const QLatin1String inputUtf16("inpututf16");
+ const QLatin1String outputUtf16("outpututf16");
+ const QLatin1String outputGlyphIDs("outputglyphids");
+ const QLatin1String name("name");
+
+ QString languageName;
+
+ QXmlStreamReader reader(&file);
+ while (!reader.atEnd()) {
+ const QXmlStreamReader::TokenType token = reader.readNext();
+ switch (token) {
+ case QXmlStreamReader::StartElement:
+ if (reader.name() == language) {
+ Q_ASSERT(reader.attributes().hasAttribute(name));
+ languageName = reader.attributes().value(name).toString();
+ } else if (reader.name() == test) {
+ if (!reader.attributes().hasAttribute(outputUtf16)
+ && !reader.attributes().hasAttribute(outputGlyphIDs))
+ continue;
+ Q_ASSERT(!languageName.isEmpty());
+ Q_ASSERT(reader.attributes().hasAttribute(name));
+ Q_ASSERT(reader.attributes().hasAttribute(inputUtf16));
+ testDataSet set;
+ set.language = languageName;
+ set.name = reader.attributes().value(name).toString();
+ set.inputOriginal = reader.attributes().value(inputUtf16).toString();
+ set.input = charHexCsv2String(set.inputOriginal);
+ set.outputOriginal = reader.attributes().value(outputUtf16).toString();
+ set.output = charHexCsv2String(set.outputOriginal);
+ set.outputGlyphIDsOriginal = reader.attributes().value(outputGlyphIDs).toString();
+ result.append(set);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ return result;
+}
+
+QImage renderedText(const QString &text, const QFont &font)
+{
+ const QFontMetrics metrics(font);
+ const QRect boundingRect = metrics.boundingRect(text);
+ QImage result(boundingRect.size(), QImage::Format_ARGB32);
+ result.fill(0);
+
+ QPainter p(&result);
+ p.setFont(font);
+ p.drawText(boundingRect.translated(-boundingRect.topLeft()), text);
+
+ return result;
+}
+
+QString dumpImageHtml(const QString &text, const QString &pathName)
+{
+ if (text.isEmpty())
+ return QLatin1String("<td/>");
+ QFont font(fontFamily);
+ font.setPixelSize(fontPixelSize);
+ const QImage textImage = renderedText(text, font);
+ const QString imageFileName =
+ (pathName + QDir::separator() + QLatin1String("%1.png"))
+ .arg(textImage.cacheKey());
+ const bool success = textImage.save(imageFileName);
+ Q_ASSERT(success);
+ return
+ QString::fromLatin1("<td title=\"%2\"><img src=\"%1\" alt=\"%2\" width=\"%3\" height=\"%4\"/></td>")
+ .arg(QDir::cleanPath(imageFileName)).arg(text).arg(textImage.width()).arg(textImage.height());
+}
+
+QString dlItem(const QString &dt, const QString &dd)
+{
+ if (!dd.trimmed().isEmpty())
+ return QString::fromLatin1("\t\t\t\t\t\t<dt>%1</dt><dd>%2</dd>\n").arg(dt).arg(dd);
+ return QString();
+}
+
+bool dumpHtml(const QString &pathName)
+{
+ QFile htmlPage(pathName + QDir::separator() + QLatin1String("index.html"));
+ if (!htmlPage.open(QFile::WriteOnly))
+ return false;
+
+ QString platformName = QString::fromLatin1(
+#if defined(Q_OS_WIN)
+ "Win32"
+#elif defined(Q_WS_X11)
+ "X11"
+#elif defined(Q_OS_SYMBIAN)
+ "Symbian"
+#else
+ ""
+#endif
+ );
+
+ QString result = QString::fromLatin1(
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
+ " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\n"
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
+ "\t<head>\n"
+ "\t\t<title>Qt on %1 glyph shaping (%2)</title>\n"
+ "\t\t<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" />\n"
+ "\t\t<style type=\"text/css\" media=\"screen\">\n"
+ "\t\t\ttable { font-family: Arial; background-color: #ccccff; font-size: 12pt; }\n"
+ "\t\t\ttd { font-family:\"%2\"; background-color: #eeeeee; font-size: %3px; }\n"
+ "\t\t\tth { font-weight:normal; }\n"
+ "\t\t\tdl { font-family: Arial; font-size: 8pt; margin: 3px; }\n"
+ "\t\t\tdt { font-weight: bold; float: left; }\n"
+ "\t\t\ttr:hover { background-color: #ddddff; }\n"
+ "\t\t\ttd:hover { background-color: #ddddff; }\n"
+ "\t\t</style>\n"
+ "\t</head>\n"
+ "\t<body>\n"
+ "\t\t<h1>Qt on %1 glyph shaping (%2)</h1>\n"
+ "\t\t<dl>\n"
+ "\t\t\t<dt>I</dt><dd>Input Utf-16 to shaper</dd>\n"
+ "\t\t\t<dt>O-Utf</dt><dd>expected output Utf-16</dd>\n"
+ "\t\t\t<dt>O-ID</dt><dd>expected output Glyph IDs for \"Series 60 Sans\"</dd>\n"
+ "\t\t</dl>\n"
+ "\t\t<table>\n"
+ ).arg(platformName).arg(fontFamily).arg(fontPixelSize);
+
+ QString languageName;
+ foreach (const testDataSet &dataSet, testDataSetList()) {
+ if (languageName != dataSet.language) {
+ result.append(QString::fromLatin1(
+ "\t\t\t<tr>\n"
+ "\t\t\t\t<th rowspan=\"2\"><h2>%1</h2></th>\n"
+ "\t\t\t\t<th colspan=\"2\">Qt/%2</th>\n"
+ "\t\t\t\t<th rowspan=\"2\">Glyphs</th>\n"
+ "\t\t\t\t<th colspan=\"2\">Browser</th>\n"
+ "\t\t\t</tr>\n"
+ "\t\t\t<tr>\n"
+ "\t\t\t\t<th>In</th>\n"
+ "\t\t\t\t<th>Out</th>\n"
+ "\t\t\t\t<th>In</th>\n"
+ "\t\t\t\t<th>Out</th>\n"
+ "\t\t\t</tr>\n"
+ ).arg(dataSet.language).arg(platformName));
+ languageName = dataSet.language;
+ }
+ QString glyphsData;
+ if (!dataSet.inputOriginal.isEmpty())
+ glyphsData.append(dlItem(QLatin1String("I"), dataSet.inputOriginal));
+ if (!dataSet.outputOriginal.isEmpty())
+ glyphsData.append(dlItem(QLatin1String("O-Utf"), dataSet.outputOriginal));
+ if (!dataSet.outputGlyphIDsOriginal.isEmpty())
+ glyphsData.append(dlItem(QLatin1String("O-ID"), dataSet.outputGlyphIDsOriginal));
+ if (!glyphsData.isEmpty()) {
+ glyphsData.prepend(QLatin1String("\t\t\t\t\t<dl>\n"));
+ glyphsData.append(QLatin1String("\t\t\t\t\t</dl>\n"));
+ }
+ result.append(QString::fromLatin1(
+ "\t\t\t<tr>\n"
+ "\t\t\t\t<th>%1</th>\n"
+ "\t\t\t\t%2\n"
+ "\t\t\t\t%3\n"
+ "\t\t\t\t<td>\n"
+ "%4"
+ "\t\t\t\t</td>\n"
+ "\t\t\t\t<td>%5</td>\n"
+ "\t\t\t\t<td>%6</td>\n"
+ "\t\t\t</tr>\n"
+ ).arg(dataSet.name)
+ .arg(dumpImageHtml(dataSet.input, pathName))
+ .arg(dumpImageHtml(dataSet.output, pathName))
+ .arg(glyphsData)
+ .arg(dataSet.input)
+ .arg(dataSet.output)
+ );
+ }
+
+ result.append(QString::fromLatin1(
+ "\t\t</table>\n"
+ "\t</body>\n"
+ "</html>")
+ );
+
+ htmlPage.write(result.toUtf8());
+
+ return true;
+}
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ return dumpHtml(QLatin1String(".")) ? 0 : 1;
+}
diff --git a/tests/manual/textrendering/textperformance/main.cpp b/tests/manual/textrendering/textperformance/main.cpp
new file mode 100644
index 0000000000..6dcc0eb44f
--- /dev/null
+++ b/tests/manual/textrendering/textperformance/main.cpp
@@ -0,0 +1,231 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+static const int lastMeasurementsCount = 50;
+
+class FontBlaster: public QWidget
+{
+ Q_OBJECT
+
+public:
+ FontBlaster(QWidget *parent = 0)
+ : QWidget(parent)
+ , m_currentMode(0)
+ {
+ setFocusPolicy(Qt::StrongFocus);
+ }
+
+ void paintEvent(QPaintEvent *event)
+ {
+ Q_UNUSED(event);
+ QPainter p(this);
+
+ if (!m_timer.isNull())
+ m_lastMeasurements.append(m_timer.elapsed());
+ m_timer.start();
+
+ p.save();
+ m_modes[m_currentMode].function(p, size());
+ p.restore();
+
+ const QFontMetrics fm = p.fontMetrics();
+ p.setOpacity(0.7);
+ p.fillRect(0, 0, width(), fm.height(), Qt::gray);
+ p.fillRect(0, height() - fm.height(), width(), height(), Qt::gray);
+ p.setOpacity(1);
+ p.setPen(palette().color(QPalette::Text));
+ p.drawText(2, fm.ascent(), m_modes[m_currentMode].name);
+
+ if (m_lastMeasurements.count() == lastMeasurementsCount) {
+ m_lastMeasurements.removeFirst();
+ int lastMsecsSum = 0;
+ foreach(const int measurement, m_lastMeasurements)
+ lastMsecsSum += measurement;
+
+ p.drawText(2, height() - fm.descent(),
+ QLatin1String("Fps: ") +
+ QString::number(1000 / ((qreal)lastMsecsSum / lastMeasurementsCount), 'f', 1)
+ );
+ }
+
+ QTimer::singleShot(0, this, SLOT(repaint()));
+ }
+
+ /*
+ Creating all kinds of size/weight/italic combinations, stress testing
+ the glyph cache.
+ Also: painting with different opacities, stress testing blitting.
+ */
+ static void paintDifferentFontStyles(QPainter &p, const QSize &size)
+ {
+ static const QString text = QLatin1String("Qt rocks!!!");
+ static const int textsPerPaint = 30;
+ for (int i = 0; i < textsPerPaint; i++) {
+ const int fontSize = 4 + (qrand() % 5);
+ const int fontWeight = (qrand() % 2) == 1 ? QFont::Normal : QFont::Bold;
+ const bool fontItalic = (qrand() % 2) == 1;
+ const QFont font("Default", fontSize, fontWeight, fontItalic);
+ p.setFont(font);
+ p.setPen(QColor::fromHsv(qrand() % 359, 155 + qrand() % 100,
+ 155 + qrand() % 100, 100 + qrand() % 155));
+ const QSize textSize(p.fontMetrics().boundingRect(text).size());
+ const QPoint position(
+ -textSize.width() / 2 + (qrand() % size.width()),
+ textSize.height() / 2 + (qrand() % size.height()));
+ p.drawText(position, text);
+ }
+ }
+
+ /*
+ Drawing a multiline latin text, stress testing the text layout system.
+ */
+ static void paintLongLatinText(QPainter &p, const QSize &size)
+ {
+ static const char* const pieces[] = {
+ "lorem ipsum",
+ "dolor sit amet",
+ "consectetuer",
+ "sed diam nonumy",
+ "eos et accusam",
+ "sea takimata sanctus"
+ };
+ static const int piecesCount = (int)(sizeof pieces / sizeof pieces[0]);
+ static const int piecesPerPaint = 30;
+
+ QString text;
+ for (int i = 0; i < piecesPerPaint; ++i) {
+ QString piece = QLatin1String(pieces[qrand() % piecesCount]);
+ if (i == 0 || qrand() % 2) {
+ // Make this piece the beginning of a new sentence.
+ piece[0] = piece[0].toUpper();
+ if (i > 0)
+ piece.prepend(QLatin1String(". "));
+ } else {
+ piece.prepend(QLatin1String(", "));
+ }
+ text.append(piece);
+ }
+ text.append(QLatin1Char('.'));
+
+ p.drawText(QRectF(QPointF(0, 0), QSizeF(size)),
+ Qt::AlignTop | Qt::AlignAbsolute | Qt::TextWordWrap, text);
+ }
+
+ /*
+ Drawing one text with several snippets of different writingSystems, stress
+ testing the font merging in the font database.
+ */
+ static void paintInternationalText(QPainter &p, const QSize &size)
+ {
+ static QStringList samples;
+ if (samples.isEmpty()) {
+ foreach (const QFontDatabase::WritingSystem system, QFontDatabase().writingSystems())
+ if (system != QFontDatabase::Ogham && system != QFontDatabase::Runic)
+ samples.append(QFontDatabase::writingSystemSample(system));
+ }
+ static const int systemsPerPaint = 65;
+ QString text;
+ for (int i = 0; i < systemsPerPaint; i++) {
+ if (i > 0)
+ text.append(QLatin1Char(' '));
+ text.append(samples.at(qrand() % samples.count()));
+ }
+ p.drawText(QRectF(QPointF(0, 0), QSizeF(size)),
+ Qt::AlignTop | Qt::AlignAbsolute | Qt::TextWordWrap, text);
+ }
+
+protected:
+ void nextMode()
+ {
+ m_currentMode = (m_currentMode + 1) % m_modesCount;
+ m_lastMeasurements.clear();
+ }
+
+ void keyPressEvent(QKeyEvent *event)
+ {
+ Q_UNUSED(event);
+ nextMode();
+ }
+
+ void mousePressEvent(QMouseEvent *event)
+ {
+ Q_UNUSED(event);
+ nextMode();
+ }
+
+private:
+ static const struct mode {
+ QString name;
+ void (*function)(QPainter &, const QSize&);
+ } m_modes[];
+ static const int m_modesCount;
+
+ int m_currentMode;
+ QList<int> m_lastMeasurements;
+ QTime m_timer;
+};
+
+const struct FontBlaster::mode FontBlaster::m_modes[] = {
+ { QLatin1String("Qt rocks!!!"), FontBlaster::paintDifferentFontStyles },
+ { QLatin1String("Latin"), FontBlaster::paintLongLatinText },
+ { QLatin1String("International"), FontBlaster::paintInternationalText }
+};
+
+const int FontBlaster::m_modesCount =
+ (int)(sizeof m_modes / sizeof m_modes[0]);
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+
+ FontBlaster dlg;
+#ifdef Q_OS_SYMBIAN
+ dlg.showFullScreen();
+#else
+ dlg.show();
+#endif
+
+ return a.exec();
+}
+
+#include "main.moc"
diff --git a/tests/manual/textrendering/textperformance/textperformance.pro b/tests/manual/textrendering/textperformance/textperformance.pro
new file mode 100644
index 0000000000..bba41b9c12
--- /dev/null
+++ b/tests/manual/textrendering/textperformance/textperformance.pro
@@ -0,0 +1 @@
+SOURCES = main.cpp