svgpath

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package svgpath parses and validates SVG path `d` attribute data — the grammar shared by <path>, <clipPath>, and CSS clip-path: path(). It has no knowledge of PSRT; callers compose it with their own policies (e.g. PSRT's ~~ block requiring a single shape — see psrt.flushPathMaskBlock).

This is a purpose-built parser rather than a third-party SVG library: available Go libraries either bundle unrelated rasterization machinery (oksvg embeds rasterx, which pulls in fill/stroke/scan code no caller here needs) or have unproven handling of the compact elliptical-arc flag notation (e.g. "A5,5,45,0030,30", where the flags are single digits glued to the following number) — handled explicitly here via readFlag.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitCommands

func SplitCommands(d string) []string

SplitCommands breaks SVG path `d` data into one string per command — useful for writers that want one command per line for readable diffs (e.g. PSRT's ~~ block serializer). It does not validate d; callers that need validity should call Parse/Validate first.

func Validate

func Validate(d string) error

Validate checks that d is syntactically valid SVG path data.

Types

type Info

type Info struct {
	// Subpaths is the number of moveto (M/m) commands in the path. More than
	// one means the path describes multiple disconnected shapes.
	Subpaths int
}

Info describes basic structural facts about a parsed path.

func Parse

func Parse(d string) (Info, error)

Parse validates d against the SVG path data grammar (https://www.w3.org/TR/SVG11/paths.html#PathData) and returns basic structural info about it.

Jump to

Keyboard shortcuts

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