font-optical-sizing applies the wrong variation value
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 May 2019 23:20:49 +0000 (23:20 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 May 2019 23:20:49 +0000 (23:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197528
<rdar://problem/50152854>

Reviewed by Antti Koivisto.

Source/WebCore:

The OpenType spec says in
https://docs.microsoft.com/en-us/typography/opentype/spec/dvaraxistag_opsz

"Scale interpretation: Values can be interpreted as text size, in points."

It turns out that it means "typographic point size" which is equal to CSS pixels, not
CSS points.

There are two parts of the font that are sensitive to optical sizing: variation values and
the trak table. We don't want to set the variation value directly because then the trak table
won't be affected. Instead, we can use kCTFontOpticalSizeAttribute to set both of them together.
We will only do this when the CSS says text-rendering:optimizeLegibility or when the font has
an opsz axis but no STAT table. Otherwise, we won't do anything special, which lets CoreText
handle the default behavior for us. This gives us the same default behavior as the rest of the
system.

Tests: fast/text/variations/optical-sizing-trak-2.html
       fast/text/variations/optical-sizing-trak.html
       fast/text/variations/optical-sizing-units.html
       fast/text/variations/optical-sizing-units-2.html

* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::FontType::FontType):
(WebCore::preparePlatformFont):
(WebCore::fontWithFamily):
(WebCore::FontCache::systemFallbackForCharacters):
* platform/graphics/cocoa/FontCacheCoreText.h:
* platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp:
(WebCore::FontFamilySpecificationCoreText::fontRanges const):
* platform/graphics/mac/FontCustomPlatformData.cpp:
(WebCore::FontCustomPlatformData::fontPlatformData):

LayoutTests:

* fast/text/variations/optical-sizing-trak-2-expected-mismatch.html: Added.
* fast/text/variations/optical-sizing-trak-2.html: Added.
* fast/text/variations/optical-sizing-trak-expected.html: Added.
* fast/text/variations/optical-sizing-trak.html: Added.
* fast/text/variations/optical-sizing-units-2-expected-mismatch.html: Added.
* fast/text/variations/optical-sizing-units-2.html: Added.
* fast/text/variations/optical-sizing-units-expected.html: Added.
* fast/text/variations/optical-sizing-units.html: Added.
* fast/text/variations/resources/Amstelvar/Amstelvar-Roman-VF104.ttf: Added.
This font havariations/s been approved by the lawyers to add for layout tests.
* fast/text/variations/resources/Amstelvar/COPYRIGHT.md: Added.
* fast/text/variations/resources/Amstelvar/OFL.txt: Added.

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

19 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/text/variations/optical-sizing-trak-2-expected-mismatch.html [new file with mode: 0644]
LayoutTests/fast/text/variations/optical-sizing-trak-2.html [new file with mode: 0644]
LayoutTests/fast/text/variations/optical-sizing-trak-expected.html [new file with mode: 0644]
LayoutTests/fast/text/variations/optical-sizing-trak.html [new file with mode: 0644]
LayoutTests/fast/text/variations/optical-sizing-units-2-expected-mismatch.html [new file with mode: 0644]
LayoutTests/fast/text/variations/optical-sizing-units-2.html [new file with mode: 0644]
LayoutTests/fast/text/variations/optical-sizing-units-expected.html [new file with mode: 0644]
LayoutTests/fast/text/variations/optical-sizing-units.html [new file with mode: 0644]
LayoutTests/fast/text/variations/resources/Amstelvar/Amstelvar-Roman-VF104.ttf [new file with mode: 0644]
LayoutTests/fast/text/variations/resources/Amstelvar/COPYRIGHT.md [new file with mode: 0644]
LayoutTests/fast/text/variations/resources/Amstelvar/OFL.txt [new file with mode: 0644]
LayoutTests/platform/win/TestExpectations
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.h
Source/WebCore/platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp
Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp

index 3920a3d..72302c7 100644 (file)
@@ -1,3 +1,24 @@
+2019-05-21  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        font-optical-sizing applies the wrong variation value
+        https://bugs.webkit.org/show_bug.cgi?id=197528
+        <rdar://problem/50152854>
+
+        Reviewed by Antti Koivisto.
+
+        * fast/text/variations/optical-sizing-trak-2-expected-mismatch.html: Added.
+        * fast/text/variations/optical-sizing-trak-2.html: Added.
+        * fast/text/variations/optical-sizing-trak-expected.html: Added.
+        * fast/text/variations/optical-sizing-trak.html: Added.
+        * fast/text/variations/optical-sizing-units-2-expected-mismatch.html: Added.
+        * fast/text/variations/optical-sizing-units-2.html: Added.
+        * fast/text/variations/optical-sizing-units-expected.html: Added.
+        * fast/text/variations/optical-sizing-units.html: Added.
+        * fast/text/variations/resources/Amstelvar/Amstelvar-Roman-VF104.ttf: Added.
+        This font havariations/s been approved by the lawyers to add for layout tests.
+        * fast/text/variations/resources/Amstelvar/COPYRIGHT.md: Added.
+        * fast/text/variations/resources/Amstelvar/OFL.txt: Added.
+
 2019-05-21  Antti Koivisto  <antti@apple.com>
 
         RTL/overflow scroll tests fail with async overflow enabled
diff --git a/LayoutTests/fast/text/variations/optical-sizing-trak-2-expected-mismatch.html b/LayoutTests/fast/text/variations/optical-sizing-trak-2-expected-mismatch.html
new file mode 100644 (file)
index 0000000..6bbe169
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<style>
+#target {
+    display: inline-block;
+    font: 10px "PingFang SC";
+    transform: scale(10);
+    transform-origin: left top;
+    text-rendering: optimizeLegibility;
+}
+</style>
+</head>
+<body>
+<span id="target">风雨中中国经济定能壮大</span>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/variations/optical-sizing-trak-2.html b/LayoutTests/fast/text/variations/optical-sizing-trak-2.html
new file mode 100644 (file)
index 0000000..c34bbbd
--- /dev/null
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<style>
+#target {
+    display: inline-block;
+    font: 10px "PingFang SC";
+    transform: scale(10);
+    transform-origin: left top;
+}
+</style>
+</head>
+<body>
+<span id="target">风雨中中国经济定能壮大</span>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/variations/optical-sizing-trak-expected.html b/LayoutTests/fast/text/variations/optical-sizing-trak-expected.html
new file mode 100644 (file)
index 0000000..cfa419f
--- /dev/null
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<style>
+#target {
+    display: inline-block;
+    font: 10px "PingFang SC";
+    transform: scale(10);
+    transform-origin: left top;
+    font-optical-sizing: none;
+}
+</style>
+</head>
+<body>
+<p>
+This test makes sure that 'trak' tables are not honored in fonts that don't have 'STAT' tables. The test passes if the text is rendered identically to the expected file, pixel-per-pixel.
+</p>
+<span id="target">风雨中中国经济定能壮大</span>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/variations/optical-sizing-trak.html b/LayoutTests/fast/text/variations/optical-sizing-trak.html
new file mode 100644 (file)
index 0000000..d1ec6af
--- /dev/null
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<style>
+#target {
+    display: inline-block;
+    font: 10px "PingFang SC";
+    transform: scale(10);
+    transform-origin: left top;
+    font-optical-sizing: auto;
+}
+</style>
+</head>
+<body>
+<p>
+This test makes sure that 'trak' tables are not honored in fonts that don't have 'STAT' tables. The test passes if the text is rendered identically to the expected file, pixel-per-pixel.
+</p>
+<span id="target">风雨中中国经济定能壮大</span>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/variations/optical-sizing-units-2-expected-mismatch.html b/LayoutTests/fast/text/variations/optical-sizing-units-2-expected-mismatch.html
new file mode 100644 (file)
index 0000000..34f8e6f
--- /dev/null
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+@font-face {
+    font-family: "Amstelvar";
+    src: url("resources/Amstelvar/Amstelvar-Roman-VF104.ttf") format("truetype");
+}
+#target {
+    font: 100px "Amstelvar";
+    font-optical-sizing: auto;
+    font-variation-settings: "opsz" 10;
+}
+</style>
+</head>
+<body>
+<span id="target">Hello, world!</span>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/variations/optical-sizing-units-2.html b/LayoutTests/fast/text/variations/optical-sizing-units-2.html
new file mode 100644 (file)
index 0000000..89d0bbc
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+@font-face {
+    font-family: "Amstelvar";
+    src: url("resources/Amstelvar/Amstelvar-Roman-VF104.ttf") format("truetype");
+}
+#target {
+    font: 100px "Amstelvar";
+    font-optical-sizing: auto;
+}
+</style>
+</head>
+<body>
+<span id="target">Hello, world!</span>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/variations/optical-sizing-units-expected.html b/LayoutTests/fast/text/variations/optical-sizing-units-expected.html
new file mode 100644 (file)
index 0000000..9cca906
--- /dev/null
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+@font-face {
+    font-family: "Amstelvar";
+    src: url("resources/Amstelvar/Amstelvar-Roman-VF104.ttf") format("truetype");
+}
+#target {
+    display: inline-block;
+    font: 10px "Amstelvar";
+    transform: scale(10);
+    transform-origin: left top;
+    font-variation-settings: "opsz" 10;
+}
+</style>
+</head>
+<body>
+<p>This test makes sure that <code>font-optical-sizing: auto</code> applies the correct value to the <code>opsz</code> variation axis. The test passes if the text below matches the expected text, pixel-per-pixel.</p>
+<span id="target">Hello, world!</span>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/variations/optical-sizing-units.html b/LayoutTests/fast/text/variations/optical-sizing-units.html
new file mode 100644 (file)
index 0000000..feadc3c
--- /dev/null
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+@font-face {
+    font-family: "Amstelvar";
+    src: url("resources/Amstelvar/Amstelvar-Roman-VF104.ttf") format("truetype");
+}
+#target {
+    display: inline-block;
+    font: 10px "Amstelvar";
+    transform: scale(10);
+    transform-origin: left top;
+    font-optical-sizing: auto;
+}
+</style>
+</head>
+<body>
+<p>This test makes sure that <code>font-optical-sizing: auto</code> applies the correct value to the <code>opsz</code> variation axis. The test passes if the text below matches the expected text, pixel-per-pixel.</p>
+<span id="target">Hello, world!</span>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/variations/resources/Amstelvar/Amstelvar-Roman-VF104.ttf b/LayoutTests/fast/text/variations/resources/Amstelvar/Amstelvar-Roman-VF104.ttf
new file mode 100644 (file)
index 0000000..23c15c5
Binary files /dev/null and b/LayoutTests/fast/text/variations/resources/Amstelvar/Amstelvar-Roman-VF104.ttf differ
diff --git a/LayoutTests/fast/text/variations/resources/Amstelvar/COPYRIGHT.md b/LayoutTests/fast/text/variations/resources/Amstelvar/COPYRIGHT.md
new file mode 100644 (file)
index 0000000..819ec2f
--- /dev/null
@@ -0,0 +1 @@
+Copyright 2016 The Amstelvar Project Authors (info@fontbureau.com)
diff --git a/LayoutTests/fast/text/variations/resources/Amstelvar/OFL.txt b/LayoutTests/fast/text/variations/resources/Amstelvar/OFL.txt
new file mode 100644 (file)
index 0000000..1e98121
--- /dev/null
@@ -0,0 +1,93 @@
+Copyright 2016 The Amstelvar Project Authors (info@fontbureau.com)
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at:
+http://scripts.sil.org/OFL
+
+
+-----------------------------------------------------------
+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
+-----------------------------------------------------------
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide
+development of collaborative font projects, to support the font creation
+efforts of academic and linguistic communities, and to provide a free and
+open framework in which fonts may be shared and improved in partnership
+with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and
+redistributed freely as long as they are not sold by themselves. The
+fonts, including any derivative works, can be bundled, embedded, 
+redistributed and/or sold with any software provided that any reserved
+names are not used by derivative works. The fonts and derivatives,
+however, cannot be released under any other type of license. The
+requirement for fonts to remain under this license does not apply
+to any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright
+Holder(s) under this license and clearly marked as such. This may
+include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the
+copyright statement(s).
+
+"Original Version" refers to the collection of Font Software components as
+distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to, deleting,
+or substituting -- in part or in whole -- any of the components of the
+Original Version, by changing formats or by porting the Font Software to a
+new environment.
+
+"Author" refers to any designer, engineer, programmer, technical
+writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Font Software, to use, study, copy, merge, embed, modify,
+redistribute, and sell modified and unmodified copies of the Font
+Software, subject to the following conditions:
+
+1) Neither the Font Software nor any of its individual components,
+in Original or Modified Versions, may be sold by itself.
+
+2) Original or Modified Versions of the Font Software may be bundled,
+redistributed and/or sold with any software, provided that each copy
+contains the above copyright notice and this license. These can be
+included either as stand-alone text files, human-readable headers or
+in the appropriate machine-readable metadata fields within text or
+binary files as long as those fields can be easily viewed by the user.
+
+3) No Modified Version of the Font Software may use the Reserved Font
+Name(s) unless explicit written permission is granted by the corresponding
+Copyright Holder. This restriction only applies to the primary font name as
+presented to the users.
+
+4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
+Software shall not be used to promote, endorse or advertise any
+Modified Version, except to acknowledge the contribution(s) of the
+Copyright Holder(s) and the Author(s) or with their explicit written
+permission.
+
+5) The Font Software, modified or unmodified, in part or in whole,
+must be distributed entirely under this license, and must not be
+distributed under any other license. The requirement for fonts to
+remain under this license does not apply to any document created
+using the Font Software.
+
+TERMINATION
+This license becomes null and void if any of the above conditions are
+not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
+OTHER DEALINGS IN THE FONT SOFTWARE.
index 9855b2b..f4c8ac7 100644 (file)
@@ -3250,8 +3250,7 @@ fast/text/system-font-weight-italic.html [ Failure ]
 fast/text/system-font-weight.html [ Failure ]
 fast/text/text-combine-shrink-on-color-change.html [ Failure ]
 fast/text/trak-optimizeLegibility.html [ Failure ]
-fast/text/variations/advances.html [ Failure ]
-fast/text/variations/getComputedStyle.html [ Failure ]
+fast/text/variations [ Failure Pass ImageOnlyFailure ]
 fast/text/whitespace/023.html [ Failure ]
 fast/transforms/bounding-rect-zoom.html [ Failure ]
 fast/xsl/xslt-extra-content-at-end.xml [ Failure ]
@@ -3380,8 +3379,6 @@ fast/text/complex-small-caps-non-bmp-capitalize.html [ ImageOnlyFailure ]
 fast/text/cursive-zh.html [ ImageOnlyFailure ]
 fast/text/emoji-single-parent-family-2.html [ ImageOnlyFailure ]
 fast/text/emoji-single-parent-family.html [ ImageOnlyFailure ]
-fast/text/variations/exist.html [ ImageOnlyFailure ]
-fast/text/variations/outofbounds.html [ ImageOnlyFailure ]
 http/tests/security/http-0.9/image-on-HTTP-0.9-default-port-page-allowed-ref-test.html [ ImageOnlyFailure ]
 mathml/presentation/non-bmp-operators-stretching.html [ ImageOnlyFailure ]
 security/contentSecurityPolicy/image-with-blob-url-allowed-by-img-src-star-with-AllowContentSecurityPolicySourceStarToMatchAnyProtocol-enabled.html [ ImageOnlyFailure ]
@@ -3556,8 +3553,6 @@ fast/text/font-style-parse.html [ Failure ]
 fast/text/font-weight-parse.html [ Failure ]
 fast/text/softbank-emoji.html [ Failure ]
 fast/text/system-font-fallback-emoji.html [ Failure ]
-fast/text/variations/font-loading-api-parse-ranges.html [ Failure ]
-fast/text/variations/optical-sizing.html [ Failure ]
 fast/text/web-font-load-invisible-during-loading.html [ Failure ]
 fast/url/standard-url.html [ Failure ]
 fast/url/tab-and-newline-stripping.html [ Failure ]
@@ -3623,8 +3618,6 @@ fast/text/accessibility-bold-system-font-2.html [ ImageOnlyFailure ]
 fast/text/emoji-overlap.html [ ImageOnlyFailure ]
 fast/text/multiple-codeunit-vertical-upright.html [ ImageOnlyFailure ]
 fast/text/simple-line-layout-simple-text-but-complex-font-path.html [ ImageOnlyFailure ]
-fast/text/variations/font-face-format.html [ ImageOnlyFailure ]
-fast/text/variations/font-face-format-woff2.html [ ImageOnlyFailure ]
 imported/blink/scrollbars/avoid-double-scrollbars-when-html-element-is-not-the-renderview.html [ ImageOnlyFailure ]
 imported/w3c/i18n/bidi/bidi-plaintext-011.html [ ImageOnlyFailure ]
 svg/custom/anchor-on-use.svg [ ImageOnlyFailure ]
