layer_canvas library
A pure-Dart 2D scene model rendered to pixels by a native Blend2D engine over FFI — rectangles, text, images, vector paths, and SVG import, composited into PNG bytes via Renderer.
Classes
- ArcTo
- Draws an elliptical arc from the current point to point.
- ClosePath
- Closes the current subpath with a straight line back to its starting point (the most recent MoveTo).
- Color32
- An immutable 32-bit color in ARGB order.
- ConicGradient
- A gradient that sweeps around center, starting at angle radians.
- CubicBezierTo
- Draws a cubic Bézier curve from the current point to point, using control1 and control2 as its two control points.
- FileImageSource
- An image read from a file path on disk at render time.
- FontRegistry
-
Registers custom fonts (raw TTF/OTF bytes) so a
TextLayer.fontFamilycan reference them by name, instead of always falling back to this package's embedded default font. - Gradient
- A smooth transition between colors, used as a LayerPaint.gradient fill source in place of a solid LayerPaint.color.
- GradientStop
- A single color stop within a Gradient's ramp.
- Group
- A composite Layer that groups other layers so they can share a single Layer.transform and Layer.opacity, and be reordered together.
- ImageLayer
- A single image composited as a layer.
- Layer
- Base type for every element that can be composited onto a Scene.
- LayerImageSource
- Where the raw image data for an ImageLayer (or a Scene background) comes from.
- LayerPaint
- Fill and stroke properties for a shape layer.
- LayerPath
- An ordered sequence of PathCommands describing arbitrary vector geometry, used as PathLayer.path.
- LayerRegistry
-
Maps a serialized Layer.type/LayerImageSource
'type'tag back to a decoder, soScene.fromJsoncan reconstruct a polymorphic layer/ image-source tree without hardcoding every possible subclass — the same "subclass it, no core changes needed" extensibility Layer's own doc comment already promises for rendering, extended to JSON round-tripping. - LayerTransform
- Common 2D transform applied to a layer before it is composited.
- LinearGradient
- A gradient that transitions along a straight line from start to end.
- LineTo
- Draws a straight line from the current point to point.
- MemoryImageSource
- An image already available as encoded bytes (PNG/JPEG/etc.) in memory.
- MoveTo
- Starts a new subpath at point without drawing anything.
- PathCommand
- A single step of a LayerPath's geometry.
- PathLayer
- Arbitrary vector geometry — lines and Bézier curves, a circle/ellipse, or a polygon/polyline built from a list of vertices — filled and/or stroked with a LayerPaint.
- Point2D
- A 2D point or vector in the Scene's logical pixel space.
- QuadraticBezierTo
- Draws a quadratic Bézier curve from the current point to point, using control as its single control point.
- RadialGradient
- A gradient that radiates outward from center up to radius.
- RectangleLayer
- A filled and/or stroked rectangle with optional rounded corners.
- Renderer
- Renders a Scene to encoded image bytes using the native Blend2D compositing engine.
- Scene
- The root of a composition: a fixed-size canvas plus an ordered list of Layers (which may themselves be Groups) painted on top of an optional background.
- Size2D
- A 2D size in the Scene's logical pixel space.
- SvgDocument
- A parsed SVG document, ready to be composited into a Scene via toGroup.
- TextLayer
- A run of styled text rendered as a layer.
- TextWeight
- Font weight on the standard 100–900 CSS/OpenType scale.
Enums
- FillRule
-
How overlapping/self-intersecting regions of a LayerPath are filled.
Only meaningful for LayerPaintStyle.fill/
fillAndStroke— ignored for a stroke-only paint. - GradientExtendMode
-
How a gradient behaves outside its defined
0.0..1.0offset range. - ImageFit
- How an ImageLayer's source image is scaled inside its Layer.size.
- LayerPaintStyle
- How a shape's geometry should be painted.
- OutputFormat
- An encoded image format a Renderer can produce.
- StrokeCap
- Shape of a stroke's two open ends. Ignored for a closed subpath.
- StrokeJoin
- Shape drawn where two stroked segments meet.
- TextAlignment
- Horizontal alignment of text within its bounding box.
Functions
-
hitTestScene(
Scene scene, Point2D point) → Layer? -
Returns the topmost visible Layer in
scenewhose bounding box containspoint(both in the scene's own logical pixel space), ornullif none does. -
parseCommonLayerJson(
Map< String, Object?> json) → CommonLayerFields -
Parses the fields Layer.commonJson adds, shared by every concrete
layer's
fromJson.
Typedefs
- CommonLayerFields = ({bool clipToBounds, String id, double opacity, Size2D? size, LayerTransform transform, bool visible, int zIndex})
-
The common Layer fields (
commonJson's output) already parsed back into their Dart types — every concreteLayer.fromJsondestructures this instead of repeating the same field lookups. -
ImageSourceFromJson
= LayerImageSource Function(Map<
String, Object?> json) - Decodes a JSON map (as produced by LayerImageSource.toJson) back into a LayerImageSource.
-
LayerFromJson
= Layer Function(Map<
String, Object?> json) - Decodes a JSON map (as produced by Layer.toJson) back into a Layer.
Exceptions / Errors
- FontRegistrationException
- Thrown when FontRegistry.register is given data the native engine can't parse as a font.
- RenderException
- Thrown when the native engine fails to render a Scene.
- SvgParseException
-
Thrown by SvgDocument.parse when its
sourceisn't well-formed XML.