summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2012-10-11 16:19:34 +0300
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-15 10:18:31 +0200
commit3e030a9652e7a95ed28e24ec258a7895e8bc1e34 (patch)
treea62f0860a6c7d1fc4c18ce168c79316c7d2489e5 /tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
parente488d0f4da4ada306e6a1686149c2aedc8bc9391 (diff)
QRawFont: improve performance and safety of glyphIndexesForString()
As of 98c1eb1750498cdff9d3b26658e5e5be9c026c92, partially initialized QGlyphLayout is ok for stringToCMap() if GlyphIndicesOnly flag is set, thus we can use the glyphIndexes buffer directly and avoid copying. Also add some checks to guarantee we're not falling into an undefined behavior for the empty text or NULL buffer. Change-Id: I662953703e4c65edbebabbe4b753972417d963f3 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'tests/auto/gui/text/qrawfont/tst_qrawfont.cpp')
-rw-r--r--tests/auto/gui/text/qrawfont/tst_qrawfont.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
index 7a254546fe..c26964e764 100644
--- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
+++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
@@ -267,6 +267,24 @@ void tst_QRawFont::glyphIndices()
expectedGlyphIndices << 44 << 83 << 83 << 70 << 69 << 86;
QCOMPARE(glyphIndices, expectedGlyphIndices);
+
+ glyphIndices = font.glyphIndexesForString(QString());
+ QVERIFY(glyphIndices.isEmpty());
+
+ QString str(QLatin1String("Foobar"));
+ int numGlyphs = str.size();
+ glyphIndices.resize(numGlyphs);
+
+ QVERIFY(!font.glyphIndexesForChars(str.constData(), 0, glyphIndices.data(), &numGlyphs));
+ QCOMPARE(numGlyphs, 0);
+
+ QVERIFY(!font.glyphIndexesForChars(str.constData(), str.size(), glyphIndices.data(), &numGlyphs));
+ QCOMPARE(numGlyphs, str.size());
+
+ QVERIFY(font.glyphIndexesForChars(str.constData(), str.size(), glyphIndices.data(), &numGlyphs));
+ QCOMPARE(numGlyphs, str.size());
+
+ QCOMPARE(glyphIndices, expectedGlyphIndices);
}
void tst_QRawFont::advances_data()
@@ -310,6 +328,33 @@ void tst_QRawFont::advances()
QVERIFY(qFuzzyIsNull(advances.at(i).y()));
}
+
+ advances = font.advancesForGlyphIndexes(QVector<quint32>());
+ QVERIFY(advances.isEmpty());
+
+ int numGlyphs = glyphIndices.size();
+ advances.resize(numGlyphs);
+
+ QVERIFY(!font.advancesForGlyphIndexes(glyphIndices.constData(), advances.data(), 0));
+
+ QVERIFY(font.advancesForGlyphIndexes(glyphIndices.constData(), advances.data(), numGlyphs));
+
+ for (int i=0; i<glyphIndices.size(); ++i) {
+#ifdef Q_OS_WIN
+ // In Windows, freetype engine returns advance of 9 when full hinting is used (default) for
+ // some of the glyphs.
+ if (font_d->fontEngine->type() == QFontEngine::Freetype
+ && (hintingPreference == QFont::PreferFullHinting || hintingPreference == QFont::PreferDefaultHinting)
+ && (i == 0 || i == 5)) {
+ QEXPECT_FAIL("", "Advance for some glyphs is not the expected with Windows Freetype engine (9 instead of 8)", Continue);
+ }
+#endif
+ QVERIFY(qFuzzyCompare(qRound(advances.at(i).x()), 8.0));
+ if (supportsSubPixelPositions)
+ QVERIFY(advances.at(i).x() > 8.0);
+
+ QVERIFY(qFuzzyIsNull(advances.at(i).y()));
+ }
}
void tst_QRawFont::textLayout()