svg

Standalone SVG scene graph and renderer

svg
graphics
moon add mizchi/svg@0.2.3
Download zip
Author
Version
0.2.3
License
Apache-2.0
Last updated
18 hours ago
Downloads
29K
README

#mizchi/svg

Standalone SVG scene graph, parser, and CPU rasterizer for MoonBit. It can render SVG markup or an external SVGNode tree into an Image or any custom pixel target.

#Install

moon add mizchi/svg

#Quick Start (SVG string -> Image)

let svg = "<svg width=\"10\" height=\"10\"><rect x=\"1\" y=\"1\" width=\"8\" height=\"8\" fill=\"red\"/></svg>"
match render_svg_to_image(svg, 16, 16) {
Some(image) => image
None => panic("parse failed")
}

#DOM Integration (external tree -> Image)

Build an SVGNode tree from your DOM, then render:

let node = rect("r", 2.0, 2.0, 6.0, 6.0)
node.fill = SolidColor(Color::black())
let doc = SVGDocument::new(node)
let image = render_svg_document_to_image(doc, 16, 16)

If you already have a scene graph:

let scene = Scene::new(node)
let image = render_svg_scene_to_image(scene, 16, 16)

#Custom Rendering Target

You can render into any target by providing a PixelSetter and RenderContext.

let image = Image::new(64, 64)
let setter : PixelSetter = { set: fn(x, y, c) { image.set_pixel(x, y, c) } }
let ctx = RenderContext::new(setter, 64, 64)
let doc = SVGDocument::new(rect("r", 0.0, 0.0, 10.0, 10.0))
doc.render(ctx)

#Main API

  • Parsing: parse_svg, parse_svg_document
  • Scene graph: SVGNode, Scene, SVGDocument
  • Rendering: RenderContext, PixelSetter, render_svg_*_to_image
  • Geometry: PathCommand, Transform, ViewBox, BoundingBox
  • Raster: raster_* (low-level drawing primitives)

#WPT (SVG Reftests)

This repo can run a static, DOM-independent subset of WPT SVG reftests. Tests are generated from the WPT submodule and rendered with the CPU rasterizer.

git submodule update --init --depth 1 wpt just wpt-svg

You can limit generation:

just wpt-svg --limit=50

Notes:
  • Only .svg reftests with <link rel=\"match\"> are included.
  • Tests with scripts/animation/foreignObject/styles are skipped.
  • Many tests will fail until the renderer covers those features.
  • Comparison uses a per-channel tolerance (<=2) and allows up to 0.5% differing pixels.

#
Align

pub(all) enum Align {
None
XMinYMin
XMidYMin
XMaxYMin
XMinYMid
XMidYMid
XMaxYMid
XMinYMax
XMidYMax
XMaxYMax
} derive(Eq,
Debug
)

preserveAspectRatio alignment values
impl Show for Align

#
AnimProperty

pub(all) enum AnimProperty {
TranslateX(Double)
TranslateY(Double)
Translate(Double, Double)
ScaleX(Double)
ScaleY(Double)
Scale(Double, Double)
ScaleUniform(Double)
Rotation(Double)
Opacity(Double)
FillColor(Color)
}

Animatable property types

#
AnimatedSprite

pub(all) struct AnimatedSprite {
sheet : SpriteSheet
frames : Array[Int]
current_frame : Int
frame_duration : Double
elapsed : Double
looping : Bool
playing : Bool
}

Animated sprite helper

#
AnimatedSprite::continue_playing

fn AnimatedSprite::continue_playing(self : AnimatedSprite) -> Unit

Continue animation

#
AnimatedSprite::from_range

fn AnimatedSprite::from_range(sheet : SpriteSheet, start : Int, end : Int, frame_duration : Double) -> AnimatedSprite

Create animation for a range of frames

#
AnimatedSprite::get_current_sprite

fn AnimatedSprite::get_current_sprite(self : AnimatedSprite) -> Sprite

Get current sprite

#
AnimatedSprite::new

fn AnimatedSprite::new(sheet : SpriteSheet, frames : Array[Int], frame_duration : Double) -> AnimatedSprite

Create an animated sprite

#
AnimatedSprite::pause

fn AnimatedSprite::pause(self : AnimatedSprite) -> Unit

Pause animation

#
AnimatedSprite::play

fn AnimatedSprite::play(self : AnimatedSprite) -> Unit

Play animation from beginning

#
AnimatedSprite::set_looping

fn AnimatedSprite::set_looping(self : AnimatedSprite, looping : Bool) -> Unit

Set looping

#
AnimatedSprite::stop

fn AnimatedSprite::stop(self : AnimatedSprite) -> Unit

Stop animation

#
AnimatedSprite::update

fn AnimatedSprite::update(self : AnimatedSprite, dt : Double) -> Unit

Update animation with delta time

#
AnimationManager

pub(all) struct AnimationManager {
tweens : Array[Tween]
}

Animation manager for coordinating multiple tweens

#
AnimationManager::add

fn AnimationManager::add(self : AnimationManager, tween : Tween) -> Unit

Add a new tween animation

#
AnimationManager::animate_opacity

fn AnimationManager::animate_opacity(self : AnimationManager, target_id : String, opacity : Double, duration : Double, easing : Easing) -> Unit

Create and add a simple opacity animation

#
AnimationManager::animate_scale

fn AnimationManager::animate_scale(self : AnimationManager, target_id : String, scale : Double, duration : Double, easing : Easing) -> Unit

Create and add a simple scale animation

#
AnimationManager::animate_translate

fn AnimationManager::animate_translate(self : AnimationManager, target_id : String, x : Double, y : Double, duration : Double, easing : Easing) -> Unit

Create and add a simple translate animation

#
AnimationManager::cleanup

fn AnimationManager::cleanup(self : AnimationManager) -> Unit

Remove completed animations

#
AnimationManager::clear

fn AnimationManager::clear(self : AnimationManager) -> Unit

Clear all animations

#
AnimationManager::is_animating

fn AnimationManager::is_animating(self : AnimationManager) -> Bool

Check if any animations are running

#
AnimationManager::new

#
AnimationManager::update

fn AnimationManager::update(self : AnimationManager, dt : Double, scene : Scene) -> Bool

Update all animations with delta time Returns true if any animations are still running

#
BlendMode

pub(all) enum BlendMode {
Normal
Multiply
Screen
Overlay
Darken
Lighten
ColorDodge
ColorBurn
HardLight
SoftLight
Difference
Exclusion
Hue
Saturation
ColorMode
Luminosity
} derive(Eq,
Debug
)

CSS mix-blend-mode values

#
BoundingBox

pub(all) struct BoundingBox {
min_x : Double
min_y : Double
max_x : Double
max_y : Double
}

Bounding box for a shape

#
BoundingBox::contains_point

fn BoundingBox::contains_point(self : BoundingBox, x : Double, y : Double) -> Bool

Check if this bounding box contains a point

#
BoundingBox::empty

fn BoundingBox::empty() -> BoundingBox

#
BoundingBox::expand_by_point

fn BoundingBox::expand_by_point(self : BoundingBox, x : Double, y : Double) -> BoundingBox

#
BoundingBox::from_rect

fn BoundingBox::from_rect(x : Double, y : Double, w : Double, h : Double) -> BoundingBox

#
BoundingBox::height

fn BoundingBox::height(self : BoundingBox) -> Double

#
BoundingBox::intersects

fn BoundingBox::intersects(self : BoundingBox, other : BoundingBox) -> Bool

Check if two bounding boxes intersect

#
BoundingBox::is_empty

fn BoundingBox::is_empty(self : BoundingBox) -> Bool

#
BoundingBox::union

fn BoundingBox::union(self : BoundingBox, other : BoundingBox) -> BoundingBox

#
BoundingBox::width

fn BoundingBox::width(self : BoundingBox) -> Double

#
Camera

pub(all) struct Camera {
x : Double
y : Double
zoom : Double
viewport_width : Int
viewport_height : Int
}

Camera for 2D scene navigation Supports pan (translation) and zoom

#
Camera::get_transform

fn Camera::get_transform(self : Camera) -> Transform

Get transform matrix for this camera

#
Camera::get_visible_bounds

fn Camera::get_visible_bounds(self : Camera) -> BoundingBox

Get the world-space bounding box visible through this camera

#
Camera::new

