LibWeb: Plumbing for svg stroke-dasharray

This commit is contained in:
Nico Weber 2024-11-20 19:23:10 -05:00 committed by Alexander Kalenik
commit 94b97aa365
Notes: github-actions[bot] 2024-11-21 17:57:47 +00:00
10 changed files with 277 additions and 172 deletions

View file

@ -855,6 +855,24 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
computed_values.set_fill_opacity(computed_style.fill_opacity());
if (auto const& stroke_dasharray_or_none = computed_style.property(CSS::PropertyID::StrokeDasharray); !stroke_dasharray_or_none.is_keyword()) {
auto const& stroke_dasharray = stroke_dasharray_or_none.as_value_list();
Vector<Variant<CSS::LengthPercentage, CSS::NumberOrCalculated>> dashes;
for (auto const& value : stroke_dasharray.values()) {
if (value->is_length())
dashes.append(CSS::LengthPercentage { value->as_length().length() });
else if (value->is_percentage())
dashes.append(CSS::LengthPercentage { value->as_percentage().percentage() });
else if (value->is_math())
dashes.append(CSS::LengthPercentage { value->as_math() });
else if (value->is_number())
dashes.append(CSS::NumberOrCalculated { value->as_number().number() });
}
computed_values.set_stroke_dasharray(move(dashes));
}
auto const& stroke_dashoffset = computed_style.property(CSS::PropertyID::StrokeDashoffset);
// FIXME: Converting to pixels isn't really correct - values should be in "user units"
// https://svgwg.org/svg2-draft/coords.html#TermUserUnits