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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/skia/FontCacheSkia.cpp

Issue 1740593002: Use Skia's matchFamilyStyleCharacter API for font fallback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 4 years, 9 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
1 /* 1 /*
2 * Copyright (c) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (c) 2006, 2007, 2008, 2009 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 namespace blink { 61 namespace blink {
62 62
63 #if OS(ANDROID) || OS(LINUX) 63 #if OS(ANDROID) || OS(LINUX)
64 // Android special locale for retrieving the color emoji font 64 // Android special locale for retrieving the color emoji font
65 // based on the proposed changes in UTR #51 for introducing 65 // based on the proposed changes in UTR #51 for introducing
66 // an Emoji script code: 66 // an Emoji script code:
67 // http://www.unicode.org/reports/tr51/proposed.html#Emoji_Script 67 // http://www.unicode.org/reports/tr51/proposed.html#Emoji_Script
68 static const char* kAndroidColorEmojiLocale = "und-Zsye"; 68 static const char* kAndroidColorEmojiLocale = "und-Zsye";
69 69
70 // SkFontMgr requires script-based locale names, like "zh-Hant" and "zh-Hans",
71 // instead of "zh-CN" and "zh-TW".
72 static CString toSkFontMgrLocale(const String& locale)
73 {
74 if (!locale.startsWith("zh", TextCaseInsensitive))
75 return locale.ascii();
76
77 switch (localeToScriptCodeForFontSelection(locale)) {
78 case USCRIPT_SIMPLIFIED_HAN:
79 return "zh-Hans";
80 case USCRIPT_TRADITIONAL_HAN:
81 return "zh-Hant";
82 default:
83 return locale.ascii();
84 }
85 }
86
87 // This function is called on android or when we are emulating android fonts on linux and the 70 // This function is called on android or when we are emulating android fonts on linux and the
88 // embedder has overriden the default fontManager with WebFontRendering::setSkia FontMgr. 71 // embedder has overriden the default fontManager with WebFontRendering::setSkia FontMgr.
89 // static 72 // static
90 AtomicString FontCache::getFamilyNameForCharacter(SkFontMgr* fm, UChar32 c, cons t FontDescription& fontDescription, FontFallbackPriority fallbackPriority) 73 AtomicString FontCache::getFamilyNameForCharacter(SkFontMgr* fm, UChar32 c, cons t FontDescription& fontDescription, FontFallbackPriority fallbackPriority)
91 { 74 {
92 ASSERT(fm); 75 ASSERT(fm);
93 76
94 const size_t kMaxLocales = 4; 77 const size_t kMaxLocales = 4;
95 const char* bcp47Locales[kMaxLocales]; 78 const char* bcp47Locales[kMaxLocales];
96 size_t localeCount = 0; 79 size_t localeCount = 0;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 if (!fontPlatformData) { 147 if (!fontPlatformData) {
165 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, mssansserifCreationPar ams, (AtomicString("Microsoft Sans Serif", AtomicString::ConstructFromLiteral))) ; 148 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, mssansserifCreationPar ams, (AtomicString("Microsoft Sans Serif", AtomicString::ConstructFromLiteral))) ;
166 fontPlatformData = getFontPlatformData(description, mssansserifCreationP arams); 149 fontPlatformData = getFontPlatformData(description, mssansserifCreationP arams);
167 } 150 }
168 #endif 151 #endif
169 152
170 ASSERT(fontPlatformData); 153 ASSERT(fontPlatformData);
171 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain); 154 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain);
172 } 155 }
173 156
174 #if OS(WIN) || OS(LINUX)
175 static inline SkFontStyle fontStyle(const FontDescription& fontDescription)
176 {
177 int width = static_cast<int>(fontDescription.stretch());
178 int weight = (fontDescription.weight() - FontWeight100 + 1) * 100;
179 SkFontStyle::Slant slant = fontDescription.style() == FontStyleItalic
180 ? SkFontStyle::kItalic_Slant
181 : SkFontStyle::kUpright_Slant;
182 return SkFontStyle(weight, width, slant);
183 }
184
185 static_assert(static_cast<int>(FontStretchUltraCondensed) == static_cast<int>(Sk FontStyle::kUltraCondensed_Width),
186 "FontStretchUltraCondensed should map to kUltraCondensed_Width");
187 static_assert(static_cast<int>(FontStretchNormal) == static_cast<int>(SkFontStyl e::kNormal_Width),
188 "FontStretchNormal should map to kNormal_Width");
189 static_assert(static_cast<int>(FontStretchUltraExpanded) == static_cast<int>(SkF ontStyle::kUltaExpanded_Width),
190 "FontStretchUltraExpanded should map to kUltaExpanded_Width");
191 #endif
192
193 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc ription, const FontFaceCreationParams& creationParams, CString& name) 157 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc ription, const FontFaceCreationParams& creationParams, CString& name)
194 { 158 {
195 #if !OS(WIN) && !OS(ANDROID) 159 #if !OS(WIN) && !OS(ANDROID)
196 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) { 160 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) {
197 if (Platform::current()->sandboxSupport()) 161 if (Platform::current()->sandboxSupport())
198 return typefaceForFontconfigInterfaceIdAndTtcIndex(creationParams.fo ntconfigInterfaceId(), creationParams.ttcIndex()); 162 return typefaceForFontconfigInterfaceIdAndTtcIndex(creationParams.fo ntconfigInterfaceId(), creationParams.ttcIndex());
199 return adoptRef(SkTypeface::CreateFromFile(creationParams.filename().dat a(), creationParams.ttcIndex())); 163 return adoptRef(SkTypeface::CreateFromFile(creationParams.filename().dat a(), creationParams.ttcIndex()));
200 } 164 }
201 #endif 165 #endif
202 166
(...skipping 16 matching lines...) Expand all
219 #if OS(WIN) 183 #if OS(WIN)
220 if (s_sideloadedFonts) { 184 if (s_sideloadedFonts) {
221 HashMap<String, RefPtr<SkTypeface>>::iterator sideloadedFont = 185 HashMap<String, RefPtr<SkTypeface>>::iterator sideloadedFont =
222 s_sideloadedFonts->find(name.data()); 186 s_sideloadedFonts->find(name.data());
223 if (sideloadedFont != s_sideloadedFonts->end()) 187 if (sideloadedFont != s_sideloadedFonts->end())
224 return sideloadedFont->value; 188 return sideloadedFont->value;
225 } 189 }
226 190
227 if (m_fontManager) { 191 if (m_fontManager) {
228 return adoptRef(useDirectWrite() 192 return adoptRef(useDirectWrite()
229 ? m_fontManager->matchFamilyStyle(name.data(), fontStyle(fontDescrip tion)) 193 ? m_fontManager->matchFamilyStyle(name.data(), fontDescription.skiaF ontStyle())
230 : m_fontManager->legacyCreateTypeface(name.data(), style) 194 : m_fontManager->legacyCreateTypeface(name.data(), style));
231 );
232 } 195 }
233 #endif 196 #endif
234 197
235 #if OS(LINUX) 198 #if OS(LINUX)
236 // On linux if the fontManager has been overridden then we should be calling the embedder 199 // On linux if the fontManager has been overridden then we should be calling the embedder
237 // provided font Manager rather than calling SkTypeface::CreateFromName whic h may redirect the 200 // provided font Manager rather than calling SkTypeface::CreateFromName whic h may redirect the
238 // call to the default font Manager. 201 // call to the default font Manager.
239 if (m_fontManager) 202 if (m_fontManager)
240 return adoptRef(m_fontManager->matchFamilyStyle(name.data(), fontStyle(f ontDescription))); 203 return adoptRef(m_fontManager->matchFamilyStyle(name.data(), fontDescrip tion.skiaFontStyle()));
241 #endif 204 #endif
242 205
243 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of 206 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of
244 // CreateFromName on all platforms. 207 // CreateFromName on all platforms.
245 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style))); 208 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style)));
246 } 209 }
247 210
248 #if !OS(WIN) 211 #if !OS(WIN)
249 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip tion& fontDescription, 212 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip tion& fontDescription,
250 const FontFaceCreationParams& creationParams, float fontSize) 213 const FontFaceCreationParams& creationParams, float fontSize)
251 { 214 {
252 CString name; 215 CString name;
253 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ; 216 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ;
254 if (!tf) 217 if (!tf)
255 return nullptr; 218 return nullptr;
256 219
257 return adoptPtr(new FontPlatformData(tf, 220 return adoptPtr(new FontPlatformData(tf,
258 name.data(), 221 name.data(),
259 fontSize, 222 fontSize,
260 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(), 223 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(),
261 ((fontDescription.style() == FontStyleItalic || fontDescription.style() == FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(), 224 ((fontDescription.style() == FontStyleItalic || fontDescription.style() == FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(),
262 fontDescription.orientation(), 225 fontDescription.orientation(),
263 fontDescription.useSubpixelPositioning())); 226 fontDescription.useSubpixelPositioning()));
264 } 227 }
265 #endif // !OS(WIN) 228 #endif // !OS(WIN)
266 229
267 } // namespace blink 230 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698