fn Camera::new(viewport_width : Int, viewport_height : Int) -> Camera

#
Camera::pan

fn Camera::pan(self : Camera, dx : Double, dy : Double) -> Unit

Move camera by delta

#
Camera::screen_to_world

fn Camera::screen_to_world(self : Camera, sx : Int, sy : Int) -> (Double, Double)

Convert screen coordinates to world coordinates

#
Camera::set_position

fn Camera::set_position(self : Camera, x : Double, y : Double) -> Unit

Set camera position

#
Camera::set_zoom

fn Camera::set_zoom(self : Camera, zoom : Double) -> Unit

Set zoom level

#
Camera::world_to_screen

fn Camera::world_to_screen(self : Camera, wx : Double, wy : Double) -> (Int, Int)

Convert world coordinates to screen coordinates

#
Camera::zoom_by

fn Camera::zoom_by(self : Camera, factor : Double) -> Unit

Zoom by factor (multiply current zoom)

#
ClipPath

pub(all) struct ClipPath {
id : String
shape : Shape
transform : Transform
clip_rule : FillRule
units : ClipPathUnits
}

Clip path definition

#
ClipPath::contains

fn ClipPath::contains(self : ClipPath, x : Double, y : Double) -> Bool

Check if a point is inside the clip path

#
ClipPath::new

fn ClipPath::new(id : String, shape : Shape) -> ClipPath

#
ClipPath::with_transform

fn ClipPath::with_transform(id : String, shape : Shape, transform : Transform) -> ClipPath

#
ClipPathRegistry

pub(all) struct ClipPathRegistry {
clips : Map[String, ClipPath]
}

Clip path registry for referencing by ID

#
ClipPathRegistry::add

fn ClipPathRegistry::add(self : ClipPathRegistry, clip : ClipPath) -> Unit

#
ClipPathRegistry::get

fn ClipPathRegistry::get(self : ClipPathRegistry, id : String) -> ClipPath?

#
ClipPathRegistry::new

#
ClipPathUnits

pub(all) enum ClipPathUnits {
UserSpaceOnUse
ObjectBoundingBox
} derive(Eq,
Debug
)

Clip path units for coordinate system

#
ClipRect

pub(all) struct ClipRect {
x : Int
y : Int
width : Int
height : Int
}

Clipping rectangle for camera/viewport

#
ClipRect::contains

fn ClipRect::contains(self : ClipRect, x : Int, y : Int) -> Bool

Check if a point is inside the clip rect

#
ClipRect::from_size

fn ClipRect::from_size(width : Int, height : Int) -> ClipRect

#
ClipRect::new

fn ClipRect::new(x : Int, y : Int, width : Int, height : Int) -> ClipRect

#
ClipRect::to_bbox

fn ClipRect::to_bbox(self : ClipRect) -> BoundingBox

Convert to BoundingBox

#
Color

pub(all) struct Color {
r : Int
g : Int
b : Int
a : Int
}

RGB Color (0-255 range)

#
Color::black

fn Color::black() -> Color

#
Color::is_transparent

fn Color::is_transparent(self : Color) -> Bool

#
Color::rgb

fn Color::rgb(r : Int, g : Int, b : Int) -> Color

#
Color::rgba

fn Color::rgba(r : Int, g : Int, b : Int, a : Int) -> Color

#
Color::transparent

fn Color::transparent() -> Color

#
Color::white

fn Color::white() -> Color

#
DefsRegistry

pub(all) struct DefsRegistry {
elements : Map[String, SVGNode]
}

Registry for reusable elements defined in

#
DefsRegistry::add

fn DefsRegistry::add(self : DefsRegistry, id : String, node : SVGNode) -> Unit

#
DefsRegistry::get

fn DefsRegistry::get(self : DefsRegistry, id : String) -> SVGNode?

#
DefsRegistry::new

#
DominantBaseline

pub(all) enum DominantBaseline {
Auto
TextTop
Hanging
Middle
Central
TextBottom
Alphabetic
Ideographic
}

Dominant baseline (vertical alignment)

#
Easing

pub(all) enum Easing {
Linear
EaseIn
EaseOut
EaseInOut
EaseInCubic
EaseOutCubic
EaseInOutCubic
} derive(Eq,
Debug
)

Easing functions for smooth animations

#
Easing::apply

fn Easing::apply(self : Easing, t : Double) -> Double

Apply easing function to a normalized time (0.0 to 1.0)

#
EmitterConfig

pub(all) struct EmitterConfig {
emit_rate : Double
life_min : Double
life_max : Double
speed_min : Double
speed_max : Double
angle_min : Double
angle_max : Double
size_start : Double
size_end : Double
color_start : Color
color_end : Color
gravity_x : Double
gravity_y : Double
}

Particle emitter configuration

#
EmitterConfig::default

fn EmitterConfig::default() -> EmitterConfig

#
EventHandler

pub(all) struct EventHandler {
call : (PointerEvent) -> Unit
}

Event handler type

#
EventListener

pub(all) struct EventListener {
event_type : EventType
handler : EventHandler
}

Event listener entry

#
EventManager

pub(all) struct EventManager {
listeners : Map[String, Array[EventListener]]
hovered_node : String?
dragging_node : String?
drag_start_x : Double
drag_start_y : Double
}

Event manager for handling input events

#
EventManager::dispatch_click

fn EventManager::dispatch_click(self : EventManager, x : Double, y : Double, button : Int, scene : Scene) -> Unit

Dispatch a click event at coordinates

#
EventManager::dispatch_mouse_down

fn EventManager::dispatch_mouse_down(self : EventManager, x : Double, y : Double, button : Int, scene : Scene) -> Unit

Dispatch mouse down event

#
EventManager::dispatch_mouse_move

fn EventManager::dispatch_mouse_move(self : EventManager, x : Double, y : Double, scene : Scene) -> Unit

Dispatch mouse move event (handles hover and drag)

#
EventManager::dispatch_mouse_up

fn EventManager::dispatch_mouse_up(self : EventManager, x : Double, y : Double, button : Int, scene : Scene) -> Unit

Dispatch mouse up event

#
EventManager::new

#
EventManager::off_all

fn EventManager::off_all(self : EventManager, node_id : String) -> Unit

Remove all listeners for a node

#
EventManager::on

fn EventManager::on(self : EventManager, node_id : String, event_type : EventType, handler : EventHandler) -> Unit

Register an event listener for a node

#
EventType

pub(all) enum EventType {
Click
MouseDown
MouseUp
MouseMove
MouseEnter
MouseLeave
DragStart
DragMove
DragEnd
} derive(Eq,
Debug
)

Event types

#
FillRule

pub(all) enum FillRule {
NonZero
EvenOdd
} derive(Eq,
Debug
)

Fill rule for paths and polygons
impl Show for FillRule

#
Filter

pub(all) enum Filter {
Blur(Double)
DropShadow(Double, Double, Double, Color)
Brightness(Double)
Contrast(Double)
Grayscale(Double)
Sepia(Double)
HueRotate(Double)
Invert(Double)
Saturate(Double)
ColorMatrix(FixedArray[Double])
}

Filter types

#
FontStyle

pub(all) enum FontStyle {
NormalStyle
Italic
Oblique
}

Font style

#
FontWeight

pub(all) enum FontWeight {
Normal
Bold
Lighter
Bolder
Weight(Int)
}

Font weight

#
Gradient

pub(all) enum Gradient {
Linear(LinearGradient)
Radial(RadialGradient)
}

Gradient definitions

#
GradientRegistry

pub(all) struct GradientRegistry {
gradients : Map[String, Gradient]
}

Gradient registry

#
GradientRegistry::add

fn GradientRegistry::add(self : GradientRegistry, id : String, gradient : Gradient) -> Unit

#
GradientRegistry::get

fn GradientRegistry::get(self : GradientRegistry, id : String) -> Gradient?

#
GradientRegistry::new

#
GradientStop

pub(all) struct GradientStop {
offset : Double
color : Color
}

Gradient stop (position 0.0-1.0 and color)

#
GradientUnits

pub(all) enum GradientUnits {
UserSpaceOnUse
ObjectBoundingBox
} derive(Eq,
Debug
)

Gradient units coordinate space

#
Image

pub(all) struct Image {
width : Int
height : Int
pixels : Array[Color]
}

Image data (RGBA pixels)

#
Image::apply_blur_in_place

