LibWeb/SVG: Resolve stroke URI reference values

This commit is contained in:
Tim Ledbetter 2025-08-20 20:41:17 +01:00 committed by Jelle Raaijmakers
parent 05432d7157
commit 030e670fcb
2 changed files with 18 additions and 7 deletions

View File

@ -180,13 +180,19 @@ Optional<Gfx::Color> SVGGraphicsElement::stroke_color() const
{
if (!layout_node())
return {};
// FIXME: In the working-draft spec, `stroke` is intended to be a shorthand, with `stroke-color`
// being what we actually want to use. But that's not final or widely supported yet.
return layout_node()->computed_values().stroke().map([](auto& paint) -> Gfx::Color {
if (!paint.is_color())
return Color::Black;
return paint.as_color();
});
auto paint = layout_node()->computed_values().stroke();
if (!paint.has_value())
return {};
if (paint->is_url()) {
if (auto referenced_element = try_resolve_url_to<SVGGraphicsElement const>(paint->as_url()))
return referenced_element->stroke_color();
return {};
}
return paint->as_color();
}
Optional<float> SVGGraphicsElement::fill_opacity() const

View File

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:h="http://www.w3.org/1999/xhtml" stroke="red" stroke-width="50">
<h:link rel="match" href="../../../../../expected/wpt-import/svg/pservers/reftests/reference/green-100x100.svg"/>
<rect x="25" y="25" width="50" height="50" fill="none" stroke="green"/>
<rect x="25" y="25" width="50" height="50" fill="none" stroke="url(#nonexisting)"/>
</svg>

After

Width:  |  Height:  |  Size: 394 B