Make self-contained test of condensed font matching and width
Fixes the test for width of condensed fonts so it doesn't depend on the presence of the Liberation font on the system, and adds another test that condensed sub-families can be matched consistently. The latter will however not work on Windows until QTBUG-53458 is solved. Task-number: QTBUG-51335. Change-Id: Id6d046274fa21b2dce0ad6b32dce7f1c8a92a4f4 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
parent
d976cee1e5
commit
90fe2c64f5
@ -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
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>LED_REAL.TTF</file>
|
||||
<file alias="testfont.ttf">../../../shared/resources/testfont.ttf</file>
|
||||
<file alias="testfont_condensed.ttf">../../../shared/resources/testfont_condensed.ttf</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -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)
|
||||
|
BIN
tests/auto/shared/resources/testfont_condensed.ttf
Normal file
BIN
tests/auto/shared/resources/testfont_condensed.ttf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user