fn Image::apply_blur_in_place(self : Image, radius : Int) -> Unit

Apply blur filter in place

#
Image::apply_brightness_in_place

fn Image::apply_brightness_in_place(self : Image, factor : Double) -> Unit

Apply brightness filter in place

#
Image::apply_color_matrix_in_place

fn Image::apply_color_matrix_in_place(self : Image, matrix : FixedArray[Double]) -> Unit

Apply color matrix filter in place

#
Image::apply_contrast_in_place

fn Image::apply_contrast_in_place(self : Image, factor : Double) -> Unit

Apply contrast filter in place

#
Image::apply_filter

fn Image::apply_filter(self : Image, filter : Filter) -> Image

Apply a filter and return a new image

#
Image::apply_grayscale_in_place

fn Image::apply_grayscale_in_place(self : Image, amount : Double) -> Unit

Apply grayscale filter in place

#
Image::apply_hue_rotate_in_place

fn Image::apply_hue_rotate_in_place(self : Image, angle_degrees : Double) -> Unit

Apply hue rotate filter in place

#
Image::apply_invert_in_place

fn Image::apply_invert_in_place(self : Image, amount : Double) -> Unit

Apply invert filter in place

#
Image::apply_saturate_in_place

fn Image::apply_saturate_in_place(self : Image, factor : Double) -> Unit

Apply saturate filter in place

#
Image::apply_sepia_in_place

fn Image::apply_sepia_in_place(self : Image, amount : Double) -> Unit

Apply sepia filter in place

#
Image::clear

fn Image::clear(self : Image) -> Unit

Clear image to transparent

#
Image::clone

fn Image::clone(self : Image) -> Image

Clone the image

#
Image::fill_horizontal_line

fn Image::fill_horizontal_line(self : Image, x1 : Int, x2 : Int, y : Int, color : Color) -> Unit

Fill a horizontal line (optimized for scanline rendering) x1 and x2 are inclusive, caller should ensure y is valid

#
Image::fill_rect

fn Image::fill_rect(self : Image, x : Int, y : Int, w : Int, h : Int, color : Color) -> Unit

Fill a rectangle region

#
Image::filled

fn Image::filled(width : Int, height : Int, color : Color) -> Image

Create an image filled with a color

#
Image::flip_horizontal

fn Image::flip_horizontal(self : Image) -> Image

Flip image horizontally

#
Image::flip_vertical

fn Image::flip_vertical(self : Image) -> Image

Flip image vertically

#
Image::get_pixel

fn Image::get_pixel(self : Image, x : Int, y : Int) -> Color

Get pixel at coordinates

#
Image::new

fn Image::new(width : Int, height : Int) -> Image

Create a new image with specified dimensions

#
Image::rotate_90_ccw

fn Image::rotate_90_ccw(self : Image) -> Image

Rotate image 90 degrees counter-clockwise

#
Image::rotate_90_cw

fn Image::rotate_90_cw(self : Image) -> Image

Rotate image 90 degrees clockwise

#
Image::set_pixel

fn Image::set_pixel(self : Image, x : Int, y : Int, color : Color) -> Unit

Set pixel at coordinates

#
Image::set_pixel_unchecked

fn Image::set_pixel_unchecked(self : Image, x : Int, y : Int, color : Color) -> Unit

Set pixel without bounds checking (caller must ensure valid coordinates)

#
Image::sub_image

fn Image::sub_image(self : Image, x : Int, y : Int, w : Int, h : Int) -> Image

Create a sub-image (crop)

#
Isolation

pub(all) enum Isolation {
Auto
Isolate
} derive(Eq,
Debug
)

CSS isolation values

#
LineCap

pub(all) enum LineCap {
Butt
Round
Square
} derive(Eq,
Debug
)

impl Show for LineCap

#
LineJoin

pub(all) enum LineJoin {
Miter
Round
Bevel
} derive(Eq,
Debug
)

impl Show for LineJoin

#
LinearGradient

pub(all) struct LinearGradient {
x1 : Double
y1 : Double
x2 : Double
y2 : Double
stops : Array[GradientStop]
spread_method : SpreadMethod
units : GradientUnits
transform : Transform
}

Linear gradient definition

#
LinearGradient::build_lut

fn LinearGradient::build_lut(self : LinearGradient, size : Int) -> Array[Color]

Build a lookup table for fast gradient color sampling Returns an array of colors for t values from 0.0 to 1.0

#
LinearGradient::color_at

fn LinearGradient::color_at(self : LinearGradient, t : Double) -> Color

Interpolate color at position t (0.0-1.0)

#
LinearGradient::horizontal

fn LinearGradient::horizontal(start_color : Color, end_color : Color) -> LinearGradient

Simple horizontal gradient (left to right)

#
LinearGradient::new

fn LinearGradient::new(x1 : Double, y1 : Double, x2 : Double, y2 : Double, stops : Array[GradientStop]) -> LinearGradient

#
LinearGradient::vertical

fn LinearGradient::vertical(start_color : Color, end_color : Color) -> LinearGradient

Simple vertical gradient (top to bottom)

#
MarkedLine

pub(all) struct MarkedLine {
points : Array[(Double, Double)]
marker_start : String?
marker_mid : String?
marker_end : String?
}

Line with markers

#
MarkedLine::get_angle_at

fn MarkedLine::get_angle_at(self : MarkedLine, index : Int) -> Double

Get angle at a point on the line

#
MarkedLine::new

fn MarkedLine::new(points : Array[(Double, Double)]) -> MarkedLine

#
MarkedLine::with_markers

fn MarkedLine::with_markers(points : Array[(Double, Double)], start : String?, mid : String?, end : String?) -> MarkedLine

#
Marker

pub(all) struct Marker {
id : String
content : SVGNode
ref_x : Double
ref_y : Double
marker_width : Double
marker_height : Double
orient : MarkerOrient
marker_units : MarkerUnits
view_box : ViewBox?
preserve_aspect_ratio : PreserveAspectRatio
clip_overflow : Bool
}

Marker definition (for line endpoints)

#
Marker::arrow

fn Marker::arrow(id : String) -> Marker

#
Marker::dot

fn Marker::dot(id : String, radius : Double) -> Marker

#
Marker::get_transform

fn Marker::get_transform(self : Marker, x : Double, y : Double, angle : Double, stroke_width : Double) -> Transform

Get transform for marker at a point with given angle

#
Marker::new

fn Marker::new(id : String, content : SVGNode) -> Marker

#
MarkerOrient

pub(all) enum MarkerOrient {
Auto
AutoStartReverse
Angle(Double)
}

#
MarkerRegistry

pub(all) struct MarkerRegistry {
markers : Map[String, Marker]
}

Marker registry

#
MarkerRegistry::add

fn MarkerRegistry::add(self : MarkerRegistry, marker : Marker) -> Unit

#
MarkerRegistry::get

fn MarkerRegistry::get(self : MarkerRegistry, id : String) -> Marker?

#
MarkerRegistry::new

#
MarkerUnits

pub(all) enum MarkerUnits {
StrokeWidth
UserSpaceOnUse_
}

#
Mask

pub(all) struct Mask {
id : String
content : Array[SVGNode]
x : Double
y : Double
width : Double
height : Double
x_is_percent : Bool
y_is_percent : Bool
width_is_percent : Bool
height_is_percent : Bool
mask_units : MaskUnits
mask_content_units : MaskUnits
mask_type : MaskType
}

Mask definition for transparency masking

#
Mask::get_mask_bounds

fn Mask::get_mask_bounds(self : Mask, target : BoundingBox) -> BoundingBox

Get the mask region bounds for a given target bounds

#
Mask::new

fn Mask::new(id : String, content : Array[SVGNode]) -> Mask

#
Mask::with_bounds

fn Mask::with_bounds(id : String, content : Array[SVGNode], x : Double, y : Double, width : Double, height : Double) -> Mask

#
MaskRegistry

pub(all) struct MaskRegistry {
masks : Map[String, Mask]
}

Mask registry for referencing by ID

#
MaskRegistry::add

fn MaskRegistry::add(self : MaskRegistry, mask : Mask) -> Unit

#
MaskRegistry::get

fn MaskRegistry::get(self : MaskRegistry, id : String) -> Mask?

#
MaskRegistry::new

#
MaskType

pub(all) enum MaskType {
Luminance
Alpha
} derive(Eq,
Debug
)

