FontConfig: Fix detection of color fonts

There were two mistakes in the code that intended to detect
if a specific font was a color font in the FontConfig database.

1. The "int n" parameter in FcPatternGet*() is not an array size,
but an index, so it should be 0 and not 1.

2. We need to add FC_COLOR to the list of properties in our pattern
when populating the database, otherwise we will just fail to match
it and none of the system fonts will be listed as color.

Fixes: QTBUG-132377
Change-Id: Ib3c112e8a354abacd05679c62283a1f1abfb40ee
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
(cherry picked from commit 2e1db6541777ee076195ff9e793e4e83afd81539)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2025-01-15 15:39:16 +01:00 committed by Qt Cherry-pick Bot
parent f9bdb80ef1
commit 87330d4bd7
10 changed files with 42 additions and 1 deletions

View File

@ -1032,6 +1032,11 @@ QList<int> QCoreTextFontDatabase::standardSizes() const
return ret;
}
bool QCoreTextFontDatabase::supportsColrv0Fonts() const
{
return true;
}
bool QCoreTextFontDatabase::supportsVariableApplicationFonts() const
{
return true;

View File

@ -47,6 +47,7 @@ public:
bool fontsAlwaysScalable() const override;
QList<int> standardSizes() const override;
bool supportsVariableApplicationFonts() const override;
bool supportsColrv0Fonts() const override;
// For iOS and macOS platform themes
QFont *themeFont(QPlatformTheme::Font) const;

View File

@ -355,6 +355,15 @@ QStringList QFreeTypeFontDatabase::addTTFile(const QByteArray &fontData, const Q
return families;
}
bool QFreeTypeFontDatabase::supportsColrv0Fonts() const
{
#if (FREETYPE_MAJOR*10000 + FREETYPE_MINOR*100 + FREETYPE_PATCH) >= 21000
return true;
#else
return false;
#endif
}
bool QFreeTypeFontDatabase::supportsVariableApplicationFonts() const
{
#if (FREETYPE_MAJOR*10000 + FREETYPE_MINOR*100 + FREETYPE_PATCH) >= 20900

View File

@ -43,6 +43,7 @@ public:
QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName, QFontDatabasePrivate::ApplicationFont *applicationFont = nullptr) override;
void releaseHandle(void *handle) override;
bool supportsVariableApplicationFonts() const override;
bool supportsColrv0Fonts() const override;
static void addNamedInstancesForFace(void *face, int faceIndex,
const QString &family, const QString &styleName,

View File

@ -657,6 +657,15 @@ bool QPlatformFontDatabase::supportsVariableApplicationFonts() const
return false;
}
/*!
Returns true if this font database supports loading color fonts in the COLRv0 format.
\since 6.9
*/
bool QPlatformFontDatabase::supportsColrv0Fonts() const
{
return false;
}
/*!
\class QPlatformFontDatabase

View File

@ -89,6 +89,7 @@ public:
virtual QList<int> standardSizes() const;
virtual bool supportsVariableApplicationFonts() const;
virtual bool supportsColrv0Fonts() const;
// helper
static QSupportedWritingSystems writingSystemsFromTrueTypeBits(quint32 unicodeRange[4], quint32 codePageRange[2]);

View File

@ -478,7 +478,7 @@ static void populateFromPattern(FcPattern *pattern,
FcBool colorFont = false;
#ifdef FC_COLOR
FcPatternGetBool(pattern, FC_COLOR, 1, &colorFont);
FcPatternGetBool(pattern, FC_COLOR, 0, &colorFont);
#endif
// Note: stretch should really be an int but registerFont incorrectly uses an enum
@ -576,6 +576,9 @@ void QFontconfigDatabase::populateFontDatabase()
FC_WIDTH, FC_FAMILYLANG,
#if FC_VERSION >= 20297
FC_CAPABILITY,
#endif
#if defined(FC_COLOR)
FC_COLOR,
#endif
(const char *)nullptr
};

View File

@ -1292,4 +1292,9 @@ bool QWindowsFontDatabase::isPrivateFontFamily(const QString &family) const
return m_eudcFonts.contains(family) || QPlatformFontDatabase::isPrivateFontFamily(family);
}
bool QWindowsFontDatabase::supportsColrv0Fonts() const
{
return true;
}
QT_END_NAMESPACE

View File

@ -46,6 +46,7 @@ public:
void populateFontDatabase() override;
void invalidate() override;
void removeApplicationFonts();
bool supportsColrv0Fonts() const override;
void populateFamily(const QString &familyName) override;
bool populateFamilyAliases(const QString &missingFamily) override;

View File

@ -769,6 +769,12 @@ void tst_QFontDatabase::addApplicationFontFallback()
void tst_QFontDatabase::addApplicationEmojiFontFamily()
{
{
QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase();
if (!pfdb->supportsColrv0Fonts())
QSKIP("This test depends on COLRv0 support.");
}
int id = -1;
auto cleanup = qScopeGuard([&id] {
if (id >= 0)