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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/AcceptLanguagesResolver.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: Fix non-Windows builds 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/fonts/AcceptLanguagesResolver.h"
6
7 #include "platform/Language.h"
8 #include "platform/text/LocaleToScriptMapping.h"
9 #include <unicode/locid.h>
10
11 namespace blink {
12
13 UScriptCode AcceptLanguagesResolver::m_preferredHanScript = USCRIPT_COMMON;
14 const char* AcceptLanguagesResolver::m_preferredHanSkFontMgrLocale = nullptr;
15
16 // SkFontMgr requires script-based locale names, like "zh-Hant" and "zh-Hans",
17 // instead of "zh-CN" and "zh-TW".
18 static const char* toSkFontMgrLocaleForHan(UScriptCode script)
19 {
20 switch (script) {
21 case USCRIPT_KATAKANA_OR_HIRAGANA:
22 return "ja-jp";
23 case USCRIPT_HANGUL:
24 return "ko-kr";
25 case USCRIPT_SIMPLIFIED_HAN:
26 return "zh-Hans";
27 case USCRIPT_TRADITIONAL_HAN:
28 return "zh-Hant";
29 default:
30 ASSERT_NOT_REACHED();
31 return nullptr;
32 }
33 }
34
35 void AcceptLanguagesResolver::acceptLanguagesChanged(
36 const String& acceptLanguages)
37 {
38 // Use the UI locale if it can disambiguate the Unified Han.
39 // Historically we use ICU on Windows. crbug.com/586520
40 #if OS(WIN)
41 // Since Chrome synchronizes the ICU default locale with its UI locale,
42 // this ICU locale tells the current UI locale of Chrome.
43 m_preferredHanScript = scriptCodeForHanFromLocale(
44 icu::Locale::getDefault().getName(), '_');
45 #else
46 m_preferredHanScript = scriptCodeForHanFromLocale(defaultLanguage());
47 #endif
48 if (m_preferredHanScript != USCRIPT_COMMON) {
49 // We don't need additional locale if defaultLanguage() can disambiguate
50 // since it's always passed to matchFamilyStyleCharacter() separately.
51 m_preferredHanSkFontMgrLocale = nullptr;
52 return;
53 }
54
55 updateFromAcceptLanguages(acceptLanguages);
56 }
57
58 void AcceptLanguagesResolver::updateFromAcceptLanguages(
59 const String& acceptLanguages)
60 {
61 // Use the first acceptLanguages that can disambiguate.
62 Vector<String> languages;
63 acceptLanguages.split(',', languages);
64 for (String token : languages) {
65 token = token.stripWhiteSpace();
66 m_preferredHanScript = scriptCodeForHanFromLocale(token);
67 if (m_preferredHanScript != USCRIPT_COMMON) {
68 m_preferredHanSkFontMgrLocale = toSkFontMgrLocaleForHan(
69 m_preferredHanScript);
70 return;
71 }
72 }
73
74 m_preferredHanScript = USCRIPT_COMMON;
75 m_preferredHanSkFontMgrLocale = nullptr;
76 }
77
78 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698