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 reason at the start of remaining.

    remaining is 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 of remaining from 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.

  • ExpectedArcFlag

    An arc flag was not 0 or 1.

  • ExpectedCommand

    A command letter was expected.

  • ExpectedMove

    Path data must begin with a move command.

  • ExpectedNumber

    A numeric argument was expected.

  • InvalidNumber(String)

    A numeric token could not be parsed as a float.

  • InvalidSeparator

    A 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.

Search Document