From d281f94c30aa15765c9c1ec0a613311514033076 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Thu, 10 Nov 2011 18:01:56 +0100 Subject: Fix application font loading in basic font db We need to reregister fonts in initializeDb because basic font db doesn't have an internal record like fontconfig does, so just repopulating the font database won't work. db->reregisterAppFonts is now used properly as intended (reregister application fonts after the system font database has been cleared). Also, static variable 'initialized' in initializeDb() is removed since we check privateDb()->count to see if it needs to be populated again. Task-number: QTBUG-22063 Change-Id: Ifc66392b56b72acbe08b99256c61421c204be5d7 Reviewed-by: Eskil Abrahamsen Blomfeldt (cherry picked from commit 89cfe9eb01ad75c14121dbd6038b7c791226acf1) Reviewed-by: Jiang Jiang --- src/gui/text/qfontdatabase_qpa.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/gui/text/qfontdatabase_qpa.cpp b/src/gui/text/qfontdatabase_qpa.cpp index 2e42f8c..8776a00 100644 --- a/src/gui/text/qfontdatabase_qpa.cpp +++ b/src/gui/text/qfontdatabase_qpa.cpp @@ -103,14 +103,22 @@ static QStringList fallbackFamilies(const QString &family, const QFont::Style &s return retList; } +static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt); + static void initializeDb() { - static int initialized = false; + QFontDatabasePrivate *db = privateDb(); - if (!initialized) { - //init by asking for the platformfontdb for the first time :) + // init by asking for the platformfontdb for the first time or after invalidation + if (!db->count) QApplicationPrivate::platformIntegration()->fontDatabase()->populateFontDatabase(); - initialized = true; + + if (db->reregisterAppFonts) { + for (int i = 0; i < db->applicationFonts.count(); i++) { + if (!db->applicationFonts.at(i).families.isEmpty()) + registerFont(&db->applicationFonts[i]); + } + db->reregisterAppFonts = false; } } @@ -133,7 +141,9 @@ void qt_applyFontDatabaseSettings(const QSettings &settings) static inline void load(const QString & = QString(), int = -1) { - initializeDb(); + // Only initialize the database if it has been cleared or not initialized yet + if (!privateDb()->count) + initializeDb(); } static -- cgit v0.12