| 
									
										
										
										
											2024-05-25 23:06:47 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2024, MacDue <macdue@dueutil.tech> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BasicShapeStyleValue.h"
 | 
					
						
							| 
									
										
										
										
											2024-08-20 17:27:08 +02:00
										 |  |  | #include <LibGfx/Path.h>
 | 
					
						
							| 
									
										
										
										
											2024-05-25 23:06:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-20 17:27:08 +02:00
										 |  |  | Gfx::Path Polygon::to_path(CSSPixelRect reference_box, Layout::Node const& node) const | 
					
						
							| 
									
										
										
										
											2024-05-25 23:06:47 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-08-20 17:27:08 +02:00
										 |  |  |     Gfx::Path path; | 
					
						
							| 
									
										
										
										
											2024-05-25 23:06:47 +01:00
										 |  |  |     bool first = true; | 
					
						
							|  |  |  |     for (auto const& point : points) { | 
					
						
							|  |  |  |         Gfx::FloatPoint resolved_point { | 
					
						
							|  |  |  |             static_cast<float>(point.x.to_px(node, reference_box.width())), | 
					
						
							|  |  |  |             static_cast<float>(point.y.to_px(node, reference_box.height())) | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         if (first) | 
					
						
							|  |  |  |             path.move_to(resolved_point); | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             path.line_to(resolved_point); | 
					
						
							|  |  |  |         first = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     path.close(); | 
					
						
							|  |  |  |     return path; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String Polygon::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     StringBuilder builder; | 
					
						
							|  |  |  |     builder.append("polygon("sv); | 
					
						
							|  |  |  |     bool first = true; | 
					
						
							|  |  |  |     for (auto const& point : points) { | 
					
						
							|  |  |  |         if (!first) | 
					
						
							|  |  |  |             builder.append(','); | 
					
						
							|  |  |  |         builder.appendff("{} {}", point.x, point.y); | 
					
						
							|  |  |  |         first = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     builder.append(')'); | 
					
						
							|  |  |  |     return MUST(builder.to_string()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BasicShapeStyleValue::~BasicShapeStyleValue() = default; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-20 17:27:08 +02:00
										 |  |  | Gfx::Path BasicShapeStyleValue::to_path(CSSPixelRect reference_box, Layout::Node const& node) const | 
					
						
							| 
									
										
										
										
											2024-05-25 23:06:47 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_basic_shape.visit([&](auto const& shape) { | 
					
						
							|  |  |  |         return shape.to_path(reference_box, node); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String BasicShapeStyleValue::to_string() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_basic_shape.visit([](auto const& shape) { | 
					
						
							|  |  |  |         return shape.to_string(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |