2023-12-17 15:35:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2024-03-18 00:22:27 -03:00
|
|
|
#include <LibURL/URL.h>
|
2026-04-18 05:54:06 -03:00
|
|
|
#include <LibWeb/Bindings/SVGTextPathElement.h>
|
2023-12-17 15:35:21 -03:00
|
|
|
#include <LibWeb/Layout/SVGTextPathBox.h>
|
|
|
|
|
#include <LibWeb/SVG/AttributeNames.h>
|
2026-05-27 07:35:55 -03:00
|
|
|
#include <LibWeb/SVG/SVGLength.h>
|
2023-12-17 15:35:21 -03:00
|
|
|
#include <LibWeb/SVG/SVGTextPathElement.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::SVG {
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DEFINE_ALLOCATOR(SVGTextPathElement);
|
2023-12-17 15:35:21 -03:00
|
|
|
|
|
|
|
|
SVGTextPathElement::SVGTextPathElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
|
|
|
|
: SVGTextContentElement(document, move(qualified_name))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-27 07:35:55 -03:00
|
|
|
void SVGTextPathElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)
|
|
|
|
|
{
|
|
|
|
|
Base::attribute_changed(name, old_value, value, namespace_);
|
|
|
|
|
|
|
|
|
|
if (name == SVG::AttributeNames::startOffset)
|
|
|
|
|
m_start_offset = AttributeParser::parse_number_percentage(value.value_or(String {}));
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<SVGGeometryElement const> SVGTextPathElement::path_or_shape() const
|
2023-12-17 15:35:21 -03:00
|
|
|
{
|
2026-05-27 07:05:28 -03:00
|
|
|
auto href = has_attribute(AttributeNames::href) ? get_attribute(AttributeNames::href) : get_attribute(AttributeNames::xlink_href);
|
2023-12-17 15:35:21 -03:00
|
|
|
if (!href.has_value())
|
|
|
|
|
return {};
|
2025-04-30 06:50:48 -03:00
|
|
|
return try_resolve_url_to<SVGGeometryElement const>(*href);
|
2023-12-17 15:35:21 -03:00
|
|
|
}
|
|
|
|
|
|
2026-05-27 07:35:55 -03:00
|
|
|
// https://svgwg.org/svg2-draft/text.html#TextPathElementStartOffsetAttribute
|
|
|
|
|
float SVGTextPathElement::start_offset_for_path_length(float path_length) const
|
|
|
|
|
{
|
|
|
|
|
if (!m_start_offset.has_value())
|
|
|
|
|
return 0;
|
|
|
|
|
return m_start_offset->resolve_relative_to(path_length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextPathElement__startOffset
|
|
|
|
|
GC::Ref<SVGAnimatedLength> SVGTextPathElement::start_offset() const
|
|
|
|
|
{
|
|
|
|
|
auto base_length = SVGLength::create(realm(), 0, m_start_offset.value_or(NumberPercentage::create_number(0)).value(), SVGLength::ReadOnly::No);
|
|
|
|
|
auto anim_length = SVGLength::create(realm(), 0, m_start_offset.value_or(NumberPercentage::create_number(0)).value(), SVGLength::ReadOnly::Yes);
|
|
|
|
|
return SVGAnimatedLength::create(realm(), base_length, anim_length);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-17 15:35:21 -03:00
|
|
|
void SVGTextPathElement::initialize(JS::Realm& realm)
|
|
|
|
|
{
|
2024-03-16 09:13:08 -03:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGTextPathElement);
|
2025-04-20 11:22:57 -03:00
|
|
|
Base::initialize(realm);
|
2023-12-17 15:35:21 -03:00
|
|
|
}
|
|
|
|
|
|
2023-11-13 21:20:44 -03:00
|
|
|
void SVGTextPathElement::visit_edges(Cell::Visitor& visitor)
|
|
|
|
|
{
|
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
|
SVGURIReferenceMixin::visit_edges(visitor);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-06 09:03:41 -03:00
|
|
|
GC::Ptr<Layout::Node> SVGTextPathElement::create_layout_node(CSS::ComputedProperties const& style)
|
2023-12-17 15:35:21 -03:00
|
|
|
{
|
2026-06-06 09:03:41 -03:00
|
|
|
return heap().allocate<Layout::SVGTextPathBox>(document(), *this, style);
|
2023-12-17 15:35:21 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|