Macro build_path
build_path!() { /* proc-macro */ }Expand description
Turn SVG path data into a PathBuilder chain, at compile time.
let heart = build_path!("M 12,21 C 2,14 2,7 7,5 c 3,-1 5,1 5,3 …").build();
d.fill(heart, CORAL);The whole SVG 1.1 path grammar is accepted: absolute and relative commands, H/V, the
smooth forms S/T, elliptical arcs, implicit command repetition, and SVG’s number syntax
(1e2, .5.5, 10-5). Malformed data is a compile error naming the offending character,
not a path that silently draws nothing.
The result is a PathBuilder, so the fill rule and any further segments still chain on:
build_path!("M0,0 h10 v10 h-10 Z").rule(FillRule::EvenOdd).build()Arcs are converted to cubics here, once, rather than by each of the nine backends at draw time, because an arc is the one command with no counterpart in the 2-D APIs Day draws through.
Everything is evaluated at compile time, so a path costs the same at runtime as writing the method chain by hand: there is no string left in the binary and no parsing on the draw path.