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

Side by Side Diff: Source/platform/fonts/win/FontCacheSkiaWin.cpp

Issue 550093005: [DirectWrite] Add support for font-stretch suffixes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: removed trailing comma Created 6 years, 3 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-stretch-variant.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 Apple Computer, Inc. 2 * Copyright (C) 2006, 2007 Apple Computer, Inc.
3 * Copyright (c) 2006, 2007, 2008, 2009, 2012 Google Inc. All rights reserved. 3 * Copyright (c) 2006, 2007, 2008, 2009, 2012 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 if (!matchesRequestedFamily) { 197 if (!matchesRequestedFamily) {
198 SkString familyName; 198 SkString familyName;
199 tf->getFamilyName(&familyName); 199 tf->getFamilyName(&familyName);
200 if (equalIgnoringCase(family, familyName)) 200 if (equalIgnoringCase(family, familyName))
201 matchesRequestedFamily = true; 201 matchesRequestedFamily = true;
202 } 202 }
203 203
204 return matchesRequestedFamily; 204 return matchesRequestedFamily;
205 } 205 }
206 206
207 207 static bool typefacesHasWeightSuffix(const AtomicString& family,
208 static bool typefacesHasVariantSuffix(const AtomicString& family,
209 AtomicString& adjustedName, FontWeight& variantWeight) 208 AtomicString& adjustedName, FontWeight& variantWeight)
210 { 209 {
211 struct FamilyVariantSuffix { 210 struct FamilyWeightSuffix {
212 const wchar_t* suffix; 211 const wchar_t* suffix;
213 size_t length; 212 size_t length;
214 FontWeight weight; 213 FontWeight weight;
215 }; 214 };
216 // Mapping from suffix to weight from the DirectWrite documentation. 215 // Mapping from suffix to weight from the DirectWrite documentation.
217 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd368082(v=vs.85) .aspx 216 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd368082.aspx
218 const static FamilyVariantSuffix variantForSuffix[] = { 217 const static FamilyWeightSuffix variantForSuffix[] = {
219 { L" thin", 5, FontWeight100 }, 218 { L" thin", 5, FontWeight100 },
220 { L" extralight", 11, FontWeight200 }, 219 { L" extralight", 11, FontWeight200 },
221 { L" ultralight", 11, FontWeight200 }, 220 { L" ultralight", 11, FontWeight200 },
222 { L" light", 6, FontWeight300 }, 221 { L" light", 6, FontWeight300 },
223 { L" medium", 7, FontWeight500 }, 222 { L" medium", 7, FontWeight500 },
224 { L" demibold", 9, FontWeight600 }, 223 { L" demibold", 9, FontWeight600 },
225 { L" semibold", 9, FontWeight600 }, 224 { L" semibold", 9, FontWeight600 },
226 { L" extrabold", 10, FontWeight800 }, 225 { L" extrabold", 10, FontWeight800 },
227 { L" ultrabold", 10, FontWeight800 }, 226 { L" ultrabold", 10, FontWeight800 },
228 { L" black", 6, FontWeight900 }, 227 { L" black", 6, FontWeight900 },
229 { L" heavy", 6, FontWeight900 } 228 { L" heavy", 6, FontWeight900 }
230 }; 229 };
231 size_t numVariants = WTF_ARRAY_LENGTH(variantForSuffix); 230 size_t numVariants = WTF_ARRAY_LENGTH(variantForSuffix);
232 bool caseSensitive = false; 231 bool caseSensitive = false;
233 for (size_t i = 0; i < numVariants; i++) { 232 for (size_t i = 0; i < numVariants; i++) {
234 const FamilyVariantSuffix& entry = variantForSuffix[i]; 233 const FamilyWeightSuffix& entry = variantForSuffix[i];
235 if (family.endsWith(entry.suffix, caseSensitive)) { 234 if (family.endsWith(entry.suffix, caseSensitive)) {
236 String familyName = family.string(); 235 String familyName = family.string();
237 familyName.truncate(family.length() - entry.length); 236 familyName.truncate(family.length() - entry.length);
238 adjustedName = AtomicString(familyName); 237 adjustedName = AtomicString(familyName);
239 variantWeight = entry.weight; 238 variantWeight = entry.weight;
240 return true; 239 return true;
241 } 240 }
242 } 241 }
243 242
244 return false; 243 return false;
245 } 244 }
246 245
246 static bool typefacesHasStretchSuffix(const AtomicString& family,
247 AtomicString& adjustedName, FontStretch& variantStretch)
248 {
249 struct FamilyStretchSuffix {
250 const wchar_t* suffix;
251 size_t length;
252 FontStretch stretch;
253 };
254 // Mapping from suffix to stretch value from the DirectWrite documentation.
255 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd368078.aspx
256 // Also includes Narrow as a synonym for Condensed to to support Arial
257 // Narrow and other fonts following the same naming scheme.
258 const static FamilyStretchSuffix variantForSuffix[] = {
259 { L" ultracondensed", 15, FontStretchUltraCondensed },
260 { L" extracondensed", 15, FontStretchExtraCondensed },
261 { L" condensed", 10, FontStretchCondensed },
262 { L" narrow", 7, FontStretchCondensed },
263 { L" semicondensed", 14, FontStretchSemiCondensed },
264 { L" semiexpanded", 13, FontStretchSemiExpanded },
265 { L" expanded", 9, FontStretchExpanded },
266 { L" extraexpanded", 14, FontStretchExtraExpanded },
267 { L" ultraexpanded", 14, FontStretchUltraExpanded }
268 };
269 size_t numVariants = WTF_ARRAY_LENGTH(variantForSuffix);
270 bool caseSensitive = false;
271 for (size_t i = 0; i < numVariants; i++) {
272 const FamilyStretchSuffix& entry = variantForSuffix[i];
273 if (family.endsWith(entry.suffix, caseSensitive)) {
274 String familyName = family.string();
275 familyName.truncate(family.length() - entry.length);
276 adjustedName = AtomicString(familyName);
277 variantStretch = entry.stretch;
278 return true;
279 }
280 }
281
282 return false;
283 }
284
247 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const FontFaceCreationParams& creationParams, float fontSize) 285 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const FontFaceCreationParams& creationParams, float fontSize)
248 { 286 {
249 ASSERT(creationParams.creationType() == CreateFontByFamily); 287 ASSERT(creationParams.creationType() == CreateFontByFamily);
250 288
251 CString name; 289 CString name;
252 RefPtr<SkTypeface> tf = createTypeface(fontDescription, creationParams, name ); 290 RefPtr<SkTypeface> tf = createTypeface(fontDescription, creationParams, name );
253 // Windows will always give us a valid pointer here, even if the face name 291 // Windows will always give us a valid pointer here, even if the face name
254 // is non-existent. We have to double-check and see if the family name was 292 // is non-existent. We have to double-check and see if the family name was
255 // really used. 293 // really used.
256 if (!tf || !typefacesMatchesFamily(tf.get(), creationParams.family())) { 294 if (!tf || !typefacesMatchesFamily(tf.get(), creationParams.family())) {
257 AtomicString adjustedName; 295 AtomicString adjustedName;
258 FontWeight variantWeight; 296 FontWeight variantWeight;
259 if (typefacesHasVariantSuffix(creationParams.family(), adjustedName, 297 FontStretch variantStretch;
298
299 if (typefacesHasWeightSuffix(creationParams.family(), adjustedName,
260 variantWeight)) { 300 variantWeight)) {
261 FontFaceCreationParams adjustedParams(adjustedName); 301 FontFaceCreationParams adjustedParams(adjustedName);
262 FontDescription adjustedFontDescription = fontDescription; 302 FontDescription adjustedFontDescription = fontDescription;
263 adjustedFontDescription.setWeight(variantWeight); 303 adjustedFontDescription.setWeight(variantWeight);
264 tf = createTypeface(adjustedFontDescription, adjustedParams, name); 304 tf = createTypeface(adjustedFontDescription, adjustedParams, name);
265 if (!tf || !typefacesMatchesFamily(tf.get(), adjustedName)) 305 if (!tf || !typefacesMatchesFamily(tf.get(), adjustedName))
266 return 0; 306 return 0;
307
308 } else if (typefacesHasStretchSuffix(creationParams.family(),
309 adjustedName, variantStretch)) {
310 FontFaceCreationParams adjustedParams(adjustedName);
311 FontDescription adjustedFontDescription = fontDescription;
312 adjustedFontDescription.setStretch(variantStretch);
313 tf = createTypeface(adjustedFontDescription, adjustedParams, name);
314 if (!tf || !typefacesMatchesFamily(tf.get(), adjustedName))
315 return 0;
316
267 } else { 317 } else {
268 return 0; 318 return 0;
269 } 319 }
270 } 320 }
271 321
272 FontPlatformData* result = new FontPlatformData(tf, 322 FontPlatformData* result = new FontPlatformData(tf,
273 name.data(), 323 name.data(),
274 fontSize, 324 fontSize,
275 fontDescription.weight() >= FontWeight600 && !tf->isBold() || fontDescri ption.isSyntheticBold(), 325 fontDescription.weight() >= FontWeight600 && !tf->isBold() || fontDescri ption.isSyntheticBold(),
276 fontDescription.style() == FontStyleItalic && !tf->isItalic() || fontDes cription.isSyntheticItalic(), 326 fontDescription.style() == FontStyleItalic && !tf->isItalic() || fontDes cription.isSyntheticItalic(),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 if (typefacesMatchesFamily(tf.get(), family)) { 370 if (typefacesMatchesFamily(tf.get(), family)) {
321 result->setMinSizeForSubpixel(minSizeForSubpixelForFont); 371 result->setMinSizeForSubpixel(minSizeForSubpixelForFont);
322 break; 372 break;
323 } 373 }
324 } 374 }
325 375
326 return result; 376 return result;
327 } 377 }
328 378
329 } // namespace blink 379 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/fast/text/font-stretch-variant.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698