diff options
author | Jiang Jiang <jiang.jiang@nokia.com> | 2010-12-02 16:28:24 (GMT) |
---|---|---|
committer | Jiang Jiang <jiang.jiang@nokia.com> | 2011-02-28 12:43:01 (GMT) |
commit | 992f233cac66384685212e03dfa600664a23b924 (patch) | |
tree | 05fb9a79409ef4f02e33333aabfac651086d7112 /src | |
parent | 49c866277e6aa7221a310a7635304c75d693bde5 (diff) | |
download | Qt-992f233cac66384685212e03dfa600664a23b924.zip Qt-992f233cac66384685212e03dfa600664a23b924.tar.gz Qt-992f233cac66384685212e03dfa600664a23b924.tar.bz2 |
Resolve font alias before testing for exact matching
It is required in X11 for resolving some default substitutions
like 'sans', 'serif', etc. It also provides stub to implement
similar replacement in other platforms like Windows.
Task-number: QTBUG-15575
Reviewed-by: Eskil
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qfont.cpp | 3 | ||||
-rw-r--r-- | src/gui/text/qfontdatabase.cpp | 6 | ||||
-rw-r--r-- | src/gui/text/qfontdatabase.h | 1 | ||||
-rw-r--r-- | src/gui/text/qfontdatabase_x11.cpp | 22 |
4 files changed, 32 insertions, 0 deletions
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 084b7ac..64eb27a 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -139,6 +139,9 @@ bool QFontDef::exactMatch(const QFontDef &other) const QFontDatabase::parseFontName(family, this_foundry, this_family); QFontDatabase::parseFontName(other.family, other_foundry, other_family); + this_family = QFontDatabase::resolveFontFamilyAlias(this_family); + other_family = QFontDatabase::resolveFontFamilyAlias(other_family); + return (styleHint == other.styleHint && styleStrategy == other.styleStrategy && weight == other.weight diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 8e92b1a..1e94bf5 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -1087,6 +1087,12 @@ QT_BEGIN_INCLUDE_NAMESPACE #elif defined(Q_OS_SYMBIAN) # include "qfontdatabase_s60.cpp" #endif +#if !defined(Q_WS_X11) +QString QFontDatabase::resolveFontFamilyAlias(const QString &family) +{ + return family; +} +#endif QT_END_INCLUDE_NAMESPACE static QtFontStyle *bestStyle(QtFontFoundry *foundry, const QtFontStyle::Key &styleKey) diff --git a/src/gui/text/qfontdatabase.h b/src/gui/text/qfontdatabase.h index 3e9483b..ae1130e 100644 --- a/src/gui/text/qfontdatabase.h +++ b/src/gui/text/qfontdatabase.h @@ -152,6 +152,7 @@ public: private: static void createDatabase(); static void parseFontName(const QString &name, QString &foundry, QString &family); + static QString resolveFontFamilyAlias(const QString &family); #if defined(Q_WS_QWS) || defined(Q_WS_QPA) || defined(Q_OS_SYMBIAN) static QFontEngine *findFont(int script, const QFontPrivate *fp, const QFontDef &request); #endif diff --git a/src/gui/text/qfontdatabase_x11.cpp b/src/gui/text/qfontdatabase_x11.cpp index f923d87..02b0148 100644 --- a/src/gui/text/qfontdatabase_x11.cpp +++ b/src/gui/text/qfontdatabase_x11.cpp @@ -2120,4 +2120,26 @@ bool QFontDatabase::supportsThreadedFontRendering() #endif } +QString QFontDatabase::resolveFontFamilyAlias(const QString &family) +{ +#if defined(QT_NO_FONTCONFIG) + return family; +#else + FcPattern *pattern = FcPatternCreate(); + if (!pattern) + return family; + + FcPatternAddString(pattern, FC_FAMILY, (const FcChar8 *) family.toUtf8().data()); + 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; +#endif +} + QT_END_NAMESPACE |