Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / painting / svg_graphics_paintable.lucb

#==============================================================================================
#
#   svg_graphics_paintable - Painting::SVGGraphicsPaintable: the paintable of an SVG graphics
#                            element and its computed transforms
#
#   DESCRIPTION:
#       Port of LibWeb/Painting/SVGGraphicsPaintable.cpp (lines 1-35) and
#       SVGGraphicsPaintable.h: ComputedTransforms (the viewBox transform and the element's
#       accumulated SVG transform, and the transforms from SVG user units to CSS and device
#       pixels), creation, the SVGMaskable overrides (masks and clip paths of the element)
#       and the reset before a relayout.
#
#       SVGMaskable is a stateful mixin (DESIGN.md ยง2.5): its struct sits at
#       `svg_maskable` inside the paintable, and the overrides recover the paintable from it.
#
#       Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

# mark: ComputedTransforms ======================================================================

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:24 Web::Painting::SVGGraphicsPaintable::ComputedTransforms::ComputedTransforms.
pub func paint_svg_graphics_paintable_computed_transforms_construct(this: PaintSvgGraphicsPaintableComputedTransforms*, svg_to_viewbox_transform: gfx.AffineTransform, svg_transform: gfx.AffineTransform):
    this.m_svg_to_viewbox_transform = svg_to_viewbox_transform
    this.m_svg_transform = svg_transform

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:30 Web::Painting::SVGGraphicsPaintable::ComputedTransforms::ComputedTransforms
## (the default constructor: both transforms are the identity).
pub func paint_svg_graphics_paintable_computed_transforms_new() -> PaintSvgGraphicsPaintableComputedTransforms:
    return PaintSvgGraphicsPaintableComputedTransforms(m_svg_to_viewbox_transform = layout_identity_affine_transform(), m_svg_transform = layout_identity_affine_transform())

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:32 Web::Painting::SVGGraphicsPaintable::ComputedTransforms::svg_to_viewbox_transform.
pub func paint_svg_graphics_paintable_computed_transforms_svg_to_viewbox_transform(this: const PaintSvgGraphicsPaintableComputedTransforms*) -> gfx.AffineTransform:
    return this.m_svg_to_viewbox_transform

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:33 Web::Painting::SVGGraphicsPaintable::ComputedTransforms::svg_transform.
pub func paint_svg_graphics_paintable_computed_transforms_svg_transform(this: const PaintSvgGraphicsPaintableComputedTransforms*) -> gfx.AffineTransform:
    return this.m_svg_transform

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:35 Web::Painting::SVGGraphicsPaintable::ComputedTransforms::svg_to_css_pixels_transform.
pub func paint_svg_graphics_paintable_computed_transforms_svg_to_css_pixels_transform(this: const PaintSvgGraphicsPaintableComputedTransforms*, additional_svg_transform: const gfx.AffineTransform*? = none) -> gfx.AffineTransform:
    var transform = layout_identity_affine_transform()
    gfx.affine_transform_multiply(&transform, paint_svg_graphics_paintable_computed_transforms_svg_to_viewbox_transform(this))
    var additional = layout_identity_affine_transform()
    if let given = additional_svg_transform:
        additional = *given
    gfx.affine_transform_multiply(&transform, additional)
    gfx.affine_transform_multiply(&transform, paint_svg_graphics_paintable_computed_transforms_svg_transform(this))
    return transform

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:41 Web::Painting::SVGGraphicsPaintable::ComputedTransforms::svg_to_device_pixels_transform.
pub func paint_svg_graphics_paintable_computed_transforms_svg_to_device_pixels_transform(this: const PaintSvgGraphicsPaintableComputedTransforms*, context: const DisplayListRecordingContext*) -> gfx.AffineTransform:
    let css_scale = display_list_recording_context_device_pixels_per_css_pixel(context)
    var transform = layout_identity_affine_transform()
    gfx.affine_transform_scale_float_point(&transform, gfx.FloatPoint(m_x = (f32)css_scale, m_y = (f32)css_scale))
    let context_svg_transform = display_list_recording_context_svg_transform(context)
    gfx.affine_transform_multiply(&transform, paint_svg_graphics_paintable_computed_transforms_svg_to_css_pixels_transform(this, &context_svg_transform))
    return transform

# mark: SVGGraphicsPaintable ====================================================================

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.cpp:19 Web::Painting::SVGGraphicsPaintable::create.
pub func paint_svg_graphics_paintable_create(layout_box: LayoutSvgGraphicsBox*) -> PaintSvgGraphicsPaintable*:
    let heap = gc.cell_heap(layout_box.cell())
    let this = (PaintSvgGraphicsPaintable*)web_heap_allocate_cell(heap, &paint_svg_graphics_paintable_class)
    gc.heap_defer_gc(heap)
    paint_svg_graphics_paintable_construct(this, layout_box)
    gc.heap_undefer_gc(heap)
    return this

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.cpp:24 Web::Painting::SVGGraphicsPaintable::SVGGraphicsPaintable.
pub func paint_svg_graphics_paintable_construct(this: PaintSvgGraphicsPaintable*, layout_box: LayoutSvgGraphicsBox*):
    paint_svg_paintable_construct(this.paint_svg_paintable(), layout_box.layout_svg_box())
    # The SVGMaskable base: its vptr, and the members' default initializers.
    paint_svg_graphics_paintable_set_maskable_class(this, &paint_svg_graphics_paintable_svg_maskable_vtable)
    this.m_computed_transforms = paint_svg_graphics_paintable_computed_transforms_new()