Mask type - how mask values are interpreted
impl Show for MaskType

#
MaskUnits

pub(all) enum MaskUnits {
UserSpaceOnUse
ObjectBoundingBox
} derive(Eq,
Debug
)

Mask content units

#
MeetOrSlice

pub(all) enum MeetOrSlice {
Meet
Slice
} derive(Eq,
Debug
)

preserveAspectRatio meet/slice
impl Show for MeetOrSlice

#
ObjectPool

pub(all) struct ObjectPool[T] {
available : Array[T]
factory : () -> T
reset : (T) -> Unit
}

Generic object pool for reusing objects

#
ObjectPool::acquire

fn[T] ObjectPool::acquire(self : ObjectPool[T]) -> T

Acquire an object from the pool

#
ObjectPool::available_count

fn[T] ObjectPool::available_count(self : ObjectPool[T]) -> Int

Get the number of available objects

#
ObjectPool::new

fn[T] ObjectPool::new(factory : () -> T, reset : (T) -> Unit, initial_size : Int) -> ObjectPool[T]

#
ObjectPool::release

fn[T] ObjectPool::release(self : ObjectPool[T], obj : T) -> Unit

Release an object back to the pool

#
Paint

pub(all) enum Paint {
None
SolidColor(Color)
LinearGrad(LinearGradient)
RadialGrad(RadialGradient)
CurrentColor
PaintServerRef(String, PaintFallback)
}

Paint style (fill or stroke)

#
PaintFallback

pub(all) enum PaintFallback {
NoPaint
SolidColor(Color)
CurrentColor
}

Paint style (fill or stroke)

#
PaintOrder

pub(all) struct PaintOrder {
order : Array[PaintOrderItem]
} derive(Eq,
Debug
)

Paint order specification (SVG 2.0)

#
PaintOrder::default

fn PaintOrder::default() -> PaintOrder

#
PaintOrderItem

pub(all) enum PaintOrderItem {
Fill
Stroke
Markers
} derive(Eq,
Debug
)

Paint order items (SVG 2.0)

#
Particle

pub(all) struct Particle {
x : Double
y : Double
vx : Double
vy : Double
life : Double
max_life : Double
size : Double
color : Color
active : Bool
}

Single particle state

#
Particle::new

fn Particle::new() -> Particle

#
ParticleEmitter

pub(all) struct ParticleEmitter {
x : Double
y : Double
config : EmitterConfig
particles : Array[Particle]
emit_accumulator : Double
active : Bool
}

Particle emitter

#
ParticleEmitter::active_count

fn ParticleEmitter::active_count(self : ParticleEmitter) -> Int

Get active particle count

#
ParticleEmitter::new

fn ParticleEmitter::new(x : Double, y : Double, config : EmitterConfig, max_particles : Int) -> ParticleEmitter

#
ParticleEmitter::update

fn ParticleEmitter::update(self : ParticleEmitter, dt : Double) -> Unit

Update particles with delta time

#
PathCommand

pub(all) enum PathCommand {
MoveTo(Double, Double)
LineTo(Double, Double)
HorizontalLineTo(Double)
VerticalLineTo(Double)
CurveTo(Double, Double, Double, Double, Double, Double)
SmoothCurveTo(Double, Double, Double, Double)
QuadraticCurveTo(Double, Double, Double, Double)
SmoothQuadraticCurveTo(Double, Double)
ArcTo(Double, Double, Double, Bool, Bool, Double, Double)
ClosePath
MoveToRel(Double, Double)
LineToRel(Double, Double)
HorizontalLineToRel(Double)
VerticalLineToRel(Double)
CurveToRel(Double, Double, Double, Double, Double, Double)
SmoothCurveToRel(Double, Double, Double, Double)
QuadraticCurveToRel(Double, Double, Double, Double)
SmoothQuadraticCurveToRel(Double, Double)
ArcToRel(Double, Double, Double, Bool, Bool, Double, Double)
} derive(
Debug
)

SVG path commands (full SVG 1.1 spec)

#
PathFollower

pub(all) struct PathFollower {
path : Array[PathCommand]
polyline : Array[(Double, Double)]
lengths : Array[Double]
total_length : Double
progress : Double
loop_anim : Bool
}

Path follower for animating along a path

#
PathFollower::get_position

fn PathFollower::get_position(self : PathFollower) -> (Double, Double)

Get position at current progress

#
PathFollower::new

fn PathFollower::new(path_data : String) -> PathFollower

#
PathFollower::update

fn PathFollower::update(self : PathFollower, dt : Double, speed : Double) -> Bool

Update progress with delta time and speed

#
Pattern

pub(all) struct Pattern {
id : String
width : Double
height : Double
content : Array[SVGNode]
pattern_units : PatternUnits
pattern_content_units : PatternUnits
transform : Transform
view_box : ViewBox?
preserve_aspect_ratio : PreserveAspectRatio
}

Pattern definition for fills

#
Pattern::get_color_at

fn Pattern::get_color_at(self : Pattern, x : Double, y : Double, bbox : BoundingBox) -> Color?

Get pattern color at a point (simplified - returns first solid color found)

#
Pattern::new

fn Pattern::new(id : String, width : Double, height : Double, content : Array[SVGNode]) -> Pattern

#
PatternRegistry

pub(all) struct PatternRegistry {
patterns : Map[String, Pattern]
}

Pattern registry

#
PatternRegistry::add

fn PatternRegistry::add(self : PatternRegistry, pattern : Pattern) -> Unit

#
PatternRegistry::get

fn PatternRegistry::get(self : PatternRegistry, id : String) -> Pattern?

#
PatternRegistry::new

#
PatternUnits

pub(all) enum PatternUnits {
UserSpaceOnUse
ObjectBoundingBox
}

#
PixelSetter

pub(all) struct PixelSetter {
set : (Int, Int, Color) -> Unit
}

Pixel setter callback type (x, y, color) -> Unit

#
PixelSetter::pixel

fn PixelSetter::pixel(self : PixelSetter, x : Int, y : Int, color : Color) -> Unit

Draw a single pixel

#
PixelSetter::with_clip

fn PixelSetter::with_clip(self : PixelSetter, clip : ClipRect) -> PixelSetter

Create a clipped pixel setter that only draws within the clip rect

#
PixelSetter::with_clip_and_offset

fn PixelSetter::with_clip_and_offset(self : PixelSetter, clip : ClipRect, offset_x : Int, offset_y : Int) -> PixelSetter

Create a clipped pixel setter with offset (for camera translation)

#
PointerEvent

pub(all) struct PointerEvent {
x : Double
y : Double
button : Int
target : String
propagation_stopped : Bool
}

Mouse/pointer event data

#
PointerEvent::new

fn PointerEvent::new(x : Double, y : Double, button : Int, target : String) -> PointerEvent

#
PointerEvent::stop_propagation

fn PointerEvent::stop_propagation(self : PointerEvent) -> Unit

Stop event propagation (prevent bubbling)

#
PreserveAspectRatio

pub(all) struct PreserveAspectRatio {
align : Align
meet_or_slice : MeetOrSlice
}

Complete preserveAspectRatio setting

#
PreserveAspectRatio::default

#
RadialGradient

pub(all) struct RadialGradient {
cx : Double
cy : Double
fx : Double
fy : Double
r : Double
stops : Array[GradientStop]
spread_method : SpreadMethod
units : GradientUnits
transform : Transform
}

Radial gradient definition

#
RadialGradient::build_lut

fn RadialGradient::build_lut(self : RadialGradient, size : Int) -> Array[Color]

Build a lookup table for fast radial gradient color sampling

#
RadialGradient::color_at

fn RadialGradient::color_at(self : RadialGradient, px : Double, py : Double, width : Double, height : Double) -> Color

Get color at a point (px, py) relative to the gradient bounds

#
RadialGradient::new

fn RadialGradient::new(cx : Double, cy : Double, r : Double, stops : Array[GradientStop]) -> RadialGradient

#
RenderContext

pub(all) struct RenderContext {
setter : PixelSetter
width : Int
height : Int
flatness : Double
clip : ClipRect?
text_to_paths : (Int, Double) -> (Array[PathCommand], Double)?
}

Render context for drawing

#
RenderContext::for_camera

fn RenderContext::for_camera(setter : PixelSetter, camera : Camera) -> RenderContext

Create a RenderContext for a camera

