| 
									
										
										
										
											2022-02-11 17:36:05 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 18:04:39 -06:00
										 |  |  | #include <LibWeb/Bindings/Intrinsics.h>
 | 
					
						
							| 
									
										
										
										
											2022-02-11 17:36:05 +00:00
										 |  |  | #include <LibWeb/SVG/AttributeNames.h>
 | 
					
						
							|  |  |  | #include <LibWeb/SVG/AttributeParser.h>
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  | #include <LibWeb/SVG/SVGPolygonElement.h>
 | 
					
						
							| 
									
										
										
										
											2022-02-11 17:36:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::SVG { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 21:00:52 +01:00
										 |  |  | SVGPolygonElement::SVGPolygonElement(DOM::Document& document, DOM::QualifiedName qualified_name) | 
					
						
							| 
									
										
										
										
											2022-02-11 17:36:05 +00:00
										 |  |  |     : SVGGeometryElement(document, qualified_name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SVGPolygonElement::initialize(JS::Realm& realm) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Base::initialize(realm); | 
					
						
							|  |  |  |     set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGPolygonElementPrototype>(realm, "SVGPolygonElement")); | 
					
						
							| 
									
										
										
										
											2022-02-11 17:36:05 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-08 19:23:00 -05:00
										 |  |  | void SVGPolygonElement::parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) | 
					
						
							| 
									
										
										
										
											2022-02-11 17:36:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     SVGGeometryElement::parse_attribute(name, value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (name == SVG::AttributeNames::points) { | 
					
						
							|  |  |  |         m_points = AttributeParser::parse_points(value); | 
					
						
							|  |  |  |         m_path.clear(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Gfx::Path& SVGPolygonElement::get_path() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_path.has_value()) | 
					
						
							|  |  |  |         return m_path.value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Gfx::Path path; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_points.is_empty()) { | 
					
						
							|  |  |  |         m_path = move(path); | 
					
						
							|  |  |  |         return m_path.value(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 1. perform an absolute moveto operation to the first coordinate pair in the list of points
 | 
					
						
							|  |  |  |     path.move_to(m_points.first()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 2. for each subsequent coordinate pair, perform an absolute lineto operation to that coordinate pair.
 | 
					
						
							|  |  |  |     for (size_t point_index = 1; point_index < m_points.size(); ++point_index) | 
					
						
							|  |  |  |         path.line_to(m_points[point_index]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 3. perform a closepath command
 | 
					
						
							|  |  |  |     path.close(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_path = move(path); | 
					
						
							|  |  |  |     return m_path.value(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |