Deferred SVG artwork as planar CAD regions, with fills, strokes and holes.
load/1 snapshots a local file; new/2 records a recipe. layout/1 evaluates
actual geometry and returns a result and revision-linked measurements.
Extrude the recipe with Smith.extrude/2, then fuse raised artwork or cut
an engraving. SVG's downward Y axis is converted to upward CAD Y.
Supported: paths (all commands), basic shapes, groups, local use references, affine transforms, viewBox, physical units, inherited presentation attributes and inline styles. Fill curves remain native curves; stroke centerlines are sampled with an explicit final-mm tolerance. Fill rules retain holes, self-intersections and disconnected islands.
Painted mode unions selected fill and stroke regions. Paint colors are
metadata, not Boolean operations or material assignments. No scripts, DTDs,
external resources, stylesheets, raster tracing, masks, filters, gradients,
dashes or partial opacity are rendered. Unsupported visible content returns
an element-specific error. Convert embedded text to paths or use Smith.Text.
Summary
Functions
Lists visible elements with stable indices, IDs, groups, and paint metadata for selection.
Uniformly fits artwork within {width,height} mm, with optional margin: 0. Preserves placement and selection.
Parses SVG bytes without native geometry or external resource access. Errors identify unsupported elements.
Evaluates positioned planar faces and returns their actual bounds, area, region count, source hash and geometry revision.
Reads and snapshots a local SVG (up to 4 MiB). Subsequent file edits do not change the asset.
Records an SVG recipe. Options
Serializes an evaluated layout as filled, even-odd SVG outlines in its local
plane. Wires are sampled with tolerance: 0.005 mm; the output records the
source geometry revision and is independent of fonts and external resources.
This is a geometry export, not a round trip of source styles or groups.
Returns positioned native wire recipes for centerline sweeps or projection, retaining open/closed subpaths and element metadata.
Writes JSON measurements and PNG/SVG previews of the converted CAD geometry. Accepts a recipe or its evaluated layout.
Types
@type layout() :: %{result: Smith.Result.t(), report: map()}
@type t() :: %Smith.SVG{asset: Smith.SVG.Asset.t(), options: keyword()}
Functions
@spec elements(Smith.SVG.Asset.t()) :: [map()]
Lists visible elements with stable indices, IDs, groups, and paint metadata for selection.
Uniformly fits artwork within {width,height} mm, with optional margin: 0. Preserves placement and selection.
@spec from_binary(binary()) :: {:ok, Smith.SVG.Asset.t()} | {:error, term()}
Parses SVG bytes without native geometry or external resource access. Errors identify unsupported elements.
Evaluates positioned planar faces and returns their actual bounds, area, region count, source hash and geometry revision.
@spec load(String.t()) :: {:ok, Smith.SVG.Asset.t()} | {:error, term()}
Reads and snapshots a local SVG (up to 4 MiB). Subsequent file edits do not change the asset.
@spec new(Smith.SVG.Asset.t(), keyword()) :: t()
Records an SVG recipe. Options:
mode: :painted(union of fills and strokes),:fill, or:strokes.width:orheight:in mm; both form a contain-fit box, never stretching.bounds: :artwork(default) or:viewportdetermines sizing/alignment.align: {:origin, :origin}preserves the source origin. Each axis also accepts:min,:center,:max.at: {0,0},on: Plane.xy()place it.select: :all, an ID/group-label string, a list of strings, an element index, or{:fill, color}/{:stroke, color}selects artwork.reference: :documentretains shared size/alignment across selections; use:selectionto fit and center only the chosen elements.stroke_width:overrides stroke width in final mm. Otherwise original stroke widths follow SVG transforms and artwork scaling.tolerance: 0.01controls stroke sampling in final mm (must exceed 1e-6).
Construction makes no native calls. Validation occurs during evaluation.
Serializes an evaluated layout as filled, even-odd SVG outlines in its local
plane. Wires are sampled with tolerance: 0.005 mm; the output records the
source geometry revision and is independent of fonts and external resources.
This is a geometry export, not a round trip of source styles or groups.
Returns positioned native wire recipes for centerline sweeps or projection, retaining open/closed subpaths and element metadata.
Writes JSON measurements and PNG/SVG previews of the converted CAD geometry. Accepts a recipe or its evaluated layout.