Skip to content

Commit

Permalink
Fix text issues when using typographic names
Browse files Browse the repository at this point in the history
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
Change-Id: Ic7b65cde26ddcbf1a257f1673b9af37154660c2f
Reviewed-by: Tor Arne Vestbø <[email protected]>
(cherry picked from commit cba147d)
Reviewed-by: Allan Sandfeld Jensen <[email protected]>
  • Loading branch information
eskilblomfeldt committed Sep 1, 2020
1 parent 1f01607 commit 0c4d476
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class QWindowsFontDatabase : public QPlatformFontDatabase
void ensureFamilyPopulated(const QString &familyName);

void populateFontDatabase() override;
bool populateFamilyAliases(const QString &missingFamily) override;
void populateFamily(const QString &familyName) override;
QFontEngine *fontEngine(const QFontDef &fontDef, void *handle) override;
QFontEngine *fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) override;
Expand Down Expand Up @@ -154,6 +155,7 @@ class QWindowsFontDatabase : public QPlatformFontDatabase

static unsigned m_fontOptions;
QStringList m_eudcFonts;
bool m_hasPopulatedAliases = false;
};

#ifndef QT_NO_DEBUG_STREAM
Expand Down

0 comments on commit 0c4d476

Please sign in to comment.