summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2023-07-06 13:16:50 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2023-09-20 21:37:50 +0200
commit5469d6a6cc741cc8fb2adec3cd08c39b8ef6c75a (patch)
tree8056b93ff84a8ccacc58f35299c1e76a7dc294fb /tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
parent3aff1e16780a5b5e132e24fb9b44c22720beb767 (diff)
Support loading variable fonts as application fonts in Freetype
When loading the fonts, we go through all the named instances and register these as subfamilies. In addition to exposing these variants by style name, we also register them with the according weights, italic style and stretch. This adds a field to FontFile to allow piping the instance index through to when we instantiate the face. [ChangeLog][Fonts] Added support for selecting named instances in variable application fonts when using the Freetype backend. Task-number: QTBUG-108624 Change-Id: I57ef6b4802756dd408c3aae1f8a6c792a89bee6a Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp')
-rw-r--r--tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
index 172cb2480b..81c402cd89 100644
--- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
+++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
@@ -61,6 +61,8 @@ private slots:
void stretchRespected();
+ void variableFont();
+
#ifdef Q_OS_WIN
void findCourier();
#endif
@@ -70,6 +72,7 @@ private:
QString m_testFont;
QString m_testFontCondensed;
QString m_testFontItalic;
+ QString m_testFontVariable;
};
tst_QFontDatabase::tst_QFontDatabase()
@@ -82,10 +85,12 @@ void tst_QFontDatabase::initTestCase()
m_testFont = QFINDTESTDATA("testfont.ttf");
m_testFontCondensed = QFINDTESTDATA("testfont_condensed.ttf");
m_testFontItalic = QFINDTESTDATA("testfont_italic.ttf");
+ m_testFontVariable = QFINDTESTDATA("testfont_variable.ttf");
QVERIFY(!m_ledFont.isEmpty());
QVERIFY(!m_testFont.isEmpty());
QVERIFY(!m_testFontCondensed.isEmpty());
QVERIFY(!m_testFontItalic.isEmpty());
+ QVERIFY(!m_testFontVariable.isEmpty());
}
void tst_QFontDatabase::styles_data()
@@ -505,5 +510,47 @@ void tst_QFontDatabase::findCourier()
}
#endif
+void tst_QFontDatabase::variableFont()
+{
+ {
+ QFont f;
+ f.setStyleStrategy(QFont::NoFontMerging);
+ QFontPrivate *font_d = QFontPrivate::get(f);
+ if (!font_d->engineForScript(QChar::Script_Common)->supportsVariableApplicationFonts())
+ QSKIP("Variable application fonts only supported on Freetype currently");
+ }
+
+ int id = QFontDatabase::addApplicationFont(m_testFontVariable);
+ if (id == -1)
+ QSKIP("Skip the test since app fonts are not supported on this system");
+
+ QString family = QFontDatabase::applicationFontFamilies(id).first();
+ {
+ QFont font(family);
+ QCOMPARE(QFontInfo(font).styleName(), u"Regular"_s);
+ QCOMPARE(QFontInfo(font).weight(), QFont::Normal);
+ }
+
+ {
+ QFont font(family);
+ font.setWeight(QFont::ExtraBold);
+ QCOMPARE(QFontInfo(font).styleName(), u"QtExtraBold"_s);
+ QCOMPARE(QFontInfo(font).weight(), QFont::ExtraBold);
+ }
+
+ {
+ QFont regularFont(family);
+ QFont extraBoldFont(family);
+ extraBoldFont.setStyleName(u"QtExtraBold"_s);
+
+ QFontMetricsF regularFm(regularFont);
+ QFontMetricsF extraBoldFm(extraBoldFont);
+
+ QVERIFY(regularFm.horizontalAdvance(QLatin1Char('1')) < extraBoldFm.horizontalAdvance(QLatin1Char('1')));
+ }
+
+ QFontDatabase::removeApplicationFont(id);
+}
+
QTEST_MAIN(tst_QFontDatabase)
#include "tst_qfontdatabase.moc"