Make font fallback list for common script locale aware
authorJiang Jiang <jiang.jiang@nokia.com>
Wed, 30 May 2012 14:43:05 +0000 (16:43 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 1 Jun 2012 01:16:08 +0000 (03:16 +0200)
Even in common script we may need to have a preferred font list
(which font should be used for CJK codepoints, Chinese, Japanese
or Korean? Since the codepoints they cover may overlap.) Adding
current default language into the pattern in that case will give
a better recommendation for the fallback list if the system have
configuration files like that.

Change-Id: Idbc7f7b0cf24108d6cc255a1add0b29b730588c0
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp

index f980a40..9d50196 100644 (file)
@@ -627,6 +627,19 @@ QStringList QFontconfigDatabase::fallbacksForFamily(const QString family, const
         FcLangSetAdd(ls, (const FcChar8*)specialLanguages[script]);
         FcPatternAddLangSet(pattern, FC_LANG, ls);
         FcLangSetDestroy(ls);
+    } else if (!family.isEmpty()) {
+        // If script is common then it may include languages like CJK,
+        // we should attach system default language set to the pattern
+        // to obtain correct font fallback list (i.e. if LANG=zh_CN
+        // then we normally want to use a Chinese font for CJK text;
+        // while a Japanese font should be use for that if LANG=ja)
+        FcPattern *dummy = FcPatternCreate();
+        FcDefaultSubstitute(dummy);
+        FcChar8 *lang = 0;
+        FcResult res = FcPatternGetString(dummy, FC_LANG, 0, &lang);
+        if (res == FcResultMatch)
+            FcPatternAddString(pattern, FC_LANG, lang);
+        FcPatternDestroy(dummy);
     }
 
     const char *stylehint = getFcFamilyForStyleHint(styleHint);