diff --git a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp index e72e741ef61..100d24d378b 100644 --- a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp @@ -2563,7 +2563,7 @@ RefPtr Parser::parse_font_feature_settings_value(TokenStreamstring_value(), OpenTypeTaggedStyleValue::create(opentype_tag->string_value(), value.release_nonnull())); + feature_tags_map.set(opentype_tag->string_value(), OpenTypeTaggedStyleValue::create(OpenTypeTaggedStyleValue::Mode::FontFeatureSettings, opentype_tag->string_value(), value.release_nonnull())); } // "The computed value contains the de-duplicated feature tags, sorted in ascending order by code unit." @@ -2609,7 +2609,7 @@ RefPtr Parser::parse_font_variation_settings_value(TokenStreamstring_value(), OpenTypeTaggedStyleValue::create(opentype_tag->string_value(), number.release_nonnull())); + axis_tags_map.set(opentype_tag->string_value(), OpenTypeTaggedStyleValue::create(OpenTypeTaggedStyleValue::Mode::FontVariationSettings, opentype_tag->string_value(), number.release_nonnull())); } // "The computed value contains the de-duplicated axis names, sorted in ascending order by code unit." diff --git a/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.cpp index fe5cd107f9b..e91fc5c8565 100644 --- a/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Sam Atkins + * Copyright (c) 2024-2025, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -13,8 +13,18 @@ String OpenTypeTaggedStyleValue::to_string(SerializationMode mode) const { StringBuilder builder; serialize_a_string(builder, m_tag); - // FIXME: For font-feature-settings, a 1 value is implicit, so we shouldn't output it. - builder.appendff(" {}", m_value->to_string(mode)); + switch (m_mode) { + case Mode::FontFeatureSettings: { + // For font-feature-settings, a 1 value is implicit, so we shouldn't output it. + auto value_string = m_value->to_string(mode); + if (value_string != "1"sv) + builder.appendff(" {}", value_string); + break; + } + case Mode::FontVariationSettings: + builder.appendff(" {}", m_value->to_string(mode)); + break; + } return builder.to_string_without_validation(); } diff --git a/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h index 28467db70ea..a328942c8f2 100644 --- a/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h +++ b/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Sam Atkins + * Copyright (c) 2024-2025, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -16,9 +16,13 @@ namespace Web::CSS { // and the ` ` construct for `font-variation-settings`. class OpenTypeTaggedStyleValue : public StyleValueWithDefaultOperators { public: - static ValueComparingNonnullRefPtr create(FlyString tag, ValueComparingNonnullRefPtr value) + enum class Mode { + FontFeatureSettings, + FontVariationSettings, + }; + static ValueComparingNonnullRefPtr create(Mode mode, FlyString tag, ValueComparingNonnullRefPtr value) { - return adopt_ref(*new (nothrow) OpenTypeTaggedStyleValue(move(tag), move(value))); + return adopt_ref(*new (nothrow) OpenTypeTaggedStyleValue(mode, move(tag), move(value))); } virtual ~OpenTypeTaggedStyleValue() override = default; @@ -30,13 +34,15 @@ public: bool properties_equal(OpenTypeTaggedStyleValue const&) const; private: - explicit OpenTypeTaggedStyleValue(FlyString tag, ValueComparingNonnullRefPtr value) + explicit OpenTypeTaggedStyleValue(Mode mode, FlyString tag, ValueComparingNonnullRefPtr value) : StyleValueWithDefaultOperators(Type::OpenTypeTagged) + , m_mode(mode) , m_tag(move(tag)) , m_value(move(value)) { } + Mode m_mode; FlyString m_tag; ValueComparingNonnullRefPtr m_value; }; diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-feature-settings-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-feature-settings-computed.txt index 5fbe156ec10..f18b5fba053 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-feature-settings-computed.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-feature-settings-computed.txt @@ -2,15 +2,15 @@ Harness status: OK Found 10 tests -2 Pass -8 Fail +8 Pass +2 Fail Pass Property font-feature-settings value 'normal' -Fail Property font-feature-settings value '"dlig"' -Fail Property font-feature-settings value '"smcp"' -Fail Property font-feature-settings value '"c2sc"' +Pass Property font-feature-settings value '"dlig"' +Pass Property font-feature-settings value '"smcp"' +Pass Property font-feature-settings value '"c2sc"' Pass Property font-feature-settings value '"liga" 0' -Fail Property font-feature-settings value '"tnum", "hist"' -Fail Property font-feature-settings value '"PKRN"' -Fail Property font-feature-settings value '"dlig", "smcp", "dlig" 0' +Pass Property font-feature-settings value '"tnum", "hist"' +Pass Property font-feature-settings value '"PKRN"' +Pass Property font-feature-settings value '"dlig", "smcp", "dlig" 0' Fail Property font-feature-settings value '"liga" calc(10 + (sign(2cqw - 10px) * 5))' Fail Property font-feature-settings value '"liga" calc(10 + (sign(2cqw - 10px) * 5)), "dlig" calc(20 + (sign(2cqw - 10px) * 5))' \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-feature-settings-valid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-feature-settings-valid.txt index 10d42418a70..df2dcc49e53 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-feature-settings-valid.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-fonts/parsing/font-feature-settings-valid.txt @@ -2,13 +2,13 @@ Harness status: OK Found 8 tests -2 Pass -6 Fail +6 Pass +2 Fail Pass e.style['font-feature-settings'] = "normal" should set the property value -Fail e.style['font-feature-settings'] = "\"dlig\" 1" should set the property value -Fail e.style['font-feature-settings'] = "\"smcp\" on" should set the property value -Fail e.style['font-feature-settings'] = "'c2sc'" should set the property value +Pass e.style['font-feature-settings'] = "\"dlig\" 1" should set the property value +Pass e.style['font-feature-settings'] = "\"smcp\" on" should set the property value +Pass e.style['font-feature-settings'] = "'c2sc'" should set the property value Pass e.style['font-feature-settings'] = "\"liga\" off" should set the property value Fail e.style['font-feature-settings'] = "\"tnum\", 'hist'" should set the property value -Fail e.style['font-feature-settings'] = "\"PKRN\"" should set the property value +Pass e.style['font-feature-settings'] = "\"PKRN\"" should set the property value Fail e.style['font-feature-settings'] = "\"dlig\" 1, \"smcp\" on, \"dlig\" 0" should set the property value \ No newline at end of file