[Cocoa] Honor the 'trak' table by opting in via text-rendering: optimizeLegibility
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Aug 2015 19:19:49 +0000 (19:19 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Aug 2015 19:19:49 +0000 (19:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148119
<rdar://problem/22291561>

Reviewed by Tim Horton.

Source/WebCore:

When the author has opted in by specifying "text-rendering: optimizeLegibility;", we should
honor the font's 'trak' table. We do this by specifying kCTFontOpticalSizeAttribute at font
creation time, and by using CTFontGetAdvancesForGlyphs() instead of
CGFontGetGlyphAdvancesForStyle().

Test: fast/text/trak-optimizeLegibility.html

* platform/graphics/FontCache.h:
(WebCore::FontDescriptionKey::makeFlagKey): Make our caches sensitive to TextRenderingMode.
* platform/graphics/FontPlatformData.cpp:
(WebCore::FontPlatformData::FontPlatformData): Add a TextRenderingMode member variable.
(WebCore::FontPlatformData::operator=): Update to consult with the new member.
* platform/graphics/FontPlatformData.h:
(WebCore::FontPlatformData::textRenderingMode): Getter.
* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::preparePlatformFont): Specify kCTFontOpticalSizeAttribute.
(WebCore::applyFontFeatureSettings): Deleted.
* platform/graphics/cocoa/FontCocoa.mm:
(WebCore::canUseFastGlyphAdvanceGetter): Use CTFontGetAdvancesForGlyphs() if we are
optimizeLegibility.
* platform/graphics/cocoa/FontPlatformDataCocoa.mm:
(WebCore::FontPlatformData::FontPlatformData): Pass the TextRenderingMode around.
* platform/graphics/ios/FontCacheIOS.mm:
(WebCore::FontCache::getSystemFontFallbackForCharacters): Update to call renamed function.
(WebCore::FontCache::createFontPlatformData): Ditto.
* platform/graphics/mac/FontCacheMac.mm:
(WebCore::fontWithFamily): Ditto.
(WebCore::FontCache::systemFallbackForCharacters): Ditto.
(WebCore::FontCache::createFontPlatformData): Ditto.
* platform/graphics/mac/FontCustomPlatformData.cpp:
(WebCore::FontCustomPlatformData::fontPlatformData): Ditto.
* platform/spi/cocoa/CoreTextSPI.h:
* rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::updateCachedSystemFontDescription): Ditto.

LayoutTests:

This test will fail until we stop mocking the system font on El Capitan. Until then,
this patch will commit the test failure as an expected result.

* fast/text/trak-optimizeLegibility-expected.html: Added
* fast/text/trak-optimizeLegibility.html: Added

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@188591 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/text/trak-optimizeLegibility-expected.txt [new file with mode: 0644]
LayoutTests/fast/text/trak-optimizeLegibility.html [new file with mode: 0644]
LayoutTests/platform/ios-simulator/fast/text/trak-optimizeLegibility-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/FontCache.h
Source/WebCore/platform/graphics/FontPlatformData.cpp
Source/WebCore/platform/graphics/FontPlatformData.h
Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
Source/WebCore/platform/graphics/cocoa/FontCocoa.mm
Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm
Source/WebCore/platform/graphics/ios/FontCacheIOS.mm
Source/WebCore/platform/graphics/mac/FontCacheMac.mm
Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp
Source/WebCore/platform/spi/cocoa/CoreTextSPI.h
Source/WebCore/rendering/RenderThemeIOS.mm

index af17bfc..9af8b07 100644 (file)
@@ -1,3 +1,17 @@
+2015-08-18  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] Honor the 'trak' table by opting in via text-rendering: optimizeLegibility
+        https://bugs.webkit.org/show_bug.cgi?id=148119
+        <rdar://problem/22291561>
+
+        Reviewed by Tim Horton.
+
+        This test will fail until we stop mocking the system font on El Capitan. Until then,
+        this patch will commit the test failure as an expected result.
+
+        * fast/text/trak-optimizeLegibility-expected.html: Added
+        * fast/text/trak-optimizeLegibility.html: Added
+
 2015-08-18  Chris Dumez  <cdumez@apple.com>
 
         Make our bindings' GetOwnPropertySlot() behave according to specification
diff --git a/LayoutTests/fast/text/trak-optimizeLegibility-expected.txt b/LayoutTests/fast/text/trak-optimizeLegibility-expected.txt
new file mode 100644 (file)
index 0000000..4ff079f
--- /dev/null
@@ -0,0 +1,12 @@
+PASS first.getClientRects().length is 1
+PASS third.getClientRects().length is 1
+FAIL first.getClientRects()[0].right should be within 4 of 346. Was 364.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+This test makes sure that you can opt-in to honoring the 'trak' table by specifying text-rendering: optimizeLegibility. The first and third lines below should have the same width. The middle one can (but doesn't have to) have a different width.
+hamburgefonstiv
+
+hamburgefonstiv
+
+hamburgefonstiv
diff --git a/LayoutTests/fast/text/trak-optimizeLegibility.html b/LayoutTests/fast/text/trak-optimizeLegibility.html
new file mode 100644 (file)
index 0000000..88494b1
--- /dev/null
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+This test makes sure that you can opt-in to honoring the 'trak' table by specifying text-rendering: optimizeLegibility.
+The first and third lines below should have the same width. The middle one can (but doesn't have to) have a different width.
+<p><span id="first" style="font: 50px '-apple-system'; font-weight: 300;">hamburgefonstiv</span></p>
+<p><span id="second" style="font: 50px '.SFNSText-Light' '.SFUIDisplay-Light';">hamburgefonstiv</span></p>
+<p><span id="third" style="font: 50px '.SFNSText-Light' '.SFUIDisplay-Light'; text-rendering: optimizeLegibility;">hamburgefonstiv</span></p>
+<script>
+var first = document.getElementById("first");
+var third = document.getElementById("third");
+shouldBe("first.getClientRects().length", "1");
+shouldBe("third.getClientRects().length", "1");
+shouldBeCloseTo("first.getClientRects()[0].right", third.getClientRects()[0].right, 4);
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/platform/ios-simulator/fast/text/trak-optimizeLegibility-expected.txt b/LayoutTests/platform/ios-simulator/fast/text/trak-optimizeLegibility-expected.txt
new file mode 100644 (file)
index 0000000..25ffc17
--- /dev/null
@@ -0,0 +1,12 @@
+PASS first.getClientRects().length is 1
+PASS third.getClientRects().length is 1
+PASS first.getClientRects()[0].right is within 4 of 369
+PASS successfullyParsed is true
+
+TEST COMPLETE
+This test makes sure that you can opt-in to honoring the 'trak' table by specifying text-rendering: optimizeLegibility. The first and third lines below should have the same width. The middle one can (but doesn't have to) have a different width.
+hamburgefonstiv
+
+hamburgefonstiv
+
+hamburgefonstiv
index 0c106b6..b732add 100644 (file)
@@ -1296,3 +1296,6 @@ webkit.org/b/147390 [ Mavericks Yosemite ElCapitan ] fast/text/fallback-language
 
 # Started to fail after r188390
 webkit.org/b/148042 http/tests/media/video-buffered-range-contains-currentTime.html [ Pass Failure ]
+
+# This test tests a particular system font, which is only on iOS and El Capitan.
+webkit.org/b/148119 [ Mavericks Yosemite ] fast/text/trak-optimizeLegibility.html [ Failure ]
index 5153505..f204531 100644 (file)
@@ -1,3 +1,46 @@
+2015-08-18  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] Honor the 'trak' table by opting in via text-rendering: optimizeLegibility
+        https://bugs.webkit.org/show_bug.cgi?id=148119
+        <rdar://problem/22291561>
+
+        Reviewed by Tim Horton.
+
+        When the author has opted in by specifying "text-rendering: optimizeLegibility;", we should
+        honor the font's 'trak' table. We do this by specifying kCTFontOpticalSizeAttribute at font
+        creation time, and by using CTFontGetAdvancesForGlyphs() instead of
+        CGFontGetGlyphAdvancesForStyle().
+
+        Test: fast/text/trak-optimizeLegibility.html
+
+        * platform/graphics/FontCache.h:
+        (WebCore::FontDescriptionKey::makeFlagKey): Make our caches sensitive to TextRenderingMode.
+        * platform/graphics/FontPlatformData.cpp:
+        (WebCore::FontPlatformData::FontPlatformData): Add a TextRenderingMode member variable.
+        (WebCore::FontPlatformData::operator=): Update to consult with the new member.
+        * platform/graphics/FontPlatformData.h:
+        (WebCore::FontPlatformData::textRenderingMode): Getter.
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::preparePlatformFont): Specify kCTFontOpticalSizeAttribute.
+        (WebCore::applyFontFeatureSettings): Deleted.
+        * platform/graphics/cocoa/FontCocoa.mm:
+        (WebCore::canUseFastGlyphAdvanceGetter): Use CTFontGetAdvancesForGlyphs() if we are
+        optimizeLegibility.
+        * platform/graphics/cocoa/FontPlatformDataCocoa.mm:
+        (WebCore::FontPlatformData::FontPlatformData): Pass the TextRenderingMode around.
+        * platform/graphics/ios/FontCacheIOS.mm:
+        (WebCore::FontCache::getSystemFontFallbackForCharacters): Update to call renamed function.
+        (WebCore::FontCache::createFontPlatformData): Ditto.
+        * platform/graphics/mac/FontCacheMac.mm:
+        (WebCore::fontWithFamily): Ditto.
+        (WebCore::FontCache::systemFallbackForCharacters): Ditto.
+        (WebCore::FontCache::createFontPlatformData): Ditto.
+        * platform/graphics/mac/FontCustomPlatformData.cpp:
+        (WebCore::FontCustomPlatformData::fontPlatformData): Ditto.
+        * platform/spi/cocoa/CoreTextSPI.h:
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderThemeIOS::updateCachedSystemFontDescription): Ditto.
+
 2015-08-18  Chris Dumez  <cdumez@apple.com>
 
         Make our bindings' GetOwnPropertySlot() behave according to specification
