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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/text/font-stretch-variant.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/fonts/win/FontCacheSkiaWin.cpp
diff --git a/Source/platform/fonts/win/FontCacheSkiaWin.cpp b/Source/platform/fonts/win/FontCacheSkiaWin.cpp
index 9fe99931a6d792ca6a3cbe20c61fd0996b7ad8fd..b6dde3176083df54eac3c9dcb5602c9c22fda770 100644
--- a/Source/platform/fonts/win/FontCacheSkiaWin.cpp
+++ b/Source/platform/fonts/win/FontCacheSkiaWin.cpp
@@ -204,18 +204,17 @@ static bool typefacesMatchesFamily(const SkTypeface* tf, const AtomicString& fam
return matchesRequestedFamily;
}
-
-static bool typefacesHasVariantSuffix(const AtomicString& family,
+static bool typefacesHasWeightSuffix(const AtomicString& family,
AtomicString& adjustedName, FontWeight& variantWeight)
{
- struct FamilyVariantSuffix {
+ struct FamilyWeightSuffix {
const wchar_t* suffix;
size_t length;
FontWeight weight;
};
// Mapping from suffix to weight from the DirectWrite documentation.
- // http://msdn.microsoft.com/en-us/library/windows/desktop/dd368082(v=vs.85).aspx
- const static FamilyVariantSuffix variantForSuffix[] = {
+ // http://msdn.microsoft.com/en-us/library/windows/desktop/dd368082.aspx
+ const static FamilyWeightSuffix variantForSuffix[] = {
{ L" thin", 5, FontWeight100 },
{ L" extralight", 11, FontWeight200 },
{ L" ultralight", 11, FontWeight200 },
@@ -231,7 +230,7 @@ static bool typefacesHasVariantSuffix(const AtomicString& family,
size_t numVariants = WTF_ARRAY_LENGTH(variantForSuffix);
bool caseSensitive = false;
for (size_t i = 0; i < numVariants; i++) {
- const FamilyVariantSuffix& entry = variantForSuffix[i];
+ const FamilyWeightSuffix& entry = variantForSuffix[i];
if (family.endsWith(entry.suffix, caseSensitive)) {
String familyName = family.string();
familyName.truncate(family.length() - entry.length);
@@ -244,6 +243,45 @@ static bool typefacesHasVariantSuffix(const AtomicString& family,
return false;
}
+static bool typefacesHasStretchSuffix(const AtomicString& family,
+ AtomicString& adjustedName, FontStretch& variantStretch)
+{
+ struct FamilyStretchSuffix {
+ const wchar_t* suffix;
+ size_t length;
+ FontStretch stretch;
+ };
+ // Mapping from suffix to stretch value from the DirectWrite documentation.
+ // http://msdn.microsoft.com/en-us/library/windows/desktop/dd368078.aspx
+ // Also includes Narrow as a synonym for Condensed to to support Arial
+ // Narrow and other fonts following the same naming scheme.
+ const static FamilyStretchSuffix variantForSuffix[] = {
+ { L" ultracondensed", 15, FontStretchUltraCondensed },
+ { L" extracondensed", 15, FontStretchExtraCondensed },
+ { L" condensed", 10, FontStretchCondensed },
+ { L" narrow", 7, FontStretchCondensed },
+ { L" semicondensed", 14, FontStretchSemiCondensed },
+ { L" semiexpanded", 13, FontStretchSemiExpanded },
+ { L" expanded", 9, FontStretchExpanded },
+ { L" extraexpanded", 14, FontStretchExtraExpanded },
+ { L" ultraexpanded", 14, FontStretchUltraExpanded }
+ };
+ size_t numVariants = WTF_ARRAY_LENGTH(variantForSuffix);
+ bool caseSensitive = false;
+ for (size_t i = 0; i < numVariants; i++) {
+ const FamilyStretchSuffix& entry = variantForSuffix[i];
+ if (family.endsWith(entry.suffix, caseSensitive)) {
+ String familyName = family.string();
+ familyName.truncate(family.length() - entry.length);
+ adjustedName = AtomicString(familyName);
+ variantStretch = entry.stretch;
+ return true;
+ }
+ }
+
+ return false;
+}
+
FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const FontFaceCreationParams& creationParams, float fontSize)
{
ASSERT(creationParams.creationType() == CreateFontByFamily);
@@ -256,7 +294,9 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
if (!tf || !typefacesMatchesFamily(tf.get(), creationParams.family())) {
AtomicString adjustedName;
FontWeight variantWeight;
- if (typefacesHasVariantSuffix(creationParams.family(), adjustedName,
+ FontStretch variantStretch;
+
+ if (typefacesHasWeightSuffix(creationParams.family(), adjustedName,
variantWeight)) {
FontFaceCreationParams adjustedParams(adjustedName);
FontDescription adjustedFontDescription = fontDescription;
@@ -264,6 +304,16 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
tf = createTypeface(adjustedFontDescription, adjustedParams, name);
if (!tf || !typefacesMatchesFamily(tf.get(), adjustedName))
return 0;
+
+ } else if (typefacesHasStretchSuffix(creationParams.family(),
+ adjustedName, variantStretch)) {
+ FontFaceCreationParams adjustedParams(adjustedName);
+ FontDescription adjustedFontDescription = fontDescription;
+ adjustedFontDescription.setStretch(variantStretch);
+ tf = createTypeface(adjustedFontDescription, adjustedParams, name);
+ if (!tf || !typefacesMatchesFamily(tf.get(), adjustedName))
+ return 0;
+
} else {
return 0;
}
« 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