Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / svg / svg_text_content_element.lucb

#==============================================================================================
#
#   svg_text_content_element - SVG::SVGTextContentElement: the base of text, tspan, textPath
#
#   DESCRIPTION:
#       Port of LibWeb/SVG/SVGTextContentElement.cpp (lines 1-64): construction, the
#       text-anchor of its layout node, the trimmed child text, getNumberOfChars() and the
#       stubbed getStartPositionOfChar().
#
#==============================================================================================

## Ported from Libraries/LibWeb/SVG/SVGTextContentElement.cpp:16 Web::SVG::SVGTextContentElement::SVGTextContentElement.
pub func svg_text_content_element_construct(this: SvgTextContentElement*, document: DomDocument*, qualified_name: DomQualifiedName):
    svg_graphics_element_construct(this.svg_graphics_element(), document, qualified_name)
    # The vptrs of the mixin bases move to SVGTextContentElement's tables.
    let element = this.svg_element()
    element.element.slottable_mixin.vtable = &svg_text_content_element_slottable_mixin_vtable
    element.element.aria_mixin.vtable = &svg_text_content_element_aria_mixin_vtable
    element.element.animatable.vtable = &svg_text_content_element_animatable_vtable
    element.global_event_handlers.vtable = &svg_text_content_element_global_event_handlers_vtable

## Ported from Libraries/LibWeb/SVG/SVGTextContentElement.cpp:21 Web::SVG::SVGTextContentElement::initialize (override).
pub func svg_text_content_element_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.svg_text_content_element)
    svg_graphics_element_initialize_impl(base, realm)

## Ported from Libraries/LibWeb/SVG/SVGTextContentElement.cpp:28 Web::SVG::SVGTextContentElement::text_anchor.
# NB: Called during painting.
pub func svg_text_content_element_text_anchor(this: SvgTextContentElement*) -> SvgTextAnchor?:
    let layout_node = dom_node_unsafe_layout_node(this.dom_node()) else return none
    match css_computed_values_text_anchor(&layout_node_computed_values(layout_node).computed_values):
        .start: return SvgTextAnchor.start
        .middle: return SvgTextAnchor.middle
        .end: return SvgTextAnchor.end
        _: trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/SVG/SVGTextContentElement.cpp:44 Web::SVG::SVGTextContentElement::text_contents.
pub func svg_text_content_element_text_contents(this: SvgTextContentElement*) -> ak.Utf16String:
    let child_text_content = dom_node_child_text_content(this.dom_node())
    return ak.utf16_string_trim_ascii_whitespace(&child_text_content)

## Ported from Libraries/LibWeb/SVG/SVGTextContentElement.cpp:50 Web::SVG::SVGTextContentElement::get_number_of_chars.
# https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__getNumberOfChars
pub func svg_text_content_element_get_number_of_chars(this: SvgTextContentElement*) -> i32!:
    let text_contents = svg_text_content_element_text_contents(this)
    return (i32)ak.utf16_string_base_length_in_code_units(&text_contents.utf16_string_base)

## Ported from Libraries/LibWeb/SVG/SVGTextContentElement.cpp:55 Web::SVG::SVGTextContentElement::get_start_position_of_char.
pub func svg_text_content_element_get_start_position_of_char(this: SvgTextContentElement*, charnum: u32) -> GeometryDomPoint*:
    let description = dom_node_debug_description(this.dom_node())
    ak.dbgln(f"(STUBBED) SVGTextContentElement::get_start_position_of_char(charnum={charnum}). Called on: {ak.string_view_text(ak.string_bytes_as_string_view(&description))}")
    return geometry_dom_point_from_point(js_cell_vm(this.js_cell()))