Add font family alias resolving to QPA
authorJiang Jiang <jiang.jiang@nokia.com>
Tue, 4 Oct 2011 12:52:13 +0000 (14:52 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 5 Oct 2011 12:55:26 +0000 (14:55 +0200)
By default it doesn't do anything special, but for fontconfig font db
it will do some tricks to convert alias like serif to actualy font
family names like Times.

Change-Id: I73058d187a5422e6f93bc1b728cecdc0250d5e1e
Reviewed-on: http://codereview.qt-project.org/5984
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
src/gui/text/qfontdatabase.cpp
src/gui/text/qfontdatabase_qpa.cpp
src/gui/text/qplatformfontdatabase_qpa.cpp
src/gui/text/qplatformfontdatabase_qpa.h
src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp
src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase_p.h

index fa67dc1..680f63e 100644 (file)
@@ -1131,7 +1131,7 @@ QT_BEGIN_INCLUDE_NAMESPACE
 #  include "qfontdatabase_s60.cpp"
 #endif
 QT_END_INCLUDE_NAMESPACE
-#if !defined(Q_WS_X11)
+#if !defined(Q_WS_X11) && !defined(Q_WS_QPA)
 QString QFontDatabase::resolveFontFamilyAlias(const QString &family)
 {
     return family;
index fbee077..4cd47da 100644 (file)
@@ -377,4 +377,9 @@ void QFontDatabase::load(const QFontPrivate *d, int script)
     }
 }
 
+QString QFontDatabase::resolveFontFamilyAlias(const QString &family)
+{
+    return QGuiApplicationPrivate::platformIntegration()->fontDatabase()->resolveFontFamilyAlias(family);
+}
+
 QT_END_NAMESPACE
index cedf481..89bc059 100644 (file)
@@ -373,6 +373,17 @@ QHash<QByteArray, QFont> QPlatformFontDatabase::defaultFonts() const
 }
 
 /*!
+    Resolve alias to actual font family names.
+
+    \since 5.0
+ */
+
+QString QPlatformFontDatabase::resolveFontFamilyAlias(const QString &family) const
+{
+    return family;
+}
+
+/*!
     \class QPlatformFontDatabase
     \brief The QPlatformFontDatabase class makes it possible to customize how fonts
     are discovered and how they are rendered
index ad94b10..901d8c2 100644 (file)
@@ -99,6 +99,7 @@ public:
 
     virtual QFont defaultFont() const;
     virtual QHash<QByteArray, QFont> defaultFonts() const;
+    virtual QString resolveFontFamilyAlias(const QString &family) const;
 
     //callback
     static void registerQPF2Font(const QByteArray &dataArray, void *handle);
index e566cee..3f4aeb2 100644 (file)
@@ -658,3 +658,21 @@ QStringList QFontconfigDatabase::addApplicationFont(const QByteArray &fontData,
     return families;
 }
 
+QString QFontconfigDatabase::resolveFontFamilyAlias(const QString &family) const
+{
+    FcPattern *pattern = FcPatternCreate();
+    if (!pattern)
+        return family;
+
+    QByteArray cs = family.toUtf8();
+    FcPatternAddString(pattern, FC_FAMILY, (const FcChar8 *) cs.constData());
+    FcConfigSubstitute(0, pattern, FcMatchPattern);
+    FcDefaultSubstitute(pattern);
+
+    FcChar8 *familyAfterSubstitution;
+    FcPatternGetString(pattern, FC_FAMILY, 0, &familyAfterSubstitution);
+    QString resolved = QString::fromUtf8((const char *) familyAfterSubstitution);
+    FcPatternDestroy(pattern);
+
+    return resolved;
+}
index eec5107..c6983e1 100644 (file)
@@ -52,6 +52,7 @@ public:
     QFontEngine *fontEngine(const QFontDef &fontDef, QUnicodeTables::Script script, void *handle);
     QStringList fallbacksForFamily(const QString family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script) const;
     QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName);
+    QString resolveFontFamilyAlias(const QString &family) const;
 };
 
 #endif // QFONTCONFIGDATABASE_H