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

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

Issue 1911863002: Revert of Add code to call skia's matchFamilyStyleCharacter API, which uses the (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fallbackproxy
Patch Set: 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
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
70 // This function is called on android or when we are emulating android fonts on linux and the 87 // This function is called on android or when we are emulating android fonts on linux and the
71 // embedder has overriden the default fontManager with WebFontRendering::setSkia FontMgr. 88 // embedder has overriden the default fontManager with WebFontRendering::setSkia FontMgr.
72 // static 89 // static
73 AtomicString FontCache::getFamilyNameForCharacter(SkFontMgr* fm, UChar32 c, cons t FontDescription& fontDescription, FontFallbackPriority fallbackPriority) 90 AtomicString FontCache::getFamilyNameForCharacter(SkFontMgr* fm, UChar32 c, cons t FontDescription& fontDescription, FontFallbackPriority fallbackPriority)
74 { 91 {
75 ASSERT(fm); 92 ASSERT(fm);
76 93
77 const size_t kMaxLocales = 4; 94 const size_t kMaxLocales = 4;
78 const char* bcp47Locales[kMaxLocales]; 95 const char* bcp47Locales[kMaxLocales];
79 size_t localeCount = 0; 96 size_t localeCount = 0;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 if (!fontPlatformData) { 164 if (!fontPlatformData) {
148 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, mssansserifCreationPar ams, (AtomicString("Microsoft Sans Serif"))); 165 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, mssansserifCreationPar ams, (AtomicString("Microsoft Sans Serif")));
149 fontPlatformData = getFontPlatformData(description, mssansserifCreationP arams); 166 fontPlatformData = getFontPlatformData(description, mssansserifCreationP arams);
150 } 167 }
151 #endif 168 #endif
152 169
153 ASSERT(fontPlatformData); 170 ASSERT(fontPlatformData);
154 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain); 171 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain);
155 } 172 }
156 173
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
157 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc ription, const FontFaceCreationParams& creationParams, CString& name) 193 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc ription, const FontFaceCreationParams& creationParams, CString& name)
158 { 194 {
159 #if !OS(WIN) && !OS(ANDROID) 195 #if !OS(WIN) && !OS(ANDROID)
160 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) { 196 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) {
161 if (Platform::current()->sandboxSupport()) 197 if (Platform::current()->sandboxSupport())
162 return typefaceForFontconfigInterfaceIdAndTtcIndex(creationParams.fo ntconfigInterfaceId(), creationParams.ttcIndex()); 198 return typefaceForFontconfigInterfaceIdAndTtcIndex(creationParams.fo ntconfigInterfaceId(), creationParams.ttcIndex());
163 return adoptRef(SkTypeface::CreateFromFile(creationParams.filename().dat a(), creationParams.ttcIndex())); 199 return adoptRef(SkTypeface::CreateFromFile(creationParams.filename().dat a(), creationParams.ttcIndex()));
164 } 200 }
165 #endif 201 #endif
166 202
(...skipping 10 matching lines...) Expand all
177 #if OS(WIN) 213 #if OS(WIN)
178 if (s_sideloadedFonts) { 214 if (s_sideloadedFonts) {
179 HashMap<String, RefPtr<SkTypeface>>::iterator sideloadedFont = 215 HashMap<String, RefPtr<SkTypeface>>::iterator sideloadedFont =
180 s_sideloadedFonts->find(name.data()); 216 s_sideloadedFonts->find(name.data());
181 if (sideloadedFont != s_sideloadedFonts->end()) 217 if (sideloadedFont != s_sideloadedFonts->end())
182 return sideloadedFont->value; 218 return sideloadedFont->value;
183 } 219 }
184 220
185 if (m_fontManager) { 221 if (m_fontManager) {
186 return adoptRef(useDirectWrite() 222 return adoptRef(useDirectWrite()
187 ? m_fontManager->matchFamilyStyle(name.data(), fontDescription.skiaF ontStyle()) 223 ? m_fontManager->matchFamilyStyle(name.data(), fontStyle(fontDescrip tion))
188 : m_fontManager->legacyCreateTypeface(name.data(), fontDescription.s kiaFontStyle())); 224 : m_fontManager->legacyCreateTypeface(name.data(), fontStyle(fontDes cription))
225 );
189 } 226 }
190 #endif 227 #endif
191 228
192 #if OS(LINUX) 229 #if OS(LINUX)
193 // On linux if the fontManager has been overridden then we should be calling the embedder 230 // On linux if the fontManager has been overridden then we should be calling the embedder
194 // provided font Manager rather than calling SkTypeface::CreateFromName whic h may redirect the 231 // provided font Manager rather than calling SkTypeface::CreateFromName whic h may redirect the
195 // call to the default font Manager. 232 // call to the default font Manager.
196 if (m_fontManager) 233 if (m_fontManager)
197 return adoptRef(m_fontManager->matchFamilyStyle(name.data(), fontDescrip tion.skiaFontStyle())); 234 return adoptRef(m_fontManager->matchFamilyStyle(name.data(), fontStyle(f ontDescription)));
198 #endif 235 #endif
199 236
200 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of 237 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of
201 // CreateFromName on all platforms. 238 // CreateFromName on all platforms.
202 int style = SkTypeface::kNormal; 239 int style = SkTypeface::kNormal;
203 if (fontDescription.weight() >= FontWeight600) 240 if (fontDescription.weight() >= FontWeight600)
204 style |= SkTypeface::kBold; 241 style |= SkTypeface::kBold;
205 if (fontDescription.style()) 242 if (fontDescription.style())
206 style |= SkTypeface::kItalic; 243 style |= SkTypeface::kItalic;
207 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style))); 244 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style)));
(...skipping 12 matching lines...) Expand all
220 name.data(), 257 name.data(),
221 fontSize, 258 fontSize,
222 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(), 259 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(),
223 ((fontDescription.style() == FontStyleItalic || fontDescription.style() == FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(), 260 ((fontDescription.style() == FontStyleItalic || fontDescription.style() == FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(),
224 fontDescription.orientation(), 261 fontDescription.orientation(),
225 fontDescription.useSubpixelPositioning())); 262 fontDescription.useSubpixelPositioning()));
226 } 263 }
227 #endif // !OS(WIN) 264 #endif // !OS(WIN)
228 265
229 } // namespace blink 266 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698