Chromium Code Reviews| Index: Source/platform/fonts/win/FontCacheSkiaWin.cpp |
| diff --git a/Source/platform/fonts/win/FontCacheSkiaWin.cpp b/Source/platform/fonts/win/FontCacheSkiaWin.cpp |
| index 1d2f3e853d0018002db197a344e6e6c50d7fdabd..0e66cf7b759f3239dcbdbc2cbcaa61e884b355f5 100644 |
| --- a/Source/platform/fonts/win/FontCacheSkiaWin.cpp |
| +++ b/Source/platform/fonts/win/FontCacheSkiaWin.cpp |
| @@ -204,21 +204,67 @@ static bool typefacesMatchesFamily(const SkTypeface* tf, const AtomicString& fam |
| return matchesRequestedFamily; |
| } |
| + |
| +static bool typefacesHasVariantSuffix(const AtomicString& family, |
| + AtomicString& adjustedName, FontWeight& variantWeight) |
| +{ |
| + struct FamilyVariantSuffix { |
| + const wchar_t* suffix; |
| + size_t length; |
| + FontWeight weight; |
| + }; |
| + const static FamilyVariantSuffix variantForSuffix[] = { |
| + { L" thin", 5, FontWeight100 }, |
| + { L" extralight", 11, FontWeight200 }, |
| + { L" ultralight", 11, FontWeight200 }, |
| + { L" light", 6, FontWeight300 }, |
| + { L" medium", 7, FontWeight500 }, |
| + { L" demibold", 9, FontWeight600 }, |
| + { L" semibold", 9, FontWeight600 }, |
| + { L" extrabold", 10, FontWeight800 }, |
| + { L" ultrabold", 10, FontWeight800 }, |
| + { L" black", 6, FontWeight900 }, |
| + { 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.
|
| + }; |
| + size_t numVariants = WTF_ARRAY_LENGTH(variantForSuffix); |
| + bool caseSensitive = false; |
| + for (size_t i = 0; i < numVariants; i++) { |
| + 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.
|
| + if (family.endsWith(entry.suffix, caseSensitive)) { |
| + String familyName = family.string(); |
| + 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
|
| + adjustedName = AtomicString(familyName); |
| + variantWeight = entry.weight; |
| + return true; |
| + } |
| + } |
| + |
| + return false; |
| +} |
| + |
| FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const FontFaceCreationParams& creationParams, float fontSize) |
| { |
| ASSERT(creationParams.creationType() == CreateFontByFamily); |
| + |
| CString name; |
| RefPtr<SkTypeface> tf = createTypeface(fontDescription, creationParams, name); |
| - if (!tf) |
| - return 0; |
| - |
| // Windows will always give us a valid pointer here, even if the face name |
| // is non-existent. We have to double-check and see if the family name was |
| // really used. |
| - // FIXME: Do we need to use predefined fonts "guaranteed" to exist |
| - // when we're running in layout-test mode? |
| - if (!typefacesMatchesFamily(tf.get(), creationParams.family())) { |
| - return 0; |
| + if (!tf || !typefacesMatchesFamily(tf.get(), creationParams.family())) { |
| + AtomicString adjustedName; |
| + FontWeight variantWeight; |
| + if (typefacesHasVariantSuffix(creationParams.family(), adjustedName, |
| + variantWeight)) { |
| + FontFaceCreationParams adjustedParams(adjustedName); |
| + FontDescription adjustedFontDescription = fontDescription; |
| + adjustedFontDescription.setWeight(variantWeight); |
| + tf = createTypeface(adjustedFontDescription, adjustedParams, name); |
| + if (!tf || !typefacesMatchesFamily(tf.get(), adjustedName)) |
| + return 0; |
| + } else { |
| + return 0; |
| + } |
| } |
| FontPlatformData* result = new FontPlatformData(tf, |