svg

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	UnitNone = Units(iota)
	UnitEM
	UnitEX
	UnitPX
	UnitIN
	UnitCM
	UnitMM
	UnitPT
	UnitPC
	UnitPercent
)

Valid unit values

View Source
const (
	PaintKindNone = PaintKind(iota)
	PaintKindRGB
	PaintKindGradient
)
View Source
const (
	GradientUnitsUnspecified = GradientUnits(iota)
	GradientUnitsUserSpaceOnUse
	GradientUnitsObjectBoundingBox
)
View Source
const (
	SpreadMethodUnspecified = SpreadMethod(iota)
	SpreadMethodPad
	SpreadMethodReflect
	SpreadMethodRepeat
)
View Source
const (
	FillRuleInherit = FillRule(iota)
	FillRuleNonZero
	FillRuleEvenOdd
)
View Source
const (
	LineCapInherit = LineCap(iota)
	LineCapButt
	LineCapRound
	LineCapSquare
)
View Source
const (
	LineJoinInerit = LineJoin(iota)
	LineJoinMiter
	LineJoinRound
	LineJoinBevel
)
View Source
const (
	PathClose = PathCommand(iota)
	PathMoveTo
	PathLineTo
	PathCurveTo
)

Variables

View Source
var ErrEmptyValue = errors.New("empty value")

Functions

func Cross

func Cross(a, b Vector) float64

func Dot

func Dot(a, b Vector) float64

func ParseOpacity added in v0.0.4

func ParseOpacity(s string) (*float64, error)

func Write

func Write(w io.Writer, s *Svg)

Types

type Circle

type Circle struct {
	Shape
	Cx     Coordinate
	Cy     Coordinate
	Radius Length
}

func (*Circle) ID

func (it *Circle) ID() string

type Coordinate

type Coordinate = Length // alias, for convenience

type Defs

type Defs struct {
	Node
	Transform *Transform
}

func (*Defs) ID

func (it *Defs) ID() string

type Ellipse

type Ellipse struct {
	Shape
	Cx Coordinate
	Cy Coordinate
	Rx Length
	Ry Length
}

func (*Ellipse) ID

func (it *Ellipse) ID() string

type FillRule

type FillRule int

FillRule implements SVG <fill-rule> type

func (FillRule) String

func (fr FillRule) String() string

func (FillRule) UnmarshalText

func (fr FillRule) UnmarshalText(text []byte) error

type Gradient

type Gradient struct {
	Units             GradientUnits
	Stops             []GradientStop
	GradientTransform Transform
	SpreadMethod      SpreadMethod
}

type GradientStop

type GradientStop struct {
	Offset  float64
	Color   RGB
	Opacity float64
}

type GradientUnits

type GradientUnits int

func (GradientUnits) String

func (gu GradientUnits) String() string

func (GradientUnits) Unmarshal

func (gu GradientUnits) Unmarshal(s string) error

type Group

type Group struct {
	Node
	Opacity   *float64
	Transform *Transform
}

func (*Group) ID

func (it *Group) ID() string

type Item

type Item interface {
	ID() string
	// contains filtered or unexported methods
}

type Length

type Length string

Length corresponds to SVG <length> data type, also can hold <percentage>, "auto", etc

func (Length) AsNumeric

func (l Length) AsNumeric() (v float64, u Units, err error)

type Line

type Line struct {
	Shape
	X1 Coordinate
	Y1 Coordinate
	X2 Coordinate
	Y2 Coordinate
}

func (*Line) ID

func (it *Line) ID() string

type LineCap

type LineCap int

func (LineCap) String

func (lc LineCap) String() string

func (LineCap) UnmarshalText

func (lc LineCap) UnmarshalText(text []byte) error

type LineJoin

type LineJoin int

func (LineJoin) UnmarshalText

func (lj LineJoin) UnmarshalText(text []byte) error

type LinearGradient

type LinearGradient struct {
	Gradient
	X1 Coordinate
	Y1 Coordinate
	X2 Coordinate
	Y2 Coordinate
}

type Node

type Node struct {
	Items []Item
	// contains filtered or unexported fields
}

func (*Node) ID

func (it *Node) ID() string

type Paint

type Paint struct {
	Kind     PaintKind
	Color    RGB
	Gradient *Gradient
}

func ParsePaint added in v0.0.4

func ParsePaint(s string) (*Paint, error)

type PaintKind

type PaintKind int

type Path

type Path struct {
	Shape
	D string
}

func (*Path) ID

func (it *Path) ID() string

type PathCommand

type PathCommand uint8

type PathData

