diff --git a/tests/auto/gui/text/qfontdatabase/qfontdatabase.pro b/tests/auto/gui/text/qfontdatabase/qfontdatabase.pro index 8a08cdc182..9d357a35f2 100644 --- a/tests/auto/gui/text/qfontdatabase/qfontdatabase.pro +++ b/tests/auto/gui/text/qfontdatabase/qfontdatabase.pro @@ -4,7 +4,5 @@ SOURCES += tst_qfontdatabase.cpp QT += testlib core-private gui-private TESTDATA += LED_REAL.TTF -android { - RESOURCES += testdata.qrc -} +RESOURCES += testdata.qrc diff --git a/tests/auto/gui/text/qfontdatabase/testdata.qrc b/tests/auto/gui/text/qfontdatabase/testdata.qrc index 8a8670bf17..81a0b5b0bf 100644 --- a/tests/auto/gui/text/qfontdatabase/testdata.qrc +++ b/tests/auto/gui/text/qfontdatabase/testdata.qrc @@ -1,5 +1,7 @@ LED_REAL.TTF + ../../../shared/resources/testfont.ttf + ../../../shared/resources/testfont_condensed.ttf diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp index f71d808390..c53792da99 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -64,20 +64,27 @@ private slots: void aliases(); void fallbackFonts(); - void liberationFont(); + void condensedFontWidth(); + void condensedFontMatching(); private: - const QString m_testFont; + QString m_ledFont; + QString m_testFont; + QString m_testFontCondensed; }; tst_QFontDatabase::tst_QFontDatabase() - : m_testFont(QFINDTESTDATA("LED_REAL.TTF")) { } void tst_QFontDatabase::initTestCase() { + m_ledFont = QFINDTESTDATA("LED_REAL.TTF"); + m_testFont = QFINDTESTDATA("testfont.ttf"); + m_testFontCondensed = QFINDTESTDATA("testfont_condensed.ttf"); + QVERIFY(!m_ledFont.isEmpty()); QVERIFY(!m_testFont.isEmpty()); + QVERIFY(!m_testFontCondensed.isEmpty()); } void tst_QFontDatabase::styles_data() @@ -209,13 +216,13 @@ void tst_QFontDatabase::addAppFont() int id; if (useMemoryFont) { - QFile fontfile(m_testFont); + QFile fontfile(m_ledFont); fontfile.open(QIODevice::ReadOnly); QByteArray fontdata = fontfile.readAll(); QVERIFY(!fontdata.isEmpty()); id = QFontDatabase::addApplicationFontFromData(fontdata); } else { - id = QFontDatabase::addApplicationFont(m_testFont); + id = QFontDatabase::addApplicationFont(m_ledFont); } #if defined(Q_OS_HPUX) && defined(QT_NO_FONTCONFIG) // Documentation says that X11 systems that don't have fontconfig @@ -277,22 +284,54 @@ void tst_QFontDatabase::fallbackFonts() } } -void tst_QFontDatabase::liberationFont() +static QString testString() { - QString libSans("Liberation Sans"); - QString libSansNarrow("Liberation Sans Narrow"); + return QStringLiteral("foo bar"); +} +void tst_QFontDatabase::condensedFontWidth() +{ QFontDatabase db; - if (!db.hasFamily(libSans) || !db.hasFamily(libSansNarrow)) - QSKIP("Requires Liberation Sans installed"); + QFontDatabase::addApplicationFont(m_testFont); + QFontDatabase::addApplicationFont(m_testFontCondensed); - QFont fontLS(libSans); - QFont fontLSN(libSansNarrow); + QVERIFY(db.hasFamily("QtBidiTestFont")); + if (!db.hasFamily("QtBidiTestFontCondensed")) + QSKIP("This platform doesn't support font sub-family names (QTBUG-55625)"); - QFontMetrics fmLS(fontLS); - QFontMetrics fmLSN(fontLSN); + // Test we really get a condensed font, and a not renormalized one (QTBUG-48043): + QFont testFont("QtBidiTestFont"); + QFont testFontCondensed("QtBidiTestFontCondensed"); + QFontMetrics fmTF(testFont); + QFontMetrics fmTFC(testFontCondensed); + QVERIFY(fmTF.width(testString()) > fmTFC.width(testString())); - QVERIFY(fmLS.width(QStringLiteral("foo bar")) > fmLSN.width(QStringLiteral("foo bar"))); +} + +void tst_QFontDatabase::condensedFontMatching() +{ + QFontDatabase db; + QFontDatabase::removeAllApplicationFonts(); + QFontDatabase::addApplicationFont(m_testFontCondensed); + if (!db.hasFamily("QtBidiTestFont")) + QSKIP("This platform doesn't support preferred font family names (QTBUG-53478)"); + QFontDatabase::addApplicationFont(m_testFont); + + // Test we correctly get the condensed font using different font matching methods: + QFont tfcByStretch("QtBidiTestFont"); + tfcByStretch.setStretch(QFont::Condensed); + QFont tfcByStyleName("QtBidiTestFont"); + tfcByStyleName.setStyleName("Condensed"); + + QCOMPARE(QFontMetrics(tfcByStretch).width(testString()), + QFontMetrics(tfcByStyleName).width(testString())); + + if (!db.hasFamily("QtBidiTestFontCondensed")) + QSKIP("This platform doesn't support font sub-family names (QTBUG-55625)"); + + QFont tfcBySubfamilyName("QtBidiTestFontCondensed"); + QCOMPARE(QFontMetrics(tfcByStyleName).width(testString()), + QFontMetrics(tfcBySubfamilyName).width(testString())); } QTEST_MAIN(tst_QFontDatabase) diff --git a/tests/auto/shared/resources/testfont_condensed.ttf b/tests/auto/shared/resources/testfont_condensed.ttf new file mode 100644 index 0000000000..6a6c536202 Binary files /dev/null and b/tests/auto/shared/resources/testfont_condensed.ttf differ