#
RenderContext::new

fn RenderContext::new(setter : PixelSetter, width : Int, height : Int) -> RenderContext

Create a RenderContext with default settings

#
RenderContext::with_clip

fn RenderContext::with_clip(setter : PixelSetter, width : Int, height : Int, clip : ClipRect) -> RenderContext

Create a RenderContext with clipping

#
RenderContext::with_font

fn RenderContext::with_font(setter : PixelSetter, width : Int, height : Int, text_to_paths : (Int, Double) -> (Array[PathCommand], Double)) -> RenderContext

Create a RenderContext with font callback for text rendering

#
SVGDocument

pub(all) struct SVGDocument {
root : SVGNode
symbols : SymbolRegistry
clips : ClipPathRegistry
masks : MaskRegistry
patterns : PatternRegistry
gradients : GradientRegistry
markers : MarkerRegistry
}

Parsed SVG document with reusable resources

#
SVGDocument::new

fn SVGDocument::new(root : SVGNode) -> SVGDocument

#
SVGDocument::render

fn SVGDocument::render(self : SVGDocument, ctx : RenderContext) -> Unit

Render a parsed SVG document with registered resources

#
SVGNode

pub(all) struct SVGNode {
id : String
shape : Shape
transform : Transform
view_box : ViewBox?
viewport_width : Double?
viewport_height : Double?
preserve_aspect_ratio : PreserveAspectRatio
preserve_aspect_ratio_is_set : Bool
fill : Paint
fill_is_set : Bool
color : Color?
color_is_set : Bool
paint_order : PaintOrder
fill_rule : FillRule
fill_opacity : Double
stroke : StrokeStyle
stroke_paint_is_set : Bool
stroke_width_is_set : Bool
stroke_opacity : Double
opacity : Double
marker_start : String?
marker_start_is_set : Bool
marker_mid : String?
marker_mid_is_set : Bool
marker_end : String?
marker_end_is_set : Bool
z_index : Int
node_dirty : Bool
prev_bounds : BoundingBox?
filters : Array[Filter]
mask_id : String?
clip_path_id : String?
clip_overflow : Bool
children : Array[SVGNode]
}

SVG node (element in the scene graph)

#
SVGNode::add_filter

fn SVGNode::add_filter(self : SVGNode, filter : Filter) -> Unit

Add a filter to the node

#
SVGNode::clear_clip_path

fn SVGNode::clear_clip_path(self : SVGNode) -> Unit

Clear clip path reference

#
SVGNode::clear_dirty

fn SVGNode::clear_dirty(self : SVGNode) -> Unit

Clear the dirty flag

#
SVGNode::clear_filters

fn SVGNode::clear_filters(self : SVGNode) -> Unit

Clear all filters from the node

#
SVGNode::clear_mask

fn SVGNode::clear_mask(self : SVGNode) -> Unit

Clear mask reference

#
SVGNode::clone

fn SVGNode::clone(self : SVGNode) -> SVGNode

Clone an SVGNode (shallow clone of children)

#
SVGNode::collides_with

fn SVGNode::collides_with(self : SVGNode, other : SVGNode) -> Bool

Check collision between two SVGNodes (considering transforms)

#
SVGNode::hit_test

fn SVGNode::hit_test(self : SVGNode, px : Double, py : Double) -> Bool

Hit test an SVGNode at a point (in world coordinates) Returns true if the point is inside the node's shape

#
SVGNode::hit_test_all

fn SVGNode::hit_test_all(self : SVGNode, px : Double, py : Double) -> Array[SVGNode]

Find all nodes at a point (recursive, returns in front-to-back order)

#
SVGNode::mark_dirty

fn SVGNode::mark_dirty(self : SVGNode) -> Unit

Mark a node as dirty (needs re-render)

#
SVGNode::new

fn SVGNode::new(shape : Shape) -> SVGNode

#
SVGNode::set_clip_path

fn SVGNode::set_clip_path(self : SVGNode, clip_path_id : String) -> Unit

Set clip path reference by ID

#
SVGNode::set_mask

fn SVGNode::set_mask(self : SVGNode, mask_id : String) -> Unit

Set mask reference by ID

#
Scene

pub(all) struct Scene {
root : SVGNode
dirty : Bool
}

Scene represents a renderable SVG scene with optimization support

#
Scene::add_child

fn Scene::add_child(self : Scene, parent_id : String, child : SVGNode) -> Bool

Add a child to a node by parent ID

#
Scene::bring_to_front

fn Scene::bring_to_front(self : Scene, id : String) -> Bool

Bring a node to front (set z_index higher than all siblings)

#
Scene::clear_all_dirty

fn Scene::clear_all_dirty(self : Scene) -> Unit

Clear all dirty flags in the scene

#
Scene::clear_dirty

fn Scene::clear_dirty(self : Scene) -> Unit

Clear the dirty flag

#
Scene::empty

fn Scene::empty() -> Scene

Create an empty scene with a group root

#
Scene::find_node

fn Scene::find_node(self : Scene, id : String) -> SVGNode?

Find a node by ID

#
Scene::get_bounds

fn Scene::get_bounds(self : Scene) -> BoundingBox

Compute the bounding box of the entire scene

#
Scene::get_dirty_region

fn Scene::get_dirty_region(self : Scene) -> BoundingBox

Compute the dirty region (union of all dirty node bounds)

#
Scene::get_root

fn Scene::get_root(self : Scene) -> SVGNode

Get the root node

#
Scene::is_dirty

fn Scene::is_dirty(self : Scene) -> Bool

Check if scene needs re-render

#
Scene::mark_dirty

fn Scene::mark_dirty(self : Scene) -> Unit

Mark the scene as dirty (needs re-render)

#
Scene::mark_node_dirty

fn Scene::mark_node_dirty(self : Scene, id : String) -> Bool

Mark a node and its ancestors as dirty

#
Scene::new

fn Scene::new(root : SVGNode) -> Scene

Create a new scene from a root SVGNode

#
Scene::remove_node

fn Scene::remove_node(self : Scene, id : String) -> Bool

Remove a node by ID

#
Scene::render

fn Scene::render(self : Scene, ctx : RenderContext) -> Unit

Render the scene to a pixel setter

#
Scene::render_dirty

fn Scene::render_dirty(self : Scene, ctx : RenderContext) -> BoundingBox

Render only nodes that intersect with the dirty region

#
Scene::render_with_camera

fn Scene::render_with_camera(self : Scene, ctx : RenderContext, camera : Camera) -> Unit

Render the scene with a camera transform

#
Scene::render_with_viewbox

fn Scene::render_with_viewbox(self : Scene, ctx : RenderContext, viewbox : ViewBox, preserve_aspect_ratio : PreserveAspectRatio) -> Unit

Render the scene with viewBox coordinate mapping

#
Scene::render_with_viewbox_and_camera

fn Scene::render_with_viewbox_and_camera(self : Scene, ctx : RenderContext, viewbox : ViewBox, preserve_aspect_ratio : PreserveAspectRatio, camera : Camera) -> Unit

Render the scene with both viewBox and camera

#
Scene::send_to_back

fn Scene::send_to_back(self : Scene, id : String) -> Bool

Send a node to back (set z_index lower than all siblings)

#
Scene::set_z_index

fn Scene::set_z_index(self : Scene, id : String, z_index : Int) -> Bool

Set z_index of a node by ID

#
Scene::update_node

fn Scene::update_node(self : Scene, id : String, updater : (SVGNode) -> SVGNode) -> Bool

Update a node by ID (returns true if found and updated)

#
Shape

pub(all) enum Shape {
Rect(Double, Double, Double, Double, Double, Double)
Circle(Double, Double, Double)
Ellipse(Double, Double, Double, Double)
Line(Double, Double, Double, Double)
Polyline(Array[(Double, Double)])
Polygon(Array[(Double, Double)])
Path(Array[PathCommand])
Text(Double, Double, String, Double)
Image(Double, Double, Double, Double, String)
Group
} derive(
Debug
)

SVG shape primitives

#
SimpleRNG

pub(all) struct SimpleRNG {
state : Int
}

Simple pseudo-random number generator

#
SimpleRNG::new

fn SimpleRNG::new(seed : Int) -> SimpleRNG

#
SimpleRNG::next

fn SimpleRNG::next(self : SimpleRNG) -> Double

#
SimpleRNG::range

