Commit 12eb772f authored by thestig@chromium.org's avatar thestig@chromium.org

Linux: Do better font substitution for Chinese characters.

This is a reland of r260354, which accidentally got reverted in r260354.

BUG=381978

Review URL: https://codereview.chromium.org/325543002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275741 0039d316-1c4b-4281-b951-d872f2087c98
parent 53ff43df
...@@ -39,7 +39,8 @@ namespace { ...@@ -39,7 +39,8 @@ namespace {
// MSCharSetToFontconfig translates a Microsoft charset identifier to a // MSCharSetToFontconfig translates a Microsoft charset identifier to a
// fontconfig language set by appending to |langset|. // fontconfig language set by appending to |langset|.
static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { // Returns true if |langset| is Latin/Greek/Cyrillic.
bool MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) {
// We have need to translate raw fdwCharSet values into terms that // We have need to translate raw fdwCharSet values into terms that
// fontconfig can understand. (See the description of fdwCharSet in the MSDN // fontconfig can understand. (See the description of fdwCharSet in the MSDN
// documentation for CreateFont: // documentation for CreateFont:
...@@ -58,6 +59,7 @@ static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { ...@@ -58,6 +59,7 @@ static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) {
// So, for each of the documented fdwCharSet values I've had to take a // So, for each of the documented fdwCharSet values I've had to take a
// guess at the set of ISO 639-1 languages intended. // guess at the set of ISO 639-1 languages intended.
bool is_lgc = false;
switch (fdwCharSet) { switch (fdwCharSet) {
case NPCharsetAnsi: case NPCharsetAnsi:
// These values I don't really know what to do with, so I'm going to map // These values I don't really know what to do with, so I'm going to map
...@@ -66,23 +68,25 @@ static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { ...@@ -66,23 +68,25 @@ static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) {
case NPCharsetMac: case NPCharsetMac:
case NPCharsetOEM: case NPCharsetOEM:
case NPCharsetSymbol: case NPCharsetSymbol:
is_lgc = true;
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("en")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("en"));
break; break;
case NPCharsetBaltic: case NPCharsetBaltic:
// The three baltic languages. // The three baltic languages.
is_lgc = true;
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("et")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("et"));
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lv")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lv"));
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lt")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("lt"));
break; break;
// TODO(jungshik): Would we be better off mapping Big5 to zh-tw
// and GB2312 to zh-cn? Fontconfig has 4 separate orthography
// files (zh-{cn,tw,hk,mo}.
case NPCharsetChineseBIG5: case NPCharsetChineseBIG5:
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-tw"));
break;
case NPCharsetGB2312: case NPCharsetGB2312:
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("zh-cn"));
break; break;
case NPCharsetEastEurope: case NPCharsetEastEurope:
// A scattering of eastern European languages. // A scattering of eastern European languages.
is_lgc = true;
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("pl")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("pl"));
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("cs")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("cs"));
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("sk")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("sk"));
...@@ -90,6 +94,7 @@ static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { ...@@ -90,6 +94,7 @@ static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) {
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hr")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("hr"));
break; break;
case NPCharsetGreek: case NPCharsetGreek:
is_lgc = true;
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("el")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("el"));
break; break;
case NPCharsetHangul: case NPCharsetHangul:
...@@ -98,6 +103,7 @@ static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { ...@@ -98,6 +103,7 @@ static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) {
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ko")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ko"));
break; break;
case NPCharsetRussian: case NPCharsetRussian:
is_lgc = true;
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ru")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ru"));
break; break;
case NPCharsetShiftJIS: case NPCharsetShiftJIS:
...@@ -105,9 +111,11 @@ static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { ...@@ -105,9 +111,11 @@ static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) {
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ja")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("ja"));
break; break;
case NPCharsetTurkish: case NPCharsetTurkish:
is_lgc = true;
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("tr")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("tr"));
break; break;
case NPCharsetVietnamese: case NPCharsetVietnamese:
is_lgc = true;
FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("vi")); FcLangSetAdd(langset, reinterpret_cast<const FcChar8*>("vi"));
break; break;
case NPCharsetArabic: case NPCharsetArabic:
...@@ -123,6 +131,7 @@ static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) { ...@@ -123,6 +131,7 @@ static void MSCharSetToFontconfig(FcLangSet* langset, unsigned fdwCharSet) {
// Don't add any languages in that case that we don't recognise the // Don't add any languages in that case that we don't recognise the
// constant. // constant.
} }
return is_lgc;
} }
} // namespace } // namespace
...@@ -437,24 +446,27 @@ void SandboxIPCHandler::HandleMatchWithFallback( ...@@ -437,24 +446,27 @@ void SandboxIPCHandler::HandleMatchWithFallback(
} }
FcLangSet* langset = FcLangSetCreate(); FcLangSet* langset = FcLangSetCreate();
MSCharSetToFontconfig(langset, charset); bool is_lgc = MSCharSetToFontconfig(langset, charset);
FcPattern* pattern = FcPatternCreate(); FcPattern* pattern = FcPatternCreate();
// TODO(agl): FC_FAMILy needs to change
FcPatternAddString( FcPatternAddString(
pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(face.c_str())); pattern, FC_FAMILY, reinterpret_cast<const FcChar8*>(face.c_str()));
// TODO(thestig) Check if we can access Chrome's per-script font preference
// here and select better default fonts for non-LGC case.
std::string generic_font_name; std::string generic_font_name;
switch (fallback_family) { if (is_lgc) {
case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF: switch (fallback_family) {
generic_font_name = "Times New Roman"; case PP_BROWSERFONT_TRUSTED_FAMILY_SERIF:
break; generic_font_name = "Times New Roman";
case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF: break;
generic_font_name = "Arial"; case PP_BROWSERFONT_TRUSTED_FAMILY_SANSSERIF:
break; generic_font_name = "Arial";
case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE: break;
generic_font_name = "Courier New"; case PP_BROWSERFONT_TRUSTED_FAMILY_MONOSPACE:
break; generic_font_name = "Courier New";
break;
}
} }
if (!generic_font_name.empty()) { if (!generic_font_name.empty()) {
const FcChar8* fc_generic_font_name = const FcChar8* fc_generic_font_name =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment