Title: [210591] trunk/Source/WebCore
Revision
210591
Author
[email protected]
Date
2017-01-11 10:26:38 -0800 (Wed, 11 Jan 2017)

Log Message

[Cocoa] Variation fonts without variations specified are not rendered as if the default variations were specified
https://bugs.webkit.org/show_bug.cgi?id=166672
<rdar://problem/29779119>
<rdar://problem/29848883>

Reviewed by Simon Fraser.

CoreText has a bug (<rdar://problem/29859207>) where variation fonts without
a specified variation value are rendered as if the minimum value is specified,
rather than the default value. The solution is to apply default values where
they are omitted.

Test: fast/text/variations/advances.html

* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::preparePlatformFont):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (210590 => 210591)


--- trunk/Source/WebCore/ChangeLog	2017-01-11 18:08:37 UTC (rev 210590)
+++ trunk/Source/WebCore/ChangeLog	2017-01-11 18:26:38 UTC (rev 210591)
@@ -1,3 +1,22 @@
+2017-01-11  Myles C. Maxfield  <[email protected]>
+
+        [Cocoa] Variation fonts without variations specified are not rendered as if the default variations were specified
+        https://bugs.webkit.org/show_bug.cgi?id=166672
+        <rdar://problem/29779119>
+        <rdar://problem/29848883>
+
+        Reviewed by Simon Fraser.
+
+        CoreText has a bug (<rdar://problem/29859207>) where variation fonts without
+        a specified variation value are rendered as if the minimum value is specified,
+        rather than the default value. The solution is to apply default values where
+        they are omitted.
+
+        Test: fast/text/variations/advances.html
+
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::preparePlatformFont):
+
 2017-01-11  Ryan Haddad  <[email protected]>
 
         Attempt to fix the Windows build after r210588.

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


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2017-01-11 18:08:37 UTC (rev 210590)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2017-01-11 18:26:38 UTC (rev 210591)
@@ -421,7 +421,19 @@
 
 RetainPtr<CTFontRef> preparePlatformFont(CTFontRef originalFont, TextRenderingMode textRenderingMode, const FontFeatureSettings* fontFaceFeatures, const FontVariantSettings* fontFaceVariantSettings, const FontFeatureSettings& features, const FontVariantSettings& variantSettings, const FontVariationSettings& variations)
 {
-    if (!originalFont || (!features.size() && variations.isEmpty() && (textRenderingMode == AutoTextRendering) && variantSettings.isAllNormal()
+    bool alwaysAddVariations = false;
+
+    // FIXME: Remove when <rdar://problem/29859207> is fixed
+#define WORKAROUND_CORETEXT_VARIATIONS_UNSPECIFIED_VALUE_BUG (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000)
+#if ENABLE(VARIATION_FONTS)
+    auto defaultValues = defaultVariationValues(originalFont);
+#if WORKAROUND_CORETEXT_VARIATIONS_UNSPECIFIED_VALUE_BUG
+    bool isSystemFont = CTFontDescriptorIsSystemUIFont(adoptCF(CTFontCopyFontDescriptor(originalFont)).get());
+    alwaysAddVariations = !isSystemFont && !defaultValues.isEmpty();
+#endif
+#endif
+
+    if (!originalFont || (!features.size() && (!alwaysAddVariations && variations.isEmpty()) && (textRenderingMode == AutoTextRendering) && variantSettings.isAllNormal()
         && (!fontFaceFeatures || !fontFaceFeatures->size()) && (!fontFaceVariantSettings || fontFaceVariantSettings->isAllNormal())))
         return originalFont;
 
@@ -458,27 +470,40 @@
         featuresToBeApplied.set(newFeature.tag(), newFeature.value());
 
 #if ENABLE(VARIATION_FONTS)
-    auto defaultValues = defaultVariationValues(originalFont);
-
     VariationsMap variationsToBeApplied;
-    for (auto& newVariation : variations) {
-        auto iterator = defaultValues.find(newVariation.tag());
-        if (iterator != defaultValues.end()) {
-            float valueToApply = std::max(std::min(newVariation.value(), iterator->value.maximumValue), iterator->value.minimumValue);
 
-            // FIXME: Remove when <rdar://problem/28707822> is fixed
+    auto applyVariationValue = [&](const FontTag& tag, float value, bool isDefaultValue) {
+        // FIXME: Remove when <rdar://problem/28707822> is fixed
 #define WORKAROUND_CORETEXT_VARIATIONS_DEFAULT_VALUE_BUG (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000)
 #if WORKAROUND_CORETEXT_VARIATIONS_DEFAULT_VALUE_BUG
-            if (valueToApply == iterator->value.defaultValue)
-                valueToApply += 0.0001;
+        if (isDefaultValue)
+            value += 0.0001;
+#else
+        UNUSED_PARAM(isDefaultValue);
 #endif
 #undef WORKAROUND_CORETEXT_VARIATIONS_DEFAULT_VALUE_BUG
+        variationsToBeApplied.set(tag, value);
+    };
 
-            variationsToBeApplied.set(newVariation.tag(), valueToApply);
-        }
+    for (auto& newVariation : variations) {
+        auto iterator = defaultValues.find(newVariation.tag());
+        if (iterator == defaultValues.end())
+            continue;
+        float valueToApply = clampTo(newVariation.value(), iterator->value.minimumValue, iterator->value.maximumValue);
+        bool isDefaultValue = valueToApply == iterator->value.defaultValue;
+        applyVariationValue(newVariation.tag(), valueToApply, isDefaultValue);
     }
+
+#if WORKAROUND_CORETEXT_VARIATIONS_UNSPECIFIED_VALUE_BUG
+    for (auto& defaultValue : defaultValues) {
+        if (!variationsToBeApplied.contains(defaultValue.key))
+            applyVariationValue(defaultValue.key, defaultValue.value.defaultValue, true);
+    }
 #endif
+#undef WORKAROUND_CORETEXT_VARIATIONS_UNSPECIFIED_VALUE_BUG
 
+#endif // ENABLE(VARIATION_FONTS)
+
     RetainPtr<CFMutableDictionaryRef> attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
     if (!featuresToBeApplied.isEmpty()) {
         RetainPtr<CFMutableArrayRef> featureArray = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, features.size(), &kCFTypeArrayCallBacks));
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to