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
#include <QtCore/qstring.h>
#include <QtGui/qfont.h>
+class tst_QFont;
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
friend class QFontEngineMultiQWS;
friend class QFontEngineMultiS60;
friend class QFontEngineMultiQPA;
+#ifdef QT_BUILD_INTERNAL
+ friend class ::tst_QFont;
+#endif
QFontDatabasePrivate *d;
};
#if defined(Q_WS_MAC)
void styleName();
#endif
+#ifdef QT_BUILD_INTERNAL
+ void defaultFamily_data();
+ void defaultFamily();
+#endif
};
// Testing get/set functions
}
#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"