@@ -3692,7 +3685,6 @@ http/tests/security/contentSecurityPolicy/allow-favicon.html [ Failure ]
 http/wpt/entries-api/interfaces.html [ Failure ]
 http/wpt/fetch/response-status-text.html [ Failure ]
 js/dom/builtin-getter-name.html [ Failure ]
-fast/text/variations/font-selection-font-weight.html [ ImageOnlyFailure ]
 fast/forms/file/entries-api/webkitdirectory-open-panel.html [ Skip ]
 
 # Requires WK2 loading support
@@ -3741,9 +3733,6 @@ imported/w3c/web-platform-tests/wasm/wasm_stream_compile_test.html  [ Skip ]
 # Animated image throttling behaves differently on WK1.
 svg/animations/animated-svg-image-outside-viewport-paused.html [ Skip ]
 
-# This test requires Skia, which isn't available on Windows.
-webkit.org/b/174079 fast/text/variations/skia-postscript-name.html [ ImageOnlyFailure ]
-
 # Beacon is not supported on WK1.
 http/tests/blink/sendbeacon/ [ Skip ]
 http/tests/inspector/network/beacon-type.html [ Skip ]
index 9973a4d..447bb18 100644 (file)
 #define HAVE_AVPLAYER_RESOURCE_CONSERVATION_LEVEL 1
 #endif
 
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000) || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 50000) || (PLATFORM(APPLETV) && __TV_OS_VERSION_MIN_REQUIRED >= 120000)
+#define HAVE_CORETEXT_AUTO_OPTICAL_SIZING 1
+#endif
+
index 3223d0e..d7075b8 100644 (file)
@@ -1,3 +1,43 @@
+2019-05-21  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        font-optical-sizing applies the wrong variation value
+        https://bugs.webkit.org/show_bug.cgi?id=197528
+        <rdar://problem/50152854>
+
+        Reviewed by Antti Koivisto.
+
+        The OpenType spec says in
+        https://docs.microsoft.com/en-us/typography/opentype/spec/dvaraxistag_opsz
+
+        "Scale interpretation: Values can be interpreted as text size, in points."
+
+        It turns out that it means "typographic point size" which is equal to CSS pixels, not
+        CSS points.
+
+        There are two parts of the font that are sensitive to optical sizing: variation values and
+        the trak table. We don't want to set the variation value directly because then the trak table
+        won't be affected. Instead, we can use kCTFontOpticalSizeAttribute to set both of them together.
+        We will only do this when the CSS says text-rendering:optimizeLegibility or when the font has
+        an opsz axis but no STAT table. Otherwise, we won't do anything special, which lets CoreText
+        handle the default behavior for us. This gives us the same default behavior as the rest of the
+        system.
+
+        Tests: fast/text/variations/optical-sizing-trak-2.html
+               fast/text/variations/optical-sizing-trak.html
+               fast/text/variations/optical-sizing-units.html
+               fast/text/variations/optical-sizing-units-2.html
+
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::FontType::FontType):
+        (WebCore::preparePlatformFont):
+        (WebCore::fontWithFamily):
+        (WebCore::FontCache::systemFallbackForCharacters):
+        * platform/graphics/cocoa/FontCacheCoreText.h:
+        * platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp:
+        (WebCore::FontFamilySpecificationCoreText::fontRanges const):
+        * platform/graphics/mac/FontCustomPlatformData.cpp:
+        (WebCore::FontCustomPlatformData::fontPlatformData):
+
 2019-05-21  Antoine Quint  <graouts@apple.com>
 
         [macOS] Compatibility mouse events aren't prevented by calling preventDefault() on pointerdown
