Fix QFont::defaultFamily() in the new QPA world.
authorPierre Rossi <pierre.rossi@nokia.com>
Wed, 5 Oct 2011 15:10:28 +0000 (17:10 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 6 Oct 2011 22:43:26 +0000 (00:43 +0200)
This is so that the results of LayoutTests in WebKit are
more in line with what things were like in Qt 4.8.

Change-Id: I25962e03bd8e0316cb303c0d94c25ac4e73ea9a8
Reviewed-on: http://codereview.qt-project.org/6162
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
src/gui/text/qfont_qpa.cpp
src/gui/text/qfontdatabase.h
tests/auto/gui/text/qfont/tst_qfont.cpp

index e151a38..d6a73cf 100644 (file)
@@ -78,23 +78,31 @@ QString QFont::defaultFamily() const
     QString familyName;
     switch(d->request.styleHint) {
         case QFont::Times:
-            familyName = QString::fromLatin1("times");
+            familyName = QString::fromLatin1("Times");
+            break;
         case QFont::Courier:
+            familyName = QString::fromLatin1("Courier");
+            break;
         case QFont::Monospace:
-            familyName = QString::fromLatin1("monospace");
+            familyName = QString::fromLatin1("Courier New");
+            break;
+        case QFont::Cursive:
+            familyName = QString::fromLatin1("Comic Sans MS");
+            break;
+        case QFont::Fantasy:
+            familyName = QString::fromLatin1("Impact");
+            break;
         case QFont::Decorative:
-            familyName = QString::fromLatin1("old english");
+            familyName = QString::fromLatin1("Old English");
+            break;
         case QFont::Helvetica:
         case QFont::System:
         default:
-            familyName = QString::fromLatin1("helvetica");
+            familyName = QString::fromLatin1("Helvetica");
     }
 
-    QStringList list = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fallbacksForFamily(familyName,QFont::StyleNormal,QFont::StyleHint(d->request.styleHint),QUnicodeTables::Common);
-    if (list.size()) {
-        familyName = list.at(0);
-    }
-    return familyName;
+    return QGuiApplicationPrivate::platformIntegration()->fontDatabase()->resolveFontFamilyAlias(familyName);
+
 }
 
 QString QFont::lastResortFamily() const
index 994a7a4..fb8ef20 100644 (file)
@@ -46,6 +46,8 @@
 #include <QtCore/qstring.h>
 #include <QtGui/qfont.h>
 
+class tst_QFont;
+
 QT_BEGIN_HEADER
 
 QT_BEGIN_NAMESPACE
@@ -167,6 +169,9 @@ private:
     friend class QFontEngineMultiQWS;
     friend class QFontEngineMultiS60;
     friend class QFontEngineMultiQPA;
+#ifdef QT_BUILD_INTERNAL
+    friend class ::tst_QFont;
+#endif
 
     QFontDatabasePrivate *d;
 };
index 48d0e43..88c9486 100644 (file)
@@ -84,6 +84,10 @@ private slots:
 #if defined(Q_WS_MAC)
     void styleName();
 #endif
+#ifdef QT_BUILD_INTERNAL
+    void defaultFamily_data();
+    void defaultFamily();
+#endif
 };
 
 // Testing get/set functions
@@ -627,5 +631,37 @@ void tst_QFont::styleName()
 }
 #endif
 
+#ifdef QT_BUILD_INTERNAL
+Q_DECLARE_METATYPE(QFont::StyleHint)
+void tst_QFont::defaultFamily_data()
+{
+    QTest::addColumn<QFont::StyleHint>("styleHint");
+    QTest::addColumn<QString>("defaultFamily");
+
+    QTest::newRow("serif") << QFont::Times << "Times";
+    QTest::newRow("courier") << QFont::Courier << "Courier";
+    QTest::newRow("monospace") << QFont::Monospace << "Courier New";
+    QTest::newRow("cursive") << QFont::Cursive << "Comic Sans MS";
+    QTest::newRow("fantasy") << QFont::Fantasy << "Impact";
+    QTest::newRow("old english") << QFont::OldEnglish<< "Old English";
+    QTest::newRow("sans-serif") << QFont::Helvetica << "Helvetica";
+}
+
+void tst_QFont::defaultFamily()
+{
+    QFETCH(QFont::StyleHint, styleHint);
+    QFETCH(QString, defaultFamily);
+
+    QFontDatabase db;
+    if (!db.hasFamily(defaultFamily))
+        QSKIP("Font family is not available on the system", SkipSingle);
+
+    QFont f;
+    f.setStyleHint(styleHint);
+    QCOMPARE(QFontDatabase::resolveFontFamilyAlias(f.defaultFamily()), QFontDatabase::resolveFontFamilyAlias(defaultFamily));
+
+}
+#endif // QT_BUILD_INTERNAL
+
 QTEST_MAIN(tst_QFont)
 #include "tst_qfont.moc"