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: Source/platform/fonts/skia/FontCacheSkia.cpp

Issue 470443004: Implement support for numeric font-weights on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: w/expectations Created 6 years, 4 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 | « LayoutTests/fast/text/font-weight.html ('k') | 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 if (!fontPlatformData) { 157 if (!fontPlatformData) {
158 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, mssansserifCreationPar ams, (AtomicString("Microsoft Sans Serif", AtomicString::ConstructFromLiteral))) ; 158 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, mssansserifCreationPar ams, (AtomicString("Microsoft Sans Serif", AtomicString::ConstructFromLiteral))) ;
159 fontPlatformData = getFontPlatformData(description, mssansserifCreationP arams); 159 fontPlatformData = getFontPlatformData(description, mssansserifCreationP arams);
160 } 160 }
161 #endif 161 #endif
162 162
163 ASSERT(fontPlatformData); 163 ASSERT(fontPlatformData);
164 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain); 164 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain);
165 } 165 }
166 166
167 #if OS(WIN)
168 static inline SkFontStyle fontStyle(const FontDescription& fontDescription)
169 {
170 int width = SkFontStyle::kNormal_Width;
171 int weight = (fontDescription.weight() - FontWeight100 + 1) * 100;
172 SkFontStyle::Slant slant = fontDescription.style() == FontStyleItalic
173 ? SkFontStyle::kItalic_Slant
174 : SkFontStyle::kUpright_Slant;
175 return SkFontStyle(weight, width, slant);
176 }
177 #endif
178
167 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc ription, const FontFaceCreationParams& creationParams, CString& name) 179 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc ription, const FontFaceCreationParams& creationParams, CString& name)
168 { 180 {
169 #if !OS(WIN) && !OS(ANDROID) 181 #if !OS(WIN) && !OS(ANDROID)
170 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) { 182 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) {
171 // TODO(dro): crbug.com/381620 Use creationParams.ttcIndex() after 183 // TODO(dro): crbug.com/381620 Use creationParams.ttcIndex() after
172 // https://code.google.com/p/skia/issues/detail?id=1186 gets fixed. 184 // https://code.google.com/p/skia/issues/detail?id=1186 gets fixed.
173 SkTypeface* typeface = nullptr; 185 SkTypeface* typeface = nullptr;
174 if (blink::Platform::current()->sandboxSupport()) 186 if (blink::Platform::current()->sandboxSupport())
175 typeface = SkTypeface::CreateFromStream(streamForFontconfigInterface Id(creationParams.fontconfigInterfaceId())); 187 typeface = SkTypeface::CreateFromStream(streamForFontconfigInterface Id(creationParams.fontconfigInterfaceId()));
176 else 188 else
(...skipping 15 matching lines...) Expand all
192 } 204 }
193 205
194 int style = SkTypeface::kNormal; 206 int style = SkTypeface::kNormal;
195 if (fontDescription.weight() >= FontWeight600) 207 if (fontDescription.weight() >= FontWeight600)
196 style |= SkTypeface::kBold; 208 style |= SkTypeface::kBold;
197 if (fontDescription.style()) 209 if (fontDescription.style())
198 style |= SkTypeface::kItalic; 210 style |= SkTypeface::kItalic;
199 211
200 #if OS(WIN) 212 #if OS(WIN)
201 if (s_sideloadedFonts) { 213 if (s_sideloadedFonts) {
202 HashMap<String, SkTypeface*>::iterator sideloadedFont = s_sideloadedFont s->find(name.data()); 214 HashMap<String, SkTypeface*>::iterator sideloadedFont =
203 if (sideloadedFont != s_sideloadedFonts->end()) { 215 s_sideloadedFonts->find(name.data());
216 if (sideloadedFont != s_sideloadedFonts->end())
204 return adoptRef(sideloadedFont->value); 217 return adoptRef(sideloadedFont->value);
205 }
206 } 218 }
207 // FIXME: Use SkFontStyle and matchFamilyStyle instead of legacyCreateTypefa ce. 219
208 if (m_fontManager) 220 if (m_fontManager) {
209 return adoptRef(m_fontManager->legacyCreateTypeface(name.data(), style)) ; 221 return adoptRef(useDirectWrite()
222 ? m_fontManager->matchFamilyStyle(name.data(), fontStyle(fontDescrip tion))
223 : m_fontManager->legacyCreateTypeface(name.data(), style)
224 );
225 }
210 #endif 226 #endif
211 227
228 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of
229 // CreateFromName on all platforms.
212 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style))); 230 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style)));
213 } 231 }
214 232
215 #if !OS(WIN) 233 #if !OS(WIN)
216 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const FontFaceCreationParams& creationParams, float fontSize) 234 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const FontFaceCreationParams& creationParams, float fontSize)
217 { 235 {
218 CString name; 236 CString name;
219 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ; 237 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ;
220 if (!tf) 238 if (!tf)
221 return 0; 239 return 0;
222 240
223 FontPlatformData* result = new FontPlatformData(tf, 241 FontPlatformData* result = new FontPlatformData(tf,
224 name.data(), 242 name.data(),
225 fontSize, 243 fontSize,
226 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(), 244 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(),
227 (fontDescription.style() && !tf->isItalic()) || fontDescription.isSynthe ticItalic(), 245 (fontDescription.style() && !tf->isItalic()) || fontDescription.isSynthe ticItalic(),
228 fontDescription.orientation(), 246 fontDescription.orientation(),
229 fontDescription.useSubpixelPositioning()); 247 fontDescription.useSubpixelPositioning());
230 return result; 248 return result;
231 } 249 }
232 #endif // !OS(WIN) 250 #endif // !OS(WIN)
233 251
234 } // namespace blink 252 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/fast/text/font-weight.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698