Documentation
¶
Index ¶
- func Any(x Element) any
- func Decode(r io.Reader) (image.Image, error)
- func DecodeConfig(r io.Reader) (image.Config, error)
- func NewContext(svg *SVG) *gg.Context
- func NewScaledContext(svg *SVG, scale float64) *gg.Context
- func Render(ctx *gg.Context, svg *SVG) error
- type BoxLengthPercentage
- type Circle
- type ClipPath
- type ClosePath
- type Color
- type CubicBezier
- type CubicBezierCoordinates
- type Cursor
- type DashArray
- type Defs
- type Element
- type ElementAttributes
- type Ellipse
- type EllipticalArc
- type EllipticalArcCoordinates
- type FilterList
- type FontFamily
- type ForeignObject
- type Gradient
- type GradientStop
- type Grouping
- type Ident
- type Image
- type Length
- type LengthIdent
- type LengthPercentage
- type LengthPercentageIdent
- type LengthPercentageNumber
- type LengthPercentageNumberIdent
- type LengthPercentageNumbers
- type Line
- type LineTo
- type LinearGradient
- type Marker
- type Mask
- type MoveTo
- type NumberIdent
- type NumberPercentage
- type Paint
- type PaintElement
- type Path
- type PathCommand
- type PathData
- type Pattern
- type Point
- type PolyPoints
- type Polygon
- type Polyline
- type QuadraticBezier
- type QuadraticBezierCoordinates
- type RadialGradient
- type Rect
- type SVG
- type SVGImage
- type SolidColor
- type Style
- type Switch
- type Symbol
- type TSpan
- type Text
- type TextPath
- type Transform
- type URLIdent
- type Units
- type Use
- type VectorEffect
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewContext ¶
NewContext creates a new render context for an SVG document.
func NewScaledContext ¶
NewScaledContext creates a new render context for an SVG document with the given scaling factor.
Types ¶
type BoxLengthPercentage ¶
type BoxLengthPercentage struct { LengthPercentage Value string }
func (*BoxLengthPercentage) UnmarshalText ¶
func (blp *BoxLengthPercentage) UnmarshalText(text []byte) error
type Circle ¶
type Circle struct { ElementAttributes XMLName xml.Name `xml:"circle"` PathLength float64 `xml:"pathLength,attr"` Cx LengthPercentage `xml:"cx,attr"` Cy LengthPercentage `xml:"cy,attr"` R LengthPercentage `xml:"r,attr"` Children []any `xml:",any"` }
Circle represents an SVG `circle` element.
type CubicBezier ¶
type CubicBezier struct { IsAbsolute bool IsSmooth bool Coordinates []CubicBezierCoordinates }
CubicBezier represents an SVG cubic Bezier curve command.
type CubicBezierCoordinates ¶
CubicBezierCoordinates represents a set of cubic Bezier curve coordinates.
type Defs ¶
type Defs struct { ElementAttributes XMLName xml.Name `xml:"defs"` Children []any `xml:",any"` }
Defs represents an SVG `defs` element.
type Element ¶
type Element interface {
// contains filtered or unexported methods
}
Element represents an SVG element.
type ElementAttributes ¶
type ElementAttributes struct { ID string `xml:"id,attr"` AlignmentBaseline Ident `xml:"alignment-baseline,attr"` BaselineShift *LengthPercentageIdent `xml:"baseline-shift,attr"` ClipPath *ClipPath `xml:"clip-path,attr"` ClipRule Ident `xml:"clip-rule,attr"` Color *Color `xml:"color,attr"` ColorInterpolation Ident `xml:"color-interpolation,attr"` ColorInterpolationFilters Ident `xml:"color-interpolation-filters,attr"` ColorRendering Ident `xml:"color-rendering,attr"` Cursor *Cursor `xml:"cursor,attr"` Direction Ident `xml:"direction,attr"` Display Ident `xml:"display,attr"` DominantBaseline Ident `xml:"dominant-baseline,attr"` Fill *Paint `xml:"fill,attr"` FillOpacity *NumberPercentage `xml:"fill-opacity,attr"` FillRule Ident `xml:"fill-rule,attr"` Filter *FilterList `xml:"filter,attr"` FloodColor *Color `xml:"flood-color,attr"` FloodOpacity *NumberPercentage `xml:"flood-opacity,attr"` FontFamily *FontFamily `xml:"font-family,attr"` FontSize *LengthPercentageNumberIdent `xml:"font-size,attr"` FontSizeAdjust *NumberIdent `xml:"font-size-adjust,attr"` FontStretch Ident `xml:"font-stretch,attr"` FontStyle Ident `xml:"font-style,attr"` FontVariant Ident `xml:"font-variant,attr"` FontWeight *NumberIdent `xml:"font-weight,attr"` ImageRendering Ident `xml:"image-rendering,attr"` LetterSpacing *LengthIdent `xml:"letter-spacing,attr"` LightingColor *Color `xml:"lighting-color,attr"` MarkerEnd *URLIdent `xml:"marker-end,attr"` MarkerMid *URLIdent `xml:"marker-mid,attr"` MarkerStart *URLIdent `xml:"marker-start,attr"` Mask *Mask `xml:"mask,attr"` Opacity *NumberIdent `xml:"opacity,attr"` Overflow Ident `xml:"overflow,attr"` PaintOrder Ident `xml:"paint-order,attr"` PointerEvents Ident `xml:"pointer-events,attr"` ShapeRendering Ident `xml:"shape-rendering,attr"` Stroke *Paint `xml:"stroke,attr"` StrokeDasharray *DashArray `xml:"stroke-dasharray,attr"` StrokeDashoffset *LengthPercentage `xml:"stroke-dashoffset,attr"` StrokeLinecap Ident `xml:"stroke-linecap,attr"` StrokeLinejoin Ident `xml:"stroke-linejoin,attr"` StrokeMiterlimit *float64 `xml:"stroke-miterlimit,attr"` StrokeOpacity *NumberPercentage `xml:"stroke-opacity,attr"` StrokeWidth *LengthPercentage `xml:"stroke-width,attr"` TextAnchor Ident `xml:"text-anchor,attr"` TextDecoration Ident `xml:"text-decoration,attr"` TextOverflow Ident `xml:"text-overflow,attr"` TextRendering Ident `xml:"text-rendering,attr"` Transform []Transform `xml:"transform,attr"` UnicodeBidi Ident `xml:"unicode-bidi,attr"` VectorEffect *VectorEffect `xml:"vector-effect,attr"` Visibility Ident `xml:"visibility,attr"` WhiteSpace Ident `xml:"white-space,attr"` WordSpacing *LengthIdent `xml:"word-spacing,attr"` WritingMode Ident `xml:"writing-mode,attr"` }
ElementAttributes contains standard SVG element attributes.
type Ellipse ¶
type Ellipse struct { ElementAttributes XMLName xml.Name `xml:"ellipse"` PathLength float64 `xml:"pathLength,attr"` Cx LengthPercentage `xml:"cx,attr"` Cy LengthPercentage `xml:"cy,attr"` Rx BoxLengthPercentage `xml:"rx,attr"` Ry BoxLengthPercentage `xml:"ry,attr"` Children []any `xml:",any"` }
Ellipse represents an SVG `ellipse` element.
type EllipticalArc ¶
type EllipticalArc struct { IsAbsolute bool Coordinates []EllipticalArcCoordinates }
EllipticalArc represents an SVG elliptical arc command.
type EllipticalArcCoordinates ¶
type EllipticalArcCoordinates struct { Point Rx float64 Ry float64 XAxisRotation float64 LargeArc bool Sweep bool }
EllipticalArcCoordinates represents a set of elliptical arc coordinates.
type FilterList ¶
type FilterList string
type FontFamily ¶
type FontFamily struct {
Values []string
}
func (*FontFamily) UnmarshalText ¶
func (ff *FontFamily) UnmarshalText(text []byte) error
type ForeignObject ¶
type ForeignObject struct { ElementAttributes XMLName xml.Name `xml:"foreignObject"` X LengthPercentage `xml:"x,attr"` Y LengthPercentage `xml:"y,attr"` Width BoxLengthPercentage `xml:"width,attr"` Height BoxLengthPercentage `xml:"height,attr"` InnerXML []byte `xml:",innerxml"` }
ForeignObject represents an SVG `foreignObject` element.
type Gradient ¶
type Gradient struct { ElementAttributes GradientUnits Units `xml:"gradientUnits,attr"` GradientTransform []Transform `xml:"gradientTransform,attr"` SpreadMethod string `xml:"spreadMethod,attr"` Href string `xml:"href,attr"` Stops []GradientStop `xml:"stop"` }
Gradient holds fields common to the `linearGradient` and `radialGradient` elements.
type GradientStop ¶
type GradientStop struct { ElementAttributes XMLName xml.Name `xml:"stop"` Offset NumberPercentage `xml:"offset,attr"` Color Color `xml:"stop-color,attr"` Opacity NumberPercentage `xml:"stop-opacity,attr"` }
GradientStop represents an SVG `stop` element.
type Grouping ¶
type Grouping struct { ElementAttributes XMLName xml.Name `xml:"g"` Children []any `xml:",any"` }
Grouping represents an SVG `g` element.
type Image ¶
type Image struct { ElementAttributes XMLName xml.Name `xml:"image"` PreserveAspectRatio string `xml:"preserveAspectRatio,attr"` Href string `xml:"href,attr"` CrossOrigin string `xml:"crossOrigin,attr"` X LengthPercentage `xml:"x,attr"` Y LengthPercentage `xml:"y,attr"` Width BoxLengthPercentage `xml:"width,attr"` Height BoxLengthPercentage `xml:"height,attr"` }
Image represents an SVG `image` element.
type LengthIdent ¶
func (*LengthIdent) UnmarshalText ¶
func (lp *LengthIdent) UnmarshalText(text []byte) error
type LengthPercentage ¶
func (*LengthPercentage) UnmarshalText ¶
func (lp *LengthPercentage) UnmarshalText(text []byte) error
type LengthPercentageIdent ¶
type LengthPercentageIdent struct { LengthPercentage Ident string }
func (*LengthPercentageIdent) UnmarshalText ¶
func (lpi *LengthPercentageIdent) UnmarshalText(text []byte) error
type LengthPercentageNumber ¶
type LengthPercentageNumber struct { LengthPercentage Number float64 }
func (*LengthPercentageNumber) UnmarshalText ¶
func (lpn *LengthPercentageNumber) UnmarshalText(text []byte) error
type LengthPercentageNumberIdent ¶
type LengthPercentageNumberIdent struct { LengthPercentageNumber Ident string }
func (*LengthPercentageNumberIdent) UnmarshalText ¶
func (lpni *LengthPercentageNumberIdent) UnmarshalText(text []byte) error
type LengthPercentageNumbers ¶
type LengthPercentageNumbers struct {
Values []LengthPercentageNumber
}
func (*LengthPercentageNumbers) UnmarshalText ¶
func (ns *LengthPercentageNumbers) UnmarshalText(text []byte) error
type Line ¶
type Line struct { ElementAttributes XMLName xml.Name `xml:"line"` PathLength float64 `xml:"pathLength,attr"` X1 LengthPercentageNumber `xml:"x1,attr"` Y1 LengthPercentageNumber `xml:"y1,attr"` X2 LengthPercentageNumber `xml:"x2,attr"` Y2 LengthPercentageNumber `xml:"y2,attr"` Children []any `xml:",any"` }
Line represents an SVG `line` element.
type LinearGradient ¶
type LinearGradient struct { Gradient XMLName xml.Name `xml:"linearGradient"` X1 LengthPercentage `xml:"x1,attr"` Y1 LengthPercentage `xml:"y1,attr"` X2 LengthPercentage `xml:"x2,attr"` Y2 LengthPercentage `xml:"y2,attr"` }
LinearGradient represents an SVG `linearGradient` element.
type Marker ¶
type Marker struct { ElementAttributes XMLName xml.Name `xml:"marker"` PreserveAspectRatio string `xml:"preserveAspectRatio,attr"` ViewBox string `xml:"viewBox,attr"` RefX Length `xml:"refX,attr"` RefY Length `xml:"refY,attr"` MarkerUnits string `xml:"markerUnits,attr"` MarkerWidth LengthPercentageNumber `xml:"markerWidth,attr"` MarkerHeight LengthPercentageNumber `xml:"markerHeight,attr"` Orient string `xml:"orient,attr"` Children []any `xml:",any"` }
Marker represents an SVG `marker` element.
type NumberIdent ¶
NumberIdent represents an XML number or identifier.
func (*NumberIdent) UnmarshalText ¶
func (ni *NumberIdent) UnmarshalText(text []byte) error
type NumberPercentage ¶
NumberPercentage represents an XML number or percentage.
func (*NumberPercentage) UnmarshalText ¶
func (np *NumberPercentage) UnmarshalText(text []byte) error
type PaintElement ¶
type PaintElement interface {
// contains filtered or unexported methods
}
type Path ¶
type Path struct { ElementAttributes XMLName xml.Name `xml:"path"` PathLength float64 `xml:"pathLength,attr"` D PathData `xml:"d,attr"` Children []any `xml:",any"` }
Path represents an SVG `path` element.
type PathCommand ¶
type PathCommand interface {
// contains filtered or unexported methods
}
PathCommand represents an SVG path command.
func ParsePathCommands ¶
func ParsePathCommands(commands string) ([]PathCommand, error)
ParsePathCommands parses a sequence of SVG path commands according to the SVG path grammar (reproduced below).
svg_path::= wsp* moveto? (moveto drawto_command*)?
drawto_command::=
moveto | closepath | lineto | horizontal_lineto | vertical_lineto | curveto | smooth_curveto | quadratic_bezier_curveto | smooth_quadratic_bezier_curveto | elliptical_arc
moveto::=
( "M" | "m" ) wsp* coordinate_pair_sequence
closepath::=
("Z" | "z")
lineto::=
("L"|"l") wsp* coordinate_pair_sequence
horizontal_lineto::=
("H"|"h") wsp* coordinate_sequence
vertical_lineto::=
("V"|"v") wsp* coordinate_sequence
curveto::=
("C"|"c") wsp* curveto_coordinate_sequence
curveto_coordinate_sequence::=
coordinate_pair_triplet | (coordinate_pair_triplet comma_wsp? curveto_coordinate_sequence)
smooth_curveto::=
("S"|"s") wsp* smooth_curveto_coordinate_sequence
smooth_curveto_coordinate_sequence::=
coordinate_pair_double | (coordinate_pair_double comma_wsp? smooth_curveto_coordinate_sequence)
quadratic_bezier_curveto::=
("Q"|"q") wsp* quadratic_bezier_curveto_coordinate_sequence
quadratic_bezier_curveto_coordinate_sequence::=
coordinate_pair_double | (coordinate_pair_double comma_wsp? quadratic_bezier_curveto_coordinate_sequence)
smooth_quadratic_bezier_curveto::=
("T"|"t") wsp* coordinate_pair_sequence
elliptical_arc::=
( "A" | "a" ) wsp* elliptical_arc_argument_sequence
elliptical_arc_argument_sequence::=
elliptical_arc_argument | (elliptical_arc_argument comma_wsp? elliptical_arc_argument_sequence)
elliptical_arc_argument::=
number comma_wsp? number comma_wsp? number comma_wsp flag comma_wsp? flag comma_wsp? coordinate_pair
coordinate_pair_double::=
coordinate_pair comma_wsp? coordinate_pair
coordinate_pair_triplet::=
coordinate_pair comma_wsp? coordinate_pair comma_wsp? coordinate_pair
coordinate_pair_sequence::=
coordinate_pair | (coordinate_pair comma_wsp? coordinate_pair_sequence)
coordinate_sequence::=
coordinate | (coordinate comma_wsp? coordinate_sequence)
coordinate_pair::= coordinate comma_wsp? coordinate
coordinate::= sign? number
sign::= "+"|"-" number ::= ([0-9])+ flag::=("0"|"1") comma_wsp::=(wsp+ ","? wsp*) | ("," wsp*) wsp ::= (#x9 | #x20 | #xA | #xC | #xD)
type PathData ¶
type PathData struct {
Commands []PathCommand
}
PathData represents SVG path data.
func (*PathData) UnmarshalText ¶
type Pattern ¶
type Pattern struct { ElementAttributes XMLName xml.Name `xml:"pattern"` ViewBox string `xml:"viewBox,attr"` PreserveAspectRatio string `xml:"preserveAspectRatio,attr"` X Length `xml:"x,attr"` Y Length `xml:"y,attr"` Width Length `xml:"width,attr"` Height Length `xml:"height,attr"` PatternUnits Units `xml:"patternUnits,attr"` PatternContentUnits Units `xml:"patternContentUnits,attr"` PatternTransform []Transform `xml:"patternTransform,attr"` Href string `xml:"href,attr"` Children []any `xml:",any"` }
Pattern represents an SVG `pattern` element.
type PolyPoints ¶
type PolyPoints []Point
func (*PolyPoints) UnmarshalText ¶
func (p *PolyPoints) UnmarshalText(text []byte) error
type Polygon ¶
type Polygon struct { ElementAttributes XMLName xml.Name `xml:"polygon"` Points PolyPoints `xml:"points,attr"` Children []any `xml:",any"` }
Polygon represents an SVG `polygon` element.
type Polyline ¶
type Polyline struct { ElementAttributes XMLName xml.Name `xml:"polyline"` Points PolyPoints `xml:"points,attr"` Children []any `xml:",any"` }
Polyline represents an SVG `polyline` element.
type QuadraticBezier ¶
type QuadraticBezier struct { IsAbsolute bool Coordinates []QuadraticBezierCoordinates }
QuadraticBezier represents an SVG cubic Bezier curve command.
type QuadraticBezierCoordinates ¶
QuadraticBezierCoordinates represents a set of cubic Bezier curve coordinates.
type RadialGradient ¶
type RadialGradient struct { Gradient XMLName xml.Name `xml:"radialGradient"` Cx LengthPercentage `xml:"cx,attr"` Cy LengthPercentage `xml:"cy,attr"` R LengthPercentage `xml:"r,attr"` Fx LengthPercentage `xml:"fx,attr"` Fy LengthPercentage `xml:"fy,attr"` Fr LengthPercentage `xml:"fr,attr"` }
RadialGradient represents an SVG `radialGradient` element.
type Rect ¶
type Rect struct { ElementAttributes XMLName xml.Name `xml:"rect"` PathLength float64 `xml:"pathLength,attr"` X LengthPercentage `xml:"x,attr"` Y LengthPercentage `xml:"y,attr"` Width BoxLengthPercentage `xml:"width,attr"` Height BoxLengthPercentage `xml:"height,attr"` Rx *BoxLengthPercentage `xml:"rx,attr"` Ry *BoxLengthPercentage `xml:"ry,attr"` Children []any `xml:",any"` }
Rect represents an SVG `rect` element.
type SVG ¶
type SVG struct { XMLName xml.Name `xml:"svg"` Style *Style `xml:"style"` X LengthPercentage `xml:"x,attr"` Y LengthPercentage `xml:"y,attr"` Width BoxLengthPercentage `xml:"width,attr"` Height BoxLengthPercentage `xml:"height,attr"` Children []any `xml:",any"` }
SVG represents an SVG document.
type SVGImage ¶
type SVGImage struct {
// contains filtered or unexported fields
}
func (*SVGImage) ColorModel ¶
type Style ¶
type Style struct { XMLName xml.Name `xml:"style"` Type string `xml:"type,attr"` Media string `xml:"media,attr"` Title string `xml:"title,attr` Style string `xml:",chardata"` }
Style represents an SVG `style` element.
type Switch ¶
type Switch struct { ElementAttributes XMLName xml.Name `xml:"switch"` Children []any `xml:",any"` }
Switch represents an SVG `switch` element.
type Symbol ¶
type Symbol struct { ElementAttributes XMLName xml.Name `xml:"symbol"` PreserveAspectRatio string `xml:"preserveAspectRatio,attr"` ViewBox string `xml:"viewBox,attr"` RefX Length `xml:"refX,attr"` RefY Length `xml:"refY,attr"` X LengthPercentage `xml:"x,attr"` Y LengthPercentage `xml:"y,attr"` Width BoxLengthPercentage `xml:"width,attr"` Height BoxLengthPercentage `xml:"height,attr"` Children []any `xml:",any"` }
Symbol represents an SVG `symbol` element.
type TSpan ¶
type TSpan struct { ElementAttributes XMLName xml.Name `xml:"tspan"` X LengthPercentageNumbers `xml:"x,attr"` Y LengthPercentageNumbers `xml:"y,attr"` Dx LengthPercentageNumbers `xml:"dx,attr"` Dy LengthPercentageNumbers `xml:"dy,attr"` Rotate LengthPercentageNumbers `xml:"rotate,attr"` TextLength LengthPercentageNumber `xml:"textLength,attr"` LengthAdjust string `xml:"lengthAdjust,attr"` Value string `xml:",chardata"` }
TSpan represents an SVG `tspan` element.
type Text ¶
type Text struct { ElementAttributes XMLName xml.Name `xml:"text"` X LengthPercentageNumbers `xml:"x,attr"` Y LengthPercentageNumbers `xml:"y,attr"` Dx LengthPercentageNumbers `xml:"dx,attr"` Dy LengthPercentageNumbers `xml:"dy,attr"` Rotate LengthPercentageNumbers `xml:"rotate,attr"` TextLength LengthPercentageNumber `xml:"textLength,attr"` Value string `xml:",chardata"` }
Text represents an SVG `text` element.
type TextPath ¶
type TextPath struct { ElementAttributes XMLName xml.Name `xml:"textPath"` Path PathData `xml:"path,attr"` Href string `xml:"href,attr"` StartOffset LengthPercentage `xml:"startOffset,attr"` Method string `xml:"method,attr"` Spacing string `xml:"spacing,attr"` Side string `xml:"side,attr"` TextLength LengthPercentageNumber `xml:"textLength,attr"` LengthAdjust string `xml:"lengthAdjust,attr"` Value string `xml:",chardata"` }
TextPath represents an SVG `textPath` element.
type URLIdent ¶
func (*URLIdent) UnmarshalText ¶
type Use ¶
type Use struct { ElementAttributes XMLName xml.Name `xml:"use"` Href string `xml:"href,attr"` X LengthPercentage `xml:"x,attr"` Y LengthPercentage `xml:"y,attr"` Width BoxLengthPercentage `xml:"width,attr"` Height BoxLengthPercentage `xml:"height,attr"` }
Use represents an SVG `use` element.
type VectorEffect ¶
type VectorEffect string