## The vptr of the SVGMaskable base of an SVGGraphicsPaintable (or a subclass, whose constructor moves it to its own table).
pub func paint_svg_graphics_paintable_set_maskable_class(this: PaintSvgGraphicsPaintable*, vtable: const PaintSvgMaskableVTable*):
    this.svg_maskable.vtable = vtable
    this.svg_maskable.class_id = this.cell().class_id

## The SVGGraphicsPaintable an SVGMaskable base belongs to (the C++ `this` adjustment).
func paint_svg_graphics_paintable_from_svg_maskable(maskable: PaintSvgMaskable*) -> PaintSvgGraphicsPaintable*:
    return (PaintSvgGraphicsPaintable*)((u8*)maskable - memory.offset_of(PaintSvgGraphicsPaintable, svg_maskable))

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:54 Web::Painting::SVGGraphicsPaintable::dom_node_of_svg (override).
pub func paint_svg_graphics_paintable_dom_node_of_svg_impl(base: PaintSvgMaskable*) -> DomNode*?:
    return paint_paintable_dom_node(paint_svg_graphics_paintable_from_svg_maskable(base).paint_paintable())

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:55 Web::Painting::SVGGraphicsPaintable::get_mask_area (override).
pub func paint_svg_graphics_paintable_get_mask_area_impl(base: PaintPaintableBox*) -> gfx.CssPixelRect?:
    return paint_svg_maskable_get_svg_mask_area(&((PaintSvgGraphicsPaintable*)base).svg_maskable)

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:56 Web::Painting::SVGGraphicsPaintable::get_mask_type (override).
pub func paint_svg_graphics_paintable_get_mask_type_impl(base: PaintPaintableBox*) -> gfx.MaskKind?:
    return paint_svg_maskable_get_svg_mask_type(&((PaintSvgGraphicsPaintable*)base).svg_maskable)

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:57 Web::Painting::SVGGraphicsPaintable::calculate_mask (override).
pub func paint_svg_graphics_paintable_calculate_mask_impl(base: PaintPaintableBox*, context: DisplayListRecordingContext*, mask_area: gfx.CssPixelRect) -> display_list.DisplayList*?:
    return paint_svg_maskable_calculate_svg_mask_display_list(&((PaintSvgGraphicsPaintable*)base).svg_maskable, context, mask_area)

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:58 Web::Painting::SVGGraphicsPaintable::get_clip_area (override).
pub func paint_svg_graphics_paintable_get_clip_area_impl(base: PaintPaintableBox*) -> gfx.CssPixelRect?:
    return paint_svg_maskable_get_svg_clip_area(&((PaintSvgGraphicsPaintable*)base).svg_maskable)

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:59 Web::Painting::SVGGraphicsPaintable::calculate_clip (override).
pub func paint_svg_graphics_paintable_calculate_clip_impl(base: PaintPaintableBox*, context: DisplayListRecordingContext*, clip_area: gfx.CssPixelRect) -> display_list.DisplayList*?:
    return paint_svg_maskable_calculate_svg_clip_display_list(&((PaintSvgGraphicsPaintable*)base).svg_maskable, context, clip_area)

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:61 Web::Painting::SVGGraphicsPaintable::set_computed_transforms.
pub func paint_svg_graphics_paintable_set_computed_transforms(this: PaintSvgGraphicsPaintable*, computed_transforms: PaintSvgGraphicsPaintableComputedTransforms):
    this.m_computed_transforms = computed_transforms

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:66 Web::Painting::SVGGraphicsPaintable::computed_transforms.
pub func paint_svg_graphics_paintable_computed_transforms(this: PaintSvgGraphicsPaintable*) -> PaintSvgGraphicsPaintableComputedTransforms:
    return this.m_computed_transforms

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.cpp:29 Web::Painting::SVGGraphicsPaintable::reset_for_relayout (override).
pub func paint_svg_graphics_paintable_reset_for_relayout_impl(base: PaintPaintableBox*):
    let this = (PaintSvgGraphicsPaintable*)base
    paint_paintable_box_reset_for_relayout_impl(base)
    this.m_computed_transforms = paint_svg_graphics_paintable_computed_transforms_new()

## Ported from Libraries/LibWeb/Painting/SVGGraphicsPaintable.h:79 Web::Painting::SVGGraphicsPaintable::is_svg_graphics_paintable (override).
pub func paint_svg_graphics_paintable_is_svg_graphics_paintable_impl(base: PaintPaintable*) -> bool:
    _ = base
    return true