Support specifying fallbacks in font request on QPA
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Thu, 10 May 2012 14:50:33 +0000 (16:50 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 16 May 2012 02:24:58 +0000 (04:24 +0200)
Because the QPA font database would query fallback families inside
findFont(), support for requesting multiple font families in order
of preference (like QFont("Times New Roman, Arial")) did not work,
because the Arial fallback was never attempted. To fix this, we
pass in the queried fallbacks and make sure they are tried before
any platform specific fallbacks.

Task-number: QTBUG-20986
Change-Id: Idb2b717856f013ce2874f00a8debaff60176d2fc
Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
src/gui/text/qfont_p.h
src/gui/text/qfontdatabase_qpa.cpp
tests/auto/gui/text/qcssparser/tst_qcssparser.cpp

index 13e5fcb..55e1b70 100644 (file)
@@ -56,6 +56,7 @@
 #include "QtGui/qfont.h"
 #include "QtCore/qmap.h"
 #include "QtCore/qobject.h"
+#include "QtCore/qstringlist.h"
 #include <private/qunicodetables_p.h>
 #include <QtGui/qfontdatabase.h>
 #include "private/qfixed_p.h"
@@ -79,6 +80,7 @@ struct QFontDef
     QString family;
     QString styleName;
 
+    QStringList fallBackFamilies;
 
     qreal pointSize;
     qreal pixelSize;
index d7e5441..622eda0 100644 (file)
@@ -317,7 +317,12 @@ QFontDatabase::findFont(int script, const QFontPrivate *fp,
 
     if (!engine) {
         if (!request.family.isEmpty()) {
-            QStringList fallbacks = fallbackFamilies(request.family,QFont::Style(request.style),QFont::StyleHint(request.styleHint),QUnicodeTables::Script(script));
+            QStringList fallbacks = request.fallBackFamilies
+                                  + fallbackFamilies(request.family,
+                                                     QFont::Style(request.style),
+                                                     QFont::StyleHint(request.styleHint),
+                                                     QUnicodeTables::Script(script));
+
             for (int i = 0; !engine && i < fallbacks.size(); i++) {
                 QFontDef def = request;
                 def.family = fallbacks.at(i);
@@ -386,7 +391,13 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
     QStringList family_list;
 
     if (!req.family.isEmpty()) {
-        family_list = familyList(req);
+        QStringList familiesForRequest = familyList(req);
+
+        // Add primary selection
+        family_list << familiesForRequest.takeFirst();
+
+        // Fallbacks requested in font request
+        req.fallBackFamilies = familiesForRequest;
 
         // add the default family
         QString defaultFamily = QGuiApplication::font().family();
@@ -409,6 +420,9 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
 
             fe = 0;
         }
+
+        // No need to check requested fallback families again
+        req.fallBackFamilies.clear();
     }
 
     if (fe->symbol || (d->request.styleStrategy & QFont::NoFontMerging)) {
index 7e0a60c..4d50601 100644 (file)
@@ -1592,11 +1592,6 @@ void tst_QCssParser::extractFontFamily()
     extractor.extractFont(&fnt, &adjustment);
     QFontInfo info(fnt);
 
-    // Note, we have to QSKIP rather than QEXPECT_FAIL because font lookup is broken
-    // such that it may work or not work depending on the order in which fonts were
-    // loaded from disk: ### fixme: Check platforms
-    QSKIP("QTBUG-20986 may fail on qpa");
-
     QTEST(info.family(), "expectedFamily");
 }