diff --git a/Tests/LibWeb/Layout/expected/zero-width-viewport-svg-image.txt b/Tests/LibWeb/Layout/expected/zero-width-viewport-svg-image.txt new file mode 100644 index 0000000000..9640c8f072 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/zero-width-viewport-svg-image.txt @@ -0,0 +1,13 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x600 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x150 children: inline + frag 0 from ImageBox start: 0, length: 0, rect: [8,8 300x150] baseline: 150 + ImageBox at (8,8) content-size 300x150 children: not-inline + (SVG-as-image isolated context) + Viewport <#document> at (0,0) content-size 300x150 [BFC] children: inline + SVGSVGBox at (0,0) content-size 300x150 [SVG] children: not-inline + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x600] + PaintableWithLines (BlockContainer) [8,8 784x150] + ImagePaintable (ImageBox) [8,8 300x150] diff --git a/Tests/LibWeb/Layout/input/zero-width-viewport-svg-image.html b/Tests/LibWeb/Layout/input/zero-width-viewport-svg-image.html new file mode 100755 index 0000000000..79dddc9a2d --- /dev/null +++ b/Tests/LibWeb/Layout/input/zero-width-viewport-svg-image.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp index fdb1f28be8..c06bf77ea8 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp @@ -155,9 +155,16 @@ Optional SVGDecodedImageData::intrinsic_aspect_ratio() const if (width.has_value() && height.has_value()) return *width / *height; - if (auto const& viewbox = m_root_element->view_box(); viewbox.has_value()) - return CSSPixels::nearest_value_for(viewbox->width) / CSSPixels::nearest_value_for(viewbox->height); + if (auto const& viewbox = m_root_element->view_box(); viewbox.has_value()) { + auto viewbox_width = CSSPixels::nearest_value_for(viewbox->width); + if (viewbox_width == 0) + return {}; + + auto viewbox_height = CSSPixels::nearest_value_for(viewbox->height); + + return viewbox_width / viewbox_height; + } return {}; }