2022-03-20 11:20:06 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2023-06-08 21:32:33 +03:00
|
|
|
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
2022-03-20 11:20:06 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2024-04-27 12:09:58 +12:00
|
|
|
#include <LibWeb/Bindings/SVGTextContentElementPrototype.h>
|
2022-03-20 11:20:06 +01:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
2025-07-09 14:13:22 -04:00
|
|
|
#include <LibWeb/Layout/Node.h>
|
2023-06-08 21:32:33 +03:00
|
|
|
#include <LibWeb/SVG/AttributeParser.h>
|
2022-03-20 11:20:06 +01:00
|
|
|
#include <LibWeb/SVG/SVGTextContentElement.h>
|
|
|
|
|
|
|
|
namespace Web::SVG {
|
|
|
|
|
|
|
|
SVGTextContentElement::SVGTextContentElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
|
|
|
: SVGGraphicsElement(document, move(qualified_name))
|
|
|
|
{
|
2023-01-10 06:28:20 -05:00
|
|
|
}
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
void SVGTextContentElement::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
{
|
2024-03-16 13:13:08 +01:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGTextContentElement);
|
2025-04-20 16:22:57 +02:00
|
|
|
Base::initialize(realm);
|
2022-03-20 11:20:06 +01:00
|
|
|
}
|
|
|
|
|
2023-07-19 19:12:00 +01:00
|
|
|
Optional<TextAnchor> SVGTextContentElement::text_anchor() const
|
|
|
|
{
|
|
|
|
if (!layout_node())
|
|
|
|
return {};
|
|
|
|
switch (layout_node()->computed_values().text_anchor()) {
|
|
|
|
case CSS::TextAnchor::Start:
|
|
|
|
return TextAnchor::Start;
|
|
|
|
case CSS::TextAnchor::Middle:
|
|
|
|
return TextAnchor::Middle;
|
|
|
|
case CSS::TextAnchor::End:
|
|
|
|
return TextAnchor::End;
|
|
|
|
default:
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-08-05 07:11:58 -04:00
|
|
|
Utf16String SVGTextContentElement::text_contents() const
|
2023-10-29 19:11:46 +00:00
|
|
|
{
|
2025-08-05 07:11:58 -04:00
|
|
|
return child_text_content().trim_ascii_whitespace();
|
2023-10-29 19:11:46 +00:00
|
|
|
}
|
|
|
|
|
2022-03-20 11:20:06 +01:00
|
|
|
// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__getNumberOfChars
|
2024-04-01 00:45:54 +01:00
|
|
|
WebIDL::ExceptionOr<WebIDL::Long> SVGTextContentElement::get_number_of_chars() const
|
2022-03-20 11:20:06 +01:00
|
|
|
{
|
2025-08-05 07:11:58 -04:00
|
|
|
return static_cast<WebIDL::Long>(text_contents().length_in_code_units());
|
2024-04-01 00:45:54 +01:00
|
|
|
}
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<Geometry::DOMPoint> SVGTextContentElement::get_start_position_of_char(WebIDL::UnsignedLong charnum)
|
2024-04-01 00:45:54 +01:00
|
|
|
{
|
|
|
|
dbgln("(STUBBED) SVGTextContentElement::get_start_position_of_char(charnum={}). Called on: {}", charnum, debug_description());
|
|
|
|
return Geometry::DOMPoint::from_point(vm(), Geometry::DOMPointInit {});
|
2022-03-20 11:20:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|