googlefonts/sleipnir

Option to emit mildly optimized svg paths

Offen

#18 geöffnet am 17.05.2024

 (1 Kommentar) (0 Reaktionen) (1 zugewiesene Person)Rust (2 Forks)auto 404
enhancementgood first issue

Repository-Metriken

Stars
 (2 Sterne)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

To enable deletion of some java code and a somewhat slow step in icon svg processing provide an optional optimized svg path that does the following if/when it produces a shorter string:

  • Use relative vs absolute coords
  • Collapse repeated lines (e.g. h20 h30 -> h50)
  • Use lineto shorthands (e.g. horizontal or vertical line)
  • Remove nop instructions, e.g. l0,0 but more generally any command that doesn't move the pen
  • Decrease accuracy of floats
  • Convert degenerate curves to lines
  • Drop leading 0 when possible (e.g 0.5 => .5)
  • Drop separator between coords when second is negative, e.g. emit 160-160 not 160,-160
  • Use "smooth" cubic/quadratic curve commands when possible (reflection of end of previous gives first control)

That is, implement most optimizations from https://github.com/svg/svgo/blob/main/plugins/convertPathData.js but apply during generation of a String for a BezPath instead of as a standalone step. Consider not implementing arc conversion; arcs have a way of breaking things.

Impact: should cut minutes off the time to produce a complete set of icons.

See:

Contributor Guide