Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / painting / svgsvg_paintable.lucb

#==============================================================================================
#
#   svgsvg_paintable - Painting::SVGSVGPaintable: the paintable of an <svg> root
#
#   DESCRIPTION:
#       Port of LibWeb/Painting/SVGSVGPaintable.cpp (lines 1-84) and SVGSVGPaintable.h:
#       creation, and painting an SVG box with its masks and clip paths, then its descendants
#       (SVG content does not form stacking contexts: it is painted in tree order).
#
#       Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/Painting/SVGSVGPaintable.cpp:16 Web::Painting::SVGSVGPaintable::create.
pub func paint_svgsvg_paintable_create(layout_box: LayoutSvgsvgBox*) -> PaintSvgsvgPaintable*:
    let heap = gc.cell_heap(layout_box.cell())
    let this = (PaintSvgsvgPaintable*)web_heap_allocate_cell(heap, &paint_svgsvg_paintable_class)
    gc.heap_defer_gc(heap)
    paint_svgsvg_paintable_construct(this, layout_box)
    gc.heap_undefer_gc(heap)
    return this

## Ported from Libraries/LibWeb/Painting/SVGSVGPaintable.cpp:21 Web::Painting::SVGSVGPaintable::SVGSVGPaintable.
pub func paint_svgsvg_paintable_construct(this: PaintSvgsvgPaintable*, layout_box: LayoutSvgsvgBox*):
    paint_paintable_box_construct_layout_box(this.paint_paintable_box(), layout_box.layout_box())

## Ported from Libraries/LibWeb/Painting/SVGSVGPaintable.cpp:26 Web::Painting::SVGSVGPaintable::paint_svg_box.
pub func paint_svgsvg_paintable_paint_svg_box(context: DisplayListRecordingContext*, svg_box: PaintPaintableBox*, phase: PaintPhase):
    let recorder = display_list_recording_context_display_list_recorder(context)
    display_list.display_list_recorder_set_accumulated_visual_context(recorder, paint_paintable_box_accumulated_visual_context_index(svg_box))

    # For elements with SVG filters, emit a transparent FillRect to trigger filter application.
    # This ensures content-generating filters (feFlood, feImage) work even with empty source.
    let filter = paint_paintable_box_filter(svg_box)
    if let bounds = filter.svg_filter_bounds:
        let device_rect = display_list_recording_context_enclosing_device_rect(context, bounds)
        display_list.display_list_recorder_fill_rect_transparent(recorder, device_rect)

    # Collect masks (SVG <mask>, SVG <clipPath>).
    var masks: ak.Vector[display_list.DisplayListRecorderMaskInfo]

    var skip_painting = false

    if let mask_area = paint_paintable_box_get_mask_area(svg_box):
        if gfx.css_pixel_rect_is_empty(&mask_area):
            skip_painting = true
        elif let mask_display_list = paint_paintable_box_calculate_mask(svg_box, context, mask_area):
            let rect = display_list_recording_context_enclosing_device_rect(context, mask_area)
            let kind = paint_paintable_box_get_mask_type(svg_box) else gfx.MaskKind.alpha
            ak.vector_append_t(&masks, display_list.DisplayListRecorderMaskInfo(display_list = mask_display_list, rect = rect, kind = kind))

    if let clip_area = paint_paintable_box_get_clip_area(svg_box):
        if gfx.css_pixel_rect_is_empty(&clip_area):
            skip_painting = true
        elif let clip_display_list = paint_paintable_box_calculate_clip(svg_box, context, clip_area):
            let rect = display_list_recording_context_enclosing_device_rect(context, clip_area)
            ak.vector_append_t(&masks, display_list.DisplayListRecorderMaskInfo(display_list = clip_display_list, rect = rect, kind = gfx.MaskKind.alpha))

    display_list.display_list_recorder_begin_masks(recorder, ak.vector_span(&masks))

    if not skip_painting:
        paint_paintable_paint(svg_box.paint_paintable(), context, PaintPhase.foreground)
        paint_svgsvg_paintable_paint_descendants(context, svg_box, phase)

    display_list.display_list_recorder_end_masks(recorder, ak.vector_span(&masks))

## Ported from Libraries/LibWeb/Painting/SVGSVGPaintable.cpp:73 Web::Painting::SVGSVGPaintable::paint_descendants.
pub func paint_svgsvg_paintable_paint_descendants(context: DisplayListRecordingContext*, paintable: PaintPaintableBox*, phase: PaintPhase):
    if phase != PaintPhase.foreground:
        return

    for child in paint_paintable_children(paintable.paint_paintable()):
        if not is_paint_paintable_box(child):
            continue
        paint_svgsvg_paintable_paint_svg_box(context, (PaintPaintableBox*)child, phase)

## Ported from Libraries/LibWeb/Painting/SVGSVGPaintable.h:28 Web::Painting::SVGSVGPaintable::is_svg_svg_paintable (override).
pub func paint_svgsvg_paintable_is_svg_svg_paintable_impl(base: PaintPaintable*) -> bool:
    _ = base
    return true