svg_path/serialize

SVG path data serializer.

This module turns paths, subpaths, and segments into SVG d attribute strings. The default output favors readable canonical forms; options can be used for relative commands, smaller whitespace, and omitted repeated command letters.

Types

Options for SVG path data serialization.

pub type Options {
  Options(
    decimal_places: option.Option(Int),
    fixed_decimals: Bool,
    relative: Bool,
    minimize_whitespace: Bool,
    repeat_commands: Bool,
  )
}

Constructors

  • Options(
      decimal_places: option.Option(Int),
      fixed_decimals: Bool,
      relative: Bool,
      minimize_whitespace: Bool,
      repeat_commands: Bool,
    )

    Arguments

    decimal_places

    Decimal places used when formatting numbers.

    fixed_decimals

    Whether formatted numbers should keep trailing zeroes.

    relative

    Whether to emit relative commands instead of absolute commands.

    minimize_whitespace

    Whether to remove optional spaces between command letters and arguments.

    repeat_commands

    Whether to repeat command letters when SVG syntax allows them to be omitted.

Values

pub fn decimal_options(decimal_places: Int) -> Options

Create options that round numbers to the given number of decimal places.

Trailing zeroes are stripped. Negative decimal places are clamped to zero.

pub fn default_options() -> Options

Default serialization options.

Defaults to readable absolute commands, up to 5 decimal places, repeated command letters, and normal whitespace.

pub fn fixed_decimal_options(decimal_places: Int) -> Options

Create options that round numbers and keep exactly the given number of decimal places.

Negative decimal places are clamped to zero.

pub fn minimize_whitespace(options: Options) -> Options

Remove optional spaces between command letters and their arguments.

pub fn path(path: svg_path.Path) -> String

Serialize a path with default options.

pub fn path_with_options(
  path path: svg_path.Path,
  options options: Options,
) -> String

Serialize a path with custom options.

pub fn relative_decimal_options(decimal_places: Int) -> Options

Create relative serialization options with decimal rounding.

pub fn relative_fixed_decimal_options(
  decimal_places: Int,
) -> Options

Create relative serialization options with fixed decimal formatting.

pub fn relative_options() -> Options

Create options that serialize with relative commands.

pub fn repeat_commands(
  options: Options,
  repeat_commands: Bool,
) -> Options

Configure whether repeated command letters should be emitted.

SVG allows some commands to omit the command letter when the same command repeats. Pass False for smaller, less verbose output.

pub fn segment(segment: svg_path.Segment) -> String

Serialize a segment with default options.

pub fn segment_with_options(
  segment segment: svg_path.Segment,
  options options: Options,
) -> String

Serialize a segment with custom options.

pub fn subpath(subpath: svg_path.Subpath) -> String

Serialize a subpath with default options.

pub fn subpath_with_options(
  subpath subpath: svg_path.Subpath,
  options options: Options,
) -> String

Serialize a subpath with custom options.

Search Document