mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 11:12:45 +00:00 
			
		
		
		
	 0d8d7ae94e
			
		
	
	
		0d8d7ae94e
		
	
	
	
	
		
			
			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.
		
			
				
	
	
		
			43 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * 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);
 | |
| }
 | |
| 
 | |
| }
 |