Documentation
¶
Overview ¶
Provides parsing and rendering of SVG images. SVG files are parsed into an abstract representation, which can then be consumed by painting drivers.
Index ¶
- Constants
- Variables
- func GetColor(clr Pattern) color.Color
- type Bounds
- type CapMode
- type DashOptions
- type ErrorMode
- type GapMode
- type GradStop
- type Gradient
- type GradientUnits
- type JoinMode
- type JoinOptions
- type Linear
- type Matrix2D
- func (t Matrix2D) CubicTo(m OpCubicTo) (fixed.Point26_6, fixed.Point26_6, fixed.Point26_6)
- func (a Matrix2D) Invert() Matrix2D
- func (t Matrix2D) LineTo(m OpLineTo) fixed.Point26_6
- func (t Matrix2D) LineWidthScale() float64
- func (t Matrix2D) MoveTo(m OpMoveTo) fixed.Point26_6
- func (a Matrix2D) Mult(b Matrix2D) Matrix2D
- func (t Matrix2D) QuadTo(m OpQuadTo) (fixed.Point26_6, fixed.Point26_6)
- func (a Matrix2D) Rotate(theta float64) Matrix2D
- func (a Matrix2D) Scale(x, y float64) Matrix2D
- func (a Matrix2D) SkewX(theta float64) Matrix2D
- func (a Matrix2D) SkewY(theta float64) Matrix2D
- func (a Matrix2D) TFixed(x fixed.Point26_6) (y fixed.Point26_6)
- func (a Matrix2D) Transform(x1, y1 float64) (x2, y2 float64)
- func (a Matrix2D) TransformVector(x1, y1 float64) (x2, y2 float64)
- func (a Matrix2D) Translate(x, y float64) Matrix2D
- type OpClose
- type OpCubicTo
- type OpLineTo
- type OpMoveTo
- type OpQuadTo
- type Operation
- type Path
- type PathStyle
- type Pattern
- type PlainColor
- type Radial
- type SpreadMethod
- type StrokeOptions
- type Svg
- type SvgMask
- type SvgPath
Constants ¶
const ( Px unite = iota Cm Mm Pt In Q Pc Perc // Special case : percentage (%) relative to the viewbox )
Absolute units supported.
Variables ¶
var DefaultStyle = PathStyle{ FillOpacity: 1.0, LineOpacity: 1.0, LineWidth: 2.0, UseNonZeroWinding: true, Join: JoinOptions{ MiterLimit: fToFixed(4.), LineJoin: Bevel, TrailLineCap: ButtCap, }, FillerColor: NewPlainColor(0x00, 0x00, 0x00, 0xff), Transform: Identity, Masks: make([]string, 0), }
DefaultStyle sets the default PathStyle to fill black, winding rule, full opacity, no stroke, ButtCap line end and Bevel line connect.
var Identity = Matrix2D{1, 0, 0, 1, 0, 0}
Identity is the identity matrix
Functions ¶
Types ¶
type Bounds ¶
type Bounds struct{ X, Y, W, H float64 }
Bounds defines a bounding box, such as a viewport or a path extent.
type DashOptions ¶
type ErrorMode ¶
type ErrorMode uint8
ErrorMode is the for setting how the parser reacts to unparsed elements
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.
type Gradient ¶
type Gradient struct { Direction gradientDirecter Stops []GradStop Bounds Bounds Matrix Matrix2D Spread SpreadMethod Units GradientUnits }
Gradient holds a description of an SVG 2.0 gradient
func (*Gradient) ApplyPathExtent ¶
func (g *Gradient) ApplyPathExtent(extent fixed.Rectangle26_6) Matrix2D
ApplyPathExtent use the given path extent to adjust the bounding box, if required by `Units`. The `Direction` field is not modified, but a matrix accounting for both the bouding box and the gradient matrix is returned
type GradientUnits ¶
type GradientUnits byte
GradientUnits is the type for gradient units
const ( ObjectBoundingBox GradientUnits = iota UserSpaceOnUse )
SVG bounds paremater constants
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.
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 Matrix2D ¶
type Matrix2D struct {
A, B, C, D, E, F float64
}
Matrix2D represents an SVG style matrix
func (Matrix2D) LineWidthScale ¶ added in v0.5.1
LineWidthScale returns the mean of the horizontal and vertical scaling members. It may be used when scaling line widths with a rasterizer that does not support scaling a line's horizontal and vertical aspects independently.
func (Matrix2D) Transform ¶
Transform multiples the input vector by matrix m and outputs the results vector components.
func (Matrix2D) TransformVector ¶
TransformVector is a modidifed version of Transform that ignores the translation components.
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) CubeBezier ¶
CubeBezier adds a cubic segment to the current curve.
func (*Path) QuadBezier ¶
QuadBezier adds a quadratic segment to the current curve.
type PathStyle ¶
type PathStyle struct {
FillOpacity, LineOpacity float64
LineWidth float64
UseNonZeroWinding bool
Join JoinOptions
Dash DashOptions
FillerColor, LinerColor Pattern // either PlainColor or Gradient
Masks []string
Transform Matrix2D // current transform
}
PathStyle holds the state of the SVG style
type Pattern ¶
type Pattern interface {
// contains filtered or unexported methods
}
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 ¶
func NewPlainColor ¶
func NewPlainColor(r, g, b, a uint8) PlainColor
type SpreadMethod ¶
type SpreadMethod byte
SpreadMethod is the type for spread parameters
const ( PadSpread SpreadMethod = iota ReflectSpread RepeatSpread )
SVG spread parameter constants
type StrokeOptions ¶
type StrokeOptions struct { LineWidth fixed.Int26_6 // width of the line Join JoinOptions Dash DashOptions }
type Svg ¶
type Svg struct { ViewBox Bounds Titles []string // Title elements collect here Descriptions []string // Description elements collect here SvgPaths []SvgPath Transform Matrix2D SvgMasks map[string]*SvgMask Width, Height string // top level width and height attributes // contains filtered or unexported fields }
Svg holds data from parsed SVGs. See the `Draw` methods to use it.
func Parse ¶
Parse reads the Icon from the given io.Reader This only supports a sub-set of SVG, but is enough to draw many svgs. errMode determines if the svg ignores, errors out, or logs a warning if it does not handle an element found in the svg file.