fn SimpleRNG::range(self : SimpleRNG, min : Double, max : Double) -> Double

#
SpreadMethod

pub(all) enum SpreadMethod {
Pad
Repeat
Reflect
} derive(Eq,
Debug
)

How gradient extends beyond its bounds

#
Sprite

pub(all) struct Sprite {
image : Image
x : Int
y : Int
width : Int
height : Int
}

Sprite definition (sub-region of an image)

#
Sprite::from_image

fn Sprite::from_image(image : Image) -> Sprite

Create a sprite from the entire image

#
Sprite::get_pixel

fn Sprite::get_pixel(self : Sprite, x : Int, y : Int) -> Color

Get pixel from sprite (local coordinates)

#
Sprite::new

fn Sprite::new(image : Image, x : Int, y : Int, width : Int, height : Int) -> Sprite

Create a sprite from an image region

#
SpriteSheet

pub(all) struct SpriteSheet {
image : Image
tile_width : Int
tile_height : Int
columns : Int
rows : Int
}

Sprite sheet for animations

#
SpriteSheet::get_sprite

fn SpriteSheet::get_sprite(self : SpriteSheet, col : Int, row : Int) -> Sprite

Get sprite at grid position

#
SpriteSheet::get_sprite_by_index

fn SpriteSheet::get_sprite_by_index(self : SpriteSheet, index : Int) -> Sprite

Get sprite by index (left-to-right, top-to-bottom)

#
SpriteSheet::new

fn SpriteSheet::new(image : Image, tile_width : Int, tile_height : Int) -> SpriteSheet

Create a sprite sheet from an image

#
SpriteSheet::sprite_count

fn SpriteSheet::sprite_count(self : SpriteSheet) -> Int

Total number of sprites in the sheet

#
StrokeStyle

pub(all) struct StrokeStyle {
paint : Paint
width : Double
linecap : LineCap
linejoin : LineJoin
miterlimit : Double
dasharray : Array[Double]?
dashoffset : Double
}

Stroke properties

#
StrokeStyle::default

fn StrokeStyle::default() -> StrokeStyle

#
Symbol

pub(all) struct Symbol {
id : String
content : SVGNode
view_box : ViewBox?
width : Double?
height : Double?
preserve_aspect_ratio : PreserveAspectRatio
display_none : Bool
}

Symbol definition (reusable graphic)

#
Symbol::new

fn Symbol::new(id : String, content : SVGNode) -> Symbol

#
Symbol::with_viewbox

fn Symbol::with_viewbox(id : String, content : SVGNode, view_box : ViewBox) -> Symbol

#
SymbolRegistry

pub(all) struct SymbolRegistry {
symbols : Map[String, Symbol]
}

Symbol registry

#
SymbolRegistry::add

fn SymbolRegistry::add(self : SymbolRegistry, symbol : Symbol) -> Unit

#
SymbolRegistry::get

fn SymbolRegistry::get(self : SymbolRegistry, id : String) -> Symbol?

#
SymbolRegistry::new

#
TextAnchor

pub(all) enum TextAnchor {
Start
Middle
End
}

Text anchor (horizontal alignment)

#
TextBlock

pub(all) struct TextBlock {
spans : Array[TextSpan]
x : Double
y : Double
style : TextStyle
inline_size : Double?
text_overflow : TextOverflow
}

Multi-line text block (SVG 2.0 extended)

#
TextBlock::add_span

fn TextBlock::add_span(self : TextBlock, span : TextSpan) -> Unit

#
TextBlock::get_anchor_x

fn TextBlock::get_anchor_x(self : TextBlock) -> Double

Get adjusted x position based on text-anchor

#
TextBlock::get_baseline_y

fn TextBlock::get_baseline_y(self : TextBlock) -> Double

Get adjusted y position based on dominant-baseline

#
TextBlock::get_height

fn TextBlock::get_height(self : TextBlock) -> Double

Get text height

#
TextBlock::get_line_count

fn TextBlock::get_line_count(self : TextBlock) -> Int

Get the number of lines when text is wrapped

#
TextBlock::get_total_height

fn TextBlock::get_total_height(self : TextBlock) -> Double

Get total height including all wrapped lines

#
TextBlock::get_width

fn TextBlock::get_width(self : TextBlock) -> Double

Calculate text width (simplified - assumes monospace)

#
TextBlock::is_vertical

fn TextBlock::is_vertical(self : TextBlock) -> Bool

Check if text is vertical (for writing-mode)

#
TextBlock::new

fn TextBlock::new(x : Double, y : Double, text : String) -> TextBlock

#
TextBlock::with_style

fn TextBlock::with_style(x : Double, y : Double, text : String, style : TextStyle) -> TextBlock

#
TextBlock::with_wrap

fn TextBlock::with_wrap(x : Double, y : Double, text : String, inline_size : Double) -> TextBlock

Create a text block with wrapping

#
TextBlock::wrap_text

fn TextBlock::wrap_text(self : TextBlock) -> Array[String]

Wrap text to fit within inline_size, returns lines

#
TextDecoration

pub(all) enum TextDecoration {
NoDecoration
Underline
Overline
LineThrough
} derive(Eq,
Debug
)

Text decoration

#
TextDecorationFull

pub(all) struct TextDecorationFull {
line : TextDecoration
style : TextDecorationStyle
color : Color?
thickness : Double?
}

Extended text decoration (SVG 2.0)

#
TextDecorationFull::default

#
TextDecorationStyle

pub(all) enum TextDecorationStyle {
Solid
Double
Dotted
Dashed
Wavy
} derive(Eq,
Debug
)

Text decoration style (SVG 2.0)

#
TextOrientation

pub(all) enum TextOrientation {
Mixed
Upright
Sideways
} derive(Eq,
Debug
)

Text orientation for vertical writing (SVG 2.0)

#
TextOverflow

pub(all) enum TextOverflow {
Clip
Ellipsis
Custom(String)
} derive(Eq,
Debug
)

Text overflow handling (SVG 2.0)

#
TextSpan

pub(all) struct TextSpan {
text : String
x : Double?
y : Double?
dx : Double
dy : Double
style : TextStyle?
}

Text span (styled portion of text)

#
TextSpan::new

fn TextSpan::new(text : String) -> TextSpan

#
TextSpan::with_offset

fn TextSpan::with_offset(text : String, dx : Double, dy : Double) -> TextSpan

#
TextStyle

pub(all) struct TextStyle {
font_family : String
font_size : Double
font_weight : FontWeight
font_style : FontStyle
text_anchor : TextAnchor
dominant_baseline : DominantBaseline
text_decoration : TextDecoration
letter_spacing : Double
word_spacing : Double
line_height : Double
writing_mode : WritingMode
text_orientation : TextOrientation
white_space : WhiteSpace
paint_order : PaintOrder
}

Complete text style (SVG 2.0 extended)

#
TextStyle::default

fn TextStyle::default() -> TextStyle

#
Transform

pub(all) struct Transform {
a : Double
b : Double
c : Double
d : Double
e : Double
f : Double
}

2D affine transformation matrix | a c e | | b d f | | 0 0 1 |

#
Transform::apply

fn Transform::apply(self : Transform, x : Double, y : Double) -> (Double, Double)

Apply transform to a point

#
Transform::apply_bbox

fn Transform::apply_bbox(self : Transform, bbox : BoundingBox) -> BoundingBox

Transform a bounding box (returns axis-aligned bounding box of transformed corners)

#
Transform::apply_point

fn Transform::apply_point(self : Transform, point : (Double, Double)) -> (Double, Double)

Apply transform to a point (struct version)

#
Transform::determinant

fn Transform::determinant(self : Transform) -> Double

Compute the determinant of the transform

#
Transform::get_rotation

fn Transform::get_rotation(self : Transform) -> Double

Get the rotation angle in radians (approximate, assumes uniform scale)

#
Transform::get_scale

fn Transform::get_scale(self : Transform) -> (Double, Double)

Get the scale factors (approximate, assumes no rotation)

#
Transform::get_translate

fn Transform::get_translate(self : Transform) -> (Double, Double)

Get the translation component

#
Transform::identity

fn Transform::identity() -> Transform

Identity transform (no transformation)

#
Transform::inverse

fn Transform::inverse(self : Transform) -> Transform

Compute the inverse transform Returns identity if not invertible

#
Transform::is_identity

