mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-22 11:02:53 +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:
parent
81a6976e90
commit
0d8d7ae94e
Notes:
sideshowbarker
2024-07-17 09:49:33 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: 0d8d7ae94e
Pull-request: https://github.com/SerenityOS/serenity/pull/19327
Reviewed-by: https://github.com/awesomekling
9 changed files with 216 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -8,6 +9,10 @@
|
|||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Utf16String.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/Layout/SVGTextBox.h>
|
||||
#include <LibWeb/SVG/AttributeNames.h>
|
||||
#include <LibWeb/SVG/AttributeParser.h>
|
||||
#include <LibWeb/SVG/SVGGeometryElement.h>
|
||||
#include <LibWeb/SVG/SVGTextContentElement.h>
|
||||
|
||||
namespace Web::SVG {
|
||||
|
@ -25,6 +30,26 @@ JS::ThrowCompletionOr<void> SVGTextContentElement::initialize(JS::Realm& realm)
|
|||
return {};
|
||||
}
|
||||
|
||||
void SVGTextContentElement::parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value)
|
||||
{
|
||||
SVGGraphicsElement::parse_attribute(name, value);
|
||||
|
||||
if (name == SVG::AttributeNames::x) {
|
||||
m_x = AttributeParser::parse_coordinate(value).value();
|
||||
} else if (name == SVG::AttributeNames::y) {
|
||||
m_y = AttributeParser::parse_coordinate(value).value();
|
||||
} else if (name == SVG::AttributeNames::dx) {
|
||||
m_dx = AttributeParser::parse_coordinate(value).value();
|
||||
} else if (name == SVG::AttributeNames::dy) {
|
||||
m_dy = AttributeParser::parse_coordinate(value).value();
|
||||
}
|
||||
}
|
||||
|
||||
JS::GCPtr<Layout::Node> SVGTextContentElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
|
||||
{
|
||||
return heap().allocate_without_realm<Layout::SVGTextBox>(document(), *this, move(style));
|
||||
}
|
||||
|
||||
// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__getNumberOfChars
|
||||
WebIDL::ExceptionOr<int> SVGTextContentElement::get_number_of_chars() const
|
||||
{
|
||||
|
@ -32,4 +57,9 @@ WebIDL::ExceptionOr<int> SVGTextContentElement::get_number_of_chars() const
|
|||
return static_cast<int>(chars.size());
|
||||
}
|
||||
|
||||
Gfx::FloatPoint SVGTextContentElement::get_offset() const
|
||||
{
|
||||
return { m_x + m_dx, m_y + m_dy };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue