mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-27 21:42:53 +00:00
LibWeb: Layout SVG <text> elements during layout (not while painting)
Previously, all SVG <text> elements were zero-sized boxes, that were only actually positioned and sized during painting. This led to a number of problems, the most visible of which being that text could not be scaled based on the viewBox. Which this patch, <text> elements get a correctly sized layout box, that can be hit-tested and respects the SVG viewBox. To share code with SVGGeometryElement's the PathData (from the prior commit) has been split into a computed path and computed transforms. The computed path is specific to geometry elements, but the computed transforms are shared between all SVG graphics elements.
This commit is contained in:
parent
dc9cb449b1
commit
c93d367d95
Notes:
sideshowbarker
2024-07-16 20:51:53 +09:00
Author: https://github.com/MacDue
Commit: c93d367d95
Pull-request: https://github.com/SerenityOS/serenity/pull/21681
Reviewed-by: https://github.com/kalenikaliaksandr ✅
16 changed files with 209 additions and 173 deletions
|
@ -15,27 +15,6 @@ SVGTextBox::SVGTextBox(DOM::Document& document, SVG::SVGTextPositioningElement&
|
|||
{
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
// FIXME: Since text layout boxes are currently 0x0 it is not possible handle viewBox scaling here.
|
||||
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<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<float>();
|
||||
return Gfx::AffineTransform {}.translate(paint_offset).translate(-origin).multiply(transform);
|
||||
}
|
||||
|
||||
JS::GCPtr<Painting::Paintable> SVGTextBox::create_paintable() const
|
||||
{
|
||||
return Painting::SVGTextPaintable::create(*this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue