Chromium Code Reviews| 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 const static FamilyVariantSuffix variantForSuffix[] = { | |
| 217 { L" thin", 5, FontWeight100 }, | |
| 218 { L" extralight", 11, FontWeight200 }, | |
| 219 { L" ultralight", 11, FontWeight200 }, | |
| 220 { L" light", 6, FontWeight300 }, | |
| 221 { L" medium", 7, FontWeight500 }, | |
| 222 { L" demibold", 9, FontWeight600 }, | |
| 223 { L" semibold", 9, FontWeight600 }, | |
| 224 { L" extrabold", 10, FontWeight800 }, | |
| 225 { L" ultrabold", 10, FontWeight800 }, | |
| 226 { L" black", 6, FontWeight900 }, | |
| 227 { L" heavy", 6, FontWeight900 } | |
|
cpu_(ooo_6.6-7.5)
2014/09/05 22:23:26
I don't know the customs of this land, but I would
eae
2014/09/05 22:32:05
Good idea, added a comment and a link.
| |
| 228 }; | |
| 229 size_t numVariants = WTF_ARRAY_LENGTH(variantForSuffix); | |
| 230 bool caseSensitive = false; | |
| 231 for (size_t i = 0; i < numVariants; i++) { | |
| 232 FamilyVariantSuffix entry = variantForSuffix[i]; | |
|
cpu_(ooo_6.6-7.5)
2014/09/05 22:23:26
const FamilyVariantSuffix& entry ?
eae
2014/09/05 22:32:05
Done.
| |
| 233 if (family.endsWith(entry.suffix, caseSensitive)) { | |
| 234 String familyName = family.string(); | |
| 235 familyName.truncate(family.length() - entry.length); | |
|
cpu_(ooo_6.6-7.5)
2014/09/05 22:23:26
just to confirm String is mutable, as in truncate(
eae
2014/09/05 22:32:05
Correct, truncate mutates the string and is define
| |
| 236 adjustedName = AtomicString(familyName); | |
| 237 variantWeight = entry.weight; | |
| 238 return true; | |
| 239 } | |
| 240 } | |
| 241 | |
| 242 return false; | |
| 243 } | |
| 244 | |
| 207 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const FontFaceCreationParams& creationParams, float fontSize) | 245 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const FontFaceCreationParams& creationParams, float fontSize) |
| 208 { | 246 { |
| 209 ASSERT(creationParams.creationType() == CreateFontByFamily); | 247 ASSERT(creationParams.creationType() == CreateFontByFamily); |
| 248 | |
| 210 CString name; | 249 CString name; |
| 211 RefPtr<SkTypeface> tf = createTypeface(fontDescription, creationParams, name ); | 250 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 | 251 // 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 | 252 // is non-existent. We have to double-check and see if the family name was |
| 217 // really used. | 253 // really used. |
| 218 // FIXME: Do we need to use predefined fonts "guaranteed" to exist | 254 if (!tf || !typefacesMatchesFamily(tf.get(), creationParams.family())) { |
| 219 // when we're running in layout-test mode? | 255 AtomicString adjustedName; |
| 220 if (!typefacesMatchesFamily(tf.get(), creationParams.family())) { | 256 FontWeight variantWeight; |
| 221 return 0; | 257 if (typefacesHasVariantSuffix(creationParams.family(), adjustedName, |
| 258 variantWeight)) { | |
| 259 FontFaceCreationParams adjustedParams(adjustedName); | |
| 260 FontDescription adjustedFontDescription = fontDescription; | |
| 261 adjustedFontDescription.setWeight(variantWeight); | |
| 262 tf = createTypeface(adjustedFontDescription, adjustedParams, name); | |
| 263 if (!tf || !typefacesMatchesFamily(tf.get(), adjustedName)) | |
| 264 return 0; | |
| 265 } else { | |
| 266 return 0; | |
| 267 } | |
| 222 } | 268 } |
| 223 | 269 |
| 224 FontPlatformData* result = new FontPlatformData(tf, | 270 FontPlatformData* result = new FontPlatformData(tf, |
| 225 name.data(), | 271 name.data(), |
| 226 fontSize, | 272 fontSize, |
| 227 fontDescription.weight() >= FontWeight600 && !tf->isBold() || fontDescri ption.isSyntheticBold(), | 273 fontDescription.weight() >= FontWeight600 && !tf->isBold() || fontDescri ption.isSyntheticBold(), |
| 228 fontDescription.style() == FontStyleItalic && !tf->isItalic() || fontDes cription.isSyntheticItalic(), | 274 fontDescription.style() == FontStyleItalic && !tf->isItalic() || fontDes cription.isSyntheticItalic(), |
| 229 fontDescription.orientation(), | 275 fontDescription.orientation(), |
| 230 s_useSubpixelPositioning); | 276 s_useSubpixelPositioning); |
| 231 | 277 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 245 if (typefacesMatchesFamily(tf.get(), entry.family)) { | 291 if (typefacesMatchesFamily(tf.get(), entry.family)) { |
| 246 result->setMinSizeForAntiAlias(entry.minSize); | 292 result->setMinSizeForAntiAlias(entry.minSize); |
| 247 break; | 293 break; |
| 248 } | 294 } |
| 249 } | 295 } |
| 250 | 296 |
| 251 return result; | 297 return result; |
| 252 } | 298 } |
| 253 | 299 |
| 254 } // namespace blink | 300 } // namespace blink |
| OLD | NEW |