index 5f68b83..5037762 100644 (file)
@@ -484,6 +484,8 @@ struct FontType {
         auto tables = adoptCF(CTFontCopyAvailableTables(font, kCTFontTableOptionNoOptions));
         if (!tables)
             return;
+        bool foundStat = false;
+        bool foundTrak = false;
         auto size = CFArrayGetCount(tables.get());
         for (CFIndex i = 0; i < size; ++i) {
             // This is so yucky.
@@ -497,6 +499,7 @@ struct FontType {
                     variationType = VariationType::TrueTypeGX;
                 break;
             case 'STAT':
+                foundStat = true;
                 variationType = VariationType::OpenType18;
                 break;
             case 'morx':
@@ -507,35 +510,38 @@ struct FontType {
             case 'GSUB':
                 openTypeShaping = true;
                 break;
+            case 'trak':
+                foundTrak = true;
+                break;
             }
         }
+        if (foundStat && foundTrak)
+            trackingType = TrackingType::Automatic;
+        else if (foundTrak)
+            trackingType = TrackingType::Manual;
     }
 
-    enum class VariationType {
-        NotVariable,
-        TrueTypeGX,
-        OpenType18
-    };
+    enum class VariationType : uint8_t { NotVariable, TrueTypeGX, OpenType18, };
     VariationType variationType { VariationType::NotVariable };
+    enum class TrackingType : uint8_t { None, Automatic, Manual, };
+    TrackingType trackingType { TrackingType::None };
     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 applyWeightWidthSlopeVariations)
