typemytype / GlyphConstruction

MIT License
70 stars 11 forks source link

Add glyph equations to built glyphs #69

Open colinmford opened 1 year ago

colinmford commented 1 year ago

Hi @typemytype,

I have been thinking for some time it might be nice to have the equation to build a glyph constructed glyph saved in the glyph's lib, like so:

# Glyph Construction
Tcommaaccent = T + commaaccent @ bottom | 021A, 0162
<!-- T_commaaccent.glif -->
<lib>
  <dict>
    <key>com.typemytype.glyphConstruction.equation</key>
    <string>Tcommaaccent = T + commaaccent @ bottom | 021A, 0162</string>
  </dict>
</lib>

A few examples of what this would allow other scripts to potentially do:

  1. Know if a glyph is a glyph constructed glyph or not, in case they either wanted not target or target constructed glyphs
  2. Allow piecemeal re-construction, for example using an event to trigger a re-construction of just a few glyphs if a base glyph's sidebearings are changed without having to go back into the extension (even if the glyph was decomposed with *)
  3. A way to customize "autoUnicodes()" in a way, since the equation is explicit in what the user wants the unicode to be

... And many more! (maybe)

The only hitch I can see is user-defined variables... I can see it working maybe 2 ways? Of course the Glyph Construction constants like descender, xHeight etc won't be touched, but we could expand the variables to put in the equation, or store the variable in the font lib.

$bottom = -4
Tcommaaccent = T + commaaccent @ $bottom | 021A, 0162

becomes

<!-- T_commaaccent.glif -->
<lib>
  <dict>
    <key>com.typemytype.glyphConstruction.equation</key>
    <string>Tcommaaccent = T + commaaccent @ -4 | 021A, 0162</string>
  </dict>
</lib>

or

<!-- fontinfo.plist -->
<lib>
  <dict>
    <key>com.typemytype.glyphConstruction.variables</key>
    <dict>
        <key>$bottom</key>
        <integer>-4</integer>
    </dict>
  </dict>
</lib>

...

<!-- T_commaaccent.glif -->
<lib>
  <dict>
    <key>com.typemytype.glyphConstruction.equation</key>
    <string>Tcommaaccent = T + commaaccent @ $bottom | 021A, 0162</string>
  </dict>
</lib>

If you like this idea, I could make a PR.

Thanks!

typemytype commented 1 year ago

to keep a reference in the glyph lib is a good plan!

one issue I see is that this lib key is not something to keep in sync, its is just a reference where the components originally came from. If a designer adjust components manually, the construction will be out of sync.

I like the second option to keep the variable in the font.lib

In the extension this could be an optional flag: Store construction in lib.

colinmford commented 1 year ago

Hm, good points, the "invalidating" of glyph construction glyphs that are then edited afterwards is giving me pause. I'm gonna give this more thought.

typemytype commented 1 year ago

duplicated data on different levels of abstraction is a pain...

however to start over from stored glyph constructions is a deliberate decision, which can be shown in a warning dialog before appling