mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-29 04:37:55 +00:00
LibWeb: Implement painting for svg text
The implementation of painting for SVG text follows the same pattern as the implementation of painting for SVG geometries. However, instead of reusing the existing PaintableWithLines to draw text, a new class called SVGTextPaintable is introduced. because everything that is painted inside an SVG is expected to inherit from SVGGraphicsPaintable. Therefore reusing the text painting from regular text nodes would require significant refactoring.
This commit is contained in:
committed by
Andreas Kling
parent
81a6976e90
commit
0d8d7ae94e
43
Userland/Libraries/LibWeb/Layout/SVGTextBox.cpp
Normal file
43
Userland/Libraries/LibWeb/Layout/SVGTextBox.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Layout/SVGTextBox.h>
|
||||
#include <LibWeb/Painting/SVGTextPaintable.h>
|
||||
#include <LibWeb/SVG/SVGSVGElement.h>
|
||||
|
||||
namespace Web::Layout {
|
||||
|
||||
SVGTextBox::SVGTextBox(DOM::Document& document, SVG::SVGTextContentElement& element, NonnullRefPtr<CSS::StyleProperties> properties)
|
||||
: SVGGraphicsBox(document, element, properties)
|
||||
{
|
||||
}
|
||||
|
||||
CSSPixelPoint SVGTextBox::viewbox_origin() const
|
||||
{
|
||||
auto* svg_box = dom_node().first_ancestor_of_type<SVG::SVGSVGElement>();
|
||||
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<Gfx::AffineTransform> SVGTextBox::layout_transform() const
|
||||
{
|
||||
auto& geometry_element = dom_node();
|
||||
auto transform = geometry_element.get_transform();
|
||||
auto* svg_box = geometry_element.first_ancestor_of_type<SVG::SVGSVGElement>();
|
||||
auto origin = viewbox_origin().to_type<double>().to_type<float>();
|
||||
Gfx::FloatPoint paint_offset = {};
|
||||
if (svg_box && svg_box->view_box().has_value())
|
||||
paint_offset = svg_box->paintable_box()->absolute_rect().location().to_type<double>().to_type<float>();
|
||||
return Gfx::AffineTransform {}.translate(paint_offset).translate(-origin).multiply(transform);
|
||||
}
|
||||
|
||||
JS::GCPtr<Painting::Paintable> SVGTextBox::create_paintable() const
|
||||
{
|
||||
return Painting::SVGTextPaintable::create(*this);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user