Skip to main content

Crate day_vector

Crate day_vector 

Source
Expand description

day-vector — Day’s vector-graphics engine (docs/vectors.md, docs/icons.md).

One crate, two consumers:

  • Build time (day-cli): day icon renders app-icon masters into every platform’s icon formats, and resource staging (§18.3) converts resource/vectors/ sources into the form each toolkit loads natively — a VectorDrawable on Android, a rasterized PNG ladder where the toolkit has no vector path.
  • Runtime (future, opt-in): the same pure byte-in/byte-out functions can rasterize a downloaded SVG inside an app. Nothing here touches day-cli types, the filesystem, or a toolkit, so the crate compiles anywhere (wasm included).

The engine is resvg/usvg with the text feature OFF — masters and vector assets must carry outlined text; a <text> element is reported as an error by the callers rather than rendered wrong. Everything else is hand-rolled here precisely because the formats are small: ICO and ICNS are trivial PNG containers, a VectorDrawable is a constrained XML serialization of the usvg tree, and an SF Symbol template is sliced/assembled textually.

Sources understood by classify:

  • plain SVG — any static SVG 1.1 art;
  • an SF Symbol template SVG (the SF Symbols app’s export, and third-party generators of the same shape): #Symbols holding Weight-Scale variant groups, #Guides with caplines/baselines — extract_variant cuts one variant out as a standalone glyph;
  • a .symbolset bundle (handled by the caller: its inner template SVG routes through here).

Re-exports§

pub use resvg;
pub use resvg::tiny_skia;
pub use resvg::usvg;
pub use roxmltree;

Modules§

icongen
Seeded app-icon generator (docs/icons.md): one u64 seed → a deterministic layered SVG master (day:background / day:foreground / day:monochrome, the contract day icon consumes), designed to read well through every downstream form — iOS squircle, Android adaptive + themed monochrome, plain PNG.

Structs§

Unsupported
Why an SVG cannot become a VectorDrawable (the caller’s fallback reason, shown in day build’s status line).
XamlGeometry
A glyph as XAML geometry: the shapes plus the viewport they are drawn in, which the backend needs to scale them into whatever box the layout gives (a Viewbox, or a scale transform on the geometry for the fixed icon slots).
XamlShape
One flat shape: geometry plus the paints it was authored with. fill/stroke are #AARRGGBB; a backend asked for a tint substitutes its own brush and ignores both.

Enums§

SourceKind
What a resource/vectors/ SVG file is. (.symbolset bundles are a directory form the caller unpacks — their inner template SVG classifies here as SourceKind::SfTemplate.)

Constants§

ENGINE
The render-engine identity stamped into icons.lock.json — byte-stable renders hold only within one engine version, so day icon --check compares generators before bytes.

Functions§

classify
Classify SVG text: an SF Symbol template, or plain art.
content_bbox
The tree content’s absolute bounding box (strokes included), or None for empty art — the input for safe-zone validation (an Android adaptive foreground overflowing the 66/108 zone).
extract_variant
Cut one Weight-Scale variant out of an SF Symbol template as a standalone glyph SVG.
pack_icns
Pack (pixel_size, png_bytes) entries into an .icns. Entries without a PNG-only slot are skipped; at least one must remain.
pack_ico
Pack (pixel_size, png_bytes) entries into a multi-size .ico. Sizes above 256 are skipped (the format caps at 256; 256 is encoded as width byte 0 per the spec).
parse
Parse SVG bytes into a usvg tree. Text is not compiled in (see the crate docs): a <text> element parses but renders as nothing, so callers that care (day-cli) probe the raw XML for <text and refuse with an “outline your text” message before calling this.
render_png
Render the tree into a px×px PNG, scaled uniformly to fit and centered. Transparent background; the caller composites/flattens where a format demands opacity (e.g. the iOS 1024 icon).
render_png_padded
Like render_png, with pad (a fraction of the edge, e.g. 0.1 = 10 %) of transparent margin on every side — the macOS icon convention (art inset on the 1024 canvas).
to_vector_drawable
Emit the tree as VectorDrawable XML, or say why it can’t be one.
to_xaml_geometry
Convert the tree to XAML geometry, or say why it can’t be.
wrap_symbolset
Wrap a standalone glyph SVG into (template_svg, contents_json) — the two files of a .symbolset bundle (<name>.svg + Contents.json).