Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Unified Diff: third_party/WebKit/Source/platform/fonts/android/FontCacheAndroid.cpp

Issue 1693563003: Take Accept-Language into account in CJK font fallback for Android/Win (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@aceept-lang
Patch Set: Minor fix Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698