| 
									
										
										
										
											2022-02-11 17:28:24 +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>
 | 
					
						
							| 
									
										
										
										
											2024-04-27 12:09:58 +12:00
										 |  |  | #include <LibWeb/Bindings/SVGPolylineElementPrototype.h>
 | 
					
						
							| 
									
										
										
										
											2022-02-11 17:28:24 +00:00
										 |  |  | #include <LibWeb/SVG/AttributeNames.h>
 | 
					
						
							|  |  |  | #include <LibWeb/SVG/AttributeParser.h>
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  | #include <LibWeb/SVG/SVGPolylineElement.h>
 | 
					
						
							| 
									
										
										
										
											2022-02-11 17:28:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::SVG { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  | JS_DEFINE_ALLOCATOR(SVGPolylineElement); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 21:00:52 +01:00
										 |  |  | SVGPolylineElement::SVGPolylineElement(DOM::Document& document, DOM::QualifiedName qualified_name) | 
					
						
							| 
									
										
										
										
											2022-02-11 17:28:24 +00:00
										 |  |  |     : SVGGeometryElement(document, qualified_name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  | void SVGPolylineElement::initialize(JS::Realm& realm) | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |     Base::initialize(realm); | 
					
						
							| 
									
										
										
										
											2024-03-16 13:13:08 +01:00
										 |  |  |     WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGPolylineElement); | 
					
						
							| 
									
										
										
										
											2022-02-11 17:28:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-19 18:10:36 +13:00
										 |  |  | void SVGPolylineElement::attribute_changed(FlyString const& name, Optional<String> const& value) | 
					
						
							| 
									
										
										
										
											2022-02-11 17:28:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-07-03 17:08:37 +02:00
										 |  |  |     SVGGeometryElement::attribute_changed(name, value); | 
					
						
							| 
									
										
										
										
											2022-02-11 17:28:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-03 20:15:06 +00:00
										 |  |  |     if (name == SVG::AttributeNames::points) | 
					
						
							| 
									
										
										
										
											2023-11-19 18:10:36 +13:00
										 |  |  |         m_points = AttributeParser::parse_points(value.value_or(String {})); | 
					
						
							| 
									
										
										
										
											2022-02-11 17:28:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-03 20:15:06 +00:00
										 |  |  | Gfx::Path SVGPolylineElement::get_path(CSSPixelSize) | 
					
						
							| 
									
										
										
										
											2022-02-11 17:28:24 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     Gfx::Path path; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-03 20:15:06 +00:00
										 |  |  |     if (m_points.is_empty()) | 
					
						
							|  |  |  |         return path; | 
					
						
							| 
									
										
										
										
											2022-02-11 17:28:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // 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]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-03 20:15:06 +00:00
										 |  |  |     return path; | 
					
						
							| 
									
										
										
										
											2022-02-11 17:28:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |