From f5e01192cce526a61d09d364222852ac1937bce8 Mon Sep 17 00:00:00 2001 From: Manuel Zahariev Date: Thu, 5 Dec 2024 14:25:35 -0800 Subject: [PATCH] LibWeb: Layout standalone SVG document with specified dimensions Before, standalone SVG documents were stretched to fit the agent viewport. --- Libraries/LibWeb/Layout/SVGFormattingContext.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Libraries/LibWeb/Layout/SVGFormattingContext.cpp b/Libraries/LibWeb/Layout/SVGFormattingContext.cpp index cc7fb562a65..66abeec1b8c 100644 --- a/Libraries/LibWeb/Layout/SVGFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/SVGFormattingContext.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -179,6 +180,18 @@ void SVGFormattingContext::run(AvailableSpace const& available_space) auto& svg_viewport = dynamic_cast(*context_box().dom_node()); auto& svg_box_state = m_state.get_mutable(context_box()); + if (!this->context_box().root().document().is_decoded_svg()) { + // Overwrite the content width/height with the styled node width/height (from ) + + // NOTE: If a height had not been provided by the svg element, it was set to the height of the container + // (see BlockFormattingContext::layout_viewport) + if (svg_box_state.node().computed_values().width().is_length()) + svg_box_state.set_content_width(svg_box_state.node().computed_values().width().length().to_px(svg_box_state.node())); + if (svg_box_state.node().computed_values().height().is_length()) + svg_box_state.set_content_height(svg_box_state.node().computed_values().height().length().to_px(svg_box_state.node())); + // FIXME: In SVG 2, length can also be a percentage. We'll need to support that. + } + // NOTE: We consider all SVG root elements to have definite size in both axes. // I'm not sure if this is good or bad, but our viewport transform logic depends on it. svg_box_state.set_has_definite_width(true);