From 18447df1d021cfed69472b867cb7593401be27a6 Mon Sep 17 00:00:00 2001
From: Jiang Jiang <jiang.jiang@nokia.com>
Date: Wed, 5 Jan 2011 19:39:00 +0100
Subject: Make application font family names locale sensitive in X11

So that they will match the family names returned by
QFontDatabase::families. Because the family names returned
by FcFreeTypeQueryFace are not sorted with locale as the
names returned by FcFontList, we have to find out the
family name matching the system language in the former case.

Task-number: QTBUG-14269
Reviewed-by: Eskil
---
 src/gui/text/qfontdatabase.cpp     |  3 +++
 src/gui/text/qfontdatabase_x11.cpp | 23 +++++++++++++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index bae2a20..ec94de9 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -664,6 +664,9 @@ public:
     }
 
     int count;
+#if defined(Q_WS_X11) && !defined(QT_NO_FONTCONFIG)
+    QString systemLang;
+#endif
     QtFontFamily **families;
 
     struct ApplicationFont {
diff --git a/src/gui/text/qfontdatabase_x11.cpp b/src/gui/text/qfontdatabase_x11.cpp
index 635d2cf..c67558b 100644
--- a/src/gui/text/qfontdatabase_x11.cpp
+++ b/src/gui/text/qfontdatabase_x11.cpp
@@ -1018,6 +1018,13 @@ static void loadFontConfig()
     QFontDatabasePrivate *db = privateDb();
     FcFontSet  *fonts;
 
+    FcPattern *pattern = FcPatternCreate();
+    FcDefaultSubstitute(pattern);
+    FcChar8 *lang = 0;
+    if (FcPatternGetString(pattern, FC_LANG, 0, &lang) == FcResultMatch)
+        db->systemLang = QString::fromUtf8((const char *) lang);
+    FcPatternDestroy(pattern);
+
     QString familyName;
     FcChar8 *value = 0;
     int weight_value;
@@ -2037,6 +2044,7 @@ static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
     int count = 0;
 
     QStringList families;
+    QFontDatabasePrivate *db = privateDb();
 
     FcPattern *pattern = 0;
     do {
@@ -2048,8 +2056,19 @@ static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
         FcPatternDel(pattern, FC_FILE);
         FcPatternAddString(pattern, FC_FILE, (const FcChar8 *)fnt->fileName.toUtf8().constData());
 
-        FcChar8 *fam = 0;
-        if (FcPatternGetString(pattern, FC_FAMILY, 0, &fam) == FcResultMatch) {
+        FcChar8 *fam = 0, *familylang = 0;
+        int i, n = 0;
+        for (i = 0; ; i++) {
+            if (FcPatternGetString(pattern, FC_FAMILYLANG, i, &familylang) != FcResultMatch)
+                break;
+            QString familyLang = QString::fromUtf8((const char *) familylang);
+            if (familyLang.compare(db->systemLang, Qt::CaseInsensitive) == 0) {
+                n = i;
+                break;
+            }
+        }
+
+        if (FcPatternGetString(pattern, FC_FAMILY, n, &fam) == FcResultMatch) {
             QString family = QString::fromUtf8(reinterpret_cast<const char *>(fam));
             families << family;
         }
-- 
cgit v0.12