/src/serenity/Userland/Libraries/LibWeb/SVG/SVGPolygonElement.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/Bindings/Intrinsics.h> |
8 | | #include <LibWeb/Bindings/SVGPolygonElementPrototype.h> |
9 | | #include <LibWeb/SVG/AttributeNames.h> |
10 | | #include <LibWeb/SVG/AttributeParser.h> |
11 | | #include <LibWeb/SVG/SVGPolygonElement.h> |
12 | | |
13 | | namespace Web::SVG { |
14 | | |
15 | | JS_DEFINE_ALLOCATOR(SVGPolygonElement); |
16 | | |
17 | | SVGPolygonElement::SVGPolygonElement(DOM::Document& document, DOM::QualifiedName qualified_name) |
18 | 0 | : SVGGeometryElement(document, qualified_name) |
19 | 0 | { |
20 | 0 | } |
21 | | |
22 | | void SVGPolygonElement::initialize(JS::Realm& realm) |
23 | 0 | { |
24 | 0 | Base::initialize(realm); |
25 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGPolygonElement); |
26 | 0 | } |
27 | | |
28 | | void SVGPolygonElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) |
29 | 0 | { |
30 | 0 | SVGGeometryElement::attribute_changed(name, old_value, value); |
31 | |
|
32 | 0 | if (name == SVG::AttributeNames::points) |
33 | 0 | m_points = AttributeParser::parse_points(value.value_or(String {})); |
34 | 0 | } |
35 | | |
36 | | Gfx::Path SVGPolygonElement::get_path(CSSPixelSize) |
37 | 0 | { |
38 | 0 | Gfx::Path path; |
39 | |
|
40 | 0 | if (m_points.is_empty()) |
41 | 0 | return path; |
42 | | |
43 | | // 1. perform an absolute moveto operation to the first coordinate pair in the list of points |
44 | 0 | path.move_to(m_points.first()); |
45 | | |
46 | | // 2. for each subsequent coordinate pair, perform an absolute lineto operation to that coordinate pair. |
47 | 0 | for (size_t point_index = 1; point_index < m_points.size(); ++point_index) |
48 | 0 | path.line_to(m_points[point_index]); |
49 | | |
50 | | // 3. perform a closepath command |
51 | 0 | path.close(); |
52 | |
|
53 | 0 | return path; |
54 | 0 | } |
55 | | |
56 | | } |