| 
									
										
										
										
											2020-07-22 15:17:39 -07:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-04-22 16:53:07 -07:00
										 |  |  |  * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org> | 
					
						
							| 
									
										
										
										
											2022-01-24 15:43:44 +00:00
										 |  |  |  * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org> | 
					
						
							| 
									
										
										
										
											2023-04-10 12:25:40 +01:00
										 |  |  |  * Copyright (c) 2023, MacDue <macdue@dueutil.tech> | 
					
						
							| 
									
										
										
										
											2023-06-20 12:57:54 +02:00
										 |  |  |  * Copyright (c) 2023, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-07-22 15:17:39 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-07-22 15:17:39 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-30 17:16:16 -06:00
										 |  |  | #include <LibWeb/Bindings/Intrinsics.h>
 | 
					
						
							| 
									
										
										
										
											2022-01-24 15:43:44 +00:00
										 |  |  | #include <LibWeb/CSS/Parser/Parser.h>
 | 
					
						
							| 
									
										
										
										
											2023-04-23 01:31:17 +01:00
										 |  |  | #include <LibWeb/DOM/Document.h>
 | 
					
						
							| 
									
										
										
										
											2022-04-10 20:16:47 +02:00
										 |  |  | #include <LibWeb/Layout/Node.h>
 | 
					
						
							| 
									
										
										
										
											2023-06-20 12:57:54 +02:00
										 |  |  | #include <LibWeb/SVG/AttributeNames.h>
 | 
					
						
							| 
									
										
										
										
											2023-04-10 12:25:40 +01:00
										 |  |  | #include <LibWeb/SVG/AttributeParser.h>
 | 
					
						
							| 
									
										
										
										
											2023-04-23 01:31:17 +01:00
										 |  |  | #include <LibWeb/SVG/SVGGradientElement.h>
 | 
					
						
							| 
									
										
										
										
											2020-07-23 09:44:42 -07:00
										 |  |  | #include <LibWeb/SVG/SVGGraphicsElement.h>
 | 
					
						
							| 
									
										
										
										
											2023-09-10 14:10:55 +01:00
										 |  |  | #include <LibWeb/SVG/SVGMaskElement.h>
 | 
					
						
							| 
									
										
										
										
											2022-04-10 20:16:47 +02:00
										 |  |  | #include <LibWeb/SVG/SVGSVGElement.h>
 | 
					
						
							| 
									
										
										
										
											2023-07-31 18:37:44 +02:00
										 |  |  | #include <LibWeb/SVG/SVGSymbolElement.h>
 | 
					
						
							| 
									
										
										
										
											2020-07-22 15:17:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-23 09:44:42 -07:00
										 |  |  | namespace Web::SVG { | 
					
						
							| 
									
										
										
										
											2020-07-22 15:17:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 21:00:52 +01:00
										 |  |  | SVGGraphicsElement::SVGGraphicsElement(DOM::Document& document, DOM::QualifiedName qualified_name) | 
					
						
							| 
									
										
										
										
											2021-02-07 11:20:15 +01:00
										 |  |  |     : SVGElement(document, move(qualified_name)) | 
					
						
							| 
									
										
										
										
											2020-07-22 15:17:39 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  | void SVGGraphicsElement::initialize(JS::Realm& realm) | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-08-07 08:41:28 +02:00
										 |  |  |     Base::initialize(realm); | 
					
						
							| 
									
										
										
										
											2023-01-10 06:28:20 -05:00
										 |  |  |     set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGGraphicsElementPrototype>(realm, "SVGGraphicsElement")); | 
					
						
							| 
									
										
										
										
											2020-07-22 15:17:39 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-03 17:08:37 +02:00
										 |  |  | void SVGGraphicsElement::attribute_changed(DeprecatedFlyString const& name, DeprecatedString const& value) | 
					
						
							| 
									
										
										
										
											2023-04-10 12:25:00 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-07-03 17:08:37 +02:00
										 |  |  |     SVGElement::attribute_changed(name, value); | 
					
						
							| 
									
										
										
										
											2023-05-19 20:35:39 +01:00
										 |  |  |     if (name == "transform"sv) { | 
					
						
							| 
									
										
										
										
											2023-04-10 12:25:40 +01:00
										 |  |  |         auto transform_list = AttributeParser::parse_transform(value); | 
					
						
							|  |  |  |         if (transform_list.has_value()) | 
					
						
							|  |  |  |             m_transform = transform_from_transform_list(*transform_list); | 
					
						
							| 
									
										
										
										
											2023-04-10 12:25:00 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-06 20:40:10 +01:00
										 |  |  | Optional<Gfx::PaintStyle const&> SVGGraphicsElement::svg_paint_computed_value_to_gfx_paint_style(SVGPaintContext const& paint_context, Optional<CSS::SVGPaint> const& paint_value) const | 
					
						
							| 
									
										
										
										
											2023-04-23 01:31:17 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     // FIXME: This entire function is an ad-hoc hack:
 | 
					
						
							| 
									
										
										
										
											2023-06-06 20:40:10 +01:00
										 |  |  |     if (!paint_value.has_value() || !paint_value->is_url()) | 
					
						
							| 
									
										
										
										
											2023-04-23 01:31:17 +01:00
										 |  |  |         return {}; | 
					
						
							| 
									
										
										
										
											2023-09-10 14:10:55 +01:00
										 |  |  |     if (auto gradient = try_resolve_url_to<SVG::SVGGradientElement const>(paint_value->as_url())) | 
					
						
							|  |  |  |         return gradient->to_gfx_paint_style(paint_context); | 
					
						
							| 
									
										
										
										
											2023-04-23 01:31:17 +01:00
										 |  |  |     return {}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-06 20:40:10 +01:00
										 |  |  | Optional<Gfx::PaintStyle const&> SVGGraphicsElement::fill_paint_style(SVGPaintContext const& paint_context) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!layout_node()) | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     return svg_paint_computed_value_to_gfx_paint_style(paint_context, layout_node()->computed_values().fill()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Optional<Gfx::PaintStyle const&> SVGGraphicsElement::stroke_paint_style(SVGPaintContext const& paint_context) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!layout_node()) | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     return svg_paint_computed_value_to_gfx_paint_style(paint_context, layout_node()->computed_values().stroke()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-10 14:10:55 +01:00
										 |  |  | JS::GCPtr<SVG::SVGMaskElement const> SVGGraphicsElement::mask() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto const& mask_reference = layout_node()->computed_values().mask(); | 
					
						
							|  |  |  |     if (!mask_reference.has_value()) | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     return try_resolve_url_to<SVG::SVGMaskElement const>(mask_reference->url()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-12 13:32:21 -04:00
										 |  |  | Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> transform_list) | 
					
						
							| 
									
										
										
										
											2023-04-10 12:25:40 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     Gfx::AffineTransform affine_transform; | 
					
						
							| 
									
										
										
										
											2023-04-12 13:32:21 -04:00
										 |  |  |     for (auto& transform : transform_list) { | 
					
						
							|  |  |  |         transform.operation.visit( | 
					
						
							| 
									
										
										
										
											2023-04-10 12:25:40 +01:00
										 |  |  |             [&](Transform::Translate const& translate) { | 
					
						
							|  |  |  |                 affine_transform.multiply(Gfx::AffineTransform {}.translate({ translate.x, translate.y })); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             [&](Transform::Scale const& scale) { | 
					
						
							|  |  |  |                 affine_transform.multiply(Gfx::AffineTransform {}.scale({ scale.x, scale.y })); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             [&](Transform::Rotate const& rotate) { | 
					
						
							|  |  |  |                 Gfx::AffineTransform translate_transform; | 
					
						
							|  |  |  |                 affine_transform.multiply( | 
					
						
							|  |  |  |                     Gfx::AffineTransform {} | 
					
						
							|  |  |  |                         .translate({ rotate.x, rotate.y }) | 
					
						
							| 
									
										
										
										
											2023-09-09 14:43:39 +02:00
										 |  |  |                         .rotate_radians(AK::to_radians(rotate.a)) | 
					
						
							| 
									
										
										
										
											2023-04-10 12:25:40 +01:00
										 |  |  |                         .translate({ -rotate.x, -rotate.y })); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             [&](Transform::SkewX const& skew_x) { | 
					
						
							| 
									
										
										
										
											2023-09-09 14:43:39 +02:00
										 |  |  |                 affine_transform.multiply(Gfx::AffineTransform {}.skew_radians(AK::to_radians(skew_x.a), 0)); | 
					
						
							| 
									
										
										
										
											2023-04-10 12:25:40 +01:00
										 |  |  |             }, | 
					
						
							|  |  |  |             [&](Transform::SkewY const& skew_y) { | 
					
						
							| 
									
										
										
										
											2023-09-09 14:43:39 +02:00
										 |  |  |                 affine_transform.multiply(Gfx::AffineTransform {}.skew_radians(0, AK::to_radians(skew_y.a))); | 
					
						
							| 
									
										
										
										
											2023-04-10 12:25:40 +01:00
										 |  |  |             }, | 
					
						
							|  |  |  |             [&](Transform::Matrix const& matrix) { | 
					
						
							|  |  |  |                 affine_transform.multiply(Gfx::AffineTransform { | 
					
						
							|  |  |  |                     matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f }); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return affine_transform; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Gfx::AffineTransform SVGGraphicsElement::get_transform() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Gfx::AffineTransform transform = m_transform; | 
					
						
							| 
									
										
										
										
											2023-05-28 18:27:35 +01:00
										 |  |  |     for (auto* svg_ancestor = shadow_including_first_ancestor_of_type<SVGGraphicsElement>(); svg_ancestor; svg_ancestor = svg_ancestor->shadow_including_first_ancestor_of_type<SVGGraphicsElement>()) { | 
					
						
							| 
									
										
										
										
											2023-08-31 08:58:41 +01:00
										 |  |  |         transform = Gfx::AffineTransform { svg_ancestor->element_transform() }.multiply(transform); | 
					
						
							| 
									
										
										
										
											2023-04-10 12:25:40 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     return transform; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-24 15:43:44 +00:00
										 |  |  | void SVGGraphicsElement::apply_presentational_hints(CSS::StyleProperties& style) const | 
					
						
							| 
									
										
										
										
											2020-07-22 15:17:39 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-09-25 15:28:05 +01:00
										 |  |  |     CSS::Parser::ParsingContext parsing_context { document(), CSS::Parser::ParsingContext::Mode::SVGPresentationAttribute }; | 
					
						
							| 
									
										
										
										
											2022-01-24 15:43:44 +00:00
										 |  |  |     for_each_attribute([&](auto& name, auto& value) { | 
					
						
							| 
									
										
										
										
											2023-03-10 08:48:54 +01:00
										 |  |  |         if (name.equals_ignoring_ascii_case("fill"sv)) { | 
					
						
							| 
									
										
										
										
											2022-01-24 15:43:44 +00:00
										 |  |  |             // FIXME: The `fill` attribute and CSS `fill` property are not the same! But our support is limited enough that they are equivalent for now.
 | 
					
						
							| 
									
										
										
										
											2023-08-19 15:01:21 +01:00
										 |  |  |             if (auto fill_value = parse_css_value(parsing_context, value, CSS::PropertyID::Fill)) | 
					
						
							| 
									
										
										
										
											2022-01-24 15:43:44 +00:00
										 |  |  |                 style.set_property(CSS::PropertyID::Fill, fill_value.release_nonnull()); | 
					
						
							| 
									
										
										
										
											2023-03-10 08:48:54 +01:00
										 |  |  |         } else if (name.equals_ignoring_ascii_case("stroke"sv)) { | 
					
						
							| 
									
										
										
										
											2022-01-24 15:43:44 +00:00
										 |  |  |             // FIXME: The `stroke` attribute and CSS `stroke` property are not the same! But our support is limited enough that they are equivalent for now.
 | 
					
						
							| 
									
										
										
										
											2023-08-19 15:01:21 +01:00
										 |  |  |             if (auto stroke_value = parse_css_value(parsing_context, value, CSS::PropertyID::Stroke)) | 
					
						
							| 
									
										
										
										
											2022-01-24 15:43:44 +00:00
										 |  |  |                 style.set_property(CSS::PropertyID::Stroke, stroke_value.release_nonnull()); | 
					
						
							| 
									
										
										
										
											2023-03-10 08:48:54 +01:00
										 |  |  |         } else if (name.equals_ignoring_ascii_case("stroke-width"sv)) { | 
					
						
							| 
									
										
										
										
											2023-08-19 15:01:21 +01:00
										 |  |  |             if (auto stroke_width_value = parse_css_value(parsing_context, value, CSS::PropertyID::StrokeWidth)) | 
					
						
							| 
									
										
										
										
											2022-01-24 15:43:44 +00:00
										 |  |  |                 style.set_property(CSS::PropertyID::StrokeWidth, stroke_width_value.release_nonnull()); | 
					
						
							| 
									
										
										
										
											2023-06-11 16:43:46 +01:00
										 |  |  |         } else if (name.equals_ignoring_ascii_case("fill-rule"sv)) { | 
					
						
							| 
									
										
										
										
											2023-08-19 15:01:21 +01:00
										 |  |  |             if (auto fill_rule_value = parse_css_value(parsing_context, value, CSS::PropertyID::FillRule)) | 
					
						
							| 
									
										
										
										
											2023-06-11 16:43:46 +01:00
										 |  |  |                 style.set_property(CSS::PropertyID::FillRule, fill_rule_value.release_nonnull()); | 
					
						
							| 
									
										
										
										
											2023-05-19 20:35:39 +01:00
										 |  |  |         } else if (name.equals_ignoring_ascii_case("fill-opacity"sv)) { | 
					
						
							| 
									
										
										
										
											2023-08-19 15:01:21 +01:00
										 |  |  |             if (auto fill_opacity_value = parse_css_value(parsing_context, value, CSS::PropertyID::FillOpacity)) | 
					
						
							| 
									
										
										
										
											2023-05-19 20:35:39 +01:00
										 |  |  |                 style.set_property(CSS::PropertyID::FillOpacity, fill_opacity_value.release_nonnull()); | 
					
						
							|  |  |  |         } else if (name.equals_ignoring_ascii_case("stroke-opacity"sv)) { | 
					
						
							| 
									
										
										
										
											2023-08-19 15:01:21 +01:00
										 |  |  |             if (auto stroke_opacity_value = parse_css_value(parsing_context, value, CSS::PropertyID::StrokeOpacity)) | 
					
						
							| 
									
										
										
										
											2023-05-19 20:35:39 +01:00
										 |  |  |                 style.set_property(CSS::PropertyID::StrokeOpacity, stroke_opacity_value.release_nonnull()); | 
					
						
							| 
									
										
										
										
											2023-06-20 12:57:54 +02:00
										 |  |  |         } else if (name.equals_ignoring_ascii_case(SVG::AttributeNames::opacity)) { | 
					
						
							| 
									
										
										
										
											2023-08-19 15:01:21 +01:00
										 |  |  |             if (auto opacity_value = parse_css_value(parsing_context, value, CSS::PropertyID::Opacity)) | 
					
						
							| 
									
										
										
										
											2023-08-16 17:47:52 +02:00
										 |  |  |                 style.set_property(CSS::PropertyID::Opacity, opacity_value.release_nonnull()); | 
					
						
							| 
									
										
										
										
											2023-07-20 20:31:01 +01:00
										 |  |  |         } else if (name.equals_ignoring_ascii_case("text-anchor"sv)) { | 
					
						
							| 
									
										
										
										
											2023-08-19 15:01:21 +01:00
										 |  |  |             if (auto text_anchor_value = parse_css_value(parsing_context, value, CSS::PropertyID::TextAnchor)) | 
					
						
							| 
									
										
										
										
											2023-07-20 20:31:01 +01:00
										 |  |  |                 style.set_property(CSS::PropertyID::TextAnchor, text_anchor_value.release_nonnull()); | 
					
						
							|  |  |  |         } else if (name.equals_ignoring_ascii_case("font-size"sv)) { | 
					
						
							| 
									
										
										
										
											2023-08-19 15:01:21 +01:00
										 |  |  |             if (auto font_size_value = parse_css_value(parsing_context, value, CSS::PropertyID::FontSize)) | 
					
						
							| 
									
										
										
										
											2023-07-20 20:31:01 +01:00
										 |  |  |                 style.set_property(CSS::PropertyID::FontSize, font_size_value.release_nonnull()); | 
					
						
							| 
									
										
										
										
											2023-09-10 14:10:55 +01:00
										 |  |  |         } else if (name.equals_ignoring_ascii_case("mask"sv)) { | 
					
						
							|  |  |  |             if (auto mask_value = parse_css_value(parsing_context, value, CSS::PropertyID::Mask)) | 
					
						
							|  |  |  |                 style.set_property(CSS::PropertyID::Mask, mask_value.release_nonnull()); | 
					
						
							| 
									
										
										
										
											2022-01-24 15:43:44 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-22 15:17:39 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 16:43:46 +01:00
										 |  |  | Optional<FillRule> SVGGraphicsElement::fill_rule() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!layout_node()) | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     switch (layout_node()->computed_values().fill_rule()) { | 
					
						
							|  |  |  |     case CSS::FillRule::Nonzero: | 
					
						
							|  |  |  |         return FillRule::Nonzero; | 
					
						
							|  |  |  |     case CSS::FillRule::Evenodd: | 
					
						
							|  |  |  |         return FillRule::Evenodd; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         VERIFY_NOT_REACHED(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-16 12:28:14 +01:00
										 |  |  | Optional<Gfx::Color> SVGGraphicsElement::fill_color() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!layout_node()) | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     // FIXME: In the working-draft spec, `fill` is intended to be a shorthand, with `fill-color`
 | 
					
						
							|  |  |  |     //        being what we actually want to use. But that's not final or widely supported yet.
 | 
					
						
							| 
									
										
										
										
											2023-04-23 01:31:17 +01:00
										 |  |  |     return layout_node()->computed_values().fill().map([&](auto& paint) -> Gfx::Color { | 
					
						
							|  |  |  |         if (!paint.is_color()) | 
					
						
							|  |  |  |             return Color::Black; | 
					
						
							| 
									
										
										
										
											2023-05-19 20:35:39 +01:00
										 |  |  |         return paint.as_color(); | 
					
						
							| 
									
										
										
										
											2023-04-10 12:25:00 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-09-16 12:28:14 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Optional<Gfx::Color> SVGGraphicsElement::stroke_color() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!layout_node()) | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     // FIXME: In the working-draft spec, `stroke` is intended to be a shorthand, with `stroke-color`
 | 
					
						
							|  |  |  |     //        being what we actually want to use. But that's not final or widely supported yet.
 | 
					
						
							| 
									
										
										
										
											2023-04-23 01:31:17 +01:00
										 |  |  |     return layout_node()->computed_values().stroke().map([](auto& paint) -> Gfx::Color { | 
					
						
							|  |  |  |         if (!paint.is_color()) | 
					
						
							|  |  |  |             return Color::Black; | 
					
						
							|  |  |  |         return paint.as_color(); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-09-16 12:28:14 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-19 20:35:39 +01:00
										 |  |  | Optional<float> SVGGraphicsElement::fill_opacity() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!layout_node()) | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     return layout_node()->computed_values().fill_opacity(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Optional<float> SVGGraphicsElement::stroke_opacity() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!layout_node()) | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     return layout_node()->computed_values().stroke_opacity(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-16 12:28:14 +01:00
										 |  |  | Optional<float> SVGGraphicsElement::stroke_width() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!layout_node()) | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     // FIXME: Converting to pixels isn't really correct - values should be in "user units"
 | 
					
						
							|  |  |  |     //        https://svgwg.org/svg2-draft/coords.html#TermUserUnits
 | 
					
						
							| 
									
										
										
										
											2023-06-15 16:51:17 +01:00
										 |  |  |     auto width = layout_node()->computed_values().stroke_width(); | 
					
						
							|  |  |  |     // Resolved relative to the "Scaled viewport size": https://www.w3.org/TR/2017/WD-fill-stroke-3-20170413/#scaled-viewport-size
 | 
					
						
							|  |  |  |     // FIXME: This isn't right, but it's something.
 | 
					
						
							|  |  |  |     CSSPixels viewport_width = 0; | 
					
						
							|  |  |  |     CSSPixels viewport_height = 0; | 
					
						
							|  |  |  |     if (auto* svg_svg_element = shadow_including_first_ancestor_of_type<SVGSVGElement>()) { | 
					
						
							|  |  |  |         if (auto* svg_svg_layout_node = svg_svg_element->layout_node()) { | 
					
						
							|  |  |  |             viewport_width = svg_svg_layout_node->computed_values().width().to_px(*svg_svg_layout_node, 0); | 
					
						
							|  |  |  |             viewport_height = svg_svg_layout_node->computed_values().height().to_px(*svg_svg_layout_node, 0); | 
					
						
							| 
									
										
										
										
											2022-04-10 20:16:47 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-01-14 16:52:14 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-08-26 15:03:04 +01:00
										 |  |  |     auto scaled_viewport_size = (viewport_width + viewport_height) * CSSPixels(0.5); | 
					
						
							| 
									
										
										
										
											2023-06-15 16:51:17 +01:00
										 |  |  |     return width.to_px(*layout_node(), scaled_viewport_size).to_double(); | 
					
						
							| 
									
										
										
										
											2021-09-16 12:28:14 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-31 18:37:44 +02:00
										 |  |  | Optional<ViewBox> SVGGraphicsElement::view_box() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (auto* svg_svg_element = shadow_including_first_ancestor_of_type<SVGSVGElement>()) { | 
					
						
							|  |  |  |         if (svg_svg_element->view_box().has_value()) | 
					
						
							|  |  |  |             return svg_svg_element->view_box(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (auto* svg_symbol_element = shadow_including_first_ancestor_of_type<SVGSymbolElement>()) { | 
					
						
							|  |  |  |         if (svg_symbol_element->view_box().has_value()) | 
					
						
							|  |  |  |             return svg_symbol_element->view_box(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return {}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 15:17:39 -07:00
										 |  |  | } |