From cba147d35915c50c2ee46041e635bdc297053e08 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 27 Aug 2020 11:54:05 +0200 Subject: [PATCH] Fix text issues when using typographic names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default, only the legacy family names are populated on Windows, since we are using GDI to do the population. The actual typographic names are added later as aliases when the font is loaded. This can cause us to fail matching a font against its typographic name before it has been loaded and e.g .in Qt Quick we will cache the glyph indexes for a fallback font instead. If the font is later loaded and aliases are populated, we will use the cached glyph indexes and get seemingly random glyphs displayed. We reuse the mechanism invented for CoreText to do lazy population of aliases. The population will now happen when the first non-match occurs, and a second attempt will be made after we populate aliases. [ChangeLog][Windows] Fixes an issue where fonts would sometimes not fail to work when selected using typographic names. Fixes: QTBUG-84786 Pick-to: 5.15 Change-Id: Ic7b65cde26ddcbf1a257f1673b9af37154660c2f Reviewed-by: Tor Arne Vestbø --- src/gui/text/windows/qwindowsfontdatabase.cpp | 15 +++++++++++++++ src/gui/text/windows/qwindowsfontdatabase_p.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/gui/text/windows/qwindowsfontdatabase.cpp b/src/gui/text/windows/qwindowsfontdatabase.cpp index b5e09970153..36d8da0ce8b 100644 --- a/src/gui/text/windows/qwindowsfontdatabase.cpp +++ b/src/gui/text/windows/qwindowsfontdatabase.cpp @@ -651,6 +651,21 @@ static int QT_WIN_CALLBACK storeFont(const LOGFONT *logFont, const TEXTMETRIC *t return 1; } +bool QWindowsFontDatabase::populateFamilyAliases(const QString &missingFamily) +{ + Q_UNUSED(missingFamily); + + if (m_hasPopulatedAliases) + return false; + + QStringList families = QFontDatabase::families(); + for (const QString &family : families) + populateFamily(family); + m_hasPopulatedAliases = true; + + return true; +} + void QWindowsFontDatabase::populateFamily(const QString &familyName) { qCDebug(lcQpaFonts) << familyName; diff --git a/src/gui/text/windows/qwindowsfontdatabase_p.h b/src/gui/text/windows/qwindowsfontdatabase_p.h index b870d6c4a0e..b4b367b1e77 100644 --- a/src/gui/text/windows/qwindowsfontdatabase_p.h +++ b/src/gui/text/windows/qwindowsfontdatabase_p.h @@ -80,6 +80,7 @@ public: void populateFontDatabase() override; void populateFamily(const QString &familyName) override; + bool populateFamilyAliases(const QString &missingFamily) override; QFontEngine *fontEngine(const QFontDef &fontDef, void *handle) override; QFontEngine *fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) override; QStringList fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const override; @@ -126,6 +127,7 @@ private: static unsigned m_fontOptions; QStringList m_eudcFonts; + bool m_hasPopulatedAliases = false; }; #ifndef QT_NO_DEBUG_STREAM