Remove hardcoded font names in QFont::defaultFamily()

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>
This commit is contained in:
Jiang Jiang 2012-03-20 11:57:35 +01:00 committed by Qt by Nokia
parent 7f18dbc30c
commit 2cc5442b02
2 changed files with 17 additions and 17 deletions

View 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);

View 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()