LibWeb/CSS: Teach OpenTypeTaggedStyleValue to serialize without "1"

This commit is contained in:
Sam Atkins 2025-04-04 12:14:22 +01:00
parent 69050da929
commit a7f7c2a821
Notes: github-actions[bot] 2025-04-07 09:02:41 +00:00
5 changed files with 39 additions and 23 deletions

View file

@ -2563,7 +2563,7 @@ RefPtr<CSSStyleValue> Parser::parse_font_feature_settings_value(TokenStream<Comp
if (!opentype_tag || !value || tag_tokens.has_next_token())
return nullptr;
feature_tags_map.set(opentype_tag->string_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<CSSStyleValue> Parser::parse_font_variation_settings_value(TokenStream<Co
if (!opentype_tag || !number || tag_tokens.has_next_token())
return nullptr;
axis_tags_map.set(opentype_tag->string_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."

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
* Copyright (c) 2024-2025, Sam Atkins <sam@ladybird.org>
*
* 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();
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
* Copyright (c) 2024-2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -16,9 +16,13 @@ namespace Web::CSS {
// and the `<opentype-tag> <number>` construct for `font-variation-settings`.
class OpenTypeTaggedStyleValue : public StyleValueWithDefaultOperators<OpenTypeTaggedStyleValue> {
public:
static ValueComparingNonnullRefPtr<OpenTypeTaggedStyleValue> create(FlyString tag, ValueComparingNonnullRefPtr<CSSStyleValue> value)
enum class Mode {
FontFeatureSettings,
FontVariationSettings,
};
static ValueComparingNonnullRefPtr<OpenTypeTaggedStyleValue> create(Mode mode, FlyString tag, ValueComparingNonnullRefPtr<CSSStyleValue> 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<CSSStyleValue> value)
explicit OpenTypeTaggedStyleValue(Mode mode, FlyString tag, ValueComparingNonnullRefPtr<CSSStyleValue> value)
: StyleValueWithDefaultOperators(Type::OpenTypeTagged)
, m_mode(mode)
, m_tag(move(tag))
, m_value(move(value))
{
}
Mode m_mode;
FlyString m_tag;
ValueComparingNonnullRefPtr<CSSStyleValue> m_value;
};

View file

@ -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))'

View file

@ -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