svg

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0, MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package svg encodes a display.Box as a standalone SVG document.

The encoder is an optional pure-Go output adapter. It consumes the visible commands exposed by render.Walk, resolves paint roles against a caller supplied Palette, and includes certified box overflow in its viewBox.

SVG output is intended for embedding and interchange, not as a stable wire protocol. Use an application-owned version if serialized output must be persisted across upgrades.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidBox reports a nil or structurally invalid display box.
	ErrInvalidBox = errors.New("svg: invalid box")
	// ErrInvalidOptions reports unsupported padding or numeric precision.
	ErrInvalidOptions = errors.New("svg: invalid options")
	// ErrInvalidWriter reports a nil output writer.
	ErrInvalidWriter = errors.New("svg: invalid writer")
)

Functions

func Marshal

func Marshal(box *display.Box, options *Options) ([]byte, error)

Marshal encodes box as a standalone SVG document.

A nil options pointer uses DefaultOptions. Marshal does not mutate box.

func Write

func Write(writer io.Writer, box *display.Box, options *Options) error

Write encodes box as a standalone SVG document to writer.

A nil options pointer uses DefaultOptions. Writer errors are returned unchanged, so an error after writing has begun can leave partial output.

Types

type Options

type Options struct {
	Padding     float32
	Precision   int
	Background  *color.NRGBA
	Palette     Palette
	Title       string
	Description string
}

Options controls SVG sizing, colors, and metadata.

Padding is added on every side of Box.Bounds(). Precision is the maximum number of fractional digits; zero emits the shortest exact float32 form. A nil Background leaves the background transparent. An all-zero Palette uses DefaultPalette. Title and Description are escaped XML text.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the default encoder options.

type Palette

type Palette struct {
	Ink         color.NRGBA
	Error       color.NRGBA
	Placeholder color.NRGBA
}

Palette supplies concrete colors for semantic display roles.

func DefaultPalette

func DefaultPalette() Palette

DefaultPalette returns the default light-background role colors.

Jump to

Keyboard shortcuts

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