Skip to content

Truly independent web browser

LibWeb: Expose normal for omitted font-face descriptors

sideshowbarkerbc5289586423
diff --git a/Libraries/LibWeb/CSS/FontFace.cpp b/Libraries/LibWeb/CSS/FontFace.cpp
index 12e391c7723..e163eb810a6 100644
--- a/Libraries/LibWeb/CSS/FontFace.cpp
+++ b/Libraries/LibWeb/CSS/FontFace.cpp
@@ -396,8 +396,19 @@ NonnullRefPtr<FontFaceState> FontFaceState::create_css_connected(JS::Realm& real
void FontFaceState::reparse_connected_css_font_face_rule_descriptors()
{
auto descriptors = connected_descriptors();
- for (auto const& attribute : font_face_attributes)
- apply_descriptor(attribute.descriptor, *descriptors.descriptor_or_initial_value(AtRuleID::FontFace, DescriptorNameAndID::from_id(attribute.descriptor)));
+ for (auto const& attribute : font_face_attributes) {
+ auto id = attribute.descriptor;
+ if (auto specified = descriptors.descriptor(DescriptorNameAndID::from_id(id))) {
+ apply_descriptor(id, *specified);
+ continue;
+ }
+ apply_descriptor(id, *descriptor_initial_value(AtRuleID::FontFace, id));
+
+ // AD-HOC: Font matching uses the descriptor's initial value, but FontFace exposes its dictionary default.
+ // https://github.com/w3c/csswg-drafts/issues/11561
+ if (first_is_one_of(id, DescriptorID::FontStyle, DescriptorID::FontWeight, DescriptorID::FontWidth))
+ m_descriptor_texts[attribute_index(id)] = "normal"_utf16;
+ }
}
// A face belongs to the agent that made it, so an agent only finds its own.
diff --git a/Tests/LibWeb/Text/expected/css/css-connected-font-face-parsing.txt b/Tests/LibWeb/Text/expected/css/css-connected-font-face-parsing.txt
index c1418a7b9de..6dae8fb35cb 100644
--- a/Tests/LibWeb/Text/expected/css/css-connected-font-face-parsing.txt
+++ b/Tests/LibWeb/Text/expected/css/css-connected-font-face-parsing.txt
@@ -4,7 +4,8 @@ auto
Ahem
normal
normal
-auto
-auto
+normal
+normal
U+0-10FFFF
-auto
+normal
+auto auto auto
diff --git a/Tests/LibWeb/Text/expected/css/font-face-css-text.txt b/Tests/LibWeb/Text/expected/css/font-face-css-text.txt
index dbff110cda4..113d5ccf072 100644
--- a/Tests/LibWeb/Text/expected/css/font-face-css-text.txt
+++ b/Tests/LibWeb/Text/expected/css/font-face-css-text.txt
@@ -3,7 +3,7 @@ replacement: 400 / U+42
excluded characters use fallback: true
same source preserves identity: true
removed unicode-range: U+0-10FFFF / 80
-renamed: Renamed / auto / 80
+renamed: Renamed / normal / 80
rename preserves identity: true
changed source replaces identity: true / false
changed source width: 80
diff --git a/Tests/LibWeb/Text/expected/css/font-face-remove-property.txt b/Tests/LibWeb/Text/expected/css/font-face-remove-property.txt
index db826e11bce..f9a8775184b 100644
--- a/Tests/LibWeb/Text/expected/css/font-face-remove-property.txt
+++ b/Tests/LibWeb/Text/expected/css/font-face-remove-property.txt
@@ -1,2 +1,2 @@
before: 700 / 700
-after: / auto
+after: / normal
diff --git a/Tests/LibWeb/Text/expected/css/font-weight-range.txt b/Tests/LibWeb/Text/expected/css/font-weight-range.txt
index 3dc0e5db3d6..75712b47eff 100644
--- a/Tests/LibWeb/Text/expected/css/font-weight-range.txt
+++ b/Tests/LibWeb/Text/expected/css/font-weight-range.txt
@@ -1,4 +1,4 @@
-No weight defined: auto
+No weight defined: normal
Two numbers: 100 200
Two numbers reversed: 200 100
Two keywords: bold normal
@@ -8,8 +8,8 @@ Number and keyword reversed: 700 normal
Number and keyword again: bold 300
Number and keyword again reversed: 300 bold
Two numbers filling the range: 1 1000
-Invalid too many: auto
-Invalid relative lighter: auto
-Invalid relative bolder: auto
-Invalid relative: auto
-Invalid out of range: auto
+Invalid too many: normal
+Invalid relative lighter: normal
+Invalid relative bolder: normal
+Invalid relative: normal
+Invalid out of range: normal
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-font-loading/fontface-css-connected-descriptors.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-font-loading/fontface-css-connected-descriptors.txt
new file mode 100644
index 00000000000..37dd113e173
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-font-loading/fontface-css-connected-descriptors.txt
@@ -0,0 +1,17 @@
+Harness status: OK
+
+Found 12 tests
+
+12 Pass
+Pass CSS-connected FontFace objects should be present
+Pass ascentOverride should be set correctly
+Pass descentOverride should be set correctly
+Pass display should be set correctly
+Pass featureSettings should be set correctly
+Pass stretch should be set correctly
+Pass font-width should initialize the width and stretch attributes
+Pass style should be set correctly
+Pass variationSettings should be set correctly
+Pass weight should be set correctly
+Pass lineGapOverride should be set correctly
+Pass unicodeRange should be set correctly
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/css/css-connected-font-face-parsing.html b/Tests/LibWeb/Text/input/css/css-connected-font-face-parsing.html
index 518cacb4f0a..50569cba5a2 100644
--- a/Tests/LibWeb/Text/input/css/css-connected-font-face-parsing.html
+++ b/Tests/LibWeb/Text/input/css/css-connected-font-face-parsing.html
@@ -5,6 +5,13 @@
font-family: Ahem;
src: url("./ahem.woff");
}
+ @font-face {
+ font-family: ExplicitAuto;
+ src: local(missing);
+ font-weight: auto;
+ font-style: auto;
+ font-stretch: auto;
+ }
</style>
<script src="../include.js"></script>
<script>
@@ -21,6 +28,9 @@
println(fontFace.style);
println(fontFace.unicodeRange);
println(fontFace.weight);
+
+ const explicit = [...document.fonts].find(face => face.family === "ExplicitAuto");
+ println([explicit.weight, explicit.style, explicit.stretch].join(" "));
});
</script>
</html>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-font-loading/fontface-css-connected-descriptors.html b/Tests/LibWeb/Text/input/wpt-import/css/css-font-loading/fontface-css-connected-descriptors.html
new file mode 100644
index 00000000000..5a23ad6b5a2
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-font-loading/fontface-css-connected-descriptors.html
@@ -0,0 +1,100 @@
+<!DOCTYPE html>
+<head>
+ <link rel="author" href="[email protected]">
+ <link rel="help" href="https://drafts.csswg.org/css-font-loading/#font-face-css-connection">
+ <title>A FontFace backed by a @font-face rule should have its descriptors initialized accordingly</title>
+ <script src="../../resources/testharness.js"></script>
+ <script src="../../resources/testharnessreport.js"></script>
+</head>
+<body>
+ <style id="baz">
+ @font-face {
+ font-family: "Lato";
+ src: url("../../fonts/Lato-Medium.ttf");
+ font-style: normal;
+ ascent-override: 50%;
+ descent-override: 30%;
+ font-display: fallback;
+ font-feature-settings: "smcp" off;
+ font-stretch: ultra-expanded;
+ font-style: oblique 40deg;
+ font-variation-settings: "wght" 500;
+ font-weight: bold;
+ line-gap-override: 10%;
+ unicode-range: U+4??;
+ }
+ @font-face {
+ font-family: "Lato Width";
+ src: url("../../fonts/Lato-Medium.ttf");
+ font-width: ultra-expanded;
+ }
+ #target {
+ font-family: "Lato";
+ }
+ #width-target {
+ font-family: "Lato Width";
+ }
+ </style>
+ <div id="target">I am a div that uses the Lato font, requiring it to be loaded before document.fonts.ready resolves</div>
+ <div id="width-target">I use the font-width descriptor</div>
+ <script>
+ setup({explicit_done:true});
+
+ document.fonts.ready.then(() => {
+ const fontFaces = [...document.fonts];
+ const latoFace = fontFaces.find(face => face.family === "Lato");
+ const widthFace = fontFaces.find(face => face.family === "Lato Width");
+
+ test(() => {
+ assert_not_equals(latoFace, undefined);
+ assert_not_equals(widthFace, undefined);
+ }, "CSS-connected FontFace objects should be present");
+
+ test(() => {
+ assert_equals(latoFace.ascentOverride, "50%");
+ }, "ascentOverride should be set correctly");
+
+ test(() => {
+ assert_equals(latoFace.descentOverride, "30%");
+ }, "descentOverride should be set correctly");
+
+ test(() => {
+ assert_equals(latoFace.display, "fallback");
+ }, "display should be set correctly");
+
+ test(() => {
+ assert_equals(latoFace.featureSettings, "\"smcp\" 0");
+ }, "featureSettings should be set correctly");
+
+ test(() => {
+ assert_equals(latoFace.stretch, "ultra-expanded");
+ }, "stretch should be set correctly");
+
+ test(() => {
+ assert_equals(widthFace.width, "ultra-expanded");
+ assert_equals(widthFace.stretch, "ultra-expanded");
+ }, "font-width should initialize the width and stretch attributes");
+
+ test(() => {
+ assert_equals(latoFace.style, "oblique 40deg");
+ }, "style should be set correctly");
+
+ test(() => {
+ assert_equals(latoFace.variationSettings, "\"wght\" 500");
+ }, "variationSettings should be set correctly");
+
+ test(() => {
+ assert_equals(latoFace.weight, "bold");
+ }, "weight should be set correctly");
+
+ test(() => {
+ assert_equals(latoFace.lineGapOverride, "10%");
+ }, "lineGapOverride should be set correctly");
+
+ test(() => {
+ assert_equals(latoFace.unicodeRange, "U+400-4FF");
+ }, "unicodeRange should be set correctly");
+ done();
+ })
+ </script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/fonts/Lato-Medium.ttf b/Tests/LibWeb/Text/input/wpt-import/fonts/Lato-Medium.ttf
new file mode 100644
index 00000000000..2c612da2ae5
Binary files /dev/null and b/Tests/LibWeb/Text/input/wpt-import/fonts/Lato-Medium.ttf differ