Keep Multi font engine in QFontCache
authorJiang Jiang <jiang.jiang@nokia.com>
Tue, 18 Oct 2011 13:11:07 +0000 (15:11 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 24 Oct 2011 09:04:04 +0000 (11:04 +0200)
If we only keep single QFontEngineFT in QFontCache, then when we
are looking for the MultiQPA next time with the same QFontDef,
the FT engine will be returned and we get no font fallback support.
That's why we need to keep the Multi engines in QFontCache as well
and distinguish them from the single item. Since QPA doesn't use
'screen' field of QFontCache::Key structure, we use it here to
indicate that we are caching a multi font engine.

Change-Id: Id899d5c5ba52f4bccf134bcd6b1c6386ba22063c
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
src/gui/text/qfontdatabase.h
src/gui/text/qfontdatabase_qpa.cpp
src/gui/text/qfontengine_qpa.cpp

index 6e05503..873d009 100644 (file)
@@ -153,7 +153,7 @@ private:
     static void createDatabase();
     static void parseFontName(const QString &name, QString &foundry, QString &family);
     static QString resolveFontFamilyAlias(const QString &family);
-    static QFontEngine *findFont(int script, const QFontPrivate *fp, const QFontDef &request);
+    static QFontEngine *findFont(int script, const QFontPrivate *fp, const QFontDef &request, bool multi = false);
     static void load(const QFontPrivate *d, int script);
 
     friend struct QFontDef;
index 4cd47da..95a0aff 100644 (file)
@@ -178,6 +178,11 @@ QFontEngine *loadEngine(int script, const QFontDef &request,
             fallbacks = family->fallbackFamilies;
 
         engine = new QFontEngineMultiQPA(engine, script, fallbacks);
+
+        // Cache Multi font engine as well in case we got the FT single
+        // font engine when we are actually looking for a Multi one
+        QFontCache::Key key(request, script, 1);
+        QFontCache::instance()->instance()->insertEngine(key, engine);
     }
 
     return engine;
@@ -230,7 +235,7 @@ bool QFontDatabase::supportsThreadedFontRendering()
 */
 QFontEngine *
 QFontDatabase::findFont(int script, const QFontPrivate *fp,
-                        const QFontDef &request)
+                        const QFontDef &request, bool multi)
 {
     QMutexLocker locker(fontDatabaseMutex());
 
@@ -240,7 +245,7 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
         initializeDb();
 
     QFontEngine *engine;
-    QFontCache::Key key(request, script);
+    QFontCache::Key key(request, script, multi ? 1 : 0);
     engine = QFontCache::instance()->findEngine(key);
     if (engine) {
         qDebug() << "Cache hit level 1";
@@ -282,7 +287,7 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
             for (int i = 0; !engine && i < fallbacks.size(); i++) {
                 QFontDef def = request;
                 def.family = fallbacks.at(i);
-                QFontCache::Key key(def,script);
+                QFontCache::Key key(def, script, multi ? 1 : 0);
                 engine = QFontCache::instance()->findEngine(key);
                 if (!engine) {
                     QtFontDesc desc;
@@ -328,7 +333,11 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
     if (req.stretch == 0)
         req.stretch = 100;
 
-    QFontCache::Key key(req, script);
+    // Until we specifically asked not to, try looking for Multi font engine
+    // first, the last '1' indicates that we want Multi font engine instead
+    // of single ones
+    bool multi = !(req.styleStrategy & QFont::NoFontMerging);
+    QFontCache::Key key(req, script, multi ? 1 : 0);
 
     if (!d->engineData)
         getEngineData(d, key);
@@ -359,7 +368,7 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
     for (; !fe && it != end; ++it) {
         req.family = *it;
 
-        fe = QFontDatabase::findFont(script, d, req);
+        fe = QFontDatabase::findFont(script, d, req, multi);
         if (fe && (fe->type()==QFontEngine::Box) && !req.family.isEmpty())
             fe = 0;
     }
index 7c09ae7..c25ed43 100644 (file)
@@ -680,7 +680,7 @@ void QFontEngineMultiQPA::loadEngine(int at)
     request.family = fallbackFamilies.at(at-1);
     engines[at] = QFontDatabase::findFont(script,
                                           /*fontprivate*/0,
-                                          request);
+                                          request, false);
     Q_ASSERT(engines[at]);
     engines[at]->ref.ref();
     engines[at]->fontDef = request;