package d2scene
Import Path
github.com/pancsta/d2/d2renderers/d2scene (on go.dev)
Dependency Relation
imports 5 packages, and imported by 7 packages
Involved Source Files
animation.go
aspect.go
Package d2scene defines the renderer-neutral scene representation used by
D2's raster export pipeline.
A Document is owned by its builder and is treated as immutable once it is
handed to a renderer. Renderers may therefore read the same document
concurrently at different animation times.
paint.go
path.go
primitive.go
scene.go
Package-Level Type Names (total 55)
const AnimateDropShadow
const AnimateFillColor
const AnimateOpacity
const AnimateStrokeColor
const AnimateStrokeDashOffset
const AnimateTransform
AnimationValue is a small tagged union so renderers must handle every value
kind explicitly. Unused fields are ignored.
Color color.NRGBA
Kind AnimationValueKind
Number float64
Shadow DropShadow
Transform Matrix
func ColorValue(value color.NRGBA) AnimationValue
func NumberValue(value float64) AnimationValue
func ShadowValue(value DropShadow) AnimationValue
func TransformValue(value Matrix) AnimationValue
const ColorAnimationValue
const NumberAnimationValue
const ShadowAnimationValue
const TransformAnimationValue
const AlignNone
const AlignXMaxYMax
const AlignXMaxYMid
const AlignXMaxYMin
const AlignXMidYMax
const AlignXMidYMid
const AlignXMidYMin
const AlignXMinYMax
const AlignXMinYMid
const AlignXMinYMin
const AspectMeet
const AspectSlice
Align AspectAlign
Fit AspectFit
func AspectRatioMatrix(source, destination Box, aspect AspectRatio) (Matrix, error)
Asset is a closed set of fully resolved, network-free scene resources.
Asset byte slices are retained by the Document and must not be mutated after
construction. Builders copy mutable caller data before retention; immutable
process-owned resources may be shared across Documents.
FontAsset
RasterAsset
VectorAsset
func github.com/pancsta/d2/d2renderers/internal/fontfallback.AssetID(ctx context.Context, font fontfallback.Font) (AssetID, error)
const BlendColorBurn
const BlendDarken
const BlendLighten
const BlendMultiply
const BlendNormal
const BlendOverlay
Bounds is an axis-aligned bounding box. Valid distinguishes an empty set
from a zero-area bound such as a point or a horizontal line.
Max Point
Min Point
Valid bool
( Bounds) Box() Box
Expand grows bounds in both directions. A negative amount shrinks it and
may produce invalid bounds.
( Bounds) Height() float64
Include returns bounds containing b and p.
Intersect returns the common area of two bounds, or invalid bounds when
they do not overlap.
( Bounds) IsFinite() bool
Transform returns the axis-aligned bounds of the transformed corners.
Translate returns bounds shifted by v.
Union returns the smallest bounds containing both operands.
( Bounds) Width() float64
func BoundsFromPoints(points ...Point) Bounds
func NewBounds(x0, y0, x1, y1 float64) Bounds
func PrimitiveBounds(primitive Primitive, m Matrix) (Bounds, error)
func Bounds.Expand(x, y float64) Bounds
func Bounds.Include(p Point) Bounds
func Bounds.Intersect(other Bounds) Bounds
func Bounds.Transform(m Matrix) Bounds
func Bounds.Translate(v Point) Bounds
func Bounds.Union(other Bounds) Bounds
func Box.Bounds() Bounds
func Path.GeometryBounds() (Bounds, error)
func Bounds.Intersect(other Bounds) Bounds
func Bounds.Union(other Bounds) Bounds
Box is an axis-aligned rectangle expressed as an origin and size.
Width and Height may be zero, but must not be negative in a valid scene.
Height float64
Width float64
X float64
Y float64
Bounds converts b to min/max form. Negative sizes are normalized here so
geometry helpers remain total; render preflight rejects them in scenes.
func Bounds.Box() Box
func AspectRatioMatrix(source, destination Box, aspect AspectRatio) (Matrix, error)
func NewDocument(viewBox Box, root *Node) *Document
CenterArc is SVG endpoint arc geometry converted to a center
parameterization. Its fields remain private so callers cannot construct an
inconsistent arc; renderers use the accessors below.
( CenterArc) DeltaAngle() float64
( CenterArc) PointAt(theta float64) Point
( CenterArc) StartAngle() float64
TransformedRadiusBound returns a conservative second-derivative bound after
applying the linear part of m. It is used to prove a device-space chord
error during adaptive flattening.
func EndpointArcToCenter(start Point, command PathCommand) (CenterArc, bool, error)
Assets map[AssetID]Asset
Links []LinkRegion
LogicalHeight float64
LogicalWidth float64
Root *Node
ViewBox Box
ViewportAlign ViewportAlign
ViewportFit ViewportFit
func NewDocument(viewBox Box, root *Node) *Document
func github.com/pancsta/d2/d2renderers/d2scenebuild.Build(ctx context.Context, diagram *d2target.Diagram, options d2scenebuild.Options) (*Document, error)
func github.com/pancsta/d2/d2renderers/d2raster.Render(ctx context.Context, document *Document, options d2raster.FrameOptions) (*image.NRGBA, error)
func github.com/pancsta/d2/d2renderers/d2raster.RenderBands(ctx context.Context, document *Document, options d2raster.FrameOptions, bandHeight int, consume func(*image.NRGBA) error) error
func github.com/pancsta/d2/d2renderers/d2raster.(*RenderSession).Render(ctx context.Context, document *Document, options d2raster.FrameOptions) (*image.NRGBA, error)
func github.com/pancsta/d2/d2renderers/d2raster.(*RenderSession).RenderBands(ctx context.Context, document *Document, options d2raster.FrameOptions, bandHeight int, consume func(*image.NRGBA) error) error
func github.com/pancsta/d2/d2renderers/d2raster.(*RenderWorkspace).Render(ctx context.Context, session *d2raster.RenderSession, document *Document, options d2raster.FrameOptions, consume func(*image.NRGBA) error) error
Color color.NRGBA
OffsetX float64
OffsetY float64
SigmaX float64
SigmaY float64
DropShadow : Filter
func ShadowValue(value DropShadow) AnimationValue
Easing describes an outgoing keyframe easing. CubicBezier uses CSS-style
control points (0,0), (X1,Y1), (X2,Y2), (1,1).
Kind EasingKind
X1 float64
X2 float64
Y1 float64
Y2 float64
const EaseCubicBezier
const EaseLinear
const EaseStepEnd
const EaseStepStart
Data []byte
FaceIndex selects one face from an OpenType collection. It is zero for a
single-face TTF/OTF and for the first face of a TTC. Keeping the index in
the resolved asset lets a scene retain host fallback fonts without asking
the network-free rasterizer to rediscover which collection face was used.
MIMEType string
FontAsset : Asset
Glyph optionally carries a shaper's exact glyph placement. Ink is relative
to Origin+Position. A renderer may shape Text itself when Glyphs is empty.
Advance float64
Asset overrides TextRun.Font.Asset for this glyph. An empty value keeps
the primary asset. This makes explicit shaping capable of retaining
mixed-font fallback decisions in the scene itself.
Empty retains an invisible shaper output (for example a default-
ignorable control) so its placement and advance survive in the scene.
Empty glyphs use ID zero and are never sent to the outline rasterizer.
ID uint32
Ink Bounds
Position Point
End Point
Spread SpreadMethod
Start Point
Stops []GradientStop
Transform Matrix
Units PaintUnits
LinearGradient : Paint
Box is expressed in the same logical coordinate space as Document.ViewBox.
Target string
Tooltip string
URL is an external or opaque link destination. Target instead names a
D2 board destination. At most one of URL and Target may be set; a region
with neither is valid when it carries tooltip-only metadata.
const MaskAlpha
const MaskLuminance
Matrix is an SVG-style affine transform:
x' = A*x + C*y + E
y' = B*x + D*y + F
The zero value is the zero transform, not identity. Use Identity explicitly.
A float64
B float64
C float64
D float64
E float64
F float64
( Matrix) Determinant() float64
( Matrix) Inverse() (Matrix, error)
( Matrix) IsFinite() bool
MaxScale is the largest singular value of the linear portion of m. It is
used to conservatively transform stroke and filter radii.
Mul composes m and right. The right transform is applied to a point first.
( Matrix) Point(p Point) Point
Vector transforms a vector, excluding translation.
func AspectRatioMatrix(source, destination Box, aspect AspectRatio) (Matrix, error)
func Identity() Matrix
func Rotate(radians float64) Matrix
func RotateAround(radians, x, y float64) Matrix
func Scale(x, y float64) Matrix
func SkewX(radians float64) Matrix
func SkewY(radians float64) Matrix
func Translate(x, y float64) Matrix
func Matrix.Inverse() (Matrix, error)
func Matrix.Mul(right Matrix) Matrix
func PrimitiveBounds(primitive Primitive, m Matrix) (Bounds, error)
func TransformValue(value Matrix) AnimationValue
func Bounds.Transform(m Matrix) Bounds
func CenterArc.TransformedRadiusBound(m Matrix) float64
func Matrix.Mul(right Matrix) Matrix
Node is one immutable-ish scene layer. Transform maps node-local coordinates
into its parent's coordinates. Callers constructing nodes directly must use
Identity for an untransformed node; NewNode supplies that default.
Animations []Track
Blend BlendMode
Children []*Node
Classes []string
Clip *Clip
Filters []Filter
ID string
Mask *Mask
Opacity float64
Primitive Primitive
Transform Matrix
func NewNode(primitive Primitive) *Node
func NewDocument(viewBox Box, root *Node) *Document
Paint is a closed set of renderer-neutral D2 paints. A nil Paint means no
paint. The closed interface makes unsupported paint kinds fail at compile
time instead of disappearing in a renderer.
LinearGradient
PatternPaint
RadialGradient
SolidPaint
func github.com/pancsta/d2/d2renderers/internal/scenepaint.Gradient(raw string) (Paint, error)
const ObjectBoundingBox
const UserSpaceOnUse
Path is both typed path geometry and a paintable scene primitive.
Commands []PathCommand
Fill Paint
FillRule FillRule
Stroke *Stroke
GeometryBounds computes exact analytic bounds of the centerline geometry.
Path : Primitive
func github.com/pancsta/d2/d2renderers/d2sketch.ConnectionDrawable(ctx context.Context, path Path, limits d2sketch.SceneLimits) (rough.Drawable, error)
PathCommand stores absolute, typed path geometry. P1 is the endpoint for a
move or line; P1/P2 are control/end for a quadratic; P1/P2/P3 are the two
controls/end for a cubic; and P1 is the endpoint for an arc. Arc rotation is
in radians.
Kind PathCommandKind
LargeArc bool
P1 Point
P2 Point
P3 Point
RadiusX float64
RadiusY float64
Rotation float64
Sweep bool
func ArcTo(rx, ry, rotation float64, largeArc, sweep bool, x, y float64) PathCommand
func ClosePath() PathCommand
func CubicTo(c1x, c1y, c2x, c2y, x, y float64) PathCommand
func LineTo(x, y float64) PathCommand
func MoveTo(x, y float64) PathCommand
func QuadraticTo(cx, cy, x, y float64) PathCommand
func github.com/pancsta/d2/d2renderers/d2svgimport.ParsePath(ctx context.Context, source, data string, limits d2svgimport.PathLimits) ([]PathCommand, error)
func EndpointArcToCenter(start Point, command PathCommand) (CenterArc, bool, error)
const ArcCommand
const CloseCommand
const CubicCommand
const LineCommand
const MoveCommand
const QuadraticCommand
PatternPaint repeats Root over Tile. Root is in Tile's local coordinate
system and is subject to Transform before the pattern is sampled.
Root *Node
Tile Box
Transform Matrix
Units PaintUnits
PatternPaint : Paint
Point is a point or vector in logical D2 coordinates.
X float64
Y float64
func CenterArc.PointAt(theta float64) Point
func Matrix.Point(p Point) Point
func Matrix.Vector(v Point) Point
func BoundsFromPoints(points ...Point) Bounds
func EndpointArcToCenter(start Point, command PathCommand) (CenterArc, bool, error)
func Bounds.Include(p Point) Bounds
func Bounds.Translate(v Point) Bounds
func Matrix.Point(p Point) Point
func Matrix.Vector(v Point) Point
Primitive is the closed set of paintable scene leaves. Groups are Nodes
with a nil Primitive and one or more Children.
Ellipse
Image
Path
Rect
TextRun
func NewNode(primitive Primitive) *Node
func PrimitiveBounds(primitive Primitive, m Matrix) (Bounds, error)
Center Point
Focal Point
FocalRadius float64
Radius float64
Spread SpreadMethod
Stops []GradientStop
Transform Matrix
Units PaintUnits
RadialGradient : Paint
RasterAsset retains one encoded raster resource. Native rendering uses the
first animation frame of GIF, APNG, and WebP data on its logical canvas and
normalizes JPEG pixels and dimensions using EXIF Orientation.
Data []byte
DecodedBytes is the resolver-proven decoded first-frame canvas footprint.
A zero value uses a conservative 4-byte-per-pixel estimate for callers
that have already normalized the asset to 8-bit RGBA. Values below that
minimum are invalid.
MIMEType string
PixelHeight int
PixelWidth int
RasterAsset : Asset
const SpreadPad
const SpreadReflect
const SpreadRepeat
Stroke describes path stroking in logical coordinates. Dashes alternate on
and off lengths and are interpreted before DashOffset, as in SVG.
Cap LineCap
DashOffset float64
Dashes []float64
Join LineJoin
MiterLimit float64
Paint Paint
Width float64
const AnchorEnd
const AnchorMiddle
const AnchorStart
TextRun is one consistently styled baseline run. Ink is the exact measured
node-local ink bounds when available. Underline and Strike are explicit so
link and label decoration does not require renderer-specific child nodes.
Anchor TextAnchor
Fallbacks is an ordered list of already-resolved font assets. Renderers
may use them for missing glyphs but must never perform font discovery or
filesystem I/O while painting a document. It lives on TextRun rather than
Font so Font remains comparable and usable as a map key.
Fill Paint
Font Font
Glyphs []Glyph
Ink Bounds
Origin Point
Strike bool
Stroke *Stroke
Text string
Underline bool
TextRun : Primitive
Track describes one typed animation. Repeat loops forever. Renderers resolve
tracks without changing the track or its node, so a scene can be rendered at
multiple times concurrently.
Delay time.Duration
Duration time.Duration
Keyframes []Keyframe
Property AnimationProperty
Repeat bool
TargetIndex selects an entry for indexed properties such as a drop
shadow in Node.Filters. It is zero for scalar node properties.
ViewportAlign controls placement when a uniform viewport fit leaves
letterbox space. The zero value anchors content at the viewport origin.
const ViewportAlignXMidYMid
const ViewportAlignXMinYMin
ViewportFit controls how a document viewbox maps into its output viewport.
The zero value selects independent-axis stretching.
const ViewportMeet
const ViewportStretch
Package-Level Functions (total 24)
func ArcTo(rx, ry, rotation float64, largeArc, sweep bool, x, y float64) PathCommand
AspectRatioMatrix maps source coordinates into destination using SVG's
preserveAspectRatio rules. Source must have positive dimensions;
destination may be empty so zero-sized image primitives remain valid and
paint no pixels.
BoundsFromPoints returns the smallest bounds containing points.
func ClosePath() PathCommand func ColorValue(value color.NRGBA) AnimationValue func CubicTo(c1x, c1y, c2x, c2y, x, y float64) PathCommand
EndpointArcToCenter implements SVG 2's endpoint-to-center conversion. The
boolean is false for the two specified degeneracies: identical endpoints
(omit the arc) and a zero radius (draw a line). Ratio exponents are
normalized before division, so finite tiny radii can be corrected without
overflowing to infinity first.
func LineTo(x, y float64) PathCommand func MoveTo(x, y float64) PathCommand
NewBounds constructs valid bounds and normalizes the two corners.
func NewDocument(viewBox Box, root *Node) *Document func NumberValue(value float64) AnimationValue
PrimitiveBounds returns conservative painted bounds after applying m. Path
and ellipse geometry extrema are analytic; stroke expansion is deliberately
conservative until the stroker computes its exact outline.
func QuadraticTo(cx, cy, x, y float64) PathCommand
Rotate returns a counter-clockwise rotation in radians in Cartesian
coordinates. In D2's screen coordinate system (positive Y down), it appears
clockwise, matching SVG transform behavior.
func RotateAround(radians, x, y float64) Matrix func ShadowValue(value DropShadow) AnimationValue func TransformValue(value Matrix) AnimationValue
Package-Level Constants (total 60)
const AlignNone AspectAlign = 0 const AlignXMaxYMax AspectAlign = 9 const AlignXMaxYMid AspectAlign = 6 const AlignXMaxYMin AspectAlign = 3 const AlignXMidYMax AspectAlign = 8 const AlignXMidYMid AspectAlign = 5 const AlignXMidYMin AspectAlign = 2 const AlignXMinYMax AspectAlign = 7 const AlignXMinYMid AspectAlign = 4 const AlignXMinYMin AspectAlign = 1 const AnchorEnd TextAnchor = 2 const AnchorMiddle TextAnchor = 1 const AnchorStart TextAnchor = 0 const AnimateDropShadow AnimationProperty = 5 const AnimateFillColor AnimationProperty = 3 const AnimateOpacity AnimationProperty = 0 const AnimateStrokeColor AnimationProperty = 4 const AnimateStrokeDashOffset AnimationProperty = 2 const AnimateTransform AnimationProperty = 1 const ArcCommand PathCommandKind = 4 const AspectMeet AspectFit = 0 const AspectSlice AspectFit = 1 const BlendColorBurn BlendMode = 3 const BlendDarken BlendMode = 2 const BlendLighten BlendMode = 5 const BlendMultiply BlendMode = 1 const BlendNormal BlendMode = 0 const BlendOverlay BlendMode = 4 const CloseCommand PathCommandKind = 5 const ColorAnimationValue AnimationValueKind = 2 const CubicCommand PathCommandKind = 3 const EaseCubicBezier EasingKind = 1 const EaseLinear EasingKind = 0 const EaseStepEnd EasingKind = 3 const EaseStepStart EasingKind = 2 const LineCommand PathCommandKind = 1 const MaskLuminance MaskType = 1 const MoveCommand PathCommandKind = 0 const NumberAnimationValue AnimationValueKind = 0 const ObjectBoundingBox PaintUnits = 0 const QuadraticCommand PathCommandKind = 2 const ShadowAnimationValue AnimationValueKind = 3 const SpreadPad SpreadMethod = 0 const SpreadReflect SpreadMethod = 1 const SpreadRepeat SpreadMethod = 2 const TransformAnimationValue AnimationValueKind = 1 const UserSpaceOnUse PaintUnits = 1 const ViewportAlignXMidYMid ViewportAlign = 1 const ViewportAlignXMinYMin ViewportAlign = 0 const ViewportMeet ViewportFit = 1 const ViewportStretch ViewportFit = 0
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |