mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
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.
This commit is contained in:
parent
ba7383d28f
commit
ba6272a0a0
3 changed files with 18 additions and 11 deletions
|
@ -25,7 +25,7 @@ CSSPixelPoint SVGGeometryBox::viewbox_origin() const
|
|||
return { svg_box->view_box().value().min_x, svg_box->view_box().value().min_y };
|
||||
}
|
||||
|
||||
Gfx::AffineTransform SVGGeometryBox::layout_transform() const
|
||||
Optional<Gfx::AffineTransform> SVGGeometryBox::layout_transform() const
|
||||
{
|
||||
auto& geometry_element = dom_node();
|
||||
auto transform = geometry_element.get_transform();
|
||||
|
@ -37,9 +37,12 @@ Gfx::AffineTransform SVGGeometryBox::layout_transform() const
|
|||
// Note: SVGFormattingContext has already done the scaling based on the viewbox,
|
||||
// we now have to derive what it was from the original bounding box size.
|
||||
// FIXME: It would be nice if we could store the transform from layout somewhere, so we don't have to solve for it here.
|
||||
auto original_bounding_box = Gfx::AffineTransform {}.translate(-origin).multiply(transform).map(const_cast<SVG::SVGGeometryElement&>(geometry_element).get_path().bounding_box());
|
||||
// If the transform (or path) results in a empty box we can't display this.
|
||||
if (original_bounding_box.is_empty())
|
||||
return {};
|
||||
auto scaled_width = paint_box()->content_width().value();
|
||||
auto scaled_height = paint_box()->content_height().value();
|
||||
auto original_bounding_box = Gfx::AffineTransform {}.translate(-origin).multiply(transform).map(const_cast<SVG::SVGGeometryElement&>(geometry_element).get_path().bounding_box());
|
||||
scaling = min(scaled_width / original_bounding_box.width(), scaled_height / original_bounding_box.height());
|
||||
auto scaled_bounding_box = original_bounding_box.scaled(scaling, scaling);
|
||||
paint_offset = (paint_box()->absolute_rect().location() - svg_box->paint_box()->absolute_rect().location()).to_type<float>() - scaled_bounding_box.location();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue