2021-09-17 23:12:16 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
2022-02-16 16:32:18 +00:00
|
|
|
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
2021-09-17 23:12:16 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/Format.h>
|
|
|
|
#include <LibWeb/Layout/SVGFormattingContext.h>
|
2022-02-11 12:37:22 +00:00
|
|
|
#include <LibWeb/Layout/SVGGeometryBox.h>
|
2021-09-17 23:12:16 +02:00
|
|
|
|
|
|
|
namespace Web::Layout {
|
|
|
|
|
2022-02-19 20:13:47 +01:00
|
|
|
SVGFormattingContext::SVGFormattingContext(FormattingState& state, Box& box, FormattingContext* parent)
|
|
|
|
: FormattingContext(Type::SVG, state, box, parent)
|
2021-09-17 23:12:16 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SVGFormattingContext::~SVGFormattingContext()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-09-18 00:06:16 +02:00
|
|
|
void SVGFormattingContext::run(Box& box, LayoutMode)
|
2021-09-17 23:12:16 +02:00
|
|
|
{
|
2021-09-18 00:06:16 +02:00
|
|
|
box.for_each_in_subtree_of_type<SVGBox>([&](auto& descendant) {
|
2022-02-11 12:37:22 +00:00
|
|
|
if (is<SVGGeometryBox>(descendant)) {
|
|
|
|
auto& geometry_box = static_cast<SVGGeometryBox&>(descendant);
|
|
|
|
auto& path = geometry_box.dom_node().get_path();
|
2022-02-16 15:17:50 +00:00
|
|
|
auto bounding_box = path.bounding_box();
|
|
|
|
|
|
|
|
// Stroke increases the path's size by stroke_width/2 per side.
|
|
|
|
auto stroke_width = geometry_box.dom_node().stroke_width().value_or(0);
|
|
|
|
bounding_box.inflate(stroke_width, stroke_width);
|
|
|
|
|
|
|
|
geometry_box.set_offset(bounding_box.top_left());
|
|
|
|
geometry_box.set_content_size(bounding_box.size());
|
2021-09-18 00:06:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
});
|
2021-09-17 23:12:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|