diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-02-11 12:32:55 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-11 21:38:27 +0100 |
commit | 326a5a82ebef1146def6e04f1930ef8c054a59bf (patch) | |
tree | b79d3603cf57b75c89a822f158611af8aab24587 | |
parent | 49fe232bc78caa7900b95f80d6823fee2cc30781 (diff) | |
download | serenity-326a5a82ebef1146def6e04f1930ef8c054a59bf.zip |
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. :^)
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/SVGPathBox.cpp | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/SVGPathBox.h | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGGeometryElement.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGGeometryElement.h | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/SVG/SVGPathElement.h | 4 |
6 files changed, 22 insertions, 18 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/SVGPathBox.cpp b/Userland/Libraries/LibWeb/Layout/SVGPathBox.cpp index 01c25706da..f9bc85b6e9 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGPathBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGPathBox.cpp @@ -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); diff --git a/Userland/Libraries/LibWeb/Layout/SVGPathBox.h b/Userland/Libraries/LibWeb/Layout/SVGPathBox.h index 9521c4cc03..624826d9e0 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGPathBox.h +++ b/Userland/Libraries/LibWeb/Layout/SVGPathBox.h @@ -7,17 +7,17 @@ #pragma once #include <LibWeb/Layout/SVGGraphicsBox.h> -#include <LibWeb/SVG/SVGPathElement.h> +#include <LibWeb/SVG/SVGGeometryElement.h> namespace Web::Layout { class SVGPathBox final : public SVGGraphicsBox { public: - SVGPathBox(DOM::Document&, SVG::SVGPathElement&, NonnullRefPtr<CSS::StyleProperties>); + SVGPathBox(DOM::Document&, SVG::SVGGeometryElement&, NonnullRefPtr<CSS::StyleProperties>); virtual ~SVGPathBox() override = default; - SVG::SVGPathElement& dom_node() { return verify_cast<SVG::SVGPathElement>(SVGGraphicsBox::dom_node()); } - SVG::SVGPathElement const& dom_node() const { return verify_cast<SVG::SVGPathElement>(SVGGraphicsBox::dom_node()); } + SVG::SVGGeometryElement& dom_node() { return verify_cast<SVG::SVGGeometryElement>(SVGGraphicsBox::dom_node()); } + SVG::SVGGeometryElement const& dom_node() const { return verify_cast<SVG::SVGGeometryElement>(SVGGraphicsBox::dom_node()); } virtual void paint(PaintContext& context, PaintPhase phase) override; diff --git a/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.cpp index 7228ec22f9..eed13009a7 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <LibWeb/Layout/SVGPathBox.h> #include <LibWeb/SVG/SVGGeometryElement.h> namespace Web::SVG { @@ -13,4 +14,9 @@ SVGGeometryElement::SVGGeometryElement(DOM::Document& document, QualifiedName qu { } +RefPtr<Layout::Node> SVGGeometryElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style) +{ + return adopt_ref(*new Layout::SVGPathBox(document(), *this, move(style))); +} + } diff --git a/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.h b/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.h index fa8dc4cf7b..8dd3776775 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.h +++ b/Userland/Libraries/LibWeb/SVG/SVGGeometryElement.h @@ -10,10 +10,15 @@ namespace Web::SVG { +// https://svgwg.org/svg2-draft/types.html#InterfaceSVGGeometryElement class SVGGeometryElement : public SVGGraphicsElement { public: using WrapperType = Bindings::SVGGeometryElementWrapper; + virtual RefPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override; + + virtual Gfx::Path& get_path() = 0; + protected: SVGGeometryElement(DOM::Document& document, QualifiedName qualified_name); }; diff --git a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp index 03530a8110..58b5104dfe 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGPathElement.cpp @@ -443,11 +443,6 @@ SVGPathElement::SVGPathElement(DOM::Document& document, QualifiedName qualified_ { } -RefPtr<Layout::Node> SVGPathElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style) -{ - return adopt_ref(*new Layout::SVGPathBox(document(), *this, move(style))); -} - void SVGPathElement::parse_attribute(const FlyString& name, const String& value) { SVGGeometryElement::parse_attribute(name, value); diff --git a/Userland/Libraries/LibWeb/SVG/SVGPathElement.h b/Userland/Libraries/LibWeb/SVG/SVGPathElement.h index 0e90900892..8fb31d51f0 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGPathElement.h +++ b/Userland/Libraries/LibWeb/SVG/SVGPathElement.h @@ -89,11 +89,9 @@ public: SVGPathElement(DOM::Document&, QualifiedName); virtual ~SVGPathElement() override = default; - virtual RefPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override; - virtual void parse_attribute(const FlyString& name, const String& value) override; - Gfx::Path& get_path(); + virtual Gfx::Path& get_path() override; private: Vector<PathInstruction> m_instructions; |