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

Side by Side Diff: Source/platform/fonts/android/FontCacheAndroid.cpp

Issue 729573003: Pass script-based locale names to Skia (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add a manual test Created 6 years, 1 month 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 | « ManualTests/zh-font-fallback-android.html ('k') | 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 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "platform/fonts/FontCache.h" 32 #include "platform/fonts/FontCache.h"
33 33
34 #include "platform/Language.h" 34 #include "platform/Language.h"
35 #include "platform/fonts/SimpleFontData.h" 35 #include "platform/fonts/SimpleFontData.h"
36 #include "platform/fonts/FontDescription.h" 36 #include "platform/fonts/FontDescription.h"
37 #include "platform/fonts/FontFaceCreationParams.h" 37 #include "platform/fonts/FontFaceCreationParams.h"
38 #include "platform/text/LocaleToScriptMapping.h"
38 #include "third_party/skia/include/core/SkTypeface.h" 39 #include "third_party/skia/include/core/SkTypeface.h"
39 #include "third_party/skia/include/ports/SkFontMgr.h" 40 #include "third_party/skia/include/ports/SkFontMgr.h"
40 41
41 namespace blink { 42 namespace blink {
42 43
44 // SkFontMgr requires script-based locale names, like "zh-Hant" and "zh-Hans",
45 // instead of "zh-CN" and "zh-TW".
46 static CString toSkFontMgrLocale(const String& locale)
47 {
48 if (!locale.startsWith("zh", false))
49 return locale.ascii();
50
51 switch (localeToScriptCodeForFontSelection(locale)) {
52 case USCRIPT_SIMPLIFIED_HAN:
53 return "zh-Hans";
54 case USCRIPT_TRADITIONAL_HAN:
55 return "zh-Hant";
56 default:
57 return locale.ascii();
58 }
59 }
60
43 static AtomicString getFamilyNameForCharacter(UChar32 c, const FontDescription& fontDescription) 61 static AtomicString getFamilyNameForCharacter(UChar32 c, const FontDescription& fontDescription)
44 { 62 {
45 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); 63 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault());
46 const char* bcp47Locales[2]; 64 const char* bcp47Locales[2];
47 int localeCount = 0; 65 int localeCount = 0;
48 CString defaultLocale = defaultLanguage().ascii(); 66 CString defaultLocale = toSkFontMgrLocale(defaultLanguage());
49 bcp47Locales[localeCount++] = defaultLocale.data(); 67 bcp47Locales[localeCount++] = defaultLocale.data();
50 CString fontLocale; 68 CString fontLocale;
51 if (!fontDescription.locale().isEmpty()) { 69 if (!fontDescription.locale().isEmpty()) {
52 fontLocale = fontDescription.locale().ascii(); 70 fontLocale = toSkFontMgrLocale(fontDescription.locale());
53 bcp47Locales[localeCount++] = fontLocale.data(); 71 bcp47Locales[localeCount++] = fontLocale.data();
54 } 72 }
55 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFo ntStyle(), bcp47Locales, localeCount, c)); 73 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFo ntStyle(), bcp47Locales, localeCount, c));
56 if (!typeface) 74 if (!typeface)
57 return emptyAtom; 75 return emptyAtom;
58 76
59 SkString skiaFamilyName; 77 SkString skiaFamilyName;
60 typeface->getFamilyName(&skiaFamilyName); 78 typeface->getFamilyName(&skiaFamilyName);
61 return skiaFamilyName.c_str(); 79 return skiaFamilyName.c_str();
62 } 80 }
(...skipping 23 matching lines...) Expand all
86 break; 104 break;
87 default: 105 default:
88 // For other scripts, use the default generic family mapping logic. 106 // For other scripts, use the default generic family mapping logic.
89 return familyName; 107 return familyName;
90 } 108 }
91 109
92 return getFamilyNameForCharacter(examplerChar, fontDescription); 110 return getFamilyNameForCharacter(examplerChar, fontDescription);
93 } 111 }
94 112
95 } // namespace blink 113 } // namespace blink
OLDNEW
« no previous file with comments | « ManualTests/zh-font-fallback-android.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698