summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/text/qrawfont/tst_qrawfont.cpp')
-rw-r--r--tests/auto/gui/text/qrawfont/tst_qrawfont.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
index c12acf65cc..b1e292f094 100644
--- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
+++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
@@ -93,6 +93,8 @@ private slots:
void multipleRawFontsFromData();
void rawFontFromInvalidData();
+
+ void kernedAdvances();
private:
QString testFont;
QString testFontBoldItalic;
@@ -954,6 +956,38 @@ void tst_QRawFont::rawFontFromInvalidData()
QVERIFY(!font.isValid());
}
+#define FUZZY_LTEQ(X, Y) (X < Y || qFuzzyCompare(X, Y))
+
+void tst_QRawFont::kernedAdvances()
+{
+ const int emSquareSize = 1000;
+ const qreal pixelSize = 16.0;
+ const int underScoreAW = 500;
+ const int underscoreTwoKerning = -500;
+ const qreal errorMargin = 1.0 / 16.0; // Fixed point error margin
+
+ QRawFont font(testFont, pixelSize);
+ QVERIFY(font.isValid());
+
+ QVector<quint32> glyphIndexes = font.glyphIndexesForString(QStringLiteral("__"));
+ QCOMPARE(glyphIndexes.size(), 2);
+
+ QVector<QPointF> advances = font.advancesForGlyphIndexes(glyphIndexes, QRawFont::KernedAdvances);
+ QCOMPARE(advances.size(), 2);
+
+ qreal expectedAdvanceWidth = pixelSize * underScoreAW / emSquareSize;
+ QVERIFY(FUZZY_LTEQ(qAbs(advances.at(0).x() - expectedAdvanceWidth), errorMargin));
+
+ glyphIndexes = font.glyphIndexesForString(QStringLiteral("_2"));
+ QCOMPARE(glyphIndexes.size(), 2);
+
+ advances = font.advancesForGlyphIndexes(glyphIndexes, QRawFont::KernedAdvances);
+ QCOMPARE(advances.size(), 2);
+
+ expectedAdvanceWidth = pixelSize * (underScoreAW + underscoreTwoKerning) / emSquareSize;
+ QVERIFY(FUZZY_LTEQ(qAbs(advances.at(0).x() - expectedAdvanceWidth), errorMargin));
+}
+
#endif // QT_NO_RAWFONT
QTEST_MAIN(tst_QRawFont)