linebender / norad

Rust crate for working with Unified Font Object files
Apache License 2.0
44 stars 12 forks source link

Better kerning & groups tooling #331

Open RickyDaMa opened 9 months ago

RickyDaMa commented 9 months ago

Working with kerning & groups in code has been a pain every time I've had to do it, and a lot of that comes from having relatively basic functionality not being available because both Python & Rust libraries; they just expose raw dictionary/map types and provide zero convenience methods. This has become somewhat of a pet peeve of mine and something I'd like to fix.

Some of my ideas are as follows, and I'd like to gauge interest/discuss them before starting work:

  1. Kerning look-up methods (one with group resolution, one without)
  2. Kerning/Group modifying methods that uphold invariants (as opposed to validation on write-to-disk)
  3. Generating reverse look-ups for kerning & groups
  4. Transparent caching of reverse look-ups to make resolving kerns faster (transparent as in, requires no thought/involvement from the library user at any point, will require interior mutability)
  5. Renaming group method
  6. Culling empty groups method
  7. Culling 0 kerns method

The breaking change would be privatising Font.kerning and Font.groups and/or changing the underlying type. Interested in hearing any use cases for kerning/group information beyond what I've outlined in my points. Iterating over groups/kerning would of course still be available

madig commented 8 months ago

Use case I just stumbled over: a Kerning::retain method that yields (first, second, value) so I don't have to do the map denesting myself.