LibWeb: Implement the SVG clip-rule attribute

This controls the fill rule used when rasterizing `<clipPath>` elements.
This commit is contained in:
MacDue 2024-05-12 20:19:43 +01:00 committed by Sam Atkins
commit 6c9069fa5d
Notes: sideshowbarker 2024-07-16 22:34:39 +09:00
13 changed files with 74 additions and 8 deletions

View file

@ -158,6 +158,7 @@ void SVGGraphicsElement::apply_presentational_hints(CSS::StyleProperties& style)
NamedPropertyID(CSS::PropertyID::Mask),
NamedPropertyID(CSS::PropertyID::MaskType),
NamedPropertyID(CSS::PropertyID::ClipPath),
NamedPropertyID(CSS::PropertyID::ClipRule),
};
CSS::Parser::ParsingContext parsing_context { document(), CSS::Parser::ParsingContext::Mode::SVGPresentationAttribute };
@ -172,11 +173,9 @@ void SVGGraphicsElement::apply_presentational_hints(CSS::StyleProperties& style)
});
}
Optional<FillRule> SVGGraphicsElement::fill_rule() const
static FillRule to_svg_fill_rule(CSS::FillRule fill_rule)
{
if (!layout_node())
return {};
switch (layout_node()->computed_values().fill_rule()) {
switch (fill_rule) {
case CSS::FillRule::Nonzero:
return FillRule::Nonzero;
case CSS::FillRule::Evenodd:
@ -186,6 +185,20 @@ Optional<FillRule> SVGGraphicsElement::fill_rule() const
}
}
Optional<FillRule> SVGGraphicsElement::fill_rule() const
{
if (!layout_node())
return {};
return to_svg_fill_rule(layout_node()->computed_values().fill_rule());
}
Optional<ClipRule> SVGGraphicsElement::clip_rule() const
{
if (!layout_node())
return {};
return to_svg_fill_rule(layout_node()->computed_values().clip_rule());
}
Optional<Gfx::Color> SVGGraphicsElement::fill_color() const
{
if (!layout_node())