Fix QRawFont test when used with bundled FreeType

The auto-hinter in the FreeType version bundled in Qt gives
slightly different advances on some glyphs. As noted in
the removed code, this was already observed on Windows and QNX,
and recently also on Android.

I'm sure it could also happen on platforms using the system library
if the system library was the same version as the one bundled in Qt.
Instead of expect-failing the test, we simply accept both the
observed results as valid.

Note that we need to accept 9 as a result for the default hinting
preference on all platforms, not just Windows, since the default
hinting preference in FreeType can be a system setting.

Change-Id: I3cc0f33f0f66dd64419770b37c10dee457706b5e
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2015-01-08 11:59:23 +01:00
parent b4031387f9
commit 1ee6fdc72c

View File

@ -307,24 +307,22 @@ void tst_QRawFont::advances()
bool supportsSubPixelPositions = font_d->fontEngine->supportsSubPixelPositions(); bool supportsSubPixelPositions = font_d->fontEngine->supportsSubPixelPositions();
QVector<QPointF> advances = font.advancesForGlyphIndexes(glyphIndices); QVector<QPointF> advances = font.advancesForGlyphIndexes(glyphIndices);
// On Windows and QNX, freetype engine returns advance of 9 for some of the glyphs bool mayDiffer = font_d->fontEngine->type() == QFontEngine::Freetype
// when full hinting is used (default on Windows). && (hintingPreference == QFont::PreferFullHinting
bool mayFail = false; || hintingPreference == QFont::PreferDefaultHinting);
#if defined (Q_OS_WIN)
mayFail = font_d->fontEngine->type() == QFontEngine::Freetype
&& (hintingPreference == QFont::PreferFullHinting
|| hintingPreference == QFont::PreferDefaultHinting);
#elif defined(Q_OS_QNX)
mayFail = font_d->fontEngine->type() == QFontEngine::Freetype
&& hintingPreference == QFont::PreferFullHinting;
#endif
for (int i = 0; i < glyphIndices.size(); ++i) { for (int i = 0; i < glyphIndices.size(); ++i) {
if (mayFail && (i == 0 || i == 5)) { if ((i == 0 || i == 5) && mayDiffer) {
QEXPECT_FAIL("", "FreeType engine reports unexpected advance " QVERIFY2(qRound(advances.at(i).x()) == 8
"for some glyphs (9 instead of 8)", Continue); || qRound(advances.at(i).x()) == 9,
qPrintable(QStringLiteral("%1 != %2 && %1 != %3")
.arg(qRound(advances.at(i).x()))
.arg(8)
.arg(9)));
} else {
QCOMPARE(qRound(advances.at(i).x()), 8);
} }
QVERIFY(qFuzzyCompare(qRound(advances.at(i).x()), 8.0));
if (supportsSubPixelPositions) if (supportsSubPixelPositions)
QVERIFY(advances.at(i).x() > 8.0); QVERIFY(advances.at(i).x() > 8.0);
@ -342,11 +340,17 @@ void tst_QRawFont::advances()
QVERIFY(font.advancesForGlyphIndexes(glyphIndices.constData(), advances.data(), numGlyphs)); QVERIFY(font.advancesForGlyphIndexes(glyphIndices.constData(), advances.data(), numGlyphs));
for (int i = 0; i < glyphIndices.size(); ++i) { for (int i = 0; i < glyphIndices.size(); ++i) {
if (mayFail && (i == 0 || i == 5)) { if ((i == 0 || i == 5) && mayDiffer) {
QEXPECT_FAIL("", "FreeType engine reports unexpected advance " QVERIFY2(qRound(advances.at(i).x()) == 8
"for some glyphs (9 instead of 8)", Continue); || qRound(advances.at(i).x()) == 9,
qPrintable(QStringLiteral("%1 != %2 && %1 != %3")
.arg(qRound(advances.at(i).x()))
.arg(8)
.arg(9)));
} else {
QCOMPARE(qRound(advances.at(i).x()), 8);
} }
QVERIFY(qFuzzyCompare(qRound(advances.at(i).x()), 8.0));
if (supportsSubPixelPositions) if (supportsSubPixelPositions)
QVERIFY(advances.at(i).x() > 8.0); QVERIFY(advances.at(i).x() > 8.0);