index bd8fa17..8c8f264 100644 (file)
@@ -105,7 +105,8 @@ private:
     static unsigned makeFlagKey(const FontDescription& description)
     {
         static_assert(USCRIPT_CODE_LIMIT < 0x1000, "Script code must fit in an unsigned along with the other flags");
-        return static_cast<unsigned>(description.script()) << 9
+        return static_cast<unsigned>(description.script()) << 11
+            | static_cast<unsigned>(description.textRenderingMode()) << 9
             | static_cast<unsigned>(description.smallCaps()) << 8
             | static_cast<unsigned>(description.fontSynthesis()) << 6
             | static_cast<unsigned>(description.widthVariant()) << 4
@@ -215,7 +216,7 @@ private:
 };
 
 #if PLATFORM(COCOA)
-RetainPtr<CTFontRef> applyFontFeatureSettings(CTFontRef, const FontFeatureSettings*);
+RetainPtr<CTFontRef> preparePlatformFont(CTFontRef, TextRenderingMode, const FontFeatureSettings*);
 #endif
 
 #if !PLATFORM(MAC)
index 3883540..dd83def 100644 (file)
@@ -43,25 +43,26 @@ FontPlatformData::FontPlatformData()
 {
 }
 
-FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant)
+FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant, TextRenderingMode textRenderingMode)
     : m_syntheticBold(syntheticBold)
     , m_syntheticOblique(syntheticOblique)
     , m_orientation(orientation)
     , m_size(size)
     , m_widthVariant(widthVariant)
+    , m_textRenderingMode(textRenderingMode)
 {
 }
 
 #if USE(CG)
-FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant)
-    : FontPlatformData(size, syntheticBold, syntheticOblique, orientation, widthVariant)
+FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant, TextRenderingMode textRenderingMode)
+    : FontPlatformData(size, syntheticBold, syntheticOblique, orientation, widthVariant, textRenderingMode)
 {
     m_cgFont = cgFont;
 }
 #endif
 
 FontPlatformData::FontPlatformData(const FontPlatformData& source)
-    : FontPlatformData(source.m_size, source.m_syntheticBold, source.m_syntheticOblique, source.m_orientation, source.m_widthVariant)
+    : FontPlatformData(source.m_size, source.m_syntheticBold, source.m_syntheticOblique, source.m_orientation, source.m_widthVariant, source.m_textRenderingMode)
 {
     m_isHashTableDeletedValue = source.m_isHashTableDeletedValue;
     m_isColorBitmapFont = source.m_isColorBitmapFont;
@@ -81,6 +82,7 @@ const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& othe
     m_size = other.m_size;
     m_widthVariant = other.m_widthVariant;
     m_isColorBitmapFont = other.m_isColorBitmapFont;
+    m_textRenderingMode = other.m_textRenderingMode;
 
     return platformDataAssign(other);
 }
index ecd9496..c4e4664 100644 (file)
@@ -81,14 +81,14 @@ public:
     FontPlatformData();
     FontPlatformData(const FontPlatformData&);
     FontPlatformData(const FontDescription&, const AtomicString& family);
-    FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
+    FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation = Horizontal, FontWidthVariant = RegularWidth, TextRenderingMode = AutoTextRendering);
 
 #if PLATFORM(COCOA)
-    WEBCORE_EXPORT FontPlatformData(CTFontRef, float size, bool syntheticBold = false, bool syntheticOblique = false, FontOrientation = Horizontal, FontWidthVariant = RegularWidth);
+    WEBCORE_EXPORT FontPlatformData(CTFontRef, float size, bool syntheticBold = false, bool syntheticOblique = false, FontOrientation = Horizontal, FontWidthVariant = RegularWidth, TextRenderingMode = AutoTextRendering);
 #endif
 
 #if USE(CG)
-    FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant);
+    FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant, TextRenderingMode);
 #endif
 
 #if PLATFORM(WIN)
@@ -136,6 +136,7 @@ public:
     bool isColorBitmapFont() const { return m_isColorBitmapFont; }
     FontOrientation orientation() const { return m_orientation; }
     FontWidthVariant widthVariant() const { return m_widthVariant; }
+    TextRenderingMode textRenderingMode() const { return m_textRenderingMode; }
     bool isForTextCombine() const { return widthVariant() != RegularWidth; } // Keep in sync with callers of FontDescription::setWidthVariant().
 
     void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
@@ -151,7 +152,7 @@ public:
         return m_font ? m_font->hash() : 0;
 #elif OS(DARWIN)
         ASSERT(m_font || !m_cgFont || isEmoji());
-        uintptr_t flags = static_cast<uintptr_t>(m_isHashTableDeletedValue << 4 | isEmoji() << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique);
+        uintptr_t flags = static_cast<uintptr_t>(m_isHashTableDeletedValue << 6 | m_textRenderingMode << 4 | isEmoji() << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique);
 #if USE(APPKIT)
         uintptr_t fontHash = (uintptr_t)m_font.get();
 #else
@@ -175,7 +176,8 @@ public:
             && m_syntheticOblique == other.m_syntheticOblique
             && m_isColorBitmapFont == other.m_isColorBitmapFont
             && m_orientation == other.m_orientation
-            && m_widthVariant == other.m_widthVariant;
+            && m_widthVariant == other.m_widthVariant
+            && m_textRenderingMode == other.m_textRenderingMode;
     }
 
     bool isHashTableDeletedValue() const
@@ -216,6 +218,7 @@ public:
     FontOrientation m_orientation { Horizontal };
     float m_size { 0 };
     FontWidthVariant m_widthVariant { RegularWidth };
+    TextRenderingMode m_textRenderingMode { AutoTextRendering };
 
 private:
 #if PLATFORM(COCOA)
index b424a98..726974f 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "FontCache.h"
 
+#include "CoreTextSPI.h"
 #include <CoreText/SFNTLayoutTypes.h>
 
 #include <wtf/NeverDestroyed.h>
@@ -137,19 +138,26 @@ static inline void appendOpenTypeFeature(CFMutableArrayRef features, const FontF
 #endif
 }
 
