1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:17:44 +00:00

LibWeb: Move SVGPathElement methods into SVGGeometryElement

From the spec:

> Interface SVGGeometryElement represents SVG elements whose rendering
> is defined by geometry with an equivalent path, and which can be
> filled and stroked. This includes paths and the basic shapes.

- https://svgwg.org/svg2-draft/types.html#InterfaceSVGGeometryElement

Making them all create an SVGPathBox, and return a Path from get_path(),
means we can implement the "basic shapes" using the path system we
already have. :^)
This commit is contained in:
Sam Atkins 2022-02-11 12:32:55 +00:00 committed by Andreas Kling
parent 49fe232bc7
commit 326a5a82eb
6 changed files with 22 additions and 18 deletions

View file

@ -11,7 +11,7 @@
namespace Web::Layout {
SVGPathBox::SVGPathBox(DOM::Document& document, SVG::SVGPathElement& element, NonnullRefPtr<CSS::StyleProperties> properties)
SVGPathBox::SVGPathBox(DOM::Document& document, SVG::SVGGeometryElement& element, NonnullRefPtr<CSS::StyleProperties> properties)
: SVGGraphicsBox(document, element, properties)
{
}
@ -26,8 +26,8 @@ void SVGPathBox::paint(PaintContext& context, PaintPhase phase)
if (phase != PaintPhase::Foreground)
return;
auto& path_element = dom_node();
auto& path = path_element.get_path();
auto& geometry_element = dom_node();
auto& path = geometry_element.get_path();
Gfx::AntiAliasingPainter painter { context.painter() };
auto& svg_context = context.svg_context();
@ -35,7 +35,7 @@ void SVGPathBox::paint(PaintContext& context, PaintPhase phase)
auto offset = absolute_position();
painter.translate(offset);
if (auto fill_color = path_element.fill_color().value_or(svg_context.fill_color()); fill_color.alpha() > 0) {
if (auto fill_color = geometry_element.fill_color().value_or(svg_context.fill_color()); fill_color.alpha() > 0) {
// We need to fill the path before applying the stroke, however the filled
// path must be closed, whereas the stroke path may not necessary be closed.
// Copy the path and close it for filling, but use the previous path for stroke
@ -49,11 +49,11 @@ void SVGPathBox::paint(PaintContext& context, PaintPhase phase)
Gfx::Painter::WindingRule::EvenOdd);
}
if (auto stroke_color = path_element.stroke_color().value_or(svg_context.stroke_color()); stroke_color.alpha() > 0) {
if (auto stroke_color = geometry_element.stroke_color().value_or(svg_context.stroke_color()); stroke_color.alpha() > 0) {
painter.stroke_path(
path,
stroke_color,
path_element.stroke_width().value_or(svg_context.stroke_width()));
geometry_element.stroke_width().value_or(svg_context.stroke_width()));
}
painter.translate(-offset);