fn Transform::is_identity(self : Transform) -> Bool

Check if this is an identity transform (optimization)

#
Transform::is_invertible

fn Transform::is_invertible(self : Transform) -> Bool

Check if the transform is invertible

#
Transform::matrix

fn Transform::matrix(a : Double, b : Double, c : Double, d : Double, e : Double, f : Double) -> Transform

Create a transform from a full matrix specification

#
Transform::multiply

fn Transform::multiply(self : Transform, other : Transform) -> Transform

Multiply two transforms (self * other) Result: first apply other, then apply self

#
Transform::rotate

fn Transform::rotate(angle : Double) -> Transform

Create a rotation transform (angle in radians)

#
Transform::rotate_around

fn Transform::rotate_around(angle : Double, cx : Double, cy : Double) -> Transform

Create a rotation transform around a point (angle in radians)

#
Transform::scale

fn Transform::scale(sx : Double, sy : Double) -> Transform

Create a scaling transform

#
Transform::scale_uniform

fn Transform::scale_uniform(s : Double) -> Transform

Create a uniform scaling transform

#
Transform::skew_x

fn Transform::skew_x(angle : Double) -> Transform

Create a skewX transform (angle in radians)

#
Transform::skew_y

fn Transform::skew_y(angle : Double) -> Transform

Create a skewY transform (angle in radians)

#
Transform::translate

fn Transform::translate(tx : Double, ty : Double) -> Transform

Create a translation transform

#
Tween

pub(all) struct Tween {
target_id : String
property : AnimProperty
start_value : AnimProperty
duration : Double
elapsed : Double
easing : Easing
started : Bool
completed : Bool
}

A single tween animation

#
Tween::is_complete

fn Tween::is_complete(self : Tween) -> Bool

Check if the tween is complete

#
Tween::new

fn Tween::new(target_id : String, property : AnimProperty, duration : Double, easing : Easing) -> Tween

Create a new tween

#
Tween::update

fn Tween::update(self : Tween, dt : Double, node : SVGNode) -> Bool

Update the tween with delta time Returns true if still running, false if complete

#
UseElement

pub(all) struct UseElement {
href : String
x : Double
y : Double
width : Double?
height : Double?
transform : Transform
}

Use element (instance of a symbol)

#
UseElement::get_id

fn UseElement::get_id(self : UseElement) -> String

Get the href ID (strips leading #)

#
UseElement::instantiate

fn UseElement::instantiate(self : UseElement, registry : SymbolRegistry) -> SVGNode?

Instantiate a use element with the symbol registry

#
UseElement::new

fn UseElement::new(href : String, x : Double, y : Double) -> UseElement

#
UseElement::with_size

fn UseElement::with_size(href : String, x : Double, y : Double, width : Double, height : Double) -> UseElement

#
ViewBox

pub(all) struct ViewBox {
min_x : Double
min_y : Double
width : Double
height : Double
}

ViewBox specification for SVG coordinate system mapping

#
ViewBox::get_transform

fn ViewBox::get_transform(self : ViewBox, viewport_width : Double, viewport_height : Double, preserve_aspect_ratio : PreserveAspectRatio) -> Transform

Calculate the transform matrix to map viewBox coordinates to viewport viewport_width/height: the actual pixel dimensions of the SVG element

#
WhiteSpace

pub(all) enum WhiteSpace {
Normal
Pre
NoWrap
PreWrap
PreLine
BreakSpaces
} derive(Eq,
Debug
)

White space handling (SVG 2.0)
impl Show for WhiteSpace

#
WritingMode

pub(all) enum WritingMode {
HorizontalTB
VerticalRL
VerticalLR
} derive(Eq,
Debug
)

Writing mode (SVG 2.0)
impl Show for WritingMode

#
apply_blur

fn apply_blur(pixels : Array[Array[Color]], radius : Int) -> Array[Array[Color]]

Apply blur filter to a region of pixels

#
apply_brightness

fn apply_brightness(color : Color, factor : Double) -> Color

Apply brightness filter to a color

#
apply_color_matrix

fn apply_color_matrix(color : Color, matrix : FixedArray[Double]) -> Color

Apply color matrix filter (feColorMatrix) Matrix is 5x4 (20 values) in row-major order: [R'] = [a00 a01 a02 a03 a04] [R] [G'] = [a10 a11 a12 a13 a14] [G] [B'] = [a20 a21 a22 a23 a24] [B] [A'] = [a30 a31 a32 a33 a34] [A] [1]

#
apply_contrast

fn apply_contrast(color : Color, factor : Double) -> Color

Apply contrast filter to a color

#
apply_drop_shadow

fn apply_drop_shadow(image : Image, offset_x : Int, offset_y : Int, blur_radius : Int, shadow_color : Color) -> Image

Apply drop shadow to an image and return new image with shadow

#
apply_filter

fn apply_filter(image : Image, filter : Filter) -> Image

Apply a filter to an image (returns new image)

#
apply_grayscale

fn apply_grayscale(color : Color, amount : Double) -> Color

Apply grayscale filter to a color

#
apply_hue_rotate

fn apply_hue_rotate(color : Color, angle_degrees : Double) -> Color

Apply hue rotation to a color

#
apply_invert

fn apply_invert(color : Color, amount : Double) -> Color

Apply invert filter to a color

#
apply_mask_to_image

fn apply_mask_to_image(image : Image, mask_buffer : Image, mask_type : MaskType) -> Image

Apply mask to an image using luminance or alpha

#
apply_saturate

fn apply_saturate(color : Color, factor : Double) -> Color

Apply saturate filter to a color

#
apply_sepia

fn apply_sepia(color : Color, amount : Double) -> Color

Apply sepia filter to a color

#
apply_text_overflow

fn apply_text_overflow(line : String, max_width : Double, char_width : Double, overflow : TextOverflow) -> String

Apply text-overflow to a line

#
blend_images

fn blend_images(backdrop : Image, source : Image, mode : BlendMode) -> Image

Blend two images using the specified blend mode

#
blend_with_mode

fn blend_with_mode(backdrop : Color, source : Color, mode : BlendMode) -> Color

Blend two colors using the specified blend mode

#
blit

fn blit(dest : Image, src : Image, dest_x : Int, dest_y : Int) -> Unit

Blit (copy) source image onto destination at position

#
blit_scaled

fn blit_scaled(dest : Image, src : Image, dest_x : Int, dest_y : Int, dest_w : Int, dest_h : Int) -> Unit

Blit with scaling

#
blit_sprite

fn blit_sprite(dest : Image, sprite : Sprite, dest_x : Int, dest_y : Int) -> Unit

Blit sprite onto image

#
circle

fn circle(id : String, cx : Double, cy : Double, r : Double) -> SVGNode

Helper: Create a circle node

#
collide_circle_circle

fn collide_circle_circle(cx1 : Double, cy1 : Double, r1 : Double, cx2 : Double, cy2 : Double, r2 : Double) -> Bool

Check collision between two circles

#
collide_circle_rect

fn collide_circle_rect(cx : Double, cy : Double, r : Double, rx : Double, ry : Double, rw : Double, rh : Double) -> Bool

Check collision between circle and rectangle

#
collide_rect_rect

fn collide_rect_rect(x1 : Double, y1 : Double, w1 : Double, h1 : Double, x2 : Double, y2 : Double, w2 : Double, h2 : Double) -> Bool

Check collision between two axis-aligned rectangles

#
collide_shapes

fn collide_shapes(shape1 : Shape, shape2 : Shape) -> Bool

Check collision between two shapes

#
compute_alpha_mask

fn compute_alpha_mask(color : Color) -> Double

Compute mask value using alpha channel

#
compute_luminance

fn compute_luminance(color : Color) -> Double

Compute mask value (0.0-1.0) at a point using luminance

#
degrees_to_radians

fn degrees_to_radians(degrees : Double) -> Double

Convert degrees to radians

#
group

fn group(id : String, children : Array[SVGNode]) -> SVGNode

Helper: Create a group node

#
hit_test_shape

fn hit_test_shape(px : Double, py : Double, shape : Shape) -> Bool

Hit test a shape (without transform)

#
hue_rotate_matrix

fn hue_rotate_matrix(angle_degrees : Double) -> FixedArray[Double]

Create hue-rotate color matrix

#
identity_matrix

fn identity_matrix() -> FixedArray[Double]

Create identity color matrix

#
line

fn line(id : String, x1 : Double, y1 : Double, x2 : Double, y2 : Double) -> SVGNode

Helper: Create a line node

#
luminance_to_alpha_matrix

fn luminance_to_alpha_matrix() -> FixedArray[Double]

Create luminance-to-alpha color matrix

#
lut_color_at

fn lut_color_at(lut : Array[Color], t : Double) -> Color

Get color from LUT (fast path)

#
parse_path

fn parse_path(data : String) -> Array[PathCommand]

Parse a path data string into an array of path commands

#
parse_svg

fn parse_svg(svg_str : String) -> SVGNode?

Parse SVG markup string into SVGNode

#
parse_svg_document

fn parse_svg_document(svg_str : String) -> SVGDocument?

Parse SVG markup string into SVGDocument with resources

#
parse_transform

fn parse_transform(value : String) -> Transform

#
path

fn path(id : String, d : String) -> SVGNode

Helper: Create a path node from path data string

#
path_bbox

fn path_bbox(commands : Array[PathCommand]) -> BoundingBox

Compute bounding box of path commands

#
path_to_polylines

fn path_to_polylines(commands : Array[PathCommand], flatness : Double) -> Array[Array[(Double, Double)]]

Convert path commands to an array of polylines (for rendering) Returns array of point arrays, each representing a subpath

#
process_white_space

fn process_white_space(text : String, mode : WhiteSpace) -> String

Process white-space according to mode

#
radians_to_degrees

fn radians_to_degrees(radians : Double) -> Double

Convert radians to degrees

#
raster_circle_fill

fn raster_circle_fill(cx : Int, cy : Int, r : Int, color : Color, setter : PixelSetter) -> Unit

Fill circle using scanlines

#
raster_circle_radial_gradient

fn raster_circle_radial_gradient(cx : Int, cy : Int, r : Int, grad : RadialGradient, opacity : Double, setter : PixelSetter) -> Unit

Draw filled circle with radial gradient

#
raster_circle_stroke

fn raster_circle_stroke(cx : Int, cy : Int, r : Int, color : Color, setter : PixelSetter) -> Unit

Midpoint circle algorithm - draw circle outline

#
raster_ellipse_fill

fn raster_ellipse_fill(cx : Int, cy : Int, rx : Int, ry : Int, color : Color, setter : PixelSetter) -> Unit

Fill ellipse using scanlines

#
raster_ellipse_radial_gradient

fn raster_ellipse_radial_gradient(cx : Int, cy : Int, rx : Int, ry : Int, grad : RadialGradient, opacity : Double, setter : PixelSetter) -> Unit

Draw filled ellipse with radial gradient

#
raster_ellipse_stroke

fn raster_ellipse_stroke(cx : Int, cy : Int, rx : Int, ry : Int, color : Color, setter : PixelSetter) -> Unit

Midpoint ellipse algorithm - draw ellipse outline

#
raster_line

fn raster_line(x0 : Int, y0 : Int, x1 : Int, y1 : Int, color : Color, setter : PixelSetter) -> Unit

Bresenham's line algorithm - integer-only, efficient line drawing

#
raster_line_dashed

fn raster_line_dashed(x0 : Int, y0 : Int, x1 : Int, y1 : Int, color : Color, dasharray : Array[Double], dashoffset : Double, setter : PixelSetter) -> Unit

Bresenham's line with dash pattern support

#
raster_path

fn raster_path(commands : Array[PathCommand], fill_color : Color?, stroke_color : Color?, flatness : Double, setter : PixelSetter) -> Unit

Rasterize path commands

#
raster_polygon_fill

fn raster_polygon_fill(points : Array[(Int, Int)], color : Color, setter : PixelSetter) -> Unit

Polygon fill using scanline algorithm with edge table

#
raster_polygon_fill_rule

fn raster_polygon_fill_rule(points : Array[(Int, Int)], color : Color, rule : FillRule, setter : PixelSetter) -> Unit

Polygon fill with specified fill rule

#
raster_polygon_stroke

fn raster_polygon_stroke(points : Array[(Int, Int)], color : Color, setter : PixelSetter) -> Unit

Draw polygon outline

#
raster_polygons_fill_rule

fn raster_polygons_fill_rule(polygons : Array[Array[(Int, Int)]], color : Color, rule : FillRule, setter : PixelSetter) -> Unit

Fill multiple polygons (subpaths) with specified fill rule

#
raster_polyline

fn raster_polyline(points : Array[(Int, Int)], color : Color, setter : PixelSetter) -> Unit

Draw polyline (open polygon)

#
raster_polyline_dashed

fn raster_polyline_dashed(points : Array[(Int, Int)], color : Color, dasharray : Array[Double], dashoffset : Double, setter : PixelSetter) -> Unit

Draw polyline with dash pattern

#
raster_rect_fill

fn raster_rect_fill(x : Int, y : Int, w : Int, h : Int, color : Color, setter : PixelSetter) -> Unit

Fill rectangle

#
raster_rect_gradient

fn raster_rect_gradient(x : Int, y : Int, w : Int, h : Int, grad : LinearGradient, opacity : Double, setter : PixelSetter) -> Unit

Draw filled rectangle with linear gradient

#
raster_rect_radial_gradient

fn raster_rect_radial_gradient(x : Int, y : Int, w : Int, h : Int, grad : RadialGradient, opacity : Double, setter : PixelSetter) -> Unit

Draw filled rectangle with radial gradient

#
raster_rect_stroke

fn raster_rect_stroke(x : Int, y : Int, w : Int, h : Int, color : Color, setter : PixelSetter) -> Unit

Draw rectangle outline (stroke only)

#
raster_rect_stroke_thick

fn raster_rect_stroke_thick(x : Int, y : Int, w : Int, h : Int, stroke_w : Int, color : Color, setter : PixelSetter) -> Unit

#
raster_rounded_rect_fill

fn raster_rounded_rect_fill(x : Int, y : Int, w : Int, h : Int, rx : Int, ry : Int, color : Color, setter : PixelSetter) -> Unit

#
raster_rounded_rect_stroke

fn raster_rounded_rect_stroke(x : Int, y : Int, w : Int, h : Int, rx : Int, ry : Int, color : Color, setter : PixelSetter) -> Unit

Draw rounded rectangle outline

#
raster_rounded_rect_stroke_thick

fn raster_rounded_rect_stroke_thick(x : Int, y : Int, w : Int, h : Int, rx : Int, ry : Int, stroke_w : Int, color : Color, setter : PixelSetter) -> Unit

#
raster_text

fn raster_text(x : Int, y : Int, text : String, font_size : Int, color : Color, setter : PixelSetter) -> Unit

Render text using bitmap font

#
raster_thick_line

fn raster_thick_line(x0 : Int, y0 : Int, x1 : Int, y1 : Int, width : Int, color : Color, setter : PixelSetter) -> Unit

Draw a thick line (stroke width > 1)

#
rect

fn rect(id : String, x : Double, y : Double, width : Double, height : Double) -> SVGNode

Helper: Create a rectangle node

#
render_path_commands_to_image

fn render_path_commands_to_image(commands : Array[PathCommand], width : Int, height : Int, fill_color : Color, transform? : Array[Double]) -> Image

Render PathCommand array directly to an Image (no SVG string parsing). This is much faster than render_svg_to_image for programmatic paths (e.g., font glyph outlines) because it skips SVG serialization and parsing.

transform is a 6-element affine transform [a, b, c, d, e, f] or empty for identity.

#
render_svg_document_to_image

fn render_svg_document_to_image(doc : SVGDocument, width : Int, height : Int) -> Image

Render an SVGDocument into an Image.

#
render_svg_node_to_image

fn render_svg_node_to_image(node : SVGNode, width : Int, height : Int) -> Image

Render a raw SVGNode tree into an Image.

#
render_svg_scene_to_image

fn render_svg_scene_to_image(scene : Scene, width : Int, height : Int) -> Image

Render a Scene into an Image.

#
render_svg_to_image

fn render_svg_to_image(svg_str : String, width : Int, height : Int) -> Image?

Parse and render an SVG markup string into an Image.

#
saturate_matrix

fn saturate_matrix(factor : Double) -> FixedArray[Double]

Create saturate color matrix

#
text

fn text(id : String, x : Double, y : Double, content : String, font_size : Double) -> SVGNode

Helper: Create a text node