-RetainPtr<CTFontRef> applyFontFeatureSettings(CTFontRef originalFont, const FontFeatureSettings* features)
+RetainPtr<CTFontRef> preparePlatformFont(CTFontRef originalFont, TextRenderingMode textRenderingMode, const FontFeatureSettings* features)
 {
-    if (!originalFont || !features || !features->size())
+    if (!originalFont || ((!features || !features->size()) && (textRenderingMode != OptimizeLegibility)))
         return originalFont;
 
-    RetainPtr<CFMutableArrayRef> featureArray = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, features->size(), &kCFTypeArrayCallBacks));
-    for (size_t i = 0; i < features->size(); ++i) {
-        appendTrueTypeFeature(featureArray.get(), features->at(i));
-        appendOpenTypeFeature(featureArray.get(), features->at(i));
+    RetainPtr<CFMutableDictionaryRef> attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+    if (features && features->size()) {
+        RetainPtr<CFMutableArrayRef> featureArray = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, features->size(), &kCFTypeArrayCallBacks));
+        for (size_t i = 0; i < features->size(); ++i) {
+            appendTrueTypeFeature(featureArray.get(), features->at(i));
+            appendOpenTypeFeature(featureArray.get(), features->at(i));
+        }
+        CFDictionaryAddValue(attributes.get(), kCTFontFeatureSettingsAttribute, featureArray.get());
+    }
+    if (textRenderingMode == OptimizeLegibility) {
+        CGFloat size = CTFontGetSize(originalFont);
+        RetainPtr<CFNumberRef> sizeNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &size));
+        CFDictionaryAddValue(attributes.get(), kCTFontOpticalSizeAttribute, sizeNumber.get());
     }
-    CFArrayRef featureArrayPtr = featureArray.get();
-    RetainPtr<CFDictionaryRef> dictionary = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, (const void**)&kCTFontFeatureSettingsAttribute, (const void**)&featureArrayPtr, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
-    RetainPtr<CTFontDescriptorRef> descriptor = adoptCF(CTFontDescriptorCreateWithAttributes(dictionary.get()));
+    RetainPtr<CTFontDescriptorRef> descriptor = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
     return adoptCF(CTFontCreateCopyWithAttributes(originalFont, CTFontGetSize(originalFont), nullptr, descriptor.get()));
 }
 
index d3ced39..f2b5392 100644 (file)
@@ -457,13 +457,9 @@ static inline bool advanceForColorBitmapFont(const FontPlatformData& platformDat
 static inline bool canUseFastGlyphAdvanceGetter(const Font& font, Glyph glyph, CGSize& advance, bool& populatedAdvance)
 {
     const FontPlatformData& platformData = font.platformData();
-    // Fast getter doesn't take custom tracking into account
-    if (font.hasCustomTracking())
+    // Fast getter doesn't doesn't work for emoji, bitmap fonts, or take custom tracking into account
+    if (font.hasCustomTracking() || platformData.isEmoji() || platformData.textRenderingMode() == OptimizeLegibility)
         return false;
-    // Fast getter doesn't work for emoji
-    if (platformData.isEmoji())
-        return false;
-    // ... or for any bitmap fonts in general
     if (advanceForColorBitmapFont(platformData, glyph, advance)) {
         populatedAdvance = true;
         return false;
index 7eb888b..a78912e 100644 (file)
@@ -41,8 +41,8 @@ namespace WebCore {
 // These CoreText Text Spacing feature selectors are not defined in CoreText.
 enum TextSpacingCTFeatureSelector { TextSpacingProportional, TextSpacingFullWidth, TextSpacingHalfWidth, TextSpacingThirdWidth, TextSpacingQuarterWidth };
 
-FontPlatformData::FontPlatformData(CTFontRef font, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant)
-    : FontPlatformData(adoptCF(CTFontCopyGraphicsFont(font, NULL)).get(), size, syntheticBold, syntheticOblique, orientation, widthVariant)
+FontPlatformData::FontPlatformData(CTFontRef font, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant, TextRenderingMode textRenderingMode)
+    : FontPlatformData(adoptCF(CTFontCopyGraphicsFont(font, NULL)).get(), size, syntheticBold, syntheticOblique, orientation, widthVariant, textRenderingMode)
 {
     ASSERT_ARG(font, font);
     m_font = font;
index 0a8394a..feea8d3 100644 (file)
@@ -92,7 +92,7 @@ PassRefPtr<Font> FontCache::getSystemFontFallbackForCharacters(const FontDescrip
     if (!substituteFont)
         return nullptr;
 
-    substituteFont = applyFontFeatureSettings(substituteFont.get(), description.featureSettings());
+    substituteFont = preparePlatformFont(substituteFont.get(), description.textRenderingMode(), description.featureSettings());
 
     CTFontSymbolicTraits originalTraits = CTFontGetSymbolicTraits(ctFont);
     CTFontSymbolicTraits actualTraits = 0;
@@ -718,7 +718,7 @@ std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
     if (!ctFont)
         return nullptr;
 
-    ctFont = applyFontFeatureSettings(ctFont.get(), fontDescription.featureSettings());
+    ctFont = preparePlatformFont(ctFont.get(), fontDescription.textRenderingMode(), fontDescription.featureSettings());
 
     CTFontSymbolicTraits actualTraits = 0;
     if (isFontWeightBold(fontDescription.weight()) || fontDescription.italic())
@@ -729,7 +729,7 @@ std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
     bool syntheticBold = (fontDescription.fontSynthesis() & FontSynthesisWeight) && (traits & kCTFontTraitBold) && !(actualTraits & kCTFontTraitBold) && !isAppleColorEmoji;
     bool syntheticOblique = (fontDescription.fontSynthesis() & FontSynthesisStyle) && (traits & kCTFontTraitItalic) && !(actualTraits & kCTFontTraitItalic) && !isAppleColorEmoji;
 
-    auto result = std::make_unique<FontPlatformData>(ctFont.get(), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant());
+    auto result = std::make_unique<FontPlatformData>(ctFont.get(), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant(), fontDescription.textRenderingMode());
     if (isAppleColorEmoji)
         result->setIsEmoji(true);
     return result;
index f27fd2a..42e1b06 100644 (file)
@@ -264,7 +264,7 @@ static Optional<NSFont*> fontWithFamilySpecialCase(const AtomicString& family, F
 // Family name is somewhat of a misnomer here. We first attempt to find an exact match
 // comparing the desiredFamily to the PostScript name of the installed fonts. If that fails
 // we then do a search based on the family names of the installed fonts.
-static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desiredTraits, FontWeight weight, const FontFeatureSettings* featureSettings, float size)
+static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desiredTraits, FontWeight weight, const FontFeatureSettings* featureSettings, TextRenderingMode textRenderingMode, float size)
 {
     if (const auto& specialCase = fontWithFamilySpecialCase(family, weight, desiredTraits, size))
         return specialCase.value();
@@ -287,7 +287,7 @@ static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desire
 
     NSString *desiredFamily = family;
     RetainPtr<CTFontRef> foundFont = adoptCF(CTFontCreateForCSS((CFStringRef)desiredFamily, toCoreTextFontWeight(weight), requestedTraits, size));
-    foundFont = applyFontFeatureSettings(foundFont.get(), featureSettings);
+    foundFont = preparePlatformFont(foundFont.get(), textRenderingMode, featureSettings);
     if (!foundFont)
         return nil;
     font = CFBridgingRelease(CFRetain(foundFont.get()));
@@ -297,6 +297,7 @@ static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desire
 #else
 
     UNUSED_PARAM(featureSettings);
+    UNUSED_PARAM(textRenderingMode);
 
     NSFontTraitMask desiredTraitsForNameMatch = desiredTraits | (weight >= FontWeight600 ? NSBoldFontMask : 0);
     if (hasDesiredFamilyToAvailableFamilyMapping(family, desiredTraitsForNameMatch, availableFamily)) {
@@ -520,7 +521,7 @@ RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& descr
     const FontPlatformData& platformData = originalFontData->platformData();
     NSFont *nsFont = platformData.nsFont();
     RetainPtr<CTFontRef> result = lookupCTFont(platformData.font(), platformData.size(), description.locale(), characters, length);
-    result = applyFontFeatureSettings(result.get(), description.featureSettings());
+    result = preparePlatformFont(result.get(), description.textRenderingMode(), description.featureSettings());
     if (!result)
         return nullptr;
 
@@ -679,7 +680,7 @@ std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
     NSFontTraitMask traits = fontDescription.italic() ? NSFontItalicTrait : 0;
     float size = fontDescription.computedPixelSize();
 
-    NSFont *nsFont = fontWithFamily(family, traits, fontDescription.weight(), fontDescription.featureSettings(), size);
+    NSFont *nsFont = fontWithFamily(family, traits, fontDescription.weight(), fontDescription.featureSettings(), fontDescription.textRenderingMode(), size);
     if (!nsFont) {
         if (!shouldAutoActivateFontIfNeeded(family))
             return nullptr;
@@ -688,7 +689,7 @@ std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
         // Ignore the result because we want to use our own algorithm to actually find the font.
         [NSFont fontWithName:family size:size];
 
-        nsFont = fontWithFamily(family, traits, fontDescription.weight(), fontDescription.featureSettings(), size);
+        nsFont = fontWithFamily(family, traits, fontDescription.weight(), fontDescription.featureSettings(), fontDescription.textRenderingMode(), size);
         if (!nsFont)
             return nullptr;
     }
@@ -703,7 +704,7 @@ std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
     bool syntheticBold = (fontDescription.fontSynthesis() & FontSynthesisWeight) && isAppKitFontWeightBold(toAppKitFontWeight(fontDescription.weight())) && !isAppKitFontWeightBold(actualWeight);
     bool syntheticOblique = (fontDescription.fontSynthesis() & FontSynthesisStyle) && (traits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait);
 
-    return std::make_unique<FontPlatformData>(toCTFont(platformFont), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant());
+    return std::make_unique<FontPlatformData>(toCTFont(platformFont), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant(), fontDescription.textRenderingMode());
 }
 
 } // namespace WebCore
index ef1227b..1c0783e 100644 (file)
@@ -41,10 +41,10 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(const FontDescription&
     FontWidthVariant widthVariant = fontDescription.widthVariant();
 #if CORETEXT_WEB_FONTS
     RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(m_fontDescriptor.get(), size, nullptr));
-    font = applyFontFeatureSettings(font.get(), fontDescription.featureSettings());
-    return FontPlatformData(font.get(), size, bold, italic, orientation, widthVariant);
+    font = preparePlatformFont(font.get(), fontDescription.textRenderingMode(), fontDescription.featureSettings());
+    return FontPlatformData(font.get(), size, bold, italic, orientation, widthVariant, fontDescription.textRenderingMode());
 #else
-    return FontPlatformData(m_cgFont.get(), size, bold, italic, orientation, widthVariant);
+    return FontPlatformData(m_cgFont.get(), size, bold, italic, orientation, widthVariant, fontDescription.textRenderingMode());
 #endif
 }
 
index 2606c26..07d5dea 100644 (file)
@@ -49,6 +49,7 @@ typedef const UniChar* (*CTUniCharProviderCallback)(CFIndex stringIndex, CFIndex
 typedef void (*CTUniCharDisposeCallback)(const UniChar* chars, void* refCon);
 
 extern const CFStringRef kCTFontReferenceURLAttribute;
+extern const CFStringRef kCTFontOpticalSizeAttribute;
 
 #if PLATFORM(COCOA)
 #if !USE(APPLE_INTERNAL_SDK)
index 55782d1..b73c5a8 100644 (file)
@@ -1261,7 +1261,7 @@ void RenderThemeIOS::updateCachedSystemFontDescription(CSSValueID valueID, FontD
 
     ASSERT(fontDescriptor);
     RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), 0, nullptr));
-    font = applyFontFeatureSettings(font.get(), fontDescription.featureSettings());
+    font = preparePlatformFont(font.get(), fontDescription.textRenderingMode(), fontDescription.featureSettings());
     fontDescription.setIsAbsoluteSize(true);
     fontDescription.setOneFamily(textStyle);
     fontDescription.setSpecifiedSize(CTFontGetSize(font.get()));