/* * Copyright (c) 2023, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include namespace Web::Layout { SVGTextBox::SVGTextBox(DOM::Document& document, SVG::SVGTextContentElement& element, NonnullRefPtr properties) : SVGGraphicsBox(document, element, properties) { } CSSPixelPoint SVGTextBox::viewbox_origin() const { auto* svg_box = dom_node().first_ancestor_of_type(); if (!svg_box || !svg_box->view_box().has_value()) return { 0, 0 }; return { svg_box->view_box().value().min_x, svg_box->view_box().value().min_y }; } Optional SVGTextBox::layout_transform() const { auto& geometry_element = dom_node(); auto transform = geometry_element.get_transform(); auto* svg_box = geometry_element.first_ancestor_of_type(); auto origin = viewbox_origin().to_type().to_type(); Gfx::FloatPoint paint_offset = {}; if (svg_box && svg_box->view_box().has_value()) paint_offset = svg_box->paintable_box()->absolute_rect().location().to_type().to_type(); return Gfx::AffineTransform {}.translate(paint_offset).translate(-origin).multiply(transform); } JS::GCPtr SVGTextBox::create_paintable() const { return Painting::SVGTextPaintable::create(*this); } }