summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
authorKonstantin Tokarev <annulen@yandex.ru>2016-08-03 15:45:02 +0300
committerKonstantin Tokarev <annulen@yandex.ru>2016-08-15 18:27:06 +0000
commitac1e87d9f373ad649d989f254b37d2f29ddf25fe (patch)
treeb39d2a1c3d207fd2f025301a4908c472c95245a4 /tests/auto/gui
parent869513a49f7902b5942e439a972807583dab9bf9 (diff)
Added capHeight() to QRawFont and QFontMetrics(F)
Cap height is an important metric of font, in particular it is required to make decent implementation of "initial-letter" CSS property in QtWebKit. Note that some fonts lack cap height metadata, so we need to fall back to measuring H letter height. Change-Id: Icf69d92159d070889085e20d31f2e397d796d940 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/text/qrawfont/testdata.qrc1
-rw-r--r--tests/auto/gui/text/qrawfont/testfont_os2_v1.ttfbin0 -> 72960 bytes
-rw-r--r--tests/auto/gui/text/qrawfont/tst_qrawfont.cpp30
3 files changed, 29 insertions, 2 deletions
diff --git a/tests/auto/gui/text/qrawfont/testdata.qrc b/tests/auto/gui/text/qrawfont/testdata.qrc
index 8f8e32ed24..c7ac9641d1 100644
--- a/tests/auto/gui/text/qrawfont/testdata.qrc
+++ b/tests/auto/gui/text/qrawfont/testdata.qrc
@@ -1,6 +1,7 @@
<RCC>
<qresource prefix="/">
<file>testfont_bold_italic.ttf</file>
+ <file>testfont_os2_v1.ttf</file>
<file alias="testfont.ttf">../../../shared/resources/testfont.ttf</file>
</qresource>
</RCC>
diff --git a/tests/auto/gui/text/qrawfont/testfont_os2_v1.ttf b/tests/auto/gui/text/qrawfont/testfont_os2_v1.ttf
new file mode 100644
index 0000000000..ee8b67d892
--- /dev/null
+++ b/tests/auto/gui/text/qrawfont/testfont_os2_v1.ttf
Binary files differ
diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
index 471b32dd50..3cf108ed62 100644
--- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
+++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
@@ -93,6 +93,7 @@ private slots:
private:
QString testFont;
QString testFontBoldItalic;
+ QString testFontOs2V1;
#endif // QT_NO_RAWFONT
};
@@ -110,6 +111,7 @@ void tst_QRawFont::initTestCase()
{
testFont = QFINDTESTDATA("testfont.ttf");
testFontBoldItalic = QFINDTESTDATA("testfont_bold_italic.ttf");
+ testFontOs2V1 = QFINDTESTDATA("testfont_os2_v1.ttf");
if (testFont.isEmpty() || testFontBoldItalic.isEmpty())
QFAIL("qrawfont unittest font files not found!");
@@ -184,6 +186,7 @@ void tst_QRawFont::correctFontData_data()
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
QTest::addColumn<qreal>("unitsPerEm");
QTest::addColumn<qreal>("pixelSize");
+ QTest::addColumn<int>("capHeight");
int hintingPreferences[] = {
int(QFont::PreferDefaultHinting),
@@ -207,7 +210,8 @@ void tst_QRawFont::correctFontData_data()
<< QFont::Normal
<< QFont::HintingPreference(*hintingPreference)
<< qreal(1000.0)
- << qreal(10.0);
+ << qreal(10.0)
+ << 7;
fileName = testFontBoldItalic;
title = fileName
@@ -221,7 +225,23 @@ void tst_QRawFont::correctFontData_data()
<< QFont::Bold
<< QFont::HintingPreference(*hintingPreference)
<< qreal(1000.0)
- << qreal(10.0);
+ << qreal(10.0)
+ << 7;
+
+ fileName = testFontOs2V1;
+ title = fileName
+ + QLatin1String(": hintingPreference=")
+ + QString::number(*hintingPreference);
+
+ QTest::newRow(qPrintable(title))
+ << fileName
+ << QString::fromLatin1("QtBidiTestFont")
+ << QFont::StyleNormal
+ << QFont::Normal
+ << QFont::HintingPreference(*hintingPreference)
+ << qreal(1000.0)
+ << qreal(10.0)
+ << 7;
++hintingPreference;
}
@@ -236,6 +256,7 @@ void tst_QRawFont::correctFontData()
QFETCH(QFont::HintingPreference, hintingPreference);
QFETCH(qreal, unitsPerEm);
QFETCH(qreal, pixelSize);
+ QFETCH(int, capHeight);
QRawFont font(fileName, 10, hintingPreference);
QVERIFY(font.isValid());
@@ -246,6 +267,11 @@ void tst_QRawFont::correctFontData()
QCOMPARE(font.hintingPreference(), hintingPreference);
QCOMPARE(font.unitsPerEm(), unitsPerEm);
QCOMPARE(font.pixelSize(), pixelSize);
+
+ // Some platforms return the actual fractional height of the
+ // H character when the value is missing from the OS/2 table,
+ // so we ceil it off to match (any touched pixel counts).
+ QCOMPARE(qCeil(font.capHeight()), capHeight);
}
void tst_QRawFont::glyphIndices()