mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-17 05:29:56 +00:00
LibWeb: Don't deduplicate font-variation-settings
values at parse time
We now only deduplicate and sort the computed value of the `font-variation-settings` property.
This commit is contained in:
parent
6cb0f0fbcd
commit
83ad5ce8a2
Notes:
github-actions[bot]
2025-09-26 10:22:16 +00:00
Author: https://github.com/tcl3
Commit: 83ad5ce8a2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6245
Reviewed-by: https://github.com/AtkinsSJ ✅
4 changed files with 38 additions and 20 deletions
|
@ -3098,11 +3098,7 @@ RefPtr<StyleValue const> Parser::parse_font_variation_settings_value(TokenStream
|
||||||
auto transaction = tokens.begin_transaction();
|
auto transaction = tokens.begin_transaction();
|
||||||
auto tag_values = parse_a_comma_separated_list_of_component_values(tokens);
|
auto tag_values = parse_a_comma_separated_list_of_component_values(tokens);
|
||||||
|
|
||||||
// "If the same axis name appears more than once, the value associated with the last appearance supersedes any
|
StyleValueVector axis_tags;
|
||||||
// previous value for that axis. This deduplication is observable by accessing the computed value of this property."
|
|
||||||
// So, we deduplicate them here using a HashSet.
|
|
||||||
|
|
||||||
OrderedHashMap<FlyString, NonnullRefPtr<OpenTypeTaggedStyleValue const>> axis_tags_map;
|
|
||||||
for (auto const& values : tag_values) {
|
for (auto const& values : tag_values) {
|
||||||
TokenStream tag_tokens { values };
|
TokenStream tag_tokens { values };
|
||||||
tag_tokens.discard_whitespace();
|
tag_tokens.discard_whitespace();
|
||||||
|
@ -3114,19 +3110,9 @@ RefPtr<StyleValue const> Parser::parse_font_variation_settings_value(TokenStream
|
||||||
if (!opentype_tag || !number || tag_tokens.has_next_token())
|
if (!opentype_tag || !number || tag_tokens.has_next_token())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
axis_tags_map.set(opentype_tag->string_value(), OpenTypeTaggedStyleValue::create(OpenTypeTaggedStyleValue::Mode::FontVariationSettings, opentype_tag->string_value(), number.release_nonnull()));
|
axis_tags.append(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."
|
|
||||||
StyleValueVector axis_tags;
|
|
||||||
axis_tags.ensure_capacity(axis_tags_map.size());
|
|
||||||
for (auto const& [key, axis_tag] : axis_tags_map)
|
|
||||||
axis_tags.append(axis_tag);
|
|
||||||
|
|
||||||
quick_sort(axis_tags, [](auto& a, auto& b) {
|
|
||||||
return a->as_open_type_tagged().tag() < b->as_open_type_tagged().tag();
|
|
||||||
});
|
|
||||||
|
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
return StyleValueList::create(move(axis_tags), StyleValueList::Separator::Comma);
|
return StyleValueList::create(move(axis_tags), StyleValueList::Separator::Comma);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/MathDepthStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/MathDepthStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
||||||
|
#include <LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/PendingSubstitutionStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/PendingSubstitutionStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
||||||
|
@ -3211,6 +3212,8 @@ NonnullRefPtr<StyleValue const> StyleComputer::compute_value_of_property(Propert
|
||||||
return compute_border_or_outline_width(specified_value, get_property_specified_value(PropertyID::BorderTopStyle), computation_context);
|
return compute_border_or_outline_width(specified_value, get_property_specified_value(PropertyID::BorderTopStyle), computation_context);
|
||||||
case PropertyID::OutlineWidth:
|
case PropertyID::OutlineWidth:
|
||||||
return compute_border_or_outline_width(specified_value, get_property_specified_value(PropertyID::OutlineStyle), computation_context);
|
return compute_border_or_outline_width(specified_value, get_property_specified_value(PropertyID::OutlineStyle), computation_context);
|
||||||
|
case PropertyID::FontVariationSettings:
|
||||||
|
return compute_font_variation_settings(specified_value);
|
||||||
case PropertyID::LetterSpacing:
|
case PropertyID::LetterSpacing:
|
||||||
case PropertyID::WordSpacing:
|
case PropertyID::WordSpacing:
|
||||||
if (specified_value->to_keyword() == Keyword::Normal)
|
if (specified_value->to_keyword() == Keyword::Normal)
|
||||||
|
@ -3257,6 +3260,35 @@ NonnullRefPtr<StyleValue const> StyleComputer::compute_animation_name(NonnullRef
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NonnullRefPtr<StyleValue const> StyleComputer::compute_font_variation_settings(NonnullRefPtr<StyleValue const> const& specified_value)
|
||||||
|
{
|
||||||
|
if (specified_value->is_keyword())
|
||||||
|
return specified_value;
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def
|
||||||
|
// If the same axis name appears more than once, the value associated with the last appearance supersedes any
|
||||||
|
// previous value for that axis. This deduplication is observable by accessing the computed value of this property."
|
||||||
|
// So, we deduplicate them here using a HashSet.
|
||||||
|
auto const& value_list = specified_value->as_value_list();
|
||||||
|
OrderedHashMap<FlyString, NonnullRefPtr<OpenTypeTaggedStyleValue const>> axis_tags_map;
|
||||||
|
for (size_t i = 0; i < value_list.values().size(); i++) {
|
||||||
|
auto const& axis_tag = value_list.values().at(i)->as_open_type_tagged();
|
||||||
|
axis_tags_map.set(axis_tag.tag(), axis_tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
StyleValueVector axis_tags;
|
||||||
|
|
||||||
|
// The computed value contains the de-duplicated axis names, sorted in ascending order by code unit.
|
||||||
|
for (auto const& [key, axis_tag] : axis_tags_map)
|
||||||
|
axis_tags.append(axis_tag);
|
||||||
|
|
||||||
|
quick_sort(axis_tags, [](auto& a, auto& b) {
|
||||||
|
return a->as_open_type_tagged().tag() < b->as_open_type_tagged().tag();
|
||||||
|
});
|
||||||
|
|
||||||
|
return StyleValueList::create(move(axis_tags), StyleValueList::Separator::Comma);
|
||||||
|
}
|
||||||
|
|
||||||
NonnullRefPtr<StyleValue const> StyleComputer::compute_border_or_outline_width(NonnullRefPtr<StyleValue const> const& specified_value, NonnullRefPtr<StyleValue const> const& style_specified_value, PropertyValueComputationContext const& computation_context)
|
NonnullRefPtr<StyleValue const> StyleComputer::compute_border_or_outline_width(NonnullRefPtr<StyleValue const> const& specified_value, NonnullRefPtr<StyleValue const> const& style_specified_value, PropertyValueComputationContext const& computation_context)
|
||||||
{
|
{
|
||||||
// https://drafts.csswg.org/css-backgrounds/#border-width
|
// https://drafts.csswg.org/css-backgrounds/#border-width
|
||||||
|
|
|
@ -209,6 +209,7 @@ public:
|
||||||
static NonnullRefPtr<StyleValue const> compute_font_style(NonnullRefPtr<StyleValue const> const& specified_value, Length::ResolutionContext const& parent_length_resolution_context);
|
static NonnullRefPtr<StyleValue const> compute_font_style(NonnullRefPtr<StyleValue const> const& specified_value, Length::ResolutionContext const& parent_length_resolution_context);
|
||||||
static NonnullRefPtr<StyleValue const> compute_font_weight(NonnullRefPtr<StyleValue const> const& specified_value, double inherited_font_weight, Length::ResolutionContext const& parent_length_resolution_context);
|
static NonnullRefPtr<StyleValue const> compute_font_weight(NonnullRefPtr<StyleValue const> const& specified_value, double inherited_font_weight, Length::ResolutionContext const& parent_length_resolution_context);
|
||||||
static NonnullRefPtr<StyleValue const> compute_font_width(NonnullRefPtr<StyleValue const> const& specified_value, Length::ResolutionContext const& parent_length_resolution_context);
|
static NonnullRefPtr<StyleValue const> compute_font_width(NonnullRefPtr<StyleValue const> const& specified_value, Length::ResolutionContext const& parent_length_resolution_context);
|
||||||
|
static NonnullRefPtr<StyleValue const> compute_font_variation_settings(NonnullRefPtr<StyleValue const> const& specified_value);
|
||||||
static NonnullRefPtr<StyleValue const> compute_line_height(NonnullRefPtr<StyleValue const> const& specified_value, Length::ResolutionContext const&);
|
static NonnullRefPtr<StyleValue const> compute_line_height(NonnullRefPtr<StyleValue const> const& specified_value, Length::ResolutionContext const&);
|
||||||
static NonnullRefPtr<StyleValue const> compute_opacity(NonnullRefPtr<StyleValue const> const& specified_value, PropertyValueComputationContext const&);
|
static NonnullRefPtr<StyleValue const> compute_opacity(NonnullRefPtr<StyleValue const> const& specified_value, PropertyValueComputationContext const&);
|
||||||
static NonnullRefPtr<StyleValue const> compute_text_underline_offset(NonnullRefPtr<StyleValue const> const& specified_value, PropertyValueComputationContext const&);
|
static NonnullRefPtr<StyleValue const> compute_text_underline_offset(NonnullRefPtr<StyleValue const> const& specified_value, PropertyValueComputationContext const&);
|
||||||
|
|
|
@ -2,12 +2,11 @@ Harness status: OK
|
||||||
|
|
||||||
Found 7 tests
|
Found 7 tests
|
||||||
|
|
||||||
5 Pass
|
7 Pass
|
||||||
2 Fail
|
|
||||||
Pass e.style['font-variation-settings'] = "normal" should set the property value
|
Pass e.style['font-variation-settings'] = "normal" should set the property value
|
||||||
Pass e.style['font-variation-settings'] = "\"wght\" 700" should set the property value
|
Pass e.style['font-variation-settings'] = "\"wght\" 700" should set the property value
|
||||||
Pass e.style['font-variation-settings'] = "'wght' 700" should set the property value
|
Pass e.style['font-variation-settings'] = "'wght' 700" should set the property value
|
||||||
Fail e.style['font-variation-settings'] = "\"wght\" 700, \"XHGT\" 0.7" should set the property value
|
Pass e.style['font-variation-settings'] = "\"wght\" 700, \"XHGT\" 0.7" should set the property value
|
||||||
Pass e.style['font-variation-settings'] = "\"a cd\" 0.5" should set the property value
|
Pass e.style['font-variation-settings'] = "\"a cd\" 0.5" should set the property value
|
||||||
Pass e.style['font-variation-settings'] = "\"ab@d\" 0.5" should set the property value
|
Pass e.style['font-variation-settings'] = "\"ab@d\" 0.5" should set the property value
|
||||||
Fail e.style['font-variation-settings'] = "'wght' 1e3, 'slnt' -450.0e-1" should set the property value
|
Pass e.style['font-variation-settings'] = "'wght' 1e3, 'slnt' -450.0e-1" should set the property value
|
Loading…
Add table
Add a link
Reference in a new issue