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.jsonindex 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.jsonindex 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.rsindex 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: &[ComponentValueParseOutcome::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.rsindex 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.rsindex 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.txtindex 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.txtindex 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 Pass4 FailPass accent-colorPass border-collapse@@ -30,6 +30,9 @@ Pass font-palettePass font-sizePass font-size-adjustPass font-style+Pass font-synthesis-small-caps+Pass font-synthesis-style+Pass font-synthesis-weightPass font-variant-alternatesPass font-variant-capsPass font-variant-east-asiandiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/inheritance.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/inheritance.txtindex 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: OKFound 39 tests-37 Pass-2 Fail+38 Pass+1 FailPass Property font-family inheritsPass Property font-feature-settings has initial value normalPass Property font-feature-settings inherits@@ -22,7 +22,7 @@ Pass Property font-stretch inheritsPass Property font-style has initial value normalPass Property font-style inheritsFail Property font-synthesis has initial value weight style small-caps position-Fail Property font-synthesis inherits+Pass Property font-synthesis inheritsPass Property font-variant has initial value normalPass Property font-variant inheritsPass Property font-variant-alternates has initial value normaldiff --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.txtindex 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: OKFound 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 filediff --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.txtindex 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: OKFound 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 valueFail 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 valueFail 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 valueFail 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 valueFail 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 valueFail e.style['font-synthesis'] = "oblique-only weight small-caps" should set the property valueFail e.style['font-synthesis'] = "oblique-only small-caps weight " should set the property valueFail e.style['font-synthesis'] = "small-caps oblique-only weight " should set the property valuediff --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.txtindex 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: OKFound 96 tests-51 Pass-45 Fail+52 Pass+44 FailPass Animation of font in ::markerPass Animation of font-family in ::markerFail Animation of font-feature-settings in ::marker@@ -60,7 +60,7 @@ Pass Transition of font-size in ::markerPass Transition of font-size-adjust in ::markerPass Transition of font-stretch in ::markerPass Transition of font-style in ::marker-Fail Transition of font-synthesis in ::marker+Pass Transition of font-synthesis in ::markerPass Transition of font-synthesis-small-caps in ::markerPass Transition of font-synthesis-style in ::markerPass Transition of font-synthesis-weight in ::markerdiff --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.txtindex 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: OKFound 102 tests-99 Pass-3 Fail+102 PassPass Can set 'font-synthesis-weight' to CSS-wide keywords: initialPass Can set 'font-synthesis-weight' to CSS-wide keywords: inheritPass 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 TypeErrPass Setting 'font-synthesis-small-caps' to a transform: translate(50%, 50%) throws TypeErrorPass Setting 'font-synthesis-small-caps' to a transform: perspective(10em) throws TypeErrorPass 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 filediff --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.txtindex 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 Pass19 FailPass SetupPass 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 functionPass 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 functionPass 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.txtindex 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 Pass19 FailPass SetupPass 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 functionPass 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 functionPass 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.txtindex 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 Pass10 FailPass SetupPass alignment-baseline (type: discrete) has testInterpolation function@@ -356,6 +356,10 @@ Pass font-language-override (type: discrete) has testInterpolation functionPass font-language-override uses discrete animation when animating between ""eng"" and "normal" with linear easingPass font-language-override uses discrete animation when animating between ""eng"" and "normal" with effect easingPass 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 easingPass font-variant-alternates (type: discrete) has testInterpolation functionPass font-variant-alternates uses discrete animation when animating between "swash(unknown)" and "stylistic(unknown)" with linear easingPass font-variant-alternates uses discrete animation when animating between "swash(unknown)" and "stylistic(unknown)" with effect easing