LibWeb: Layout standalone SVG document with specified dimensions

Before, standalone SVG documents were stretched to fit the agent
viewport.
This commit is contained in:
Manuel Zahariev 2024-12-05 14:25:35 -08:00 committed by Sam Atkins
parent f4c03d548e
commit f5e01192cc
Notes: github-actions[bot] 2024-12-13 15:04:04 +00:00

View file

@ -18,6 +18,7 @@
#include <LibWeb/Layout/SVGGeometryBox.h>
#include <LibWeb/Layout/SVGImageBox.h>
#include <LibWeb/Layout/SVGMaskBox.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/SVG/SVGAElement.h>
#include <LibWeb/SVG/SVGClipPathElement.h>
#include <LibWeb/SVG/SVGForeignObjectElement.h>
@ -179,6 +180,18 @@ void SVGFormattingContext::run(AvailableSpace const& available_space)
auto& svg_viewport = dynamic_cast<SVG::SVGViewport const&>(*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 <svg width height ...>)
// 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);