+RetainPtr<CTFontRef> preparePlatformFont(CTFontRef originalFont, const FontDescription& fontDescription, const FontFeatureSettings* fontFaceFeatures, const FontVariantSettings* fontFaceVariantSettings, FontSelectionSpecifiedCapabilities fontFaceCapabilities, bool applyWeightWidthSlopeVariations)
 {
-    bool alwaysAddVariations = false;
+    if (!originalFont)
+        return originalFont;
 
-    // FIXME: Remove when <rdar://problem/29859207> is fixed
 #if ENABLE(VARIATION_FONTS)
     auto defaultValues = defaultVariationValues(originalFont);
-    alwaysAddVariations = !defaultValues.isEmpty();
 
     auto fontSelectionRequest = fontDescription.fontSelectionRequest();
     auto fontOpticalSizing = fontDescription.opticalSizing();
     auto fontStyleAxis = fontDescription.fontStyleAxis();
 #else
     UNUSED_PARAM(fontFaceCapabilities);
-    UNUSED_PARAM(size);
     UNUSED_PARAM(applyWeightWidthSlopeVariations);
 #endif
 
@@ -544,8 +550,20 @@ RetainPtr<CTFontRef> preparePlatformFont(CTFontRef originalFont, const FontDescr
     const auto& variations = fontDescription.variationSettings();
     auto textRenderingMode = fontDescription.textRenderingMode();
 
-    if (!originalFont || (!features.size() && (!alwaysAddVariations && variations.isEmpty()) && (textRenderingMode == TextRenderingMode::AutoTextRendering) && variantSettings.isAllNormal()
-        && (!fontFaceFeatures || !fontFaceFeatures->size()) && (!fontFaceVariantSettings || fontFaceVariantSettings->isAllNormal())))
+    FontType fontType { originalFont };
+
+    bool forceOpticalSizingOn = fontOpticalSizing == FontOpticalSizing::Enabled && fontType.variationType == FontType::VariationType::TrueTypeGX && defaultValues.contains({{'o', 'p', 's', 'z'}});
+    bool forceVariations = defaultValues.contains({{'w', 'g', 'h', 't'}}) || defaultValues.contains({{'w', 'd', 't', 'h'}}) || (fontStyleAxis == FontStyleAxis::ital && defaultValues.contains({{'i', 't', 'a', 'l'}})) || (fontStyleAxis == FontStyleAxis::slnt && defaultValues.contains({{'s', 'l', 'n', 't'}}));
+
+    // We might want to check fontType.trackingType == FontType::TrackingType::Manual here, but in order to maintain compatibility with the rest of the system, we don't.
+    bool noFontFeatureSettings = features.isEmpty();
+    bool noFontVariationSettings = !forceVariations && variations.isEmpty();
+    bool textRenderingModeIsAuto = textRenderingMode == TextRenderingMode::AutoTextRendering;
+    bool variantSettingsIsNormal = variantSettings.isAllNormal();
+    bool dontNeedToApplyOpticalSizing = fontOpticalSizing == FontOpticalSizing::Enabled && !forceOpticalSizingOn;
+    bool fontFaceDoesntSpecifyFeatures = !fontFaceFeatures || fontFaceFeatures->isEmpty();
+    bool fontFaceDoesntSpecifyVariations = !fontFaceVariantSettings || fontFaceVariantSettings->isAllNormal();
+    if (noFontFeatureSettings && noFontVariationSettings && textRenderingModeIsAuto && variantSettingsIsNormal && dontNeedToApplyOpticalSizing && fontFaceDoesntSpecifyFeatures && fontFaceDoesntSpecifyVariations)
         return originalFont;
 
     // This algorithm is described at http://www.w3.org/TR/css3-fonts/#feature-precedence
@@ -580,8 +598,6 @@ RetainPtr<CTFontRef> preparePlatformFont(CTFontRef originalFont, const FontDescr
     for (auto& newFeature : features)
         featuresToBeApplied.set(newFeature.tag(), newFeature.value());
 
-    FontType fontType(originalFont);
-
 #if ENABLE(VARIATION_FONTS)
     VariationsMap variationsToBeApplied;
 
@@ -619,14 +635,8 @@ RetainPtr<CTFontRef> preparePlatformFont(CTFontRef originalFont, const FontDescr
             applyVariation({{'s', 'l', 'n', 't'}}, slope);
     }
 
-    if (fontOpticalSizing == FontOpticalSizing::Enabled) {
-        const float pxToPtRatio = 3.0f / 4;
-        applyVariation({{'o', 'p', 's', 'z'}}, size * pxToPtRatio);
-    }
-
     for (auto& newVariation : variations)
         applyVariation(newVariation.tag(), newVariation.value());
-
 #endif // ENABLE(VARIATION_FONTS)
 
     auto attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
@@ -655,11 +665,20 @@ RetainPtr<CTFontRef> preparePlatformFont(CTFontRef originalFont, const FontDescr
     }
 #endif
 
-    if (textRenderingMode == TextRenderingMode::OptimizeLegibility) {
-        CGFloat size = CTFontGetSize(originalFont);
+    if (forceOpticalSizingOn || textRenderingMode == TextRenderingMode::OptimizeLegibility) {
+#if HAVE(CORETEXT_AUTO_OPTICAL_SIZING)
+        CFDictionaryAddValue(attributes.get(), kCTFontOpticalSizeAttribute, CFSTR("auto"));
+#else
+        auto size = CTFontGetSize(originalFont);
         auto sizeNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &size));
         CFDictionaryAddValue(attributes.get(), kCTFontOpticalSizeAttribute, sizeNumber.get());
+#endif
+    } else if (fontOpticalSizing == FontOpticalSizing::Disabled) {
+#if HAVE(CORETEXT_AUTO_OPTICAL_SIZING)
+        CFDictionaryAddValue(attributes.get(), kCTFontOpticalSizeAttribute, CFSTR("none"));
+#endif
     }
+
     auto descriptor = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get()));
     auto result = adoptCF(CTFontCreateCopyWithAttributes(originalFont, CTFontGetSize(originalFont), nullptr, descriptor.get()));
     return result;
@@ -1223,7 +1242,7 @@ static RetainPtr<CTFontRef> fontWithFamily(const AtomicString& family, const Fon
     fontLookup.result = platformFontWithFamilySpecialCase(family, request, size, fontDescription.shouldAllowUserInstalledFonts());
     if (!fontLookup.result)
         fontLookup = platformFontLookupWithFamily(family, request, size, fontDescription.shouldAllowUserInstalledFonts());
-    return preparePlatformFont(fontLookup.result.get(), fontDescription, fontFaceFeatures, fontFaceVariantSettings, fontFaceCapabilities, size, !fontLookup.createdFromPostScriptName);
+    return preparePlatformFont(fontLookup.result.get(), fontDescription, fontFaceFeatures, fontFaceVariantSettings, fontFaceCapabilities, !fontLookup.createdFromPostScriptName);
 }
 
 #if PLATFORM(MAC)
@@ -1374,7 +1393,7 @@ RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& descr
         m_fontNamesRequiringSystemFallbackForPrewarming.add(fullName);
 
     auto result = lookupFallbackFont(platformData.font(), description.weight(), description.locale(), characters, length);
-    result = preparePlatformFont(result.get(), description, nullptr, nullptr, { }, description.computedSize());
+    result = preparePlatformFont(result.get(), description, nullptr, nullptr, { });
 
     if (!result)
         return lastResortFallbackFont(description);