type PathData struct {
	Commands []PathCommand
	Vertices []Vertex
}

PathData represents a command in svg.Path D (Data) attribute

func ParsePath

func ParsePath(s string) (*PathData, error)

func (*PathData) Arc

func (pd *PathData) Arc(lastX, lastY, rx, ry, axisRotation float64, largeArc, sweep bool, x, y float64)

func (*PathData) ArcSegment

func (pd *PathData) ArcSegment(xc, yc, th0, th1, rx, ry, axisRotation float64)

func (*PathData) Close

func (p *PathData) Close()

func (*PathData) CurveTo

func (p *PathData) CurveTo(c1, c2, v Vertex)

func (*PathData) LineTo

func (p *PathData) LineTo(v Vertex)

func (*PathData) MoveTo

func (p *PathData) MoveTo(v Vertex)

func (*PathData) String

func (pd *PathData) String() string

type Polygon added in v0.0.4

type Polygon struct {
	Shape
	Points string
}

func (*Polygon) ID added in v0.0.4

func (it *Polygon) ID() string

type Polyline added in v0.0.4

type Polyline struct {
	Shape
	Points string
}

func (*Polyline) ID added in v0.0.4

func (it *Polyline) ID() string

type RGB

type RGB struct {
	R uint8
	G uint8
	B uint8
}

type RadialGradient

type RadialGradient struct {
	Gradient
	Cx     Coordinate
	Cy     Coordinate
	Radius Length
	Fx     Coordinate
	Fy     Coordinate
}

type Rect

type Rect struct {
	Shape
	X      Coordinate
	Y      Coordinate
	Width  Length
	Height Length
	Rx     Length
	Ry     Length
}

func (*Rect) ID

func (it *Rect) ID() string

type Shape

type Shape struct {
	Fill           *Paint
	FillRule       *FillRule
	FillOpacity    *float64
	Stroke         *Paint
	StrokeWidth    Length
	StrokeOpacity  *float64
	StrokeLineCap  *LineCap
	StrokeLineJoin *LineJoin
	Opacity        *float64
	Transform      *Transform
	// contains filtered or unexported fields
}

func (*Shape) ID

func (it *Shape) ID() string

type SpreadMethod

type SpreadMethod int

func (SpreadMethod) String

func (sm SpreadMethod) String() string

func (SpreadMethod) Unmarshal

func (sm SpreadMethod) Unmarshal(s string) error

type Svg

type Svg struct {
	Group
	ViewBox ViewBox
	X       Coordinate
	Y       Coordinate
	Width   Length
	Height  Length
}

Svg implements SVG <svg> element

func Parse

func Parse(in string) (*Svg, error)

func (*Svg) ID

func (it *Svg) ID() string

type Transform

type Transform struct {
	A float64
	B float64
	C float64
	D float64
	E float64
	F float64
}

func Concatenate

func Concatenate(a, b *Transform) *Transform

func Rotation

func Rotation(a float64) *Transform

func Scaling

func Scaling(sx, sy float64) *Transform

func SkewX

func SkewX(a float64) *Transform

func SkewY

func SkewY(a float64) *Transform

func Translation

func Translation(tx, ty float64) *Transform

func UnitTransform

func UnitTransform() *Transform

func (*Transform) Calc

func (t *Transform) Calc(x, y float64, relative bool) (float64, float64)

func (*Transform) CalcAbs

func (t *Transform) CalcAbs(x, y float64) (float64, float64)

func (*Transform) CalcRel

func (t *Transform) CalcRel(x, y float64) (float64, float64)

func (*Transform) Unmarshal

func (t *Transform) Unmarshal(s string) (err error)

type Units

type Units int

Units defines length and coordinate units

func (Units) String

func (u Units) String() string

String implements unit stringer interface

type Vector

type Vector struct {
	X float64
	Y float64
}

func Add

func Add(vv ...Vector) Vector

func Div

func Div(a Vector, b float64) Vector

func Mul

func Mul(a Vector, b float64) Vector

func Sub

func Sub(a, b Vector) Vector

func (Vector) Length

func (v Vector) Length() float64

func (Vector) Norm

func (v Vector) Norm() float64

func (Vector) Normalized

func (v Vector) Normalized() Vector

type Vertex

type Vertex = Vector

func ParsePoints added in v0.0.4

func ParsePoints(s string) ([]Vertex, error)

type ViewBox

type ViewBox string

func (ViewBox) Parse

func (b ViewBox) Parse() (vb *ViewBoxValue, err error)

type ViewBoxValue

type ViewBoxValue struct {
	MinX   float64
	MinY   float64
	Width  float64
	Height float64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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