LibWeb: Simplify handling of font-variation-settings

Since we resolve any relative lengths at compute time there's no need
for the value to be passed around as a `NumberOrCalculated` and we can
just resolve it within `ComputedProperties::font_variation_settings`.

The only place this is used it is used with value_or so there's no need
to return it is an `Optional`.

This is only used for loading fonts (which occurs during style
computation) so there's no need to store it in `ComputedValues`
This commit is contained in:
Callum Law 2025-11-06 15:55:21 +13:00 committed by Sam Atkins
parent 4fb28539a9
commit dfa47d9ed6
Notes: github-actions[bot] 2025-12-05 10:04:40 +00:00
7 changed files with 14 additions and 23 deletions

View file

@ -1811,7 +1811,7 @@ CSSPixels StyleComputer::relative_size_mapping(RelativeSize relative_size, CSSPi
VERIFY_NOT_REACHED();
}
RefPtr<Gfx::FontCascadeList const> StyleComputer::compute_font_for_style_values(StyleValue const& font_family, CSSPixels const& font_size, int slope, double font_weight, Percentage const& font_width, HashMap<FlyString, NumberOrCalculated> const& font_variation_settings, Length::ResolutionContext const& length_resolution_context) const
RefPtr<Gfx::FontCascadeList const> StyleComputer::compute_font_for_style_values(StyleValue const& font_family, CSSPixels const& font_size, int slope, double font_weight, Percentage const& font_width, HashMap<FlyString, double> const& font_variation_settings) const
{
// FIXME: We round to int here as that is what is expected by our font infrastructure below
auto width = round_to<int>(font_width.value());
@ -1836,21 +1836,14 @@ RefPtr<Gfx::FontCascadeList const> StyleComputer::compute_font_for_style_values(
Gfx::FontVariationSettings variation;
variation.set_weight(font_weight);
CalculationResolutionContext context {
.length_resolution_context = length_resolution_context,
};
for (auto const& [tag_string, value] : font_variation_settings) {
auto string_view = tag_string.bytes_as_string_view();
if (string_view.length() != 4)
continue;
auto tag = Gfx::FourCC(string_view.characters_without_null_termination());
auto resolved_value = value.resolved(context);
if (!resolved_value.has_value())
continue;
variation.axes.set(tag, resolved_value.release_value());
variation.axes.set(tag, value);
}
for (auto const& loader : loaders) {
@ -1992,7 +1985,7 @@ void StyleComputer::compute_font(ComputedProperties& style, Optional<DOM::Abstra
auto const& font_family = style.property(CSS::PropertyID::FontFamily);
auto font_list = compute_font_for_style_values(font_family, style.font_size(), style.font_slope(), style.font_weight(), style.font_width(), style.font_variation_settings().value_or({}), font_computation_context.length_resolution_context);
auto font_list = compute_font_for_style_values(font_family, style.font_size(), style.font_slope(), style.font_weight(), style.font_width(), style.font_variation_settings());
VERIFY(font_list);
VERIFY(!font_list->is_empty());