svg

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

README

svgicon

SVG parser and renderer written in Go.

This code is based on github.com/benoitkugler/oksvg, which itself is a heavily modified fork of github.com/srwiley/oksvg.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultStyle = PathStyle{
	FillOpacity:       1.0,
	LineOpacity:       1.0,
	LineWidth:         2.0,
	UseNonZeroWinding: true,
	Join: JoinOptions{
		MiterLimit:   fixed.Int26_6(4. * 64),
		LineJoin:     Bevel,
		TrailLineCap: ButtCap,
	},
	FillColor: PlainColor{A: 255},
	Transform: matrix.Identity,
}

DefaultStyle sets the default PathStyle to fill black, winding rule, full opacity, no stroke, ButtCap line end and Bevel line connect.

Functions

This section is empty.

Types

type CapMode

type CapMode uint8

CapMode defines how to draw caps on the ends of lines

const (
	NilCap CapMode = iota // default value
	ButtCap
	SquareCap
	RoundCap
	CubicCap     // Not part of the SVG2.0 standard.
	QuadraticCap // Not part of the SVG2.0 standard.
)

func (CapMode) String

func (c CapMode) String() string

type DashOptions

type DashOptions struct {
	Dash       []float64 // values for the dash pattern (nil or an empty slice for no dashes)
	DashOffset float64   // starting offset into the dash array
}

type Definition

type Definition struct {
	ID, Tag string
	Attrs   []xml.Attr
}

Definition is used to store what's given in a def tag

type GapMode

type GapMode uint8

GapMode defines how to bridge gaps when the miter limit is exceeded, and is not part of the SVG2.0 standard.

const (
	NilGap GapMode = iota
	FlatGap
	RoundGap
	CubicGap
	QuadraticGap
)

func (GapMode) String

func (g GapMode) String() string

type GradDirection

type GradDirection interface {
	Type() GradType
	Params() []float64
}

GradDirection is either Radial or Linear

type GradStop

type GradStop struct {
	StopColor color.Color
	Offset    float64
	Opacity   float64
}

GradStop represents a stop in the SVG 2.0 gradient specification

type GradType

type GradType byte
const (
	Linear GradType = iota
	Radial
)

type GradUnits

type GradUnits byte

GradUnits is the type for gradient units

const (
	ObjectBoundingBox GradUnits = iota
	UserSpaceOnUse
)

SVG bounds paremater constants

type Gradient

type Gradient struct {
	Direction GradDirection
	Stops     []GradStop
	Bounds    ViewBox
	Matrix    matrix.Matrix2D
	Spread    SpreadMethod
	Units     GradUnits
}

Gradient holds a description of an SVG 2.0 gradient

func (*Gradient) ApplyPathExtent

func (g *Gradient) ApplyPathExtent(extent fixed.Rectangle26_6) matrix.Matrix2D

ApplyPathExtent use the given path extent to adjust the bounding box, if required by `Units`. The `Params` field is not modified, but a matrix accounting for both the bounding box and the gradient matrix is returned

func (Gradient) IsPattern

func (Gradient) IsPattern()

type Icon

type Icon struct {
	ViewBox   ViewBox
	Paths     []StyledPath
	Transform matrix.Matrix2D
}

func (*Icon) SetTarget

func (i *Icon) SetTarget(x, y, w, h float64)

SetTarget sets the Transform matrix to draw within the bounds of the rectangle arguments

type JoinMode

type JoinMode uint8

JoinMode type to specify how segments join.

const (
	Arc JoinMode = iota // New in SVG2
	Round
	Bevel
	Miter
	MiterClip // New in SVG2
	ArcClip   // Like MiterClip applied to arcs, and is not part of the SVG2.0 standard.
)

JoinMode constants determine how stroke segments bridge the gap at a join ArcClip mode is like MiterClip applied to arcs, and is not part of the SVG2.0 standard.

func (JoinMode) String

func (s JoinMode) String() string

type JoinOptions

type JoinOptions struct {
	MiterLimit   fixed.Int26_6 // he miter cutoff value for miter, arc, miterclip and arcClip joinModes
	LineJoin     JoinMode      // JoinMode for curve segments
	TrailLineCap CapMode       // capping functions for leading and trailing line ends. If one is nil, the other function is used at both ends.

	LeadLineCap CapMode // not part of the standard specification
	LineGap     GapMode // not part of the standard specification. determines how a gap on the convex side of two lines joining is filled
}

type LinearParams

type LinearParams [4]float64

LinearParams contains the linear gradient parameters x1, y1, x2, y2

func (LinearParams) Params

func (p LinearParams) Params() []float64

func (LinearParams) Type

func (LinearParams) Type() GradType

type OpClose

type OpClose struct{}

OpClose close the current path.

func (OpClose) String

func (op OpClose) String() string

type OpCubicTo

type OpCubicTo [3]fixed.Point26_6

OpCubicTo draws a cubic Bezier curve from the current point, and updates it.

func (OpCubicTo) String

func (op OpCubicTo) String() string

type OpLineTo

type OpLineTo fixed.Point26_6

OpLineTo draws a line from the current point, and updates it.

func (OpLineTo) String

func (op OpLineTo) String() string

type OpMoveTo

type OpMoveTo fixed.Point26_6

OpMoveTo moves the current point.

func (OpMoveTo) String

func (op OpMoveTo) String() string

type OpQuadTo

type OpQuadTo [2]fixed.Point26_6

OpQuadTo draws a quadratic Bezier curve from the current point, and updates it.

func (OpQuadTo) String

func (op OpQuadTo) String() string

type Operation

type Operation interface {
	// SVG text representation of the command
	fmt.Stringer
}

Operation groups the different SVG commands

type Path

type Path []Operation

Path describes a sequence of basic SVG operations, which should not be nil Higher-level shapes may be reduced to a path.

func (*Path) AddArc

func (p *Path) AddArc(points []float64, cx, cy, px, py float64) (lx, ly float64)

addArc adds an arc to the adder p

func (*Path) AddRoundRect

func (p *Path) AddRoundRect(minX, minY, maxX, maxY, rx, ry, rot float64)

addRoundRect adds a rectangle of the indicated size, rotated around the center by rot degrees with rounded corners of radius rx in the x axis and ry in the y axis. gf specifes the shape of the filleting function.

func (*Path) Clear

func (p *Path) Clear()

Clear zeros the path slice

func (*Path) CubeBezier

func (p *Path) CubeBezier(b, c, d fixed.Point26_6)

CubeBezier adds a cubic segment to the current curve.

func (*Path) Line

func (p *Path) Line(b fixed.Point26_6)

Line adds a linear segment to the current curve.

func (*Path) QuadBezier

func (p *Path) QuadBezier(b, c fixed.Point26_6)

QuadBezier adds a quadratic segment to the current curve.

func (*Path) Start

func (p *Path) Start(a fixed.Point26_6)

Start starts a new curve at the given point.

func (*Path) Stop

func (p *Path) Stop(closeLoop bool)

Stop joins the ends of the path

func (Path) String

func (p Path) String() string

String returns a readable representation of a Path.

func (Path) ToSVGPath

func (p Path) ToSVGPath() string

ToSVGPath returns a string representation of the path

type PathStyle

type PathStyle struct {
	FillOpacity       float64
	LineOpacity       float64
	LineWidth         float64
	UseNonZeroWinding bool

	Join      JoinOptions
	Dash      DashOptions
	FillColor Pattern // either PlainColor or Gradient
	LineColor Pattern // either PlainColor or Gradient

	Transform matrix.Matrix2D // current transform
}

PathStyle holds the state of the SVG style

type Pattern

type Pattern interface {
	IsPattern()
}

Pattern groups a basic color and a gradient pattern A nil value may by used to indicated that the function (fill or stroke) is off

type PlainColor

type PlainColor color.NRGBA

func (PlainColor) IsPattern

func (PlainColor) IsPattern()

func (PlainColor) RGBA

func (c PlainColor) RGBA() (r, g, b, a uint32)

type RadialParams

type RadialParams [6]float64

RadialParams contains the radial gradiant parameters cx, cy, fx, fy, r, fr

func (RadialParams) Params

func (p RadialParams) Params() []float64

func (RadialParams) Type

func (RadialParams) Type() GradType

type SpreadMethod

type SpreadMethod byte

SpreadMethod is the type for spread parameters

const (
	PadSpread SpreadMethod = iota
	ReflectSpread
	RepeatSpread
)

SVG spread parameter constants

type StyledPath

type StyledPath struct {
	Path  Path
	Style PathStyle
}

StyledPath binds a style to a path

type ViewBox

type ViewBox struct{ X, Y, W, H float64 }

ViewBox defines a bounding box, such as a viewport or a path extent.

func (ViewBox) AspectMeet

func (viewbox ViewBox) AspectMeet(dx, dy, ax, ay float64) (X, Y, W, H float64)

AspectMeet positions and sizes the ViewBox inside the rectangle defined by the arguments, while maintaining the aspect ratio. The arguments dx,dy are the width and height of a rectangle (with X and Y both 0.0) and the alignment of the rectangle. Where {ax:0.0,ay:0.0} is left/top and {ax:1.0,ay:1.0} is right/bottom.

Directories

Path Synopsis
dummy
Package dummy is a debugging driver that logs every draw call.
Package dummy is a debugging driver that logs every draw call.
gio module
Provides parsing and rendering of SVG images.
Provides parsing and rendering of SVG images.

Jump to

Keyboard shortcuts

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