2023-07-22 19:24:55 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2023-07-22 19:24:55 +01:00
|
|
|
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2024-04-27 12:09:58 +12:00
|
|
|
#include <LibWeb/Bindings/SVGTextPositioningElementPrototype.h>
|
2023-07-22 19:24:55 +01:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
#include <LibWeb/SVG/AttributeNames.h>
|
|
|
|
#include <LibWeb/SVG/AttributeParser.h>
|
|
|
|
#include <LibWeb/SVG/SVGTextPositioningElement.h>
|
|
|
|
|
|
|
|
namespace Web::SVG {
|
|
|
|
|
|
|
|
SVGTextPositioningElement::SVGTextPositioningElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
|
|
|
: SVGTextContentElement(document, move(qualified_name))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
void SVGTextPositioningElement::initialize(JS::Realm& realm)
|
2023-07-22 19:24:55 +01:00
|
|
|
{
|
2024-03-16 13:13:08 +01:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGTextPositioningElement);
|
2025-04-20 16:22:57 +02:00
|
|
|
Base::initialize(realm);
|
2023-07-22 19:24:55 +01:00
|
|
|
}
|
|
|
|
|
2024-11-14 08:14:16 -05:00
|
|
|
void SVGTextPositioningElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)
|
2023-07-22 19:24:55 +01:00
|
|
|
{
|
2024-11-14 08:14:16 -05:00
|
|
|
Base::attribute_changed(name, old_value, value, namespace_);
|
2023-07-22 19:24:55 +01:00
|
|
|
|
|
|
|
if (name == SVG::AttributeNames::x) {
|
2024-07-21 16:21:28 +02:00
|
|
|
m_x = AttributeParser::parse_number_percentage(value.value_or(String {}));
|
2023-07-22 19:24:55 +01:00
|
|
|
} else if (name == SVG::AttributeNames::y) {
|
2024-07-21 16:21:28 +02:00
|
|
|
m_y = AttributeParser::parse_number_percentage(value.value_or(String {}));
|
2023-07-22 19:24:55 +01:00
|
|
|
} else if (name == SVG::AttributeNames::dx) {
|
2024-07-21 16:21:28 +02:00
|
|
|
m_dx = AttributeParser::parse_number_percentage(value.value_or(String {}));
|
2023-07-22 19:24:55 +01:00
|
|
|
} else if (name == SVG::AttributeNames::dy) {
|
2024-07-21 16:21:28 +02:00
|
|
|
m_dy = AttributeParser::parse_number_percentage(value.value_or(String {}));
|
2023-07-22 19:24:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-21 16:21:28 +02:00
|
|
|
Gfx::FloatPoint SVGTextPositioningElement::get_offset(CSSPixelSize const& viewport_size) const
|
2023-07-22 19:24:55 +01:00
|
|
|
{
|
2024-07-21 16:21:28 +02:00
|
|
|
auto const viewport_width = viewport_size.width().to_float();
|
|
|
|
auto const viewport_height = viewport_size.height().to_float();
|
|
|
|
|
|
|
|
float const x = m_x.value_or({ 0, false }).resolve_relative_to(viewport_width);
|
|
|
|
float const y = m_y.value_or({ 0, false }).resolve_relative_to(viewport_height);
|
|
|
|
float const dx = m_dx.value_or({ 0, false }).resolve_relative_to(viewport_width);
|
|
|
|
float const dy = m_dy.value_or({ 0, false }).resolve_relative_to(viewport_height);
|
|
|
|
|
|
|
|
return { x + dx, y + dy };
|
2023-07-22 19:24:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|