simoncozens / babelfont

Interrogate and manipulate UFO, TTF and OTF fonts with a common interface
Apache License 2.0
53 stars 9 forks source link

Create "cleaned up" glyphs file? (i.e. apply filters and feature variations) #66

Open arrowtype opened 3 months ago

arrowtype commented 3 months ago

Hi Simon, I know you are currently very busy, so I’m hoping you will respond to this later, when you have time. However, I want to get the question down, so I don’t forget it.

In a GlyphsLib issue regarding feature variation syntax, you said:

I've just added Glyphs3 variable feature support to babelfont, so you could try that, either as a font compiler or as a filter to produce a "clean" Glyphs file.

Awesome! Thanks for the idea – that sounds really appealing.

My goal/hope is that I could take in a Glyphs3 source that uses various special techniques of Glyphs – like expandable strokes, export filters, and feature variations syntax – and convert these into more basic data that could be easily compiled by FontMake into TTFs or UFOs.

I’ve poked around the docs and tinkered with it a bit, and I’ve managed to load, then save a Glyphs3 file. However, this doesn’t seem to apply any changes that I am hoping for.

from babelfont import load

input = "test.glyphs"
output = "test-cleaned.ttf"

f = load(input)
f.save(output, format=3)

Have I missed something? Is there some way to expand strokes, apply export filters, and convert feature vars to alternate layers?

Thank you for any insights!

One extra note: Many glyphs in the original file have horizontally flipped/mirrored components. The version loaded and saved by Babelfont has added a vertical flip to these. (Example: ж uses a component for the diagonal part, and mirrors this for the left side. The font output by Babelfont has flipped this left side vertically, and pushed it way down below the baseline.) It’s not my font, and it’s not something I would think of when drawing a font, but the outcome seems non-ideal and worth mentioning.

simoncozens commented 3 months ago

Yes, this is a design goal. Babelfont compiles to TTF (and other formats) through a series of font filters, which are source-to-source transformations. Use "babelfont in.glyphs -f whatever -f whatever2 out.glyphs" to load, filter and save. See "babelfont" or look in src/babelfont/fontFilters for a list of transformations.

arrowtype commented 3 months ago

Ah, awesome! Thanks for sharing that specific command syntax.

Looking at fontFilters, it seems like "round corners" is not yet supported... correct?

simoncozens commented 3 months ago

Yep, no round corners filter yet. I'm focusing on source-to-source transformation filters needed as part of a standard compilation pipeline (open corners, alternate layers, etc.) rather than the add-on "custom parameter" type things that Glyphs calls filters.

arrowtype commented 3 months ago

Okay, good to know! Thanks for taking the time to clarify that for me. Excited to see the progress here, and what’s to come!