Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / svg / svg_polygon_element.lucb

#==============================================================================================
#
#   svg_polygon_element - SVG::SVGPolygonElement: <polygon>
#
#   DESCRIPTION:
#       Port of LibWeb/SVG/SVGPolygonElement.cpp: the `points` attribute and the path through
#       them (https://svgwg.org/svg2-draft/shapes.html#PolygonElement).
#
#==============================================================================================

## Ported from Libraries/LibWeb/SVG/SVGPolygonElement.cpp:19 Web::SVG::SVGPolygonElement::SVGPolygonElement.
pub func svg_polygon_element_construct(this: SvgPolygonElement*, document: DomDocument*, qualified_name: DomQualifiedName):
    svg_geometry_element_construct(this.svg_geometry_element(), document, qualified_name)
    # The vptrs of the mixin bases move to SVGPolygonElement's tables.
    let element = this.svg_element()
    element.element.slottable_mixin.vtable = &svg_polygon_element_slottable_mixin_vtable
    element.element.aria_mixin.vtable = &svg_polygon_element_aria_mixin_vtable
    element.element.animatable.vtable = &svg_polygon_element_animatable_vtable
    element.global_event_handlers.vtable = &svg_polygon_element_global_event_handlers_vtable

## Ported from Libraries/LibWeb/SVG/SVGPolygonElement.cpp:24 Web::SVG::SVGPolygonElement::initialize (override).
pub func svg_polygon_element_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.svg_polygon_element)
    svg_geometry_element_initialize_impl(base, realm)

## Ported from Libraries/LibWeb/SVG/SVGPolygonElement.cpp:30 Web::SVG::SVGPolygonElement::attribute_changed (override).
pub func svg_polygon_element_attribute_changed_impl(base: DomElement*, name: ak.FlyString, old_value: ak.String?, value: ak.String?, namespace_: ak.FlyString?):
    let this = (SvgPolygonElement*)base
    svg_graphics_element_attribute_changed_impl(base, name, old_value, value, namespace_)
    let value_text = value else ak.String()  # value.value_or(String {})

    if ak.fly_string_eq_fly_string(&name, &svg_attribute_names_points):
        this.m_points = svg_attribute_parser_parse_points(ak.string_bytes_as_string_view(&value_text))
        dom_node_set_needs_layout_update(base.dom_node(), DomSetNeedsLayoutReason.style_change)

## Ported from Libraries/LibWeb/SVG/SVGPolygonElement.cpp:40 Web::SVG::SVGPolygonElement::get_path (override).
pub func svg_polygon_element_get_path_impl(base: SvgGeometryElement*, viewport_size: gfx.CssPixelSize) -> gfx.Path:
    let this = (SvgPolygonElement*)base
    var path: gfx.Path

    if ak.vector_is_empty(&this.m_points):
        return path

    # 1. perform an absolute moveto operation to the first coordinate pair in the list of points
    gfx.path_move_to(&path, *ak.vector_first(&this.m_points))

    # 2. for each subsequent coordinate pair, perform an absolute lineto operation to that coordinate pair.
    for point_index in 1..<ak.vector_size(&this.m_points):
        gfx.path_line_to(&path, *ak.vector_at(&this.m_points, point_index))

    # 3. perform a closepath command
    gfx.path_close(&path)

    return path