googlefonts / fontations

Reading and writing font files
Apache License 2.0
392 stars 24 forks source link

codegen: consider generating wrappers on format enums for shared variant methods #687

Open cmyr opened 1 year ago

cmyr commented 1 year ago

As in, if there are multiple formats for a table, but those formats share some set of methods, we should generate a method on the enum that forwards the call to each of those variants.

We could also get fancier here and generate methods on the wrapper even when only one variant has the method, and make it return None? But that feels like it could get noisy. In that case, we could consider adding an annotation that would be added to specific methods on a variant which would cause us to generate a a method call on the enum (e.g. make this opt-in, in the case where not all variants have a method)

see #682 for an example of the code this would save us hand-writing.

rsheeter commented 1 year ago

I suggest we start with only the case where all variants support; the user having to drill down to the specific variant seems pretty reasonable when that's not the case.