Skip to content
Permalink
Browse files
[Cocoa] Stop treating the system font as a non-variable font
https://bugs.webkit.org/show_bug.cgi?id=228176

Reviewed by Sam Weinig.

Source/WebCore:

Modern versions of macOS and iOS can treat the system font as a variable font,
and be able to apply weights like "342" instead of just "300" or "400".

Tests: fast/text/variable-system-font-2.html
       fast/text/variable-system-font.html

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

Source/WTF:

* wtf/PlatformUse.h:

LayoutTests:

Update tests.

* fast/text/resources/Ahem-trak.ttf: Added. This is a font which has a trak table.
* fast/text/trak-optimizeLegibility-expected-mismatch.html: Added.
* fast/text/trak-optimizeLegibility-expected.txt: Removed.
* fast/text/trak-optimizeLegibility.html:
* fast/text/variable-system-font-2-expected-mismatch.html: Added.
* fast/text/variable-system-font-2.html: Added.
* fast/text/variable-system-font-expected-mismatch.html: Added.
* fast/text/variable-system-font.html: Added.
* svg/dom/altGlyph-dom-expected.txt:
* svg/dom/resources/altGlyph-dom.js:

Canonical link: https://commits.webkit.org/240715@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281291 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
litherum committed Aug 20, 2021
1 parent 5c7e1ac commit 2e35f7f8a9e951f7f7404ff0ec4ee34841407f31
Showing 18 changed files with 151 additions and 33 deletions.
@@ -1,3 +1,23 @@
2021-08-19 Myles C. Maxfield <mmaxfield@apple.com>

[Cocoa] Stop treating the system font as a non-variable font
https://bugs.webkit.org/show_bug.cgi?id=228176

Reviewed by Sam Weinig.

Update tests.

* fast/text/resources/Ahem-trak.ttf: Added. This is a font which has a trak table.
* fast/text/trak-optimizeLegibility-expected-mismatch.html: Added.
* fast/text/trak-optimizeLegibility-expected.txt: Removed.
* fast/text/trak-optimizeLegibility.html:
* fast/text/variable-system-font-2-expected-mismatch.html: Added.
* fast/text/variable-system-font-2.html: Added.
* fast/text/variable-system-font-expected-mismatch.html: Added.
* fast/text/variable-system-font.html: Added.
* svg/dom/altGlyph-dom-expected.txt:
* svg/dom/resources/altGlyph-dom.js:

2021-08-19 Eric Hutchison <ehutchison@apple.com>

[iOS] 3 imported/w3c/web-platform-tests/css/css-typed-om/ tests are flaky failure.
@@ -5127,3 +5127,6 @@ http/wpt/crypto/aes-cbc-crash.any.html [ DumpJSConsoleLogInStdErr ]
http/wpt/crypto/aes-ctr-crash.any.html [ DumpJSConsoleLogInStdErr ]
imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/aes_cbc.https.any.html [ DumpJSConsoleLogInStdErr ]
imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/aes_ctr.https.any.html [ DumpJSConsoleLogInStdErr ]

webkit.org/b/228176 fast/text/variable-system-font.html [ Pass ImageOnlyFailure ]
webkit.org/b/228176 fast/text/variable-system-font-2.html [ Pass ImageOnlyFailure ]
Binary file not shown.
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
@font-face {
font-family: "WebFont";
src: url("resources/Ahem-trak.ttf") format("truetype");
}
div {
font: 64px "WebFont";
}
</style>
</head>
<body>
<div>abc</div>
</body>
</html>

This file was deleted.

@@ -1,21 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<meta charset="utf-8">
<style>
@font-face {
font-family: "WebFont";
src: url("resources/Ahem-trak.ttf") format("truetype");
}
div {
font: 64px "WebFont";
text-rendering: optimizeLegibility;
}
</style>
</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: 100px 'system-ui'; font-weight: 300;">hamburgefonstiv</span></p>
<p><span id="second" style="font: 100px '.AppleSystemUIFontLight', '.SFNSDisplay-Light', '.SFUIDisplay-Light';">hamburgefonstiv</span></p>
<p><span id="third" style="font: 100px '.AppleSystemUIFontLight', '.SFNSDisplay-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");
shouldBe("first.getClientRects()[0].right", "third.getClientRects()[0].right");
</script>
<script src="../../resources/js-test-post.js"></script>
<div>abc</div>
</body>
</html>
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<style>
div {
font: 300 48px system-ui;
}
</style>
</head>
<body>
<div>Hello test</div>
</body>
</html>
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<style>
div {
font: 351 48px system-ui;
}
</style>
</head>
<body>
<div>Hello test</div>
</body>
</html>
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<style>
div {
font: 400 48px system-ui;
}
</style>
</head>
<body>
<div>Hello test</div>
</body>
</html>
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<style>
div {
font: 351 48px system-ui;
}
</style>
</head>
<body>
<div>Hello test</div>
</body>
</html>
@@ -3482,4 +3482,7 @@ imported/w3c/web-platform-tests/css/css-typed-om/width-by-min-px-em.html [ Pass
imported/w3c/web-platform-tests/css/css-typed-om/rotate-by-added-angle.html [ Pass Failure ]
imported/w3c/web-platform-tests/css/css-typed-om/width-by-max-px-em.html [ Pass Failure ]

webkit.org/b/228200 editing/selection/ios/scrolling-to-focused-element-inside-iframe.html [ Failure ]
webkit.org/b/228200 editing/selection/ios/scrolling-to-focused-element-inside-iframe.html [ Failure ]

webkit.org/b/228176 fast/text/variable-system-font.html [ ImageOnlyFailure ]
webkit.org/b/228176 fast/text/variable-system-font-2.html [ Pass ]
@@ -2328,3 +2328,6 @@ webkit.org/b/229291 imported/w3c/web-platform-tests/html/rendering/replaced-elem

webkit.org/b/228396 fast/speechsynthesis/speech-synthesis-speak-empty-string.html [ Pass Failure ]

webkit.org/b/228176 [ Mojave Catalina BigSur ] fast/text/variable-system-font.html [ ImageOnlyFailure ]
webkit.org/b/228176 [ Monterey ] fast/text/variable-system-font.html [ Pass ]
webkit.org/b/228176 [ Mojave Catalina BigSur Monterey ] fast/text/variable-system-font-2.html [ Pass ]
@@ -8,7 +8,6 @@ PASS altGlyph.tagName is "altGlyph"
PASS altGlyph.namespaceURI is "http://www.w3.org/2000/svg"
PASS altGlyph.format is "image/svg+xml"
PASS altGlyph.format = 'x' threw exception NoModificationAllowedError: The object can not be modified..
FAIL altGlyph.getStartPositionOfChar(0).x should be 0. Was 72.
PASS successfullyParsed is true

TEST COMPLETE
@@ -9,8 +9,4 @@ shouldBe("altGlyph.tagName", '"altGlyph"');
shouldBe("altGlyph.namespaceURI", '"http://www.w3.org/2000/svg"');
shouldBe("altGlyph.format", '"image/svg+xml"');
shouldThrow("altGlyph.format = 'x'");

shouldBe("altGlyph.getStartPositionOfChar(0).x", '0');


successfullyParsed = true;
@@ -1,3 +1,12 @@
2021-08-19 Myles C. Maxfield <mmaxfield@apple.com>

[Cocoa] Stop treating the system font as a non-variable font
https://bugs.webkit.org/show_bug.cgi?id=228176

Reviewed by Sam Weinig.

* wtf/PlatformUse.h:

2021-08-19 Aditya Keerthi <akeerthi@apple.com>

Remove __has_include guard for _UIDatePickerOverlayPresentation
@@ -312,6 +312,13 @@
#define USE_CTFONTSHAPEGLYPHS_WORKAROUND 1
#endif

#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 120000) \
|| (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED < 150000) \
|| (PLATFORM(WATCHOS) && !PLATFORM(IOS_FAMILY_SIMULATOR) && __WATCH_OS_VERSION_MIN_REQUIRED < 80000) \
|| (PLATFORM(APPLETV) && !PLATFORM(IOS_FAMILY_SIMULATOR) && __TV_OS_VERSION_MIN_REQUIRED < 150000)
#define USE_NON_VARIABLE_SYSTEM_FONT 1
#endif

#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
#define USE_LEGACY_CFNETWORK_DOWNLOADS 1
#endif
@@ -1,3 +1,19 @@
2021-08-19 Myles C. Maxfield <mmaxfield@apple.com>

[Cocoa] Stop treating the system font as a non-variable font
https://bugs.webkit.org/show_bug.cgi?id=228176

Reviewed by Sam Weinig.

Modern versions of macOS and iOS can treat the system font as a variable font,
and be able to apply weights like "342" instead of just "300" or "400".

Tests: fast/text/variable-system-font-2.html
fast/text/variable-system-font.html

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

2021-08-19 Jean-Yves Avenard <jya@apple.com>

Touchbar not showing time scrubbing
@@ -335,6 +335,7 @@ VariationDefaultsMap defaultVariationValues(CTFontRef font)
return result;
}

#if USE(NON_VARIABLE_SYSTEM_FONT)
static inline bool fontIsSystemFont(CTFontRef font)
{
if (isSystemFont(font))
@@ -343,6 +344,7 @@ static inline bool fontIsSystemFont(CTFontRef font)
auto name = adoptCF(CTFontCopyPostScriptName(font));
return fontNameIsSystemFont(name.get());
}
#endif

// 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.
@@ -505,7 +507,11 @@ RetainPtr<CTFontRef> preparePlatformFont(CTFontRef originalFont, const FontDescr

// Step 2: font-weight, font-stretch, and font-style
// The system font is somewhat magical. Don't mess with its variations.
if (applyWeightWidthSlopeVariations && !fontIsSystemFont(originalFont)) {
if (applyWeightWidthSlopeVariations
#if USE(NON_VARIABLE_SYSTEM_FONT)
&& !fontIsSystemFont(originalFont)
#endif
) {
float weight = fontSelectionRequest.weight;
float width = fontSelectionRequest.width;
float slope = fontSelectionRequest.slope.value_or(normalItalicValue());

0 comments on commit 2e35f7f

Please sign in to comment.