/src/serenity/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
3 | | * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com> |
4 | | * |
5 | | * SPDX-License-Identifier: BSD-2-Clause |
6 | | */ |
7 | | |
8 | | #include <AK/Utf16View.h> |
9 | | #include <LibJS/Runtime/Completion.h> |
10 | | #include <LibJS/Runtime/Utf16String.h> |
11 | | #include <LibWeb/Bindings/SVGTextContentElementPrototype.h> |
12 | | #include <LibWeb/CSS/Parser/Parser.h> |
13 | | #include <LibWeb/DOM/Document.h> |
14 | | #include <LibWeb/Layout/SVGTextBox.h> |
15 | | #include <LibWeb/SVG/AttributeNames.h> |
16 | | #include <LibWeb/SVG/AttributeParser.h> |
17 | | #include <LibWeb/SVG/SVGGeometryElement.h> |
18 | | #include <LibWeb/SVG/SVGTextContentElement.h> |
19 | | |
20 | | namespace Web::SVG { |
21 | | |
22 | | SVGTextContentElement::SVGTextContentElement(DOM::Document& document, DOM::QualifiedName qualified_name) |
23 | 0 | : SVGGraphicsElement(document, move(qualified_name)) |
24 | 0 | { |
25 | 0 | } |
26 | | |
27 | | void SVGTextContentElement::initialize(JS::Realm& realm) |
28 | 0 | { |
29 | 0 | Base::initialize(realm); |
30 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGTextContentElement); |
31 | 0 | } |
32 | | |
33 | | Optional<TextAnchor> SVGTextContentElement::text_anchor() const |
34 | 0 | { |
35 | 0 | if (!layout_node()) |
36 | 0 | return {}; |
37 | 0 | switch (layout_node()->computed_values().text_anchor()) { |
38 | 0 | case CSS::TextAnchor::Start: |
39 | 0 | return TextAnchor::Start; |
40 | 0 | case CSS::TextAnchor::Middle: |
41 | 0 | return TextAnchor::Middle; |
42 | 0 | case CSS::TextAnchor::End: |
43 | 0 | return TextAnchor::End; |
44 | 0 | default: |
45 | 0 | VERIFY_NOT_REACHED(); |
46 | 0 | } |
47 | 0 | } |
48 | | |
49 | | ByteString SVGTextContentElement::text_contents() const |
50 | 0 | { |
51 | 0 | return child_text_content().to_byte_string().trim_whitespace(); |
52 | 0 | } |
53 | | |
54 | | // https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__getNumberOfChars |
55 | | WebIDL::ExceptionOr<WebIDL::Long> SVGTextContentElement::get_number_of_chars() const |
56 | 0 | { |
57 | 0 | auto chars = TRY_OR_THROW_OOM(vm(), utf8_to_utf16(text_contents())); |
58 | 0 | return static_cast<WebIDL::Long>(chars.size()); |
59 | 0 | } |
60 | | |
61 | | JS::NonnullGCPtr<Geometry::DOMPoint> SVGTextContentElement::get_start_position_of_char(WebIDL::UnsignedLong charnum) |
62 | 0 | { |
63 | 0 | dbgln("(STUBBED) SVGTextContentElement::get_start_position_of_char(charnum={}). Called on: {}", charnum, debug_description()); |
64 | 0 | return Geometry::DOMPoint::from_point(vm(), Geometry::DOMPointInit {}); |
65 | 0 | } |
66 | | |
67 | | } |