Skip to content

Truly independent web browser

LibWeb: Add the font-synthesis shorthand

Andreas Kling3dea02bd48e2
diff --git a/Libraries/LibWeb/CSS/Keywords.json b/Libraries/LibWeb/CSS/Keywords.json
index 63549c50544..ea270a672dc 100644
--- a/Libraries/LibWeb/CSS/Keywords.json
+++ b/Libraries/LibWeb/CSS/Keywords.json
@@ -836,6 +836,7 @@
"wait",
"warang-citi",
"wavy",
+ "weight",
"width",
"window",
"windowframe",
diff --git a/Libraries/LibWeb/CSS/Properties.json b/Libraries/LibWeb/CSS/Properties.json
index 3cd7990135f..b61152ba863 100644
--- a/Libraries/LibWeb/CSS/Properties.json
+++ b/Libraries/LibWeb/CSS/Properties.json
@@ -2594,6 +2594,17 @@
"font-style"
]
},
+ "font-synthesis": {
+ "initial": "weight style small-caps",
+ "longhands": [
+ "font-synthesis-small-caps",
+ "font-synthesis-style",
+ "font-synthesis-weight"
+ ],
+ "valid-types": [
+ "string"
+ ]
+ },
"font-synthesis-position": {
"animation-type": "discrete",
"inherited": true,
diff --git a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
index c629992a345..2d123a7fc35 100644
--- a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
+++ b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
@@ -5013,6 +5013,57 @@ fn parse_border_image_shorthand(context: &ParseContext, values: &[ComponentValue
ParseOutcome::Invalid
}
+// https://drafts.csswg.org/css-fonts-4/#font-synthesis
+fn parse_font_synthesis_shorthand(values: &[ComponentValue]) -> ParseOutcome {
+ // INTEROP: Chrome and Safari support weight, style, and small-caps, but not position or oblique-only.
+ let Some(keywords) = values
+ .iter()
+ .filter(|value| !value.is_whitespace())
+ .map(|value| value.ident().and_then(keyword_from_ascii_case_insensitive))
+ .collect::<Option<Vec<_>>>()
+ else {
+ return ParseOutcome::Invalid;
+ };
+ if keywords.is_empty() || keywords.len() > 3 {
+ return ParseOutcome::Invalid;
+ }
+ let mut enabled = [false; 3];
+ if keywords.as_slice() != [keyword::NONE] {
+ for keyword in keywords {
+ let index = match keyword {
+ keyword::WEIGHT => 0,
+ keyword::STYLE => 1,
+ keyword::SMALL_CAPS => 2,
+ _ => return ParseOutcome::Invalid,
+ };
+ if enabled[index] {
+ return ParseOutcome::Invalid;
+ }
+ enabled[index] = true;
+ }
+ }
+ let properties = longhands_for_shorthand(property_id::FONT_SYNTHESIS);
+ let values = properties
+ .iter()
+ .map(|property| {
+ let index = match *property {
+ property_id::FONT_SYNTHESIS_WEIGHT => 0,
+ property_id::FONT_SYNTHESIS_STYLE => 1,
+ property_id::FONT_SYNTHESIS_SMALL_CAPS => 2,
+ _ => unreachable!(),
+ };
+ StyleValueData::Keyword {
+ keyword: if enabled[index] { keyword::AUTO } else { keyword::NONE },
+ }
+ })
+ .collect();
+ ParseOutcome::Parsed(shared_style_value(shorthand_value(
+ property_id::FONT_SYNTHESIS,
+ properties.to_vec(),
+ values,
+ )))
+}
+
fn parse_font_variant_shorthand(context: &ParseContext, values: &[ComponentValue]) -> ParseOutcome {
let components = values
.iter()
@@ -6008,6 +6059,9 @@ fn parse_css_value_after_substitution_scan(
if property_id == property_id::BORDER_IMAGE {
return parse_border_image_shorthand(context, values);
}
+ if property_id == property_id::FONT_SYNTHESIS {
+ return parse_font_synthesis_shorthand(values);
+ }
if property_id == property_id::FONT_VARIANT {
return parse_font_variant_shorthand(context, values);
}
diff --git a/Libraries/LibWeb/Rust/src/css/serialize.rs b/Libraries/LibWeb/Rust/src/css/serialize.rs
index af58be44779..958f61b83b3 100644
--- a/Libraries/LibWeb/Rust/src/css/serialize.rs
+++ b/Libraries/LibWeb/Rust/src/css/serialize.rs
@@ -3528,6 +3528,7 @@ fn serialize_shorthand(
property_id::BORDER,
property_id::BACKGROUND_POSITION,
property_id::FONT,
+ property_id::FONT_SYNTHESIS,
property_id::FONT_VARIANT,
property_id::GRID,
property_id::GRID_AREA,
diff --git a/Libraries/LibWeb/Rust/src/css/serialize/shorthand.rs b/Libraries/LibWeb/Rust/src/css/serialize/shorthand.rs
index 80a56c15b7f..224b5752d9d 100644
--- a/Libraries/LibWeb/Rust/src/css/serialize/shorthand.rs
+++ b/Libraries/LibWeb/Rust/src/css/serialize/shorthand.rs
@@ -454,6 +454,33 @@ pub(super) fn serialize(
write(sink, get(property_id::BORDER_WIDTH), mode);
}
}
+ property_id::FONT_SYNTHESIS => {
+ let components = [
+ (property_id::FONT_SYNTHESIS_WEIGHT, "weight"),
+ (property_id::FONT_SYNTHESIS_STYLE, "style"),
+ (property_id::FONT_SYNTHESIS_SMALL_CAPS, "small-caps"),
+ ];
+ if components.iter().any(|(property, _)| {
+ !keyword_is(get(*property), keyword::NONE) && !keyword_is(get(*property), keyword::AUTO)
+ }) {
+ return;
+ }
+ let mut first = true;
+ for (property, name) in components {
+ let value = get(property);
+ if keyword_is(value, keyword::NONE) {
+ continue;
+ }
+ if !first {
+ sink.push_ascii(" ");
+ }
+ sink.push_ascii(name);
+ first = false;
+ }
+ if first {
+ sink.push_ascii("none");
+ }
+ }
property_id::FONT_VARIANT => {
let ids = [
property_id::FONT_VARIANT_LIGATURES,
diff --git a/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt b/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt
index 19a6fcf02e4..d3a9fb667e7 100644
--- a/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt
+++ b/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt
@@ -555,6 +555,8 @@ All supported properties and their default values exposed from CSSStylePropertie
'font-stretch': '100%'
'fontStyle': 'normal'
'font-style': 'normal'
+'fontSynthesis': 'weight style small-caps'
+'font-synthesis': 'weight style small-caps'
'fontSynthesisPosition': 'auto'
'font-synthesis-position': 'auto'
'fontSynthesisSmallCaps': 'auto'
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/all-prop-revert-layer.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/all-prop-revert-layer.txt
index fa4a7dc2c09..33c94fe5319 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/all-prop-revert-layer.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-cascade/all-prop-revert-layer.txt
@@ -1,8 +1,8 @@
Harness status: OK
-Found 350 tests
+Found 353 tests
-346 Pass
+349 Pass
4 Fail
Pass accent-color
Pass border-collapse
@@ -30,6 +30,9 @@ Pass font-palette
Pass font-size
Pass font-size-adjust
Pass font-style
+Pass font-synthesis-small-caps
+Pass font-synthesis-style
+Pass font-synthesis-weight
Pass font-variant-alternates
Pass font-variant-caps
Pass font-variant-east-asian
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/inheritance.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/inheritance.txt
index b403c6dffd6..27664b83553 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/inheritance.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/inheritance.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 39 tests
-37 Pass
-2 Fail
+38 Pass
+1 Fail
Pass Property font-family inherits
Pass Property font-feature-settings has initial value normal
Pass Property font-feature-settings inherits
@@ -22,7 +22,7 @@ Pass Property font-stretch inherits
Pass Property font-style has initial value normal
Pass Property font-style inherits
Fail Property font-synthesis has initial value weight style small-caps position
-Fail Property font-synthesis inherits
+Pass Property font-synthesis inherits
Pass Property font-variant has initial value normal
Pass Property font-variant inherits
Pass Property font-variant-alternates has initial value normal
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-synthesis-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-synthesis-computed.txt
index e37153cf366..a0083a2c926 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-synthesis-computed.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-synthesis-computed.txt
@@ -2,25 +2,26 @@ Harness status: OK
Found 21 tests
-21 Fail
-Fail Property font-synthesis value 'none'
-Fail Property font-synthesis value 'weight'
-Fail Property font-synthesis value 'style'
+8 Pass
+13 Fail
+Pass Property font-synthesis value 'none'
+Pass Property font-synthesis value 'weight'
+Pass Property font-synthesis value 'style'
Fail Property font-synthesis value 'oblique-only'
-Fail Property font-synthesis value 'small-caps'
+Pass Property font-synthesis value 'small-caps'
Fail Property font-synthesis value 'position'
Fail Property font-synthesis value 'small-caps position'
-Fail Property font-synthesis value 'style small-caps'
+Pass Property font-synthesis value 'style small-caps'
Fail Property font-synthesis value 'style position'
Fail Property font-synthesis value 'style small-caps position'
Fail Property font-synthesis value 'oblique-only small-caps'
Fail Property font-synthesis value 'oblique-only position'
Fail Property font-synthesis value 'oblique-only small-caps position'
-Fail Property font-synthesis value 'weight small-caps'
-Fail Property font-synthesis value 'weight style'
+Pass Property font-synthesis value 'weight small-caps'
+Pass Property font-synthesis value 'weight style'
Fail Property font-synthesis value 'weight oblique-only'
Fail Property font-synthesis value 'weight position'
-Fail Property font-synthesis value 'weight style small-caps'
+Pass Property font-synthesis value 'weight style small-caps'
Fail Property font-synthesis value 'weight style small-caps position'
Fail Property font-synthesis value 'weight oblique-only small-caps'
Fail Property font-synthesis value 'weight oblique-only small-caps position'
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-synthesis-valid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-synthesis-valid.txt
index bcb5d56ae5d..9d4cda0d35b 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-synthesis-valid.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-synthesis-valid.txt
@@ -2,21 +2,22 @@ Harness status: OK
Found 23 tests
-23 Fail
-Fail e.style['font-synthesis'] = "none" should set the property value
-Fail e.style['font-synthesis'] = "weight" should set the property value
-Fail e.style['font-synthesis'] = "style" should set the property value
+10 Pass
+13 Fail
+Pass e.style['font-synthesis'] = "none" should set the property value
+Pass e.style['font-synthesis'] = "weight" should set the property value
+Pass e.style['font-synthesis'] = "style" should set the property value
Fail e.style['font-synthesis'] = "oblique-only" should set the property value
-Fail e.style['font-synthesis'] = "small-caps" should set the property value
+Pass e.style['font-synthesis'] = "small-caps" should set the property value
Fail e.style['font-synthesis'] = "position" should set the property value
-Fail e.style['font-synthesis'] = "style weight" should set the property value
+Pass e.style['font-synthesis'] = "style weight" should set the property value
Fail e.style['font-synthesis'] = "oblique-only weight" should set the property value
-Fail e.style['font-synthesis'] = "small-caps weight" should set the property value
-Fail e.style['font-synthesis'] = "small-caps style" should set the property value
+Pass e.style['font-synthesis'] = "small-caps weight" should set the property value
+Pass e.style['font-synthesis'] = "small-caps style" should set the property value
Fail e.style['font-synthesis'] = "small-caps oblique-only" should set the property value
-Fail e.style['font-synthesis'] = "style weight small-caps" should set the property value
-Fail e.style['font-synthesis'] = "style small-caps weight " should set the property value
-Fail e.style['font-synthesis'] = "small-caps style weight " should set the property value
+Pass e.style['font-synthesis'] = "style weight small-caps" should set the property value
+Pass e.style['font-synthesis'] = "style small-caps weight " should set the property value
+Pass e.style['font-synthesis'] = "small-caps style weight " should set the property value
Fail e.style['font-synthesis'] = "oblique-only weight small-caps" should set the property value
Fail e.style['font-synthesis'] = "oblique-only small-caps weight " should set the property value
Fail e.style['font-synthesis'] = "small-caps oblique-only weight " should set the property value
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/parsing/marker-supported-properties-in-animation.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/parsing/marker-supported-properties-in-animation.txt
index 865510ae948..b6a13012f01 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/parsing/marker-supported-properties-in-animation.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/parsing/marker-supported-properties-in-animation.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 96 tests
-51 Pass
-45 Fail
+52 Pass
+44 Fail
Pass Animation of font in ::marker
Pass Animation of font-family in ::marker
Fail Animation of font-feature-settings in ::marker
@@ -60,7 +60,7 @@ Pass Transition of font-size in ::marker
Pass Transition of font-size-adjust in ::marker
Pass Transition of font-stretch in ::marker
Pass Transition of font-style in ::marker
-Fail Transition of font-synthesis in ::marker
+Pass Transition of font-synthesis in ::marker
Pass Transition of font-synthesis-small-caps in ::marker
Pass Transition of font-synthesis-style in ::marker
Pass Transition of font-synthesis-weight in ::marker
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-synthesis.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-synthesis.txt
index f9189fc68f3..db929f0e368 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-synthesis.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-synthesis.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 102 tests
-99 Pass
-3 Fail
+102 Pass
Pass Can set 'font-synthesis-weight' to CSS-wide keywords: initial
Pass Can set 'font-synthesis-weight' to CSS-wide keywords: inherit
Pass Can set 'font-synthesis-weight' to CSS-wide keywords: unset
@@ -103,6 +102,6 @@ Pass Setting 'font-synthesis-small-caps' to a number: calc(2 + 3) throws TypeErr
Pass Setting 'font-synthesis-small-caps' to a transform: translate(50%, 50%) throws TypeError
Pass Setting 'font-synthesis-small-caps' to a transform: perspective(10em) throws TypeError
Pass Setting 'font-synthesis-small-caps' to a transform: translate3d(0px, 1px, 2px) translate(0px, 1px) rotate3d(1, 2, 3, 45deg) rotate(45deg) scale3d(1, 2, 3) scale(1, 2) skew(1deg, 1deg) skewX(1deg) skewY(45deg) perspective(1px) matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) matrix(1, 2, 3, 4, 5, 6) throws TypeError
-Fail 'font-synthesis' does not support 'weight style'
-Fail 'font-synthesis' does not support 'style small-caps'
-Fail 'font-synthesis' does not support 'small-caps weight style'
\ No newline at end of file
+Pass 'font-synthesis' does not support 'weight style'
+Pass 'font-synthesis' does not support 'style small-caps'
+Pass 'font-synthesis' does not support 'small-caps weight style'
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/web-animations/animation-model/animation-types/accumulation-per-property-001.txt b/Tests/LibWeb/Text/expected/wpt-import/web-animations/animation-model/animation-types/accumulation-per-property-001.txt
index 3fe52f33b20..cad3cc145a0 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/web-animations/animation-model/animation-types/accumulation-per-property-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/web-animations/animation-model/animation-types/accumulation-per-property-001.txt
@@ -1,8 +1,8 @@
Harness status: OK
-Found 359 tests
+Found 362 tests
-340 Pass
+343 Pass
19 Fail
Pass Setup
Pass alignment-baseline (type: discrete) has testAccumulation function
@@ -293,6 +293,9 @@ Pass font-kerning: "auto" onto "normal"
Pass font-language-override (type: discrete) has testAccumulation function
Pass font-language-override: "normal" onto ""eng""
Pass font-language-override: ""eng"" onto "normal"
+Pass font-synthesis (type: discrete) has testAccumulation function
+Pass font-synthesis: "weight style" onto "none"
+Pass font-synthesis: "none" onto "weight style"
Pass font-variant-alternates (type: discrete) has testAccumulation function
Pass font-variant-alternates: "stylistic(unknown)" onto "swash(unknown)"
Pass font-variant-alternates: "swash(unknown)" onto "stylistic(unknown)"
diff --git a/Tests/LibWeb/Text/expected/wpt-import/web-animations/animation-model/animation-types/addition-per-property-001.txt b/Tests/LibWeb/Text/expected/wpt-import/web-animations/animation-model/animation-types/addition-per-property-001.txt
index a66f15157a6..258cbcb2c0b 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/web-animations/animation-model/animation-types/addition-per-property-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/web-animations/animation-model/animation-types/addition-per-property-001.txt
@@ -1,8 +1,8 @@
Harness status: OK
-Found 359 tests
+Found 362 tests
-340 Pass
+343 Pass
19 Fail
Pass Setup
Pass alignment-baseline (type: discrete) has testAddition function
@@ -293,6 +293,9 @@ Pass font-kerning: "auto" onto "normal"
Pass font-language-override (type: discrete) has testAddition function
Pass font-language-override: "normal" onto ""eng""
Pass font-language-override: ""eng"" onto "normal"
+Pass font-synthesis (type: discrete) has testAddition function
+Pass font-synthesis: "weight style" onto "none"
+Pass font-synthesis: "none" onto "weight style"
Pass font-variant-alternates (type: discrete) has testAddition function
Pass font-variant-alternates: "stylistic(unknown)" onto "swash(unknown)"
Pass font-variant-alternates: "swash(unknown)" onto "stylistic(unknown)"
diff --git a/Tests/LibWeb/Text/expected/wpt-import/web-animations/animation-model/animation-types/interpolation-per-property-001.txt b/Tests/LibWeb/Text/expected/wpt-import/web-animations/animation-model/animation-types/interpolation-per-property-001.txt
index dae661b20f3..3bcbe5d7b29 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/web-animations/animation-model/animation-types/interpolation-per-property-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/web-animations/animation-model/animation-types/interpolation-per-property-001.txt
@@ -1,8 +1,8 @@
Harness status: OK
-Found 446 tests
+Found 450 tests
-436 Pass
+440 Pass
10 Fail
Pass Setup
Pass alignment-baseline (type: discrete) has testInterpolation function
@@ -356,6 +356,10 @@ Pass font-language-override (type: discrete) has testInterpolation function
Pass font-language-override uses discrete animation when animating between ""eng"" and "normal" with linear easing
Pass font-language-override uses discrete animation when animating between ""eng"" and "normal" with effect easing
Pass font-language-override uses discrete animation when animating between ""eng"" and "normal" with keyframe easing
+Pass font-synthesis (type: discrete) has testInterpolation function
+Pass font-synthesis uses discrete animation when animating between "none" and "weight style" with linear easing
+Pass font-synthesis uses discrete animation when animating between "none" and "weight style" with effect easing
+Pass font-synthesis uses discrete animation when animating between "none" and "weight style" with keyframe easing
Pass font-variant-alternates (type: discrete) has testInterpolation function
Pass font-variant-alternates uses discrete animation when animating between "swash(unknown)" and "stylistic(unknown)" with linear easing
Pass font-variant-alternates uses discrete animation when animating between "swash(unknown)" and "stylistic(unknown)" with effect easing