OLD | NEW |
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 Loading... |
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 |
| 208 static bool typefacesHasVariantSuffix(const AtomicString& family, |
| 209 AtomicString& adjustedName, FontWeight& variantWeight) |
| 210 { |
| 211 struct FamilyVariantSuffix { |
| 212 const wchar_t* suffix; |
| 213 size_t length; |
| 214 FontWeight weight; |
| 215 }; |
| 216 // Mapping from suffix to weight from the DirectWrite documentation. |
| 217 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd368082(v=vs.85)
.aspx |
| 218 const static FamilyVariantSuffix variantForSuffix[] = { |
| 219 { L" thin", 5, FontWeight100 }, |
| 220 { L" extralight", 11, FontWeight200 }, |
| 221 { L" ultralight", 11, FontWeight200 }, |
| 222 { L" light", 6, FontWeight300 }, |
| 223 { L" medium", 7, FontWeight500 }, |
| 224 { L" demibold", 9, FontWeight600 }, |
| 225 { L" semibold", 9, FontWeight600 }, |
| 226 { L" extrabold", 10, FontWeight800 }, |
| 227 { L" ultrabold", 10, FontWeight800 }, |
| 228 { L" black", 6, FontWeight900 }, |
| 229 { L" heavy", 6, FontWeight900 } |
| 230 }; |
| 231 size_t numVariants = WTF_ARRAY_LENGTH(variantForSuffix); |
| 232 bool caseSensitive = false; |
| 233 for (size_t i = 0; i < numVariants; i++) { |
| 234 const FamilyVariantSuffix& entry = variantForSuffix[i]; |
| 235 if (family.endsWith(entry.suffix, caseSensitive)) { |
| 236 String familyName = family.string(); |
| 237 familyName.truncate(family.length() - entry.length); |
| 238 adjustedName = AtomicString(familyName); |
| 239 variantWeight = entry.weight; |
| 240 return true; |
| 241 } |
| 242 } |
| 243 |
| 244 return false; |
| 245 } |
| 246 |
207 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
escription, const FontFaceCreationParams& creationParams, float fontSize) | 247 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
escription, const FontFaceCreationParams& creationParams, float fontSize) |
208 { | 248 { |
209 ASSERT(creationParams.creationType() == CreateFontByFamily); | 249 ASSERT(creationParams.creationType() == CreateFontByFamily); |
| 250 |
210 CString name; | 251 CString name; |
211 RefPtr<SkTypeface> tf = createTypeface(fontDescription, creationParams, name
); | 252 RefPtr<SkTypeface> tf = createTypeface(fontDescription, creationParams, name
); |
212 if (!tf) | |
213 return 0; | |
214 | |
215 // Windows will always give us a valid pointer here, even if the face name | 253 // Windows will always give us a valid pointer here, even if the face name |
216 // is non-existent. We have to double-check and see if the family name was | 254 // is non-existent. We have to double-check and see if the family name was |
217 // really used. | 255 // really used. |
218 // FIXME: Do we need to use predefined fonts "guaranteed" to exist | 256 if (!tf || !typefacesMatchesFamily(tf.get(), creationParams.family())) { |
219 // when we're running in layout-test mode? | 257 AtomicString adjustedName; |
220 if (!typefacesMatchesFamily(tf.get(), creationParams.family())) { | 258 FontWeight variantWeight; |
221 return 0; | 259 if (typefacesHasVariantSuffix(creationParams.family(), adjustedName, |
| 260 variantWeight)) { |
| 261 FontFaceCreationParams adjustedParams(adjustedName); |
| 262 FontDescription adjustedFontDescription = fontDescription; |
| 263 adjustedFontDescription.setWeight(variantWeight); |
| 264 tf = createTypeface(adjustedFontDescription, adjustedParams, name); |
| 265 if (!tf || !typefacesMatchesFamily(tf.get(), adjustedName)) |
| 266 return 0; |
| 267 } else { |
| 268 return 0; |
| 269 } |
222 } | 270 } |
223 | 271 |
224 FontPlatformData* result = new FontPlatformData(tf, | 272 FontPlatformData* result = new FontPlatformData(tf, |
225 name.data(), | 273 name.data(), |
226 fontSize, | 274 fontSize, |
227 fontDescription.weight() >= FontWeight600 && !tf->isBold() || fontDescri
ption.isSyntheticBold(), | 275 fontDescription.weight() >= FontWeight600 && !tf->isBold() || fontDescri
ption.isSyntheticBold(), |
228 fontDescription.style() == FontStyleItalic && !tf->isItalic() || fontDes
cription.isSyntheticItalic(), | 276 fontDescription.style() == FontStyleItalic && !tf->isItalic() || fontDes
cription.isSyntheticItalic(), |
229 fontDescription.orientation(), | 277 fontDescription.orientation(), |
230 s_useSubpixelPositioning); | 278 s_useSubpixelPositioning); |
231 | 279 |
(...skipping 13 matching lines...) Expand all Loading... |
245 if (typefacesMatchesFamily(tf.get(), entry.family)) { | 293 if (typefacesMatchesFamily(tf.get(), entry.family)) { |
246 result->setMinSizeForAntiAlias(entry.minSize); | 294 result->setMinSizeForAntiAlias(entry.minSize); |
247 break; | 295 break; |
248 } | 296 } |
249 } | 297 } |
250 | 298 |
251 return result; | 299 return result; |
252 } | 300 } |
253 | 301 |
254 } // namespace blink | 302 } // namespace blink |
OLD | NEW |