svg_path/stroke

Stroke outline construction.

Stroke _with operations accept shared offset.Options construction settings, obtained from offset.default_options(). Stroke trimming remains fixed: both side-local cusp passes are disabled and final band trimming is enabled. Width, joins, and caps are explicit operation arguments.

This module turns path geometry into filled outline paths by delegating nonzero strokes to symmetric bands in svg_path/offset. That module owns the side construction, caps, and trimming. This module also exposes SVG-style dash extraction: turning a continuous path into the open subpaths that would be stroked as visible dashes.

Outline operations take explicit join and cap arguments, including the forms that use default options. Pure dash extraction takes neither.

Types

Options for SVG-style dash extraction.

Dash lengths are already-resolved user-coordinate lengths. CSS parsing, percentages, and pathLength scaling are intentionally outside this type. Empty patterns and all-zero patterns behave like stroke-dasharray: none.

pub type DashOptions {
  DashOptions(
    pattern: List(Float),
    offset: Float,
    length_options: svg_path.LengthOptions,
  )
}

Constructors

  • DashOptions(
      pattern: List(Float),
      offset: Float,
      length_options: svg_path.LengthOptions,
    )

    Arguments

    pattern

    Alternating visible and hidden lengths in path-coordinate units.

    offset

    Signed path-coordinate offset into the repeated dash pattern.

    length_options

    Options used for arc-length measurement and splitting.

Errors returned by stroke helpers.

pub type Error {
  PathError(error: svg_path.Error)
  OffsetError(error: offset.Error)
  InvalidWidth(width: Float)
  InvalidDashLength(length: Float)
  InvalidDashOffset(offset: Float)
  InvalidDashPatternLength
}

Constructors

  • PathError(error: svg_path.Error)

    An underlying path operation failed.

  • OffsetError(error: offset.Error)

    An underlying offset operation failed.

  • InvalidWidth(width: Float)

    Stroke width must be finite and greater than zero.

  • InvalidDashLength(length: Float)

    Dash lengths must be finite and non-negative.

  • InvalidDashOffset(offset: Float)

    Dash offset must be finite.

  • InvalidDashPatternLength

    The normalized dash pattern’s total length must be finite.

Values

pub fn default_dash_options(
  pattern pattern: List(Float),
  offset offset: Float,
) -> DashOptions

Return default dash extraction options for a pattern and dash offset.

pattern and offset are interpreted as resolved user-coordinate lengths.

pub fn path(
  path: svg_path.Path,
  width width: Float,
  join join: offset.Join,
  cap cap: offset.Cap,
) -> Result(svg_path.Path, Error)

Stroke every subpath in a path using default options with the given width.

pub fn path_dashed(
  path: svg_path.Path,
  width width: Float,
  pattern pattern: List(Float),
  offset offset: Float,
  join join: offset.Join,
  cap cap: offset.Cap,
) -> Result(svg_path.Path, Error)

Stroke a path after applying SVG dasharray semantics to each subpath.

The dash pattern resets at the start of each subpath.

pub fn path_dashed_with(
  path path: svg_path.Path,
  width width: Float,
  join join: offset.Join,
  cap cap: offset.Cap,
  options options: offset.Options,
  dash_options dash_options: DashOptions,
) -> Result(svg_path.Path, Error)

Stroke a path after applying SVG dasharray semantics using explicit stroke and dash options.

The dash pattern resets at the start of each subpath.

pub fn path_dashes(
  path: svg_path.Path,
  pattern pattern: List(Float),
  offset offset: Float,
) -> Result(svg_path.Path, Error)

Return the visible dash pieces of every subpath in a path.

The dash pattern resets at the start of each subpath.

pub fn path_dashes_with(
  path path: svg_path.Path,
  dash_options dash_options: DashOptions,
) -> Result(svg_path.Path, Error)

Return the visible dash pieces of every subpath in a path using explicit dash options.

The dash pattern resets at the start of each subpath.

pub fn path_with(
  path path: svg_path.Path,
  width width: Float,
  join join: offset.Join,
  cap cap: offset.Cap,
  options options: offset.Options,
) -> Result(svg_path.Path, Error)

Stroke every subpath in a path using explicit options.

pub fn segment(
  segment: svg_path.Segment,
  width width: Float,
  join join: offset.Join,
  cap cap: offset.Cap,
) -> Result(svg_path.Path, Error)

Stroke a segment using default options with the given width.

pub fn segment_with(
  segment segment: svg_path.Segment,
  width width: Float,
  join join: offset.Join,
  cap cap: offset.Cap,
  options options: offset.Options,
) -> Result(svg_path.Path, Error)

Stroke a segment using explicit options.

pub fn subpath(
  subpath: svg_path.Subpath,
  width width: Float,
  join join: offset.Join,
  cap cap: offset.Cap,
) -> Result(svg_path.Path, Error)

Stroke a subpath using default options with the given width.

pub fn subpath_dashed(
  subpath: svg_path.Subpath,
  width width: Float,
  pattern pattern: List(Float),
  offset offset: Float,
  join join: offset.Join,
  cap cap: offset.Cap,
) -> Result(svg_path.Path, Error)

Stroke a subpath after applying SVG dasharray semantics.

This first extracts open dash subpaths, then strokes each dash independently.

pub fn subpath_dashed_with(
  subpath subpath: svg_path.Subpath,
  width width: Float,
  join join: offset.Join,
  cap cap: offset.Cap,
  options options: offset.Options,
  dash_options dash_options: DashOptions,
) -> Result(svg_path.Path, Error)

Stroke a subpath after applying SVG dasharray semantics using explicit stroke and dash options.

This first extracts open dash subpaths, then strokes each dash independently. Zero-length visible dashes produce Round or Square caps (nothing for Butt). Square caps use the source direction at the dash address.

pub fn subpath_dashes(
  subpath: svg_path.Subpath,
  pattern pattern: List(Float),
  offset offset: Float,
) -> Result(List(svg_path.Subpath), Error)

Return the visible dash pieces of a subpath using SVG dasharray semantics.

Each returned dash is an open subpath preserving the original segment types where possible. Empty and all-zero patterns return the original continuous subpath as a singleton when the subpath has positive length. An active dash pattern on a closed subpath has a visible seam: a dash covering the whole closed subpath is opened at the subpath start so cap styles can apply there. Zero-length visible entries are retained as coincident-endpoint Lines.

pub fn subpath_dashes_with(
  subpath subpath: svg_path.Subpath,
  dash_options dash_options: DashOptions,
) -> Result(List(svg_path.Subpath), Error)

Return the visible dash pieces of a subpath using explicit dash options.

pub fn subpath_with(
  subpath subpath: svg_path.Subpath,
  width width: Float,
  join join: offset.Join,
  cap cap: offset.Cap,
  options options: offset.Options,
) -> Result(svg_path.Path, Error)

Stroke a subpath as a symmetric band with offsets -width/2 and +width/2. Band construction owns normalization, side construction, caps, and trimming. Strokes disable per-side cusp trimming and always enable final in-band trimming.

✨ Search Document