Chromium Code Reviews| Index: third_party/WebKit/Source/platform/fonts/android/FontCacheAndroid.cpp |
| diff --git a/third_party/WebKit/Source/platform/fonts/android/FontCacheAndroid.cpp b/third_party/WebKit/Source/platform/fonts/android/FontCacheAndroid.cpp |
| index 335b243f3066233ece5ccbb28fe24987cb9ba115..293ab6d804eae7b010a754fe9cf37e0237def64c 100644 |
| --- a/third_party/WebKit/Source/platform/fonts/android/FontCacheAndroid.cpp |
| +++ b/third_party/WebKit/Source/platform/fonts/android/FontCacheAndroid.cpp |
| @@ -57,16 +57,58 @@ static CString toSkFontMgrLocale(const String& locale) |
| } |
| } |
| -void FontCache::acceptLanguagesChanged(const String&) |
| +static const char* toSkFontMgrLocaleForHan(UScriptCode script) |
| { |
| - // TODO(kojii): Take acceptLanguages into account for ambiguos scripts. |
| + switch (script) { |
| + case USCRIPT_KATAKANA_OR_HIRAGANA: |
| + return "ja-jp"; |
| + case USCRIPT_HANGUL: |
| + return "ko-kr"; |
| + case USCRIPT_SIMPLIFIED_HAN: |
| + return "zh-Hans"; |
| + case USCRIPT_TRADITIONAL_HAN: |
| + return "zh-Hant"; |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + return nullptr; |
| + } |
| +} |
| + |
| +static const char* computeLocaleForHan(const String& acceptLanguages) |
| +{ |
| + // If defaultLanguage() can disambiguate the Unified Han, additional locales |
| + // are not needed. |
| + UScriptCode script = scriptCodeForHanFromLocale(defaultLanguage()); |
| + if (script != USCRIPT_COMMON) |
| + return nullptr; |
| + |
| + // Use acceptLanguages if it has a language that can disambiguate. |
| + Vector<String> languages; |
| + acceptLanguages.split(',', languages); |
| + for (String token : languages) { |
| + token = token.stripWhiteSpace(); |
| + script = scriptCodeForHanFromLocale(token); |
| + if (script != USCRIPT_COMMON) |
| + return toSkFontMgrLocaleForHan(script); |
| + } |
| + |
| + return nullptr; |
| +} |
| + |
| +static const char* localeForHan = nullptr; |
| + |
| +void FontCache::acceptLanguagesChanged(const String& acceptLanguages) |
|
drott
2016/02/12 12:07:30
Could we move this listener to a new singleton cal
|
| +{ |
| + localeForHan = computeLocaleForHan(acceptLanguages); |
| } |
| static AtomicString getFamilyNameForCharacter(UChar32 c, const FontDescription& fontDescription) |
| { |
| RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); |
| - const char* bcp47Locales[2]; |
| + const char* bcp47Locales[3]; |
| int localeCount = 0; |
| + if (localeForHan) |
| + bcp47Locales[localeCount++] = localeForHan; |
| CString defaultLocale = toSkFontMgrLocale(defaultLanguage()); |
| bcp47Locales[localeCount++] = defaultLocale.data(); |
| CString fontLocale; |