svg

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 13 Imported by: 0 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 parses SVG documents and draws them into pixels, for the icons and pictures of package ui, in Go alone.

It draws paths and the basic shapes, groups, nested svg elements, use and symbol elements, transforms, fills and strokes (with joins, caps and dashes) of colors, currentColor and linear and radial gradients, opacity, clip paths and masks, and style sheets of simple selectors (type, class and id). Text, embedded images, patterns, markers and filters are not drawn.

Index

Constants

View Source
const (
	PathMove  = opMove
	PathLine  = opLine
	PathCubic = opCubic
	PathClose = opClose
)

The segments of path data: a move to a point, a line to one, a cubic Bézier curve through two control points to its end, and a close.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doc

type Doc struct {
	// contains filtered or unexported fields
}

Doc is a parsed SVG document. Draw may draw it from any goroutine.

func Parse

func Parse(data []byte) (*Doc, error)

Parse parses an SVG document.

func (*Doc) Draw

func (d *Doc) Draw(dst *image.RGBA, current color.NRGBA, stretch bool)

Draw draws the document over the pixels of dst, fitting its viewBox in them as its preserveAspectRatio says, or stretched to them with stretch. currentColor is current where the document does not set the color property.

func (*Doc) DrawRotated

func (d *Doc) DrawRotated(dst *image.RGBA, current color.NRGBA, w, h, degrees float64)

DrawRotated draws the document as Draw does in a box w×h pixels at the center of dst, turned by degrees clockwise around it.

func (*Doc) Size

func (d *Doc) Size() (w, h float64)

Size returns the document's size in pixels: its width and height, or those of its viewBox.

func (*Doc) UsesCurrentColor

func (d *Doc) UsesCurrentColor() bool

UsesCurrentColor reports whether the color Draw takes for currentColor changes what it draws.

type PathOp added in v0.1.17

type PathOp = pathOp

PathOp is what a segment of path data ParsePath parsed does.

func ParsePath added in v0.1.17

func ParsePath(d string) (ops []PathOp, pts [][2]float64, err error)

ParsePath parses SVG path data, as a path element's d attribute holds it, into its segments, in user units: ops, each taking its points from pts in turn, a move and a line one, a cubic curve three, a close none; quadratic curves and arcs become cubic ones. At an error it stops, as SVG draws a path up to its first error, and returns the error, with the segments before it.

Jump to

Keyboard shortcuts

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