Title: [218919] trunk/Source/WebCore
Revision
218919
Author
mmaxfi...@apple.com
Date
2017-06-28 22:45:44 -0700 (Wed, 28 Jun 2017)

Log Message

Only apply font features for the particular type of font they are being applied to
https://bugs.webkit.org/show_bug.cgi?id=172661
<rdar://problem/31534119>
<rdar://problem/32799624>

Reviewed by Simon Fraser.

There are two types of font formats which support features: AAT and OTF. Each of them has
a different idea about what the identity of a feature is. We were specifying both types
of feature identities to Core Text; however, this is causing Core Text to get confused.
Instead, we should only apply AAT features to AAT fonts and OTF features to OTF fonts.

Test: Un-marking these tests as failure on High Sierra:
      css3/font-variant-petite-caps-synthesis-coverage.html
      css3/font-variant-small-caps-synthesis-coverage.html

* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::FontType::FontType):
(WebCore::preparePlatformFont):
(WebCore::variationCapabilitiesForFontDescriptor):
(WebCore::isGXVariableFont): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (218918 => 218919)


--- trunk/Source/WebCore/ChangeLog	2017-06-29 05:43:04 UTC (rev 218918)
+++ trunk/Source/WebCore/ChangeLog	2017-06-29 05:45:44 UTC (rev 218919)
@@ -1,3 +1,27 @@
+2017-06-28  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        Only apply font features for the particular type of font they are being applied to
+        https://bugs.webkit.org/show_bug.cgi?id=172661
+        <rdar://problem/31534119>
+        <rdar://problem/32799624>
+
+        Reviewed by Simon Fraser.
+
+        There are two types of font formats which support features: AAT and OTF. Each of them has
+        a different idea about what the identity of a feature is. We were specifying both types
+        of feature identities to Core Text; however, this is causing Core Text to get confused.
+        Instead, we should only apply AAT features to AAT fonts and OTF features to OTF fonts.
+
+        Test: Un-marking these tests as failure on High Sierra:
+              css3/font-variant-petite-caps-synthesis-coverage.html
+              css3/font-variant-small-caps-synthesis-coverage.html
+
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::FontType::FontType):
+        (WebCore::preparePlatformFont):
+        (WebCore::variationCapabilitiesForFontDescriptor):
+        (WebCore::isGXVariableFont): Deleted.
+
 2017-06-28  Chris Dumez  <cdu...@apple.com>
 
         [ResourceLoadStatistics] Simplify PrevalentResourceTelemetry struct

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp (218918 => 218919)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2017-06-29 05:43:04 UTC (rev 218918)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2017-06-29 05:45:44 UTC (rev 218919)
@@ -420,24 +420,6 @@
     return CFStringGetLength(name.get()) > 0 && CFStringGetCharacterAtIndex(name.get(), 0) == '.';
 }
 
-static inline bool isGXVariableFont(CTFontRef font)
-{
-    auto tables = adoptCF(CTFontCopyAvailableTables(font, kCTFontTableOptionNoOptions));
-    if (!tables)
-        return false;
-    auto size = CFArrayGetCount(tables.get());
-    for (CFIndex i = 0; i < size; ++i) {
-        // This is so yucky.
-        // https://developer.apple.com/reference/coretext/1510774-ctfontcopyavailabletables
-        // "The returned set will contain unboxed values, which can be extracted like so:"
-        // "CTFontTableTag tag = (CTFontTableTag)(uintptr_t)CFArrayGetValueAtIndex(tags, index);"
-        CTFontTableTag tableTag = static_cast<CTFontTableTag>(reinterpret_cast<uintptr_t>(CFArrayGetValueAtIndex(tables.get(), i)));
-        if (tableTag == 'STAT')
-            return false;
-    }
-    return true;
-}
-
 // These values were calculated by performing a linear regression on the CSS weights/widths/slopes and Core Text weights/widths/slopes of San Francisco.
 // FIXME: <rdar://problem/31312602> Get the real values from Core Text.
 static inline float normalizeWeight(float value)
@@ -488,6 +470,49 @@
 }
 #endif
 
+struct FontType {
+    FontType(CTFontRef font)
+    {
+        auto tables = adoptCF(CTFontCopyAvailableTables(font, kCTFontTableOptionNoOptions));
+        if (!tables)
+            return;
+        auto size = CFArrayGetCount(tables.get());
+        for (CFIndex i = 0; i < size; ++i) {
+            // This is so yucky.
+            // https://developer.apple.com/reference/coretext/1510774-ctfontcopyavailabletables
+            // "The returned set will contain unboxed values, which can be extracted like so:"
+            // "CTFontTableTag tag = (CTFontTableTag)(uintptr_t)CFArrayGetValueAtIndex(tags, index);"
+            CTFontTableTag tableTag = static_cast<CTFontTableTag>(reinterpret_cast<uintptr_t>(CFArrayGetValueAtIndex(tables.get(), i)));
+            switch (tableTag) {
+            case 'fvar':
+                if (variationType == VariationType::NotVariable)
+                    variationType = VariationType::TrueTypeGX;
+                break;
+            case 'STAT':
+                variationType = VariationType::OpenType18;
+                break;
+            case 'morx':
+            case 'mort':
+                aatShaping = true;
+                break;
+            case 'GPOS':
+            case 'GSUB':
+                openTypeShaping = true;
+                break;
+            }
+        }
+    }
+
+    enum class VariationType {
+        NotVariable,
+        TrueTypeGX,
+        OpenType18
+    };
+    VariationType variationType { VariationType::NotVariable };
+    bool openTypeShaping { false };
+    bool aatShaping { false };
+};
+
 RetainPtr<CTFontRef> preparePlatformFont(CTFontRef originalFont, const FontDescription& fontDescription, const FontFeatureSettings* fontFaceFeatures, const FontVariantSettings* fontFaceVariantSettings, FontSelectionSpecifiedCapabilities fontFaceCapabilities, float size)
 {
     bool alwaysAddVariations = false;
@@ -546,10 +571,12 @@
     for (auto& newFeature : features)
         featuresToBeApplied.set(newFeature.tag(), newFeature.value());
 
+    FontType fontType(originalFont);
+
 #if ENABLE(VARIATION_FONTS)
     VariationsMap variationsToBeApplied;
 
-    bool needsConversion = isGXVariableFont(originalFont);
+    bool needsConversion = fontType.variationType == FontType::VariationType::TrueTypeGX;
 
     auto applyVariation = [&](const FontTag& tag, float value) {
         auto iterator = defaultValues.find(tag);
@@ -598,8 +625,10 @@
         auto featureArray = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, features.size(), &kCFTypeArrayCallBacks));
         for (auto& p : featuresToBeApplied) {
             auto feature = FontFeature(p.key, p.value);
-            appendTrueTypeFeature(featureArray.get(), feature);
-            appendOpenTypeFeature(featureArray.get(), feature);
+            if (fontType.aatShaping)
+                appendTrueTypeFeature(featureArray.get(), feature);
+            if (fontType.openTypeShaping)
+                appendOpenTypeFeature(featureArray.get(), feature);
         }
         CFDictionaryAddValue(attributes.get(), kCTFontFeatureSettingsAttribute, featureArray.get());
     }
@@ -963,7 +992,7 @@
             result.slope = extractVariationBounds(axis);
     }
 
-    if (isGXVariableFont(font.get())) {
+    if (FontType(font.get()).variationType == FontType::VariationType::TrueTypeGX) {
         if (result.weight)
             result.weight = {{ normalizeWeight(result.weight.value().minimum), normalizeWeight(result.weight.value().maximum) }};
         if (result.width)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to