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

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

Issue 1912013002: Use the new legacyCreateTypeface that has an SkFontStyle parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary ifdef Created 4 years, 8 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) 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 if (!fontPlatformData) { 164 if (!fontPlatformData) {
165 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, mssansserifCreationPar ams, (AtomicString("Microsoft Sans Serif"))); 165 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, mssansserifCreationPar ams, (AtomicString("Microsoft Sans Serif")));
166 fontPlatformData = getFontPlatformData(description, mssansserifCreationP arams); 166 fontPlatformData = getFontPlatformData(description, mssansserifCreationP arams);
167 } 167 }
168 #endif 168 #endif
169 169
170 ASSERT(fontPlatformData); 170 ASSERT(fontPlatformData);
171 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain); 171 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain);
172 } 172 }
173 173
174 #if OS(WIN) || OS(LINUX)
175 static inline SkFontStyle fontStyle(const FontDescription& fontDescription) 174 static inline SkFontStyle fontStyle(const FontDescription& fontDescription)
176 { 175 {
177 int width = static_cast<int>(fontDescription.stretch()); 176 int width = static_cast<int>(fontDescription.stretch());
178 int weight = (fontDescription.weight() - FontWeight100 + 1) * 100; 177 int weight = (fontDescription.weight() - FontWeight100 + 1) * 100;
179 SkFontStyle::Slant slant = fontDescription.style() == FontStyleItalic 178 SkFontStyle::Slant slant = fontDescription.style() == FontStyleItalic
180 ? SkFontStyle::kItalic_Slant 179 ? SkFontStyle::kItalic_Slant
181 : SkFontStyle::kUpright_Slant; 180 : SkFontStyle::kUpright_Slant;
182 return SkFontStyle(weight, width, slant); 181 return SkFontStyle(weight, width, slant);
183 } 182 }
184 183
185 static_assert(static_cast<int>(FontStretchUltraCondensed) == static_cast<int>(Sk FontStyle::kUltraCondensed_Width), 184 static_assert(static_cast<int>(FontStretchUltraCondensed) == static_cast<int>(Sk FontStyle::kUltraCondensed_Width),
186 "FontStretchUltraCondensed should map to kUltraCondensed_Width"); 185 "FontStretchUltraCondensed should map to kUltraCondensed_Width");
187 static_assert(static_cast<int>(FontStretchNormal) == static_cast<int>(SkFontStyl e::kNormal_Width), 186 static_assert(static_cast<int>(FontStretchNormal) == static_cast<int>(SkFontStyl e::kNormal_Width),
188 "FontStretchNormal should map to kNormal_Width"); 187 "FontStretchNormal should map to kNormal_Width");
189 static_assert(static_cast<int>(FontStretchUltraExpanded) == static_cast<int>(SkF ontStyle::kUltaExpanded_Width), 188 static_assert(static_cast<int>(FontStretchUltraExpanded) == static_cast<int>(SkF ontStyle::kUltaExpanded_Width),
190 "FontStretchUltraExpanded should map to kUltaExpanded_Width"); 189 "FontStretchUltraExpanded should map to kUltaExpanded_Width");
191 #endif
192 190
193 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc ription, const FontFaceCreationParams& creationParams, CString& name) 191 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc ription, const FontFaceCreationParams& creationParams, CString& name)
194 { 192 {
195 #if !OS(WIN) && !OS(ANDROID) 193 #if !OS(WIN) && !OS(ANDROID)
196 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) { 194 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) {
197 if (Platform::current()->sandboxSupport()) 195 if (Platform::current()->sandboxSupport())
198 return typefaceForFontconfigInterfaceIdAndTtcIndex(creationParams.fo ntconfigInterfaceId(), creationParams.ttcIndex()); 196 return typefaceForFontconfigInterfaceIdAndTtcIndex(creationParams.fo ntconfigInterfaceId(), creationParams.ttcIndex());
199 return adoptRef(SkTypeface::CreateFromFile(creationParams.filename().dat a(), creationParams.ttcIndex())); 197 return adoptRef(SkTypeface::CreateFromFile(creationParams.filename().dat a(), creationParams.ttcIndex()));
200 } 198 }
201 #endif 199 #endif
(...skipping 25 matching lines...) Expand all
227 #endif 225 #endif
228 226
229 #if OS(LINUX) 227 #if OS(LINUX)
230 // On linux if the fontManager has been overridden then we should be calling the embedder 228 // On linux if the fontManager has been overridden then we should be calling the embedder
231 // provided font Manager rather than calling SkTypeface::CreateFromName whic h may redirect the 229 // provided font Manager rather than calling SkTypeface::CreateFromName whic h may redirect the
232 // call to the default font Manager. 230 // call to the default font Manager.
233 if (m_fontManager) 231 if (m_fontManager)
234 return adoptRef(m_fontManager->matchFamilyStyle(name.data(), fontStyle(f ontDescription))); 232 return adoptRef(m_fontManager->matchFamilyStyle(name.data(), fontStyle(f ontDescription)));
235 #endif 233 #endif
236 234
237 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of 235 // FIXME: Use m_fontManager, matchFamilyStyle instead of
238 // CreateFromName on all platforms. 236 // legacyCreateTypeface on all platforms.
239 int style = SkTypeface::kNormal; 237 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault());
240 if (fontDescription.weight() >= FontWeight600) 238 return adoptRef(fm->legacyCreateTypeface(name.data(),
241 style |= SkTypeface::kBold; 239 fontStyle(fontDescription)));
bungeman-skia 2016/04/22 19:00:21 nit: eae probably knows about this better than I d
242 if (fontDescription.style())
243 style |= SkTypeface::kItalic;
244 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style)));
245 } 240 }
246 241
247 #if !OS(WIN) 242 #if !OS(WIN)
248 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip tion& fontDescription, 243 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip tion& fontDescription,
249 const FontFaceCreationParams& creationParams, float fontSize) 244 const FontFaceCreationParams& creationParams, float fontSize)
250 { 245 {
251 CString name; 246 CString name;
252 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ; 247 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ;
253 if (!tf) 248 if (!tf)
254 return nullptr; 249 return nullptr;
255 250
256 return adoptPtr(new FontPlatformData(tf, 251 return adoptPtr(new FontPlatformData(tf,
257 name.data(), 252 name.data(),
258 fontSize, 253 fontSize,
259 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(), 254 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(),
260 ((fontDescription.style() == FontStyleItalic || fontDescription.style() == FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(), 255 ((fontDescription.style() == FontStyleItalic || fontDescription.style() == FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(),
261 fontDescription.orientation(), 256 fontDescription.orientation(),
262 fontDescription.useSubpixelPositioning())); 257 fontDescription.useSubpixelPositioning()));
263 } 258 }
264 #endif // !OS(WIN) 259 #endif // !OS(WIN)
265 260
266 } // namespace blink 261 } // 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