Title: [214594] trunk/Source/WebCore
Revision
214594
Author
mmaxfi...@apple.com
Date
2017-03-29 19:58:37 -0700 (Wed, 29 Mar 2017)

Log Message

Migrate to kCTFontCSSWidthAttribute
https://bugs.webkit.org/show_bug.cgi?id=170265

Reviewed by Darin Adler.

Previously, we were mapping from Core Text widths to CSS widths in WebKit.
However, on some OSes, Core Text can directly tell us what the CSS width
value is.

No new tests because there is no behavior change.

* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::getCSSAttribute):
(WebCore::capabilitiesForFontDescriptor):
* platform/spi/cocoa/CoreTextSPI.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (214593 => 214594)


--- trunk/Source/WebCore/ChangeLog	2017-03-30 02:58:15 UTC (rev 214593)
+++ trunk/Source/WebCore/ChangeLog	2017-03-30 02:58:37 UTC (rev 214594)
@@ -1,3 +1,21 @@
+2017-03-29  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        Migrate to kCTFontCSSWidthAttribute
+        https://bugs.webkit.org/show_bug.cgi?id=170265
+
+        Reviewed by Darin Adler.
+
+        Previously, we were mapping from Core Text widths to CSS widths in WebKit.
+        However, on some OSes, Core Text can directly tell us what the CSS width
+        value is.
+
+        No new tests because there is no behavior change.
+
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::getCSSAttribute):
+        (WebCore::capabilitiesForFontDescriptor):
+        * platform/spi/cocoa/CoreTextSPI.h:
+
 2017-03-28  Simon Fraser  <simon.fra...@apple.com>
 
         Make it possible to dump touch event regions for testing

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


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2017-03-30 02:58:15 UTC (rev 214593)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2017-03-30 02:58:37 UTC (rev 214594)
@@ -36,6 +36,7 @@
 #include <wtf/NeverDestroyed.h>
 
 #define SHOULD_USE_CORE_TEXT_FONT_LOOKUP (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200)
+#define HAS_CORE_TEXT_WIDTH_ATTRIBUTE ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000))
 
 namespace WebCore {
 
@@ -419,8 +420,7 @@
     }
     return result;
 }
-#endif
-#if ENABLE(VARIATION_FONTS)
+
 static inline bool fontIsSystemFont(CTFontRef font)
 {
     if (CTFontDescriptorIsSystemUIFont(adoptCF(CTFontCopyFontDescriptor(font)).get()))
@@ -477,6 +477,7 @@
 }
 #endif
 
+#if !HAS_CORE_TEXT_WIDTH_ATTRIBUTE || ENABLE(VARIATION_FONTS)
 static inline float normalizeWidth(float value)
 {
     if (value < 0.5)
@@ -483,6 +484,7 @@
         return value * 50 + 100;
     return value * 150 + 50;
 }
+#endif
 
 RetainPtr<CTFontRef> preparePlatformFont(CTFontRef originalFont, TextRenderingMode textRenderingMode, const FontFeatureSettings* fontFaceFeatures, const FontVariantSettings* fontFaceVariantSettings, const FontFeatureSettings& features, const FontVariantSettings& variantSettings, FontSelectionRequest fontSelectionRequest, const FontVariationSettings& variations, FontOpticalSizing fontOpticalSizing, float size)
 {
@@ -664,6 +666,7 @@
     return nullptr;
 }
 
+#if !HAS_CORE_TEXT_WIDTH_ATTRIBUTE
 static float stretchFromCoreTextTraits(CFDictionaryRef traits)
 {
     auto widthNumber = static_cast<CFNumberRef>(CFDictionaryGetValue(traits, kCTFontWidthTrait));
@@ -675,6 +678,7 @@
     ASSERT_UNUSED(success, success);
     return normalizeWidth(ctWidth);
 }
+#endif
 
 static void invalidateFontCache();
 
@@ -971,6 +975,19 @@
     return result;
 }
 
