Remove hardcoded font names in QFont::defaultFamily()
authorJiang Jiang <jiang.jiang@nokia.com>
Tue, 20 Mar 2012 10:57:35 +0000 (11:57 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 21 Mar 2012 08:00:22 +0000 (09:00 +0100)
QFont::defaultFamily() should not use any hardcoded font names like
"Helvetica" or "Times" as they might not be present in certain systems,
it should rather use abstract names like "sans-serif", "serif" and
"monospace" then let the platform plugin to decide which font map to
them.

Change-Id: I5aafb103a5238c17b10773711ad504806c6fc3ce
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
src/gui/text/qfont_qpa.cpp
tests/auto/gui/text/qfont/tst_qfont.cpp

index 29ba776..6576f23 100644 (file)
@@ -77,28 +77,29 @@ QString QFont::defaultFamily() const
 {
     QString familyName;
     switch(d->request.styleHint) {
-        case QFont::Times:
-            familyName = QString::fromLatin1("Times");
+        case QFont::SansSerif:
+            familyName = QString::fromLatin1("sans-serif");
             break;
-        case QFont::Courier:
-            familyName = QString::fromLatin1("Courier");
+        case QFont::Serif:
+            familyName = QString::fromLatin1("serif");
             break;
+        case QFont::TypeWriter:
         case QFont::Monospace:
-            familyName = QString::fromLatin1("Courier New");
+            familyName = QString::fromLatin1("monospace");
             break;
         case QFont::Cursive:
-            familyName = QString::fromLatin1("Comic Sans MS");
+            familyName = QString::fromLatin1("cursive");
             break;
         case QFont::Fantasy:
-            familyName = QString::fromLatin1("Impact");
+            familyName = QString::fromLatin1("fantasy");
             break;
         case QFont::Decorative:
-            familyName = QString::fromLatin1("Old English");
+            familyName = QString::fromLatin1("decorative");
             break;
-        case QFont::Helvetica:
         case QFont::System:
         default:
-            familyName = QString::fromLatin1("Helvetica");
+            familyName = QString();
+            break;
     }
 
     return QGuiApplicationPrivate::platformIntegration()->fontDatabase()->resolveFontFamilyAlias(familyName);
index ead4c8e..1cedfa5 100644 (file)
@@ -630,13 +630,12 @@ 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";
+    QTest::newRow("serif") << QFont::Times << "serif";
+    QTest::newRow("monospace") << QFont::Monospace << "monospace";
+    QTest::newRow("sans-serif") << QFont::SansSerif << "sans-serif";
+    QTest::newRow("cursive") << QFont::Cursive << "cursive";
+    QTest::newRow("fantasy") << QFont::Fantasy << "fantasy";
+    QTest::newRow("old english") << QFont::OldEnglish << "Old English";
 }
 
 void tst_QFont::defaultFamily()