dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / painting / svg_paintable.lucb
#==============================================================================================
#
# svg_paintable - Painting::SVGPaintable: the paintable of an SVG element inside an <svg>
#
# DESCRIPTION:
# Port of LibWeb/Painting/SVGPaintable.cpp (lines 1-82) and SVGPaintable.h: construction,
# the layout box, the bounds and contribution of a <clipPath> child
# (https://drafts.csswg.org/css-masking-1/#ClipPathElement), the absolute rect (relative
# to the nearest <svg> root's chain of containing blocks) and anti-aliasing from
# shape-rendering.
#
# Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
# SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================
## Ported from Libraries/LibWeb/Painting/SVGPaintable.cpp:16 Web::Painting::SVGPaintable::SVGPaintable.
pub func paint_svg_paintable_construct(this: PaintSvgPaintable*, layout_box: LayoutSvgBox*):
paint_paintable_box_construct_layout_box(this.paint_paintable_box(), layout_box.layout_box())
## Ported from Libraries/LibWeb/Painting/SVGPaintable.cpp:21 Web::Painting::SVGPaintable::layout_box.
pub func paint_svg_paintable_layout_box(this: PaintSvgPaintable*) -> LayoutSvgBox*:
return (LayoutSvgBox*)paint_paintable_layout_node(this.paint_paintable())
## Ported from Libraries/LibWeb/Painting/SVGPaintable.cpp:27 Web::Painting::SVGPaintable::contributes_to_clip_path.
# https://drafts.csswg.org/css-masking-1/#ClipPathElement
pub func paint_svg_paintable_contributes_to_clip_path(this: PaintSvgPaintable*) -> bool:
# If a child element is made invisible by display or visibility it does not contribute to the clipping path.
let display = paint_paintable_display(this.paint_paintable())
return css_computed_values_visibility(&paint_paintable_computed_values(this.paint_paintable()).computed_values) == css_data.Visibility.visible and not css_display_is_none(&display)
## Ported from Libraries/LibWeb/Painting/SVGPaintable.cpp:34 Web::Painting::SVGPaintable::clip_path_geometry_bounds (virtual).
# https://drafts.csswg.org/css-masking-1/#ClipPathElement
pub func paint_svg_paintable_clip_path_geometry_bounds_impl(this: PaintSvgPaintable*, additional_transform: gfx.AffineTransform) -> gfx.CssPixelRect?:
if not paint_svg_paintable_contributes_to_clip_path(this):
return none
# When the clipPath element contains multiple child elements, the silhouettes of the child elements are
# logically OR'd together to create a single silhouette which is then used to restrict the region onto
# which paint can be applied. Thus, a point is inside the clipping path if it is inside any of the
# children of the clipPath.
var bounding_box = css_pixel_bounding_box_new()
for child in paint_paintable_children(this.paint_paintable()):
if not is_paint_paintable_box(child):
continue
let svg_paintable = as_if_paint_svg_paintable(child) else continue
let child_bounds = paint_svg_paintable_clip_path_geometry_bounds(svg_paintable, additional_transform) else continue
css_pixel_bounding_box_add_point(&bounding_box, gfx.css_pixel_rect_left(&child_bounds), gfx.css_pixel_rect_top(&child_bounds))
css_pixel_bounding_box_add_point(&bounding_box, gfx.css_pixel_rect_right(&child_bounds), gfx.css_pixel_rect_bottom(&child_bounds))
if css_pixel_bounding_box_has_no_points(&bounding_box):
return none
return css_pixel_bounding_box_to_rect(&bounding_box)
## Ported from Libraries/LibWeb/Painting/SVGPaintable.cpp:63 Web::Painting::SVGPaintable::compute_absolute_rect (override).
pub func paint_svg_paintable_compute_absolute_rect_impl(base: PaintPaintableBox*) -> gfx.CssPixelRect:
let this = (PaintSvgPaintable*)base
if let svg_svg_box = tree_node_first_ancestor_of_type(paint_svg_paintable_layout_box(this).layout_node(), &layout_svgsvg_box_class):
var rect: gfx.CssPixelRect = ---
gfx.css_pixel_rect_construct_css_pixel_point(&rect, paint_paintable_box_offset(base), paint_paintable_box_content_size(base))
var ancestor: LayoutBox*? = (LayoutBox*)svg_svg_box
while let at = ancestor:
let ancestor_paintable_box = layout_box_paintable_box(at) else trap("VERIFY: an ancestor of an SVG box has a paintable box")
gfx.css_pixel_rect_translate_by_css_pixel_point(&rect, paint_paintable_box_offset(ancestor_paintable_box))
ancestor = layout_node_containing_block(at.layout_node())
return rect
return paint_paintable_box_compute_absolute_rect_impl(base)
## Ported from Libraries/LibWeb/Painting/SVGPaintable.cpp:74 Web::Painting::SVGPaintable::should_anti_alias.
pub func paint_svg_paintable_should_anti_alias(this: PaintSvgPaintable*) -> display_list.ShouldAntiAlias:
let shape_rendering = css_computed_values_shape_rendering(&paint_paintable_computed_values(this.paint_paintable()).computed_values)
if shape_rendering == css_data.ShapeRendering.optimizespeed or shape_rendering == css_data.ShapeRendering.crispedges:
return display_list.ShouldAntiAlias.no
return display_list.ShouldAntiAlias.yes
## Ported from Libraries/LibWeb/Painting/SVGPaintable.h:23 Web::Painting::SVGPaintable::is_svg_paintable (override).
pub func paint_svg_paintable_is_svg_paintable_impl(base: PaintPaintable*) -> bool:
_ = base
return true