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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 Google Inc. All rights reserved. 2 * Copyright (c) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 switch (localeToScriptCodeForFontSelection(locale)) { 50 switch (localeToScriptCodeForFontSelection(locale)) {
51 case USCRIPT_SIMPLIFIED_HAN: 51 case USCRIPT_SIMPLIFIED_HAN:
52 return "zh-Hans"; 52 return "zh-Hans";
53 case USCRIPT_TRADITIONAL_HAN: 53 case USCRIPT_TRADITIONAL_HAN:
54 return "zh-Hant"; 54 return "zh-Hant";
55 default: 55 default:
56 return locale.ascii(); 56 return locale.ascii();
57 } 57 }
58 } 58 }
59 59
60 void FontCache::acceptLanguagesChanged(const String&) 60 static const char* toSkFontMgrLocaleForHan(UScriptCode script)
61 { 61 {
62 // TODO(kojii): Take acceptLanguages into account for ambiguos scripts. 62 switch (script) {
63 case USCRIPT_KATAKANA_OR_HIRAGANA:
64 return "ja-jp";
65 case USCRIPT_HANGUL:
66 return "ko-kr";
67 case USCRIPT_SIMPLIFIED_HAN:
68 return "zh-Hans";
69 case USCRIPT_TRADITIONAL_HAN:
70 return "zh-Hant";
71 default:
72 ASSERT_NOT_REACHED();
73 return nullptr;
74 }
75 }
76
77 static const char* computeLocaleForHan(const String& acceptLanguages)
78 {
79 // If defaultLanguage() can disambiguate the Unified Han, additional locales
80 // are not needed.
81 UScriptCode script = scriptCodeForHanFromLocale(defaultLanguage());
82 if (script != USCRIPT_COMMON)
83 return nullptr;
84
85 // Use acceptLanguages if it has a language that can disambiguate.
86 Vector<String> languages;
87 acceptLanguages.split(',', languages);
88 for (String token : languages) {
89 token = token.stripWhiteSpace();
90 script = scriptCodeForHanFromLocale(token);
91 if (script != USCRIPT_COMMON)
92 return toSkFontMgrLocaleForHan(script);
93 }
94
95 return nullptr;
96 }
97
98 static const char* localeForHan = nullptr;
99
100 void FontCache::acceptLanguagesChanged(const String& acceptLanguages)
drott 2016/02/12 12:07:30 Could we move this listener to a new singleton cal
101 {
102 localeForHan = computeLocaleForHan(acceptLanguages);
63 } 103 }
64 104
65 static AtomicString getFamilyNameForCharacter(UChar32 c, const FontDescription& fontDescription) 105 static AtomicString getFamilyNameForCharacter(UChar32 c, const FontDescription& fontDescription)
66 { 106 {
67 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); 107 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault());
68 const char* bcp47Locales[2]; 108 const char* bcp47Locales[3];
69 int localeCount = 0; 109 int localeCount = 0;
110 if (localeForHan)
111 bcp47Locales[localeCount++] = localeForHan;
70 CString defaultLocale = toSkFontMgrLocale(defaultLanguage()); 112 CString defaultLocale = toSkFontMgrLocale(defaultLanguage());
71 bcp47Locales[localeCount++] = defaultLocale.data(); 113 bcp47Locales[localeCount++] = defaultLocale.data();
72 CString fontLocale; 114 CString fontLocale;
73 if (!fontDescription.locale().isEmpty()) { 115 if (!fontDescription.locale().isEmpty()) {
74 fontLocale = toSkFontMgrLocale(fontDescription.locale()); 116 fontLocale = toSkFontMgrLocale(fontDescription.locale());
75 bcp47Locales[localeCount++] = fontLocale.data(); 117 bcp47Locales[localeCount++] = fontLocale.data();
76 } 118 }
77 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFo ntStyle(), bcp47Locales, localeCount, c)); 119 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFo ntStyle(), bcp47Locales, localeCount, c));
78 if (!typeface) 120 if (!typeface)
79 return emptyAtom; 121 return emptyAtom;
(...skipping 28 matching lines...) Expand all
108 break; 150 break;
109 default: 151 default:
110 // For other scripts, use the default generic family mapping logic. 152 // For other scripts, use the default generic family mapping logic.
111 return familyName; 153 return familyName;
112 } 154 }
113 155
114 return getFamilyNameForCharacter(examplerChar, fontDescription); 156 return getFamilyNameForCharacter(examplerChar, fontDescription);
115 } 157 }
116 158
117 } // namespace blink 159 } // namespace blink
OLDNEW
« 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