Index: Source/platform/fonts/win/FontFallbackWin.cpp |
diff --git a/Source/platform/fonts/win/FontFallbackWin.cpp b/Source/platform/fonts/win/FontFallbackWin.cpp |
index a7f5be4cdc1052d3035da781586990baa85dbd20..0ba9eb1c35571978d89d5fc1b91e0008871912cb 100644 |
--- a/Source/platform/fonts/win/FontFallbackWin.cpp |
+++ b/Source/platform/fonts/win/FontFallbackWin.cpp |
@@ -35,6 +35,7 @@ |
#include "SkFontMgr.h" |
#include "SkTypeface.h" |
#include "wtf/HashMap.h" |
+#include "wtf/StringExtras.h" |
#include "wtf/text/StringHash.h" |
#include "wtf/text/WTFString.h" |
#include <limits> |
@@ -92,6 +93,32 @@ void initializeScriptMonospaceFontMap(ScriptToFontMap& scriptFontMap, SkFontMgr* |
scriptFontMap[fontMap[i].script] = fontMap[i].family; |
} |
+static UScriptCode scriptCodeForUnifiedHanFromDefaultLocale() |
drott
2015/09/04 08:26:15
I think it would be helpful if you would give this
|
+{ |
+ // Since Chrome synchronizes the ICU default locale with its UI locale, |
+ // this ICU locale tells the current UI locale of Chrome. |
+ const icu::Locale& locale = icu::Locale::getDefault(); |
+ |
+ // ICU default locale may have country as an empty string or differently. |
+ // Avoid fullName comparisons for Japanese and Korean where language() |
+ // can safely disambiguate. |
+ if (strcasecmp(locale.getLanguage(), icu::Locale::getJapanese().getLanguage()) == 0) |
+ return USCRIPT_HIRAGANA; |
+ if (strcasecmp(locale.getLanguage(), icu::Locale::getKorean().getLanguage()) == 0) |
+ return USCRIPT_HANGUL; |
+ |
+ const icu::Locale& traditionalChinese = icu::Locale::getTraditionalChinese(); |
+ if (strcasecmp(locale.getLanguage(), traditionalChinese.getLanguage()) == 0 |
+ && (strcasecmp(locale.getCountry(), traditionalChinese.getCountry()) == 0 |
+ || strcasecmp(locale.getCountry(), "HK") == 0 |
+ || strcasecmp(locale.getScript(), "Hant") == 0)) { |
+ return USCRIPT_TRADITIONAL_HAN; |
+ } |
+ |
+ // For other locales, use the simplified Chinese font for Han. |
+ return USCRIPT_SIMPLIFIED_HAN; |
+} |
+ |
void initializeScriptFontMap(ScriptToFontMap& scriptFontMap, SkFontMgr* fontManager) |
{ |
struct FontMap { |
@@ -216,20 +243,7 @@ void initializeScriptFontMap(ScriptToFontMap& scriptFontMap, SkFontMgr* fontMana |
} |
// Initialize the locale-dependent mapping. |
- // Since Chrome synchronizes the ICU default locale with its UI locale, |
- // this ICU locale tells the current UI locale of Chrome. |
- icu::Locale locale = icu::Locale::getDefault(); |
- const UChar* localeFamily = 0; |
- if (locale == icu::Locale::getJapanese()) { |
- localeFamily = scriptFontMap[USCRIPT_HIRAGANA]; |
- } else if (locale == icu::Locale::getKorean()) { |
- localeFamily = scriptFontMap[USCRIPT_HANGUL]; |
- } else if (locale == icu::Locale::getTraditionalChinese()) { |
- localeFamily = scriptFontMap[USCRIPT_TRADITIONAL_HAN]; |
- } else { |
- // For other locales, use the simplified Chinese font for Han. |
- localeFamily = scriptFontMap[USCRIPT_SIMPLIFIED_HAN]; |
- } |
+ const UChar* localeFamily = scriptFontMap[scriptCodeForUnifiedHanFromDefaultLocale()]; |
if (localeFamily) |
scriptFontMap[USCRIPT_HAN] = localeFamily; |
} |