diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-12-08 13:54:55 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-12-08 14:53:37 +0100 |
commit | 1c42b1e8c754b45dfa9e183ae37a3bc823f82463 (patch) | |
tree | b0774a717fc68ba68e1d63073d95ab7ecd3c9e1c /src | |
parent | 2bc7d38bd63843c4598ed501e3adbf0e39162c61 (diff) |
QIcon: harden font file discovery in Android icon engine
Amend f54393ba70d6dc56b201cf8ff7691a4bf04626d6 by trying more font file
candidates, and don't try to download fonts if the query is pointing at
a resource.
Change-Id: I3fffc6fb3faa45b95540ebdf6cdf8ee4a49ebd78
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformiconengine.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/plugins/platforms/android/qandroidplatformiconengine.cpp b/src/plugins/platforms/android/qandroidplatformiconengine.cpp index fdf12f2c83..c66a6bd211 100644 --- a/src/plugins/platforms/android/qandroidplatformiconengine.cpp +++ b/src/plugins/platforms/android/qandroidplatformiconengine.cpp @@ -59,7 +59,7 @@ static QString fetchFont(const QString &query) const QByteArray fontData = file.readAll(); int fontId = QFontDatabase::addApplicationFontFromData(fontData); loadedFamilies << QFontDatabase::applicationFontFamilies(fontId); - } else { + } else if (!query.startsWith(u":/"_s)) { const QString package = u"com.google.android.gms"_s; const QString authority = u"com.google.android.gms.fonts"_s; @@ -250,17 +250,33 @@ QAndroidPlatformIconEngine::QAndroidPlatformIconEngine(const QString &iconName) : m_iconName(iconName) , m_glyphs(glyphs()) { - // The MaterialIcons-Regular.ttf font file is available from - // https://github.com/google/material-design-icons/tree/master/font. If it's packaged - // as a resource with the application, then we use it. Otherwise we try to download - // the Outlined version of Material Symbols, and failing that we try Material Icons. - QString fontFamily = FontProvider::fetchFont(u":/qt-project.org/icons/MaterialIcons-Regular.ttf"_s); + QString fontFamily; + // The MaterialIcons-*.ttf and MaterialSymbols* font files are available from + // https://github.com/google/material-design-icons/tree/master. If one of them is + // packaged as a resource with the application, then we use it. We prioritize + // a variable font. + const QStringList fontCandidates = { + "MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].ttf", + "MaterialSymbolsRounded[FILL,GRAD,opsz,wght].ttf", + "MaterialSymbolsSharp[FILL,GRAD,opsz,wght].ttf", + "MaterialIcons-Regular.ttf", + "MaterialIconsOutlined-Regular.otf", + "MaterialIconsRound-Regular.otf", + "MaterialIconsSharp-Regular.otf", + "MaterialIconsTwoTone-Regular.otf", + }; + for (const auto &fontCandidate : fontCandidates) { + fontFamily = FontProvider::fetchFont(u":/qt-project.org/icons/%1"_s.arg(fontCandidate)); + if (!fontFamily.isEmpty()) + break; + } + // Otherwise we try to download the Outlined version of Material Symbols const QString key = qEnvironmentVariable("QT_GOOGLE_FONTS_KEY"); if (fontFamily.isEmpty() && !key.isEmpty()) fontFamily = FontProvider::fetchFont(u"key=%1&name=Material+Symbols+Outlined"_s.arg(key)); - // last resort - use the old Material Icons + // last resort - use any Material Icons if (fontFamily.isEmpty()) fontFamily = u"Material Icons"_s; m_iconFont = QFont(fontFamily); |