Open abey79 opened 1 year ago
Initial implementation in 50c3a6b569089c36e5c0d1f12a25033d81e486f6. Far from implementing the full spec. svg
is probably too limited to handle that properly, in particular with regards to indentation. Maybe it can still help in the context of a more manual approach.
Edit: it's super slow too! ~13s for Drain4tests.svg!
Edit: no it's ok, it just needs a BufWriter
.
Working on my initial take at the SVG writer, it appears useful to come up with some quick and dirty spec, more or less inspired by what is currently implemented in vpype.
1) No real need for an xml prolog as we're utf-8 (vpype includes one). 2) Metadata in the correct format, as vpype currently does.
3) All path in their respective layers. 4) Attributes that are uniform within a layer should appear at the layer level (as opposed to the path level). 5) Attributes whose value corresponds to the SVG default should be omitted. 6) Path should be converted to the closest corresponding SVG representation.
<polyline>
/<polygon>
for purely linear path (FlattenedPath
andPath
without Béziers)<p>
otherwiseThe motivation for this is that polygon/polyline are possibly leaner to parse. 7) The resulting SVG should be human-readable (i.e. indented) on a best-effort basis. 8) If page size is available, use it. Otherwise, use bounds and original coordinates, and adjusting
viewBox
accordingly (vpype shifts coordinates such as to have a 0, 0 top-left inviewBox
). 9) Use cm forwidth
andheight
.