googlefonts / ufo2ft

A bridge from UFOs to FontTools objects (and therefore, OTFs and TTFs).
MIT License
151 stars 43 forks source link

Support TrueType hinting, 4th try #654

Closed jenskutilek closed 1 year ago

jenskutilek commented 2 years ago

Continued from #577

moyogo commented 2 years ago

@anthrotype What do you recommend for InstructionCompiler in the end? Mixin, functions, merge into OutlineTTFCompiler?

jenskutilek commented 1 year ago

There is now a tool publicly available that can store TrueType hinting in UFOs, discussion here: https://typedrawers.com/discussion/4622/a-new-graphical-editor-for-truetype-hints

What can we do to get this PR merged? :)

moyogo commented 1 year ago

@jenskutilek It seems a separate tool like https://github.com/daltonmaag/vttLib that is run on the generated TTF with the UFO as input would be preferred. @anthrotype can you confirm?

verbosus commented 1 year ago

I don’t know if this helps in any way with moving the PR forward, either in this state (which seems ready to go?) or as a separate lib, but I’m very interested in this functionality as it would allow for far better source management / build reproducibility & all the good stuff we know and love. So it’s a definite +1 for me, for whatever it’s worth.

verbosus commented 1 year ago

I should add: THANK YOU and CONGRATULATIONS to Jens for the excellent work on this.

jenskutilek commented 1 year ago

Thank you @verbosus for your kind words!

Without having heard any arguments in favor of making this a standalone tool, let me say this: vttLib is different in that it takes a language (VTT assembly) that is part of neither the UFO nor the TrueType spec, and compiles and optimizes it and writes it into a font. My PR here is merely the implementation to support a part of the UFO spec that is still missing from the toolchain, that is transforming TTX assembly into binary TrueType instructions.

Saying this should be a standalone tool is a bit like saying the compilation of UFO outlines into a font should be a standalone tool ;)

When my PR gets merged, vttLib could even be simplified so that it compiles the VTT assembly to TTX assembly, stores it into an UFO, and lets ufo2ft handle the rest.

I wonder if this PR has somehow been confused with a suggestion I made in a different place, which was to make a standalone compiler for GlyphsApp high-level TrueType commands to TTX assembly?

Let me just reiterate that I'm using my ufo2ft branch regularly to build variable fonts with hinting, so IMHO it is pretty stable. I'm using a proprietary tool to compile high-level FontLab 5 TT hinting as found in vfb2ufo output UFOs to VTT assembly, which in turn is compiled by vttLib into TTX assembly and also stored inside the UFOs, from where it is then picked up by ufo2ft.

anthrotype commented 1 year ago

i'm giving this another review round now, thanks for the patience..

anthrotype commented 1 year ago

@jenskutilek while reviewing, I'm also making some minor modifications if you don't mind, please don't add more commits to this while I'm done with it - thanks

anthrotype commented 1 year ago

@jenskutilek can you please take a look at my latest changes and see if they look good to you? I think we are in a good shape now, will probably merge tomorrow. Thanks

anthrotype commented 1 year ago

Question: does this work with variable fonts?

jenskutilek commented 1 year ago

Thank you @anthrotype! I will check take a look as soon as possible, hopefully this afternoon.

Yes, it does support variable fonts. In my usage scenario, all master UFOs contain identical fpgm, prep, and glyf programs. The cvts are usually different in each master, of course. fontTools.varLib will build a cvar from the different cvts, and copy the fpgm, prep and glyf programs when that's the case.

It should also be enough if the default master contains the fpgm, prep, and glyf programs, but I need to check again.

anthrotype commented 1 year ago

I see, thanks for confirming. If we don't have one already, we should add a test that compiles a VF with hinting and confirms that varLib generates the cvar deltas

jenskutilek commented 1 year ago

It should also be enough if the default master contains the fpgm, prep, and glyf programs, but I need to check again.

Confirmed.

I've run the latest version on a couple of fonts, and the resulting fonts are identical. Haven't looked at the code yet.

jenskutilek commented 1 year ago

I see, thanks for confirming. If we don't have one already, we should add a test that compiles a VF with hinting and confirms that varLib generates the cvar deltas

It's tested in fontTools.varLib when building from TTF masters (https://github.com/fonttools/fonttools/pull/1069). Or do you mean we should a test here for building from UFO?

jenskutilek commented 1 year ago

@anthrotype I've had a look at your changes. LGTM.

anthrotype commented 1 year ago

yeah we could/should add a test here as well as a sort of integration test for variable+hinted builds

jenskutilek commented 1 year ago

I've added TrueType data to the integration test. I stumbled over https://github.com/fonttools/fonttools/issues/3036 while preparing the expected ttx data, but I fixed it for now by converting the input to fromAssembly() to a list.