index 5cf6cd2..d11db98 100644 (file)
@@ -50,7 +50,7 @@ struct SynthesisPair {
     bool needsSyntheticOblique;
 };
 
-RetainPtr<CTFontRef> preparePlatformFont(CTFontRef, const FontDescription&, const FontFeatureSettings* fontFaceFeatures, const FontVariantSettings* fontFaceVariantSettings, FontSelectionSpecifiedCapabilities fontFaceCapabilities, float size, bool applyWeightWidthSlopeVariations = true);
+RetainPtr<CTFontRef> preparePlatformFont(CTFontRef, const FontDescription&, const FontFeatureSettings* fontFaceFeatures, const FontVariantSettings* fontFaceVariantSettings, FontSelectionSpecifiedCapabilities fontFaceCapabilities, bool applyWeightWidthSlopeVariations = true);
 SynthesisPair computeNecessarySynthesis(CTFontRef, const FontDescription&, bool isPlatformFont = false);
 RetainPtr<CTFontRef> platformFontWithFamilySpecialCase(const AtomicString& family, FontSelectionRequest, float size, AllowUserInstalledFonts);
 RetainPtr<CTFontRef> platformFontWithFamily(const AtomicString& family, FontSelectionRequest, TextRenderingMode, float size);
index b749cda..c8911c4 100644 (file)
@@ -108,7 +108,7 @@ FontRanges FontFamilySpecificationCoreText::fontRanges(const FontDescription& fo
             fontForSynthesisComputation = physicalFont;
 #endif
 
-        font = preparePlatformFont(font.get(), fontDescription, nullptr, nullptr, { }, fontDescription.computedSize());
+        font = preparePlatformFont(font.get(), fontDescription, nullptr, nullptr, { });
 
         bool syntheticBold, syntheticOblique;
         std::tie(syntheticBold, syntheticOblique) = computeNecessarySynthesis(fontForSynthesisComputation.get(), fontDescription).boldObliquePair();
index 8c19a7f..3d5ef09 100644 (file)
@@ -46,7 +46,7 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(const FontDescription&
     FontOrientation orientation = fontDescription.orientation();
     FontWidthVariant widthVariant = fontDescription.widthVariant();
     RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(modifiedFontDescriptor.get(), size, nullptr));
-    font = preparePlatformFont(font.get(), fontDescription, &fontFaceFeatures, &fontFaceVariantSettings, fontFaceCapabilities, fontDescription.computedSize());
+    font = preparePlatformFont(font.get(), fontDescription, &fontFaceFeatures, &fontFaceVariantSettings, fontFaceCapabilities);
     ASSERT(font);
     return FontPlatformData(font.get(), size, bold, italic, orientation, widthVariant, fontDescription.textRenderingMode());
 }