summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Painting
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2023-04-11 00:18:28 +0100
committerAndreas Kling <kling@serenityos.org>2023-04-12 07:40:22 +0200
commitba6272a0a0e2dceccc9f1378d3c4f47d9aaea6d6 (patch)
tree8f160734a6f8c3c65a72783c3242ccdabc445e23 /Userland/Libraries/LibWeb/Painting
parentba7383d28ff6431d65485fd38c136da26c25c029 (diff)
downloadserenity-ba6272a0a0e2dceccc9f1378d3c4f47d9aaea6d6.zip
LibWeb: Don't try to paint SVG elements transformed to zero size
Otherwise, the Gfx::Painter will get choked up on NaNs and start infinitely splitting paths till it OOMs.
Diffstat (limited to 'Userland/Libraries/LibWeb/Painting')
-rw-r--r--Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp b/Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp
index e0238659e9..07aa283de4 100644
--- a/Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/SVGGeometryPaintable.cpp
@@ -33,10 +33,12 @@ Optional<HitTestResult> SVGGeometryPaintable::hit_test(CSSPixelPoint position, H
if (!result.has_value())
return {};
auto& geometry_element = layout_box().dom_node();
- auto transformed_bounding_box = layout_box().layout_transform().map_to_quad(
- const_cast<SVG::SVGGeometryElement&>(geometry_element).get_path().bounding_box());
- if (!transformed_bounding_box.contains(position.to_type<float>()))
- return {};
+ if (auto transform = layout_box().layout_transform(); transform.has_value()) {
+ auto transformed_bounding_box = transform->map_to_quad(
+ const_cast<SVG::SVGGeometryElement&>(geometry_element).get_path().bounding_box());
+ if (!transformed_bounding_box.contains(position.to_type<float>()))
+ return {};
+ }
return result;
}
@@ -56,6 +58,7 @@ void SVGGeometryPaintable::paint(PaintContext& context, PaintPhase phase) const
auto& svg_context = context.svg_context();
// FIXME: This should not be trucated to an int.
+ Gfx::PainterStateSaver save_painter { context.painter() };
auto offset = context.floored_device_point(svg_context.svg_element_position()).to_type<int>().to_type<float>();
painter.translate(offset);
@@ -65,7 +68,10 @@ void SVGGeometryPaintable::paint(PaintContext& context, PaintPhase phase) const
context.painter().add_clip_rect(context.enclosing_device_rect(absolute_rect()).to_type<int>());
auto css_scale = context.device_pixels_per_css_pixel();
- Gfx::Path path = const_cast<SVG::SVGGeometryElement&>(geometry_element).get_path().copy_transformed(Gfx::AffineTransform {}.scale(css_scale, css_scale).multiply(layout_box().layout_transform()));
+ auto transform = layout_box().layout_transform();
+ if (!transform.has_value())
+ return;
+ Gfx::Path path = const_cast<SVG::SVGGeometryElement&>(geometry_element).get_path().copy_transformed(Gfx::AffineTransform {}.scale(css_scale, css_scale).multiply(*transform));
if (auto fill_color = geometry_element.fill_color().value_or(svg_context.fill_color()); fill_color.alpha() > 0) {
// We need to fill the path before applying the stroke, however the filled
@@ -87,9 +93,6 @@ void SVGGeometryPaintable::paint(PaintContext& context, PaintPhase phase) const
stroke_color,
geometry_element.stroke_width().value_or(svg_context.stroke_width()) * context.device_pixels_per_css_pixel());
}
-
- painter.translate(-offset);
- context.painter().clear_clip_rect();
}
}