+#if !SHOULD_USE_CORE_TEXT_FONT_LOOKUP || HAS_CORE_TEXT_WIDTH_ATTRIBUTE
+static float getCSSAttribute(CTFontDescriptorRef fontDescriptor, const CFStringRef attribute, float fallback)
+{
+    auto number = adoptCF(static_cast<CFNumberRef>(CTFontDescriptorCopyAttribute(fontDescriptor, attribute)));
+    if (!number)
+        return fallback;
+    float cssValue;
+    auto success = CFNumberGetValue(number.get(), kCFNumberFloatType, &cssValue);
+    ASSERT_UNUSED(success, success);
+    return cssValue;
+}
+#endif
+
 FontSelectionCapabilities capabilitiesForFontDescriptor(CTFontDescriptorRef fontDescriptor)
 {
     if (!fontDescriptor)
@@ -978,19 +995,21 @@
 
     VariationCapabilities variationCapabilities = variationCapabilitiesForFontDescriptor(fontDescriptor);
 
-#if SHOULD_USE_CORE_TEXT_FONT_LOOKUP
-    bool weightComesFromTraits = !variationCapabilities.weight;
+#if SHOULD_USE_CORE_TEXT_FONT_LOOKUP || !HAS_CORE_TEXT_WIDTH_ATTRIBUTE
+    bool weightOrWidthComeFromTraits = !variationCapabilities.weight || !variationCapabilities.width;
 #else
-    bool weightComesFromTraits = false;
+    bool weightOrWidthComeFromTraits = false;
 #endif
 
-    if (!variationCapabilities.slope || !variationCapabilities.width || weightComesFromTraits) {
+    if (!variationCapabilities.slope || weightOrWidthComeFromTraits) {
         auto traits = adoptCF(static_cast<CFDictionaryRef>(CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontTraitsAttribute)));
         if (traits) {
+#if !HAS_CORE_TEXT_WIDTH_ATTRIBUTE
             if (!variationCapabilities.width) {
                 auto widthValue = stretchFromCoreTextTraits(traits.get());
                 variationCapabilities.width = {{ widthValue, widthValue }};
             }
+#endif
 
             if (!variationCapabilities.slope) {
                 auto symbolicTraitsNumber = static_cast<CFNumberRef>(CFDictionaryGetValue(traits.get(), kCTFontSymbolicTrait));
@@ -1022,17 +1041,18 @@
 
 #if !SHOULD_USE_CORE_TEXT_FONT_LOOKUP
     if (!variationCapabilities.weight) {
-        auto weightNumber = adoptCF(static_cast<CFNumberRef>(CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontCSSWeightAttribute)));
-        if (weightNumber) {
-            float cssWeight;
-            auto success = CFNumberGetValue(weightNumber.get(), kCFNumberFloatType, &cssWeight);
-            ASSERT_UNUSED(success, success);
-            variationCapabilities.weight = {{ cssWeight, cssWeight }};
-        } else
-            variationCapabilities.weight = {{ static_cast<float>(normalWeightValue()), static_cast<float>(normalWeightValue()) }};
+        auto value = getCSSAttribute(fontDescriptor, kCTFontCSSWeightAttribute, static_cast<float>(normalWeightValue()));
+        variationCapabilities.weight = {{ value, value }};
     }
 #endif
 
+#if HAS_CORE_TEXT_WIDTH_ATTRIBUTE
+    if (!variationCapabilities.width) {
+        auto value = getCSSAttribute(fontDescriptor, kCTFontCSSWidthAttribute, static_cast<float>(normalStretchValue()));
+        variationCapabilities.width = {{ value, value }};
+    }
+#endif
+
     return {{ FontSelectionValue(variationCapabilities.weight.value().minimum), FontSelectionValue(variationCapabilities.weight.value().maximum) },
         { FontSelectionValue(variationCapabilities.width.value().minimum), FontSelectionValue(variationCapabilities.width.value().maximum) },
         { FontSelectionValue(variationCapabilities.slope.value().minimum), FontSelectionValue(variationCapabilities.slope.value().maximum) }};

Modified: trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h (214593 => 214594)


--- trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h	2017-03-30 02:58:15 UTC (rev 214593)
+++ trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h	2017-03-30 02:58:37 UTC (rev 214594)
@@ -85,6 +85,7 @@
 CTFontDescriptorRef CTFontDescriptorCreateWithAttributesAndOptions(CFDictionaryRef attributes, CTFontDescriptorOptions);
 
 extern const CFStringRef kCTFontCSSWeightAttribute;
+extern const CFStringRef kCTFontCSSWidthAttribute;
 extern const CFStringRef kCTFontDescriptorTextStyleAttribute;
 extern const CFStringRef kCTFontUIFontDesignTrait;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to