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

Side by Side Diff: sky/engine/platform/fonts/android/FontCacheAndroid.cpp

Issue 723343002: Update from https://crrev.com/304121 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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 | « sky/engine/platform/fonts/FontCache.h ('k') | sky/viewer/platform/weblayertreeview_impl.cc » ('j') | 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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
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 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 "third_party/skia/include/core/SkTypeface.h" 38 #include "third_party/skia/include/core/SkTypeface.h"
39 #include "third_party/skia/include/ports/SkFontMgr.h" 39 #include "third_party/skia/include/ports/SkFontMgr.h"
40 40
41 namespace blink { 41 namespace blink {
42 42
43 static AtomicString getFamilyNameForCharacter(UChar32 c, UScriptCode script) 43 static AtomicString getFamilyNameForCharacter(UChar32 c, const FontDescription& fontDescription)
44 { 44 {
45 // This is a hack to use the preferred font for CJK scripts. 45 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault());
46 // FIXME: Use new Skia API once Android system supports per-family and per-s cript fallback fonts. 46 const char* bcp47Locales[2];
47 const char* locale; 47 int localeCount = 0;
48 switch (script) { 48 CString defaultLocale = defaultLanguage().ascii();
49 case USCRIPT_SIMPLIFIED_HAN: 49 bcp47Locales[localeCount++] = defaultLocale.data();
50 locale = "zh-CN"; 50 CString fontLocale;
51 break; 51 if (!fontDescription.locale().isEmpty()) {
52 case USCRIPT_TRADITIONAL_HAN: 52 fontLocale = fontDescription.locale().ascii();
53 locale = "zh-TW"; 53 bcp47Locales[localeCount++] = fontLocale.data();
54 break;
55 case USCRIPT_KATAKANA_OR_HIRAGANA:
56 locale = "ja";
57 break;
58 case USCRIPT_HANGUL:
59 locale = "ko";
60 break;
61 default:
62 locale = 0;
63 break;
64 } 54 }
65 55 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFo ntStyle(), bcp47Locales, localeCount, c));
66 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault());
67 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFo ntStyle(), locale, c));
68 if (!typeface) 56 if (!typeface)
69 return emptyAtom; 57 return emptyAtom;
70 58
71 SkString skiaFamilyName; 59 SkString skiaFamilyName;
72 typeface->getFamilyName(&skiaFamilyName); 60 typeface->getFamilyName(&skiaFamilyName);
73 return skiaFamilyName.c_str(); 61 return skiaFamilyName.c_str();
74 } 62 }
75 63
76 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip tion& fontDescription, UChar32 c, const SimpleFontData*) 64 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip tion& fontDescription, UChar32 c, const SimpleFontData*)
77 { 65 {
78 AtomicString familyName = getFamilyNameForCharacter(c, fontDescription.scrip t()); 66 AtomicString familyName = getFamilyNameForCharacter(c, fontDescription);
79 if (familyName.isEmpty()) 67 if (familyName.isEmpty())
80 return getLastResortFallbackFont(fontDescription, DoNotRetain); 68 return getLastResortFallbackFont(fontDescription, DoNotRetain);
81 return fontDataFromFontPlatformData(getFontPlatformData(fontDescription, Fon tFaceCreationParams(familyName)), DoNotRetain); 69 return fontDataFromFontPlatformData(getFontPlatformData(fontDescription, Fon tFaceCreationParams(familyName)), DoNotRetain);
82 } 70 }
83 71
84 // static 72 // static
85 AtomicString FontCache::getGenericFamilyNameForScript(const AtomicString& family Name, UScriptCode script) 73 AtomicString FontCache::getGenericFamilyNameForScript(const AtomicString& family Name, const FontDescription& fontDescription)
86 { 74 {
87 // This is a hack to use the preferred font for CJK scripts. 75 // This is a hack to use the preferred font for CJK scripts.
88 // FIXME: Use new Skia API once Android system supports per-family and per-s cript fallback fonts. 76 // FIXME: Use new Skia API once Android system supports per-family and per-s cript fallback fonts.
89 UChar32 examplerChar; 77 UChar32 examplerChar;
90 switch (script) { 78 switch (fontDescription.script()) {
91 case USCRIPT_SIMPLIFIED_HAN: 79 case USCRIPT_SIMPLIFIED_HAN:
92 case USCRIPT_TRADITIONAL_HAN: 80 case USCRIPT_TRADITIONAL_HAN:
93 case USCRIPT_KATAKANA_OR_HIRAGANA: 81 case USCRIPT_KATAKANA_OR_HIRAGANA:
94 examplerChar = 0x4E00; // A common character in Japanese and Chinese. 82 examplerChar = 0x4E00; // A common character in Japanese and Chinese.
95 break; 83 break;
96 case USCRIPT_HANGUL: 84 case USCRIPT_HANGUL:
97 examplerChar = 0xAC00; 85 examplerChar = 0xAC00;
98 break; 86 break;
99 default: 87 default:
100 // For other scripts, use the default generic family mapping logic. 88 // For other scripts, use the default generic family mapping logic.
101 return familyName; 89 return familyName;
102 } 90 }
103 91
104 return getFamilyNameForCharacter(examplerChar, script); 92 return getFamilyNameForCharacter(examplerChar, fontDescription);
105 } 93 }
106 94
107 } // namespace blink 95 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/platform/fonts/FontCache.h ('k') | sky/viewer/platform/weblayertreeview_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698