This library can turn SVG path data to tagged sexp format (compatible with SXML). You can switch between absolute and relative coordinates, and turn it into a minified string.
The procedures work on both this library’s own tagged format and on path data strings.
The data format uses single-letter symbols for the commands and exacts for the numbers. Every node is always a separate list, even when there’s multiple subsequent nodes of the same command.
Every node can have attributes with an @
attribute marker, just like
in SXML.
You can put in any attributes you want so you can keep track of node-local data. They’re stripped out when you export the path back to string.
Here’s an example of an H
command with one argument, which happens
to be 105
, and with absolute coords added as an attribute:
(H (@ (coords (x 105) (y 200))) 105)
(path->string "M100 100 L101,101 90 102")
⇒ "M100 100l1 1-11 1"
Reads a path (in sexp or string format) and returns a minified string.
(->apath "M100 200L200 100-100-200")
⇒ ((M 100 200) (L 200 100) (L -100 -200))
Reads a path (in sexp or string format) and returns sexp format with absolute coordinates.
(->rpath "M100 200L200 100-100-200")
⇒ ((m 100 200) (l 100 -100) (l -300 -300))
Reads a path (in sexp or string format) and returns sexp format with relative coordinates.
(->mpath "M100 200L200 100-100-200")
⇒ ((M 100 200) (L 200 100) (L -100 -200))
Reads a path (in sexp or string format) and returns sexp format with
whatever coordinate format will print the shortest. This is almost
never that useful when doing path programming, but path->string
uses
it internally.
Change a path (in sexp or string format) into sexp format with a
coords
attribute added that stores the absolute coordinates of the
node. If the path already had coords, only the newly computated coords
will be returned.
Change a path (in sexp or string format) into sexp format with a
distance
attribute added that stores the pythagorean diagonal
distance from the previous node. If the path has a coords
attribute
on all of its nodes, they will be trusted, otherwise new ones will be
calculated and added for all nodes.
Convenience function returning a sub of the distances in a path.
Reads a path in any format and returns it in sexp format reversed. Any attributes in the input path are stripped.
For a repo,
git clone https://idiomdrottning.org/svgpath