googlefonts / googlefonts/sleipnir

Option to emit mildly optimized svg paths

Open
#18 1 comment 0 reactions 1 assignee Claimed by @rsheeter View on GitHub
enhancement good first issue
Dominant language
Rust
Stars
2
Forks
1
Avg merge
2d 9h
Merged PRs (30d)
7

Description

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:

- [x] Use relative vs absolute coords
- [ ] Collapse repeated lines (e.g. h20 h30 -> h50)
- [x] Use lineto shorthands (e.g. horizontal or vertical line)
- [x] Remove nop instructions, e.g. `l0,0` but more generally any command that doesn't move the pen
- [x] Decrease accuracy of floats
- [ ] Convert degenerate curves to lines
- [ ] Drop leading 0 when possible (e.g 0.5 => .5)
- [x] Drop separator between coords when second is negative, e.g. emit `160-160` not `160,-160`
- [x] 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:

* https://www.w3.org/TR/SVG11/paths.html#PathData
* https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#path_commands
* https://svgo.dev/docs/preset-default/#plugins-list
* Note that as we generate the svg many remove element steps are avoided by simply not generating them

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.