Fix application font loading in basic font db
authorJiang Jiang <jiang.jiang@nokia.com>
Thu, 10 Nov 2011 17:01:56 +0000 (18:01 +0100)
committerQt by Nokia <qt-info@nokia.com>
Fri, 11 Nov 2011 15:47:23 +0000 (16:47 +0100)
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 <eskil.abrahamsen-blomfeldt@nokia.com>
src/gui/text/qfontdatabase_qpa.cpp

index 95a0aff..fa96a0d 100644 (file)
@@ -105,22 +105,30 @@ 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 || db->reregisterAppFonts) {
-        //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)
         QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFontDatabase();
+
+    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;
-        initialized = true;
     }
 }
 
 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