path_svg.go
Functions
func ParseSVGPath
func ParseSVGPath(d string) (*Path, error) {
p := &svgParser{
input: d,
path: NewPath(),
}
if err := p.parse(); err != nil {
return nil, err
}
return p.path, nil
}
func ParseSVGPath(d string) (*Path, error) {
p := &svgParser{
input: d,
path: NewPath(),
}
if err := p.parse(); err != nil {
return nil, err
}
return p.path, nil
}
ParseSVGPath parses an SVG path data string (d attribute) into a Path.
It supports all SVG path commands: M/m, L/l, H/h, V/v, C/c, S/s, Q/q, T/t, A/a, Z/z.
Uppercase commands use absolute coordinates; lowercase use relative coordinates
(offsets from the current point).
The parser follows the SVG 1.1 specification for path data grammar, including:
- Comma and whitespace separation between numbers
- Implicit repeat of commands when extra coordinate pairs are provided
- Implicit LineTo after MoveTo with extra coordinate pairs
- Negative sign as number separator (e.g., "10-20" means "10, -20")
- Scientific notation in numbers (e.g., "1e-5")
- Flag values (0 or 1) in arc commands without separators
Reference: https://www.w3.org/TR/SVG11/paths.html#PathData