Expand description
day-vector — Day’s vector-graphics engine (docs/vectors.md, docs/icons.md).
One crate, two consumers:
- Build time (day-cli):
day iconrenders app-icon masters into every platform’s icon formats, and resource staging (§18.3) convertsresource/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):
#SymbolsholdingWeight-Scalevariant groups,#Guideswith caplines/baselines —extract_variantcuts one variant out as a standalone glyph; - a
.symbolsetbundle (handled by the caller: its inner template SVG routes through here).
Re-exports§
Modules§
- icongen
- Seeded app-icon generator (docs/icons.md): one
u64seed → a deterministic layered SVG master (day:background/day:foreground/day:monochrome, the contractday iconconsumes), 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). - Xaml
Geometry - 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). - Xaml
Shape - One flat shape: geometry plus the paints it was authored with.
fill/strokeare#AARRGGBB; a backend asked for a tint substitutes its own brush and ignores both.
Enums§
- Source
Kind - What a
resource/vectors/SVG file is. (.symbolsetbundles are a directory form the caller unpacks — their inner template SVG classifies here asSourceKind::SfTemplate.)
Constants§
- ENGINE
- The render-engine identity stamped into
icons.lock.json— byte-stable renders hold only within one engine version, soday icon --checkcompares 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
Nonefor empty art — the input for safe-zone validation (an Android adaptive foreground overflowing the 66/108 zone). - extract_
variant - Cut one
Weight-Scalevariant 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<textand refuse with an “outline your text” message before calling this. - render_
png - Render the tree into a
px×pxPNG, 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, withpad(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.symbolsetbundle (<name>.svg+Contents.json).