Title: [221630] trunk
Revision
221630
Author
mmaxfi...@apple.com
Date
2017-09-05 12:57:08 -0700 (Tue, 05 Sep 2017)

Log Message

Update font selection algorithm to match latest CSS spec
https://bugs.webkit.org/show_bug.cgi?id=175236

Reviewed by Darin Adler.

Source/WebCore:

The CSS WG tweaked the generalization of the font selection
algorithm between levels 3 and 4. In particular, the behavior
of weights between 400 and 500 works a little differently.

https://github.com/w3c/csswg-drafts/commit/f6973a21847f1c200ed38bff05dc543cebe1c827

Test: fast/text/variations/font-selection-font-weight.html

* platform/graphics/FontSelectionAlgorithm.cpp:
(WebCore::FontSelectionAlgorithm::weightDistance const):
* platform/graphics/FontSelectionAlgorithm.h:
(WebCore::lowerWeightSearchThreshold):
(WebCore::upperWeightSearchThreshold):
(WebCore::weightSearchThreshold): Deleted.

LayoutTests:

* fast/text/variations/font-selection-font-weight-expected.html: Added.
* fast/text/variations/font-selection-font-weight.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (221629 => 221630)


--- trunk/LayoutTests/ChangeLog	2017-09-05 19:56:07 UTC (rev 221629)
+++ trunk/LayoutTests/ChangeLog	2017-09-05 19:57:08 UTC (rev 221630)
@@ -1,3 +1,13 @@
+2017-09-05  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        Update font selection algorithm to match latest CSS spec
+        https://bugs.webkit.org/show_bug.cgi?id=175236
+
+        Reviewed by Darin Adler.
+
+        * fast/text/variations/font-selection-font-weight-expected.html: Added.
+        * fast/text/variations/font-selection-font-weight.html: Added.
+
 2017-09-05  Matt Lewis  <jlew...@apple.com>
 
         Marked media/W3C/video/events/event_progress.html as flaky.

Added: trunk/LayoutTests/fast/text/variations/font-selection-font-weight-expected.html (0 => 221630)


--- trunk/LayoutTests/fast/text/variations/font-selection-font-weight-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/variations/font-selection-font-weight-expected.html	2017-09-05 19:57:08 UTC (rev 221630)
@@ -0,0 +1,554 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+.namespace {
+    display: inline-block;
+    height: 48px;
+    width: 48px;
+    border: 0px;
+}
+#container {
+    line-height: 48px;
+}
+</style>
+</head>
+<body>
+<p>This test makes sure that that font selection distance function is correctly honored when selecting for font-weight. The test passes if you only see black rectangles below.</p>
+
+
+<div id="container">
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 300 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 300 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 300 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 400 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 400 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 400 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 400 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 400 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 400 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 450 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 450 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 450 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 450 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 450 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 450 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 500 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 500 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 500 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 500 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 500 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 500 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+</div>
+</body>
+<html>

Added: trunk/LayoutTests/fast/text/variations/font-selection-font-weight.html (0 => 221630)


--- trunk/LayoutTests/fast/text/variations/font-selection-font-weight.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/variations/font-selection-font-weight.html	2017-09-05 19:57:08 UTC (rev 221630)
@@ -0,0 +1,1067 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+.namespace {
+    display: inline-block;
+    height: 48px;
+    width: 48px;
+    border: 0px;
+}
+#container {
+    line-height: 48px;
+}
+</style>
+</head>
+<body>
+<p>This test makes sure that that font selection distance function is correctly honored when selecting for font-weight. The test passes if you only see black rectangles below.</p>
+
+
+<div id="container">
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 250;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 301;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 450;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 300 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 301;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 450;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 300 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 301;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 450;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 300 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 250;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 425;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 475;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 500;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 400 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 250;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 475;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 500;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 400 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 250;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 500;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 400 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 250;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 400 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 400 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 400 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 250;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 425;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 475;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 500;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 450 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 250;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 425;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 500;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 450 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 250;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 425;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 450 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 250;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 450 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 450 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 450 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 250;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 400;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 425;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 475;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 500 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 250;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 400;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 425;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 500 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 250;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 400;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 500 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 250;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 500 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 150;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 500 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 600;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 700;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 500 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 200;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 300;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 400;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 425;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 475;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 500;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 700;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 800;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 200;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 300;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 400;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 425;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 475;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 500;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 800;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 200;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 300;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 400;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 425;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 475;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 500;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 200;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 300;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 400;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 425;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 475;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 200;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 300;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 400;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 425;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 200;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 300;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 400;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+
+<iframe class="namespace" srcdoc="<!DOCTYPE html>
+<html>
+<head>
+<style>
+.test {
+    font-synthesis: none;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Helvetica');
+    font-weight: 200;
+}
+@font-face {
+    font-family: 'WebFont';
+    src: local('Ahem');
+    font-weight: 300;
+}
+</style>
+</head>
+<body style='margin: 0px;'>
+<div class='test' style='font: 600 48px WebFont;'>A</div>
+</body>
+</html>"></iframe>
+
+</div>
+</body>
+<html>

Modified: trunk/Source/WebCore/ChangeLog (221629 => 221630)


--- trunk/Source/WebCore/ChangeLog	2017-09-05 19:56:07 UTC (rev 221629)
+++ trunk/Source/WebCore/ChangeLog	2017-09-05 19:57:08 UTC (rev 221630)
@@ -1,3 +1,25 @@
+2017-09-05  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        Update font selection algorithm to match latest CSS spec
+        https://bugs.webkit.org/show_bug.cgi?id=175236
+
+        Reviewed by Darin Adler.
+
+        The CSS WG tweaked the generalization of the font selection
+        algorithm between levels 3 and 4. In particular, the behavior
+        of weights between 400 and 500 works a little differently.
+
+        https://github.com/w3c/csswg-drafts/commit/f6973a21847f1c200ed38bff05dc543cebe1c827
+
+        Test: fast/text/variations/font-selection-font-weight.html
+
+        * platform/graphics/FontSelectionAlgorithm.cpp:
+        (WebCore::FontSelectionAlgorithm::weightDistance const):
+        * platform/graphics/FontSelectionAlgorithm.h:
+        (WebCore::lowerWeightSearchThreshold):
+        (WebCore::upperWeightSearchThreshold):
+        (WebCore::weightSearchThreshold): Deleted.
+
 2017-09-05  Per Arne Vollan  <pvol...@apple.com>
 
         [Win] Compile errors in pathByAppendingComponents.

Modified: trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.cpp (221629 => 221630)


--- trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.cpp	2017-09-05 19:56:07 UTC (rev 221629)
+++ trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.cpp	2017-09-05 19:57:08 UTC (rev 221630)
@@ -99,26 +99,28 @@
     if (weight.includes(m_request.weight))
         return { FontSelectionValue(), m_request.weight };
 
-    // The spec states: "If the desired weight is 400, 500 is checked first ... If the desired weight is 500, 400 is checked first"
-    FontSelectionValue offset(1);
-    if (m_request.weight == FontSelectionValue(400) && weight.includes(FontSelectionValue(500)))
-        return { offset, FontSelectionValue(500) };
-    if (m_request.weight == FontSelectionValue(500) && weight.includes(FontSelectionValue(400)))
-        return { offset, FontSelectionValue(400) };
-
-    if (m_request.weight <= weightSearchThreshold()) {
+    if (m_request.weight >= lowerWeightSearchThreshold() && m_request.weight <= upperWeightSearchThreshold()) {
+        if (weight.minimum > m_request.weight && weight.minimum <= upperWeightSearchThreshold())
+            return { weight.minimum - m_request.weight, weight.minimum };
         if (weight.maximum < m_request.weight)
-            return { m_request.weight - weight.maximum + offset, weight.maximum };
+            return { upperWeightSearchThreshold() - weight.maximum, weight.maximum };
+        ASSERT(weight.minimum > upperWeightSearchThreshold());
+        auto threshold = std::min(m_request.weight, m_capabilitiesBounds.weight.minimum);
+        return { weight.minimum - threshold, weight.minimum };
+    }
+    if (m_request.weight < lowerWeightSearchThreshold()) {
+        if (weight.maximum < m_request.weight)
+            return { m_request.weight - weight.maximum, weight.maximum };
         ASSERT(weight.minimum > m_request.weight);
         auto threshold = std::min(m_request.weight, m_capabilitiesBounds.weight.minimum);
-        return { weight.minimum - threshold + offset, weight.minimum };
+        return { weight.minimum - threshold, weight.minimum };
     }
-
+    ASSERT(m_request.weight >= upperWeightSearchThreshold());
     if (weight.minimum > m_request.weight)
-        return { weight.minimum - m_request.weight + offset, weight.minimum };
+        return { weight.minimum - m_request.weight, weight.minimum };
     ASSERT(weight.maximum < m_request.weight);
     auto threshold = std::max(m_request.weight, m_capabilitiesBounds.weight.maximum);
-    return { threshold - weight.maximum + offset, weight.maximum };
+    return { threshold - weight.maximum, weight.maximum };
 }
 
 void FontSelectionAlgorithm::filterCapability(DistanceResult(FontSelectionAlgorithm::*computeDistance)(FontSelectionCapabilities) const, FontSelectionRange FontSelectionCapabilities::*inclusionRange)

Modified: trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.h (221629 => 221630)


--- trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.h	2017-09-05 19:56:07 UTC (rev 221629)
+++ trunk/Source/WebCore/platform/graphics/FontSelectionAlgorithm.h	2017-09-05 19:57:08 UTC (rev 221630)
@@ -219,8 +219,14 @@
     return fontWeight >= boldThreshold();
 }
 
-static inline FontSelectionValue weightSearchThreshold()
+static inline FontSelectionValue lowerWeightSearchThreshold()
 {
+    static NeverDestroyed<FontSelectionValue> result = FontSelectionValue(400);
+    return result.get();
+}
+
+static inline FontSelectionValue upperWeightSearchThreshold()
+{
     static NeverDestroyed<FontSelectionValue> result = FontSelectionValue(500);
     return result.get();
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to