svg

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BezierCurveSegment

func BezierCurveSegment(p1, p2, p3, p4 *geo.Point, t0, t1 float64) (geo.Point, geo.Point, geo.Point, geo.Point)

Given control points p1, p2, p3, p4, calculate the segment of this bezier curve from t0 -> t1 where {0 <= t0 < t1 <= 1}. Uses De Casteljau's algorithm, referenced: https://stackoverflow.com/questions/11703283/cubic-bezier-curve-segment/11704152#11704152

func EscapeText

func EscapeText(text string) string

func FormatFloat added in v0.9.0

func FormatFloat(value float64) string

FormatFloat serializes an SVG coordinate with the same six decimal places as %f, but omits redundant trailing zeros. Keeping the original rounding is important: formatting the full float or reducing precision changes geometry.

func GetStrokeDashAttributes

func GetStrokeDashAttributes(strokeWidth, dashGapSize float64) (float64, float64)

func IsSupportedExternalDoctype added in v0.9.0

func IsSupportedExternalDoctype(document, directive []byte) bool

IsSupportedExternalDoctype reports whether directive is the encoding/xml token for one canonical W3C SVG 1.0 or SVG 1.1 external DOCTYPE declaration in document's raw prolog. Requiring both inputs prevents encoding/xml's directive normalization from widening the accepted raw syntax. It accepts no internal subset and performs no DTD resolution. Callers remain responsible for enforcing that the declaration occurs at most once and before the root.

func SVGID

func SVGID(text string) string

func SplitPath

func SplitPath(path string, percentage float64) (string, string, error)

Splits an SVG path into two SVG paths, with the first path being ~{percentage}% of the path

Types

type PathCommand added in v0.9.0

type PathCommand struct {
	Kind     PathCommandKind
	Control1 geo.Point
	Control2 geo.Point
	End      geo.Point
}

PathCommand contains absolute path geometry. End is used by move, line, and cubic commands. Control1 and Control2 are additionally used by cubic commands.

type PathCommandKind added in v0.9.0

type PathCommandKind uint8

PathCommandKind identifies one of the renderer-neutral path operations produced by SvgPathContext. SvgPathContext normalizes horizontal and vertical SVG commands to PathCommandLine so consumers only need to handle absolute move, line, cubic, and close operations.

const (
	PathCommandMove PathCommandKind = iota
	PathCommandLine
	PathCommandCubic
	PathCommandClose
)

type SvgPathContext

type SvgPathContext struct {
	Path     []geo.Intersectable
	Commands []string

	Start   *geo.Point
	Current *geo.Point
	TopLeft *geo.Point
	ScaleX  float64
	ScaleY  float64
	// contains filtered or unexported fields
}

func NewSVGPathContext

func NewSVGPathContext(tl *geo.Point, sx, sy float64) *SvgPathContext

func (*SvgPathContext) Absolute

func (c *SvgPathContext) Absolute(x, y float64) *geo.Point

func (*SvgPathContext) C

func (c *SvgPathContext) C(isLowerCase bool, x1, y1, x2, y2, x3, y3 float64)

func (*SvgPathContext) H

func (c *SvgPathContext) H(isLowerCase bool, x float64)

func (*SvgPathContext) L

func (c *SvgPathContext) L(isLowerCase bool, x, y float64)

func (*SvgPathContext) PathCommands added in v0.9.0

func (c *SvgPathContext) PathCommands() []PathCommand

PathCommands returns a defensive copy of the absolute typed path commands.

func (*SvgPathContext) PathData

func (c *SvgPathContext) PathData() string

func (*SvgPathContext) Relative

func (c *SvgPathContext) Relative(base *geo.Point, dx, dy float64) *geo.Point

func (*SvgPathContext) StartAt

func (c *SvgPathContext) StartAt(p *geo.Point)

func (*SvgPathContext) V

func (c *SvgPathContext) V(isLowerCase bool, y float64)

func (*SvgPathContext) Z

func (c *SvgPathContext) Z()

Jump to

Keyboard shortcuts

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