render

package
v0.3.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2026 License: BSD-3-Clause Imports: 12 Imported by: 1

README

paint render API

This package defines interfaces and data types for paint Renderer and Render:

  • Render is a sequence (slice) of Item elements that are generated by paint.Painter functions, such as Circle, DrawImage, or TextLines.

  • Renderer gets Render data and renders it into a specific form. The rasterx.Renderer generates an image.RGBA image of the paint commands. htmlcanvas.Renderer uses html canvas on the web to render. SVG and PDF create the corresponding documents.

In core, the Scene.Painter creates the appropriate Renderer for the current platform, using the paint.NewSourceRenderer function, and the platform-specific composer.Source knows how to use this renderer to create the relevant rendering for that platform. On the web, the composer.Composer manages the web canvases to produce the correct overall results across the multiple sources that are composed to make a final viewed image in an app.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bounds

type Bounds struct {
	// Rect is a rectangular bounding box.
	Rect math32.Box2

	// Radius is the border radius for rounded rectangles, can be per corner
	// or one value for all.
	Radius sides.Floats

	// Path is the computed clipping path for the Rect and Radius.
	Path ppath.Path
}

Bounds represents an optimized rounded rectangle form of clipping, which is critical for GUI rendering.

func NewBounds

func NewBounds(x, y, w, h float32, radius sides.Floats) *Bounds

func NewBoundsRect

func NewBoundsRect(rect image.Rectangle, radius sides.Floats) *Bounds

type Context

type Context struct {

	// Style has the accumulated style values.
	// Individual elements inherit from this style.
	Style styles.Paint

	// Transform is the transformation matrix for this stack level.
	Transform math32.Matrix2

	// Cumulative is the accumulated transformation matrix.
	Cumulative math32.Matrix2

	// Bounds is the rounded rectangle clip boundary.
	// This is applied to the effective Path prior to adding to Render.
	Bounds Bounds

	// ClipPath is the current shape-based clipping path,
	// in addition to the Bounds, which is applied to the effective Path
	// prior to adding to Render.
	ClipPath ppath.Path

	// Mask is the current masking element, as rendered to a separate image.
	// This is composited with the rendering output to produce the final result.
	Mask image.Image
}

Context contains all of the rendering constraints / filters / masks that are applied to elements being rendered. For SVG compliant rendering, we need a stack of these Context elements that apply to all elements in the group. Each level always represents the compounded effects of any parent groups, with the compounding being performed when a new Context is pushed on the stack. https://www.w3.org/TR/SVG2/render.html#Grouping

func NewContext

func NewContext(sty *styles.Paint, bounds *Bounds, parent *Context) *Context

NewContext returns a new Context using given paint style, bounds, and parent Context. See Context.Init for details.

func (*Context) Init

func (ctx *Context) Init(sty *styles.Paint, bounds *Bounds, parent *Context)

Init initializes context based on given style, bounds and parent Context. If parent is present, then bounds can be nil, in which case it gets the bounds from the parent. All the values from the style are used to update the Context, accumulating anything from the parent.

func (*Context) SetBounds

func (ctx *Context) SetBounds(bounds *Bounds)

SetBounds sets the context bounds, and updates the Bounds.Path

type ContextPop

type ContextPop struct {
}

ContextPop is a Context pop render item, which can be used by renderers that track group structure (e.g., SVG).

func (*ContextPop) IsRenderItem

func (p *ContextPop) IsRenderItem()

interface assertion.

func (*ContextPop) String added in v0.3.13

func (p *ContextPop) String() string

type ContextPush

type ContextPush struct {
	Context Context
}

ContextPush is a Context push render item, which can be used by renderers that track group structure (e.g., SVG).

func (*ContextPush) IsRenderItem

func (p *ContextPush) IsRenderItem()

interface assertion.

func (*ContextPush) String added in v0.3.13

func (p *ContextPush) String() string

type Item

type Item interface {
	fmt.Stringer

	IsRenderItem()
}

Item is a union interface for render items: Path, Text, [Image], and ContextPush.

type Path

type Path struct {
	// Path specifies the shape(s) to be drawn, using commands:
	// MoveTo, LineTo, QuadTo, CubeTo, ArcTo, and Close.
	// Each command has the applicable coordinates appended after it,
	// like the SVG path element. The coordinates are in the original
	// units as specified in the Paint drawing commands, without any
	// transforms applied. See [Path.Transform].
	Path ppath.Path

	// Context has the full accumulated style, transform, etc parameters
	// for rendering the path, combining the current state context (e.g.,
	// from any higher-level groups) with the current element's style parameters.
	Context Context
}

Path is a path drawing render Item: responsible for all vector graphics drawing functionality.

func NewPath

func NewPath(pt ppath.Path, sty *styles.Paint, ctx *Context) *Path

func (*Path) IsRenderItem

func (p *Path) IsRenderItem()

interface assertion.

func (*Path) String added in v0.3.13

func (p *Path) String() string

type Render

type Render []Item

Render is the sequence of painting [Item]s recorded from a [paint.Painter]

func (*Render) Add

func (pr *Render) Add(item ...Item) *Render

Add adds item(s) to render. Filters any nil items.

func (*Render) Clone

func (pr *Render) Clone() Render

Clone returns a copy of this Render, with shallow clones of the Items and Renderers lists.

func (*Render) Reset

func (pr *Render) Reset()

Reset resets back to an empty Render state. It preserves the existing slice memory for re-use.

func (*Render) String added in v0.3.13

func (pr *Render) String() string

type Renderer

type Renderer interface {

	// Render renders the given Render data.
	Render(r Render) Renderer

	// Size returns the size of the render target, in its preferred units.
	// For [Image] types, it will be [units.UnitDot] to indicate the actual
	// raw pixel size.
	Size() (units.Units, math32.Vector2)

	// SetSize sets the render size in given units. [units.UnitDot] is
	// used for [Image] and [Draw] renderers. Direct configuration of
	// other Renderer properties happens outside of this interface.
	// This is used for resizing [Image] and [Draw] renderers when
	// the relevant Scene size changes.
	SetSize(un units.Units, size math32.Vector2)

	// Image returns the rendered image after rendering.
	// If nil, then images are not supported by this renderer.
	Image() image.Image

	// Source returns the document source code representation
	// of the rendering output. This is supported by e.g., SVG
	// and PDF renderers.
	Source() []byte
}

Renderer is the interface for all backend rendering outputs.

type Text

type Text struct {
	// Text contains shaped Lines of text to be rendered, as produced by a
	// [shaped.Shaper]. Typically this text is  configured so that the
	// Postion is at the upper left corner of the resulting text rendering.
	Text *shaped.Lines

	// Position to render, which typically specifies the upper left corner of
	// the Text. This is added directly to the offsets and is transformed by the
	// active transform matrix. See also PositionAbs
	Position math32.Vector2

	// Context has the full accumulated style, transform, etc parameters
	// for rendering, combining the current state context (e.g.,
	// from any higher-level groups) with the current element's style parameters.
	Context Context
}

Text is a text rendering render item.

func NewText

func NewText(txt *shaped.Lines, sty *styles.Paint, ctx *Context, pos math32.Vector2) *Text

func (*Text) IsRenderItem

func (tx *Text) IsRenderItem()

interface assertion.

func (*Text) String added in v0.3.13

func (tx *Text) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL