svg_path/parse
SVG path data parser.
This module parses the d attribute syntax used by SVG paths. It supports
comma and whitespace separators, compact signed numbers, relative commands,
implicit repeated commands, smooth curves, and arcs.
Types
Errors returned while parsing SVG path data.
pub type Error {
ParseError(reason: ErrorReason, remaining: String)
}
Constructors
-
ParseError(reason: ErrorReason, remaining: String)Parsing failed for
reasonat the start ofremaining.remainingis the exact suffix of the original input beginning at the failure location. It is empty when the failure is at end of input. A UTF-8 byte offset can be recovered by subtracting the byte size ofremainingfrom the byte size of the original input.
The reason SVG path-data parsing failed.
pub type ErrorReason {
PathError(svg_path.Error)
ExpectedArcFlag
ExpectedCommand
ExpectedMove
ExpectedNumber
InvalidNumber(String)
InvalidSeparator
UnsupportedCommand(String)
}
Constructors
-
PathError(svg_path.Error)A parsed path was internally invalid according to the core path model.
-
ExpectedArcFlagAn arc flag was not
0or1. -
ExpectedCommandA command letter was expected.
-
ExpectedMovePath data must begin with a move command.
-
ExpectedNumberA numeric argument was expected.
-
InvalidNumber(String)A numeric token could not be parsed as a float.
-
InvalidSeparatorA comma appeared somewhere SVG path grammar does not permit one.
-
UnsupportedCommand(String)The command letter is not supported by this library.
Values
pub fn path(input: String) -> Result(svg_path.Path, Error)
Parse an SVG path data string into a Path.
Empty strings parse as an empty path. Move-only subpaths are preserved as empty subpaths with start points. Closepath commands mark subpaths as closed, inserting a straight line back to the subpath start when needed.