svg_path_editor.path_parser#
Classes#
Low-level SVG path string parser. |
Module Contents#
- class svg_path_editor.path_parser.PathParser[source]#
Low-level SVG path string parser.
This class understands the SVG path mini-language (M/L/H/V/Z/C/S/Q/T/A) and converts a path string into a list of token lists
[command, arg1, arg2, ...]without interpreting coordinates.- static components(cmd_type, path, cursor)[source]#
Parse a run of components for a single command type.
Starting at
cursor, this consumes as many valid components ofcmd_typeas possible (including implicit repeats of the command) and returns the new cursor position together with the parsed components.- Parameters:
cmd_type (str) – Single-letter SVG path command (e.g.
"M","l").path (str) – Full SVG path string being parsed.
cursor (int) – Current index in
pathto start parsing from.
- Returns:
A tuple
(new_cursor, components)wherecomponentsis a list of[command, arg1, arg2, ...]token lists.- Raises:
ValueError – If the path is malformed at or after
cursor.- Return type:
tuple[int, list[list[str]]]
- static parse(path)[source]#
Parse an SVG path data string into a list of token lists.
Each element in the returned list is of the form
[command, arg1, arg2, ...], where all items are strings and no semantic interpretation (e.g. absolute vs. relative coordinates) is performed here.- Parameters:
path (str) – Raw SVG path data string (the value of a
dattribute).- Returns:
A list of command components as token lists.
- Raises:
ValueError – If the path is syntactically malformed.
- Return type:
list[list[str]]