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

This commit is contained in:
Sam Atkins 2025-04-04 12:14:22 +01:00
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;
};