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

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: 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 case FontFallbackPriority::Symbols: 209 case FontFallbackPriority::Symbols:
210 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kSymbolsFonts); ++i) 210 for (size_t i = 0; i < WTF_ARRAY_LENGTH(kSymbolsFonts); ++i)
211 returnVector.append(kSymbolsFonts[i]); 211 returnVector.append(kSymbolsFonts[i]);
212 break; 212 break;
213 default: 213 default:
214 ASSERT_NOT_REACHED(); 214 ASSERT_NOT_REACHED();
215 } 215 }
216 return returnVector; 216 return returnVector;
217 } 217 }
218 218
219 #if OS(WIN)
220 static inline SkFontStyle fontStyle(const FontDescription& fontDescription)
221 {
222 int width = static_cast<int>(fontDescription.stretch());
223 int weight = (fontDescription.weight() - FontWeight100 + 1) * 100;
224 SkFontStyle::Slant slant = fontDescription.style() == FontStyleItalic
225 ? SkFontStyle::kItalic_Slant
226 : SkFontStyle::kUpright_Slant;
227 return SkFontStyle(weight, width, slant);
228 }
229
230 static_assert(static_cast<int>(FontStretchUltraCondensed) == static_cast<int>(Sk FontStyle::kUltraCondensed_Width),
231 "FontStretchUltraCondensed should map to kUltraCondensed_Width");
232 static_assert(static_cast<int>(FontStretchNormal) == static_cast<int>(SkFontStyl e::kNormal_Width),
233 "FontStretchNormal should map to kNormal_Width");
234 static_assert(static_cast<int>(FontStretchUltraExpanded) == static_cast<int>(SkF ontStyle::kUltaExpanded_Width),
235 "FontStretchUltraExpanded should map to kUltaExpanded_Width");
236 #endif
237
238 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc ription, const FontFaceCreationParams& creationParams, CString& name) 219 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc ription, const FontFaceCreationParams& creationParams, CString& name)
239 { 220 {
240 #if !OS(WIN) && !OS(ANDROID) 221 #if !OS(WIN) && !OS(ANDROID)
241 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) { 222 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) {
242 if (Platform::current()->sandboxSupport()) 223 if (Platform::current()->sandboxSupport())
243 return typefaceForFontconfigInterfaceIdAndTtcIndex(creationParams.fo ntconfigInterfaceId(), creationParams.ttcIndex()); 224 return typefaceForFontconfigInterfaceIdAndTtcIndex(creationParams.fo ntconfigInterfaceId(), creationParams.ttcIndex());
244 return adoptRef(SkTypeface::CreateFromFile(creationParams.filename().dat a(), creationParams.ttcIndex())); 225 return adoptRef(SkTypeface::CreateFromFile(creationParams.filename().dat a(), creationParams.ttcIndex()));
245 } 226 }
246 #endif 227 #endif
247 228
(...skipping 16 matching lines...) Expand all
264 #if OS(WIN) 245 #if OS(WIN)
265 if (s_sideloadedFonts) { 246 if (s_sideloadedFonts) {
266 HashMap<String, RefPtr<SkTypeface>>::iterator sideloadedFont = 247 HashMap<String, RefPtr<SkTypeface>>::iterator sideloadedFont =
267 s_sideloadedFonts->find(name.data()); 248 s_sideloadedFonts->find(name.data());
268 if (sideloadedFont != s_sideloadedFonts->end()) 249 if (sideloadedFont != s_sideloadedFonts->end())
269 return sideloadedFont->value; 250 return sideloadedFont->value;
270 } 251 }
271 252
272 if (m_fontManager) { 253 if (m_fontManager) {
273 return adoptRef(useDirectWrite() 254 return adoptRef(useDirectWrite()
274 ? m_fontManager->matchFamilyStyle(name.data(), fontStyle(fontDescrip tion)) 255 ? m_fontManager->matchFamilyStyle(name.data(), fontDescription.skiaF ontStyle())
275 : m_fontManager->legacyCreateTypeface(name.data(), style) 256 : m_fontManager->legacyCreateTypeface(name.data(), style));
276 );
277 } 257 }
278 #endif 258 #endif
279 259
280 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of 260 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of
281 // CreateFromName on all platforms. 261 // CreateFromName on all platforms.
282 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style))); 262 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style)));
283 } 263 }
284 264
285 #if !OS(WIN) 265 #if !OS(WIN)
286 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip tion& fontDescription, 266 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip tion& fontDescription,
287 const FontFaceCreationParams& creationParams, float fontSize) 267 const FontFaceCreationParams& creationParams, float fontSize)
288 { 268 {
289 CString name; 269 CString name;
290 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ; 270 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ;
291 if (!tf) 271 if (!tf)
292 return nullptr; 272 return nullptr;
293 273
294 return adoptPtr(new FontPlatformData(tf, 274 return adoptPtr(new FontPlatformData(tf,
295 name.data(), 275 name.data(),
296 fontSize, 276 fontSize,
297 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(), 277 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(),
298 ((fontDescription.style() == FontStyleItalic || fontDescription.style() == FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(), 278 ((fontDescription.style() == FontStyleItalic || fontDescription.style() == FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(),
299 fontDescription.orientation(), 279 fontDescription.orientation(),
300 fontDescription.useSubpixelPositioning())); 280 fontDescription.useSubpixelPositioning()));
301 } 281 }
302 #endif // !OS(WIN) 282 #endif // !OS(WIN)
303 283
304 } // namespace blink 284 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698