googlefonts / fontc

Where in we pursue oxidizing (context: https://github.com/googlefonts/oxidize) fontmake.
Apache License 2.0
85 stars 14 forks source link

Feature's LookupListIndices *not* sorted when fontc is run via gftools #1080

Closed anthrotype closed 3 weeks ago

anthrotype commented 3 weeks ago

we have code in ttx_diff.py to make sure that the order of LookuListIndex values in a Feature record is sorted in the fonts generated by fontmake, because fontc supposedly always has them sorted (and the order doesn't matter anyway):

https://github.com/googlefonts/fontc/blob/0a5482f9366d6eef296158ff4fa2163055593bab/resources/scripts/ttx_diff.py#L408-L421

however, I noticed that when building https://github.com/JAMO-TYPEFACE/Moirai#Sources/Moirai.glyphs in both default and gftools mode, the GPOS tables that fontc (ignore fontmake) generates differ between each other like so:

$ diff -u build/{default,gftools}/fontc.GPOS.ttx
--- build/default/fontc.GPOS.ttx    2024-10-30 18:53:00
+++ build/gftools/fontc.GPOS.ttx    2024-10-30 19:15:40
@@ -50,8 +50,8 @@
         <FeatureTag value="kern"/>
         <Feature>
           <!-- LookupCount=2 -->
-          <LookupListIndex index="0" value="0"/>
-          <LookupListIndex index="1" value="1"/>
+          <LookupListIndex index="0" value="1"/>
+          <LookupListIndex index="1" value="0"/>
         </Feature>
       </FeatureRecord>
     </FeatureList>
\ No newline at end of file

This is weird. Even weirder is that the only diff when comparing fontc vs fontmake fonts build with --compare gftools mode, is exactly the same as above:

$ diff -u build/gftools/fontc.GPOS.ttx build/gftools/fontmake.GPOS.ttx
--- /Users/clupo/oss/fontc/build/gftools/fontc.GPOS.ttx 2024-10-30 19:15:40
+++ /Users/clupo/oss/fontc/build/gftools/fontmake.GPOS.ttx  2024-10-30 19:15:41
@@ -50,8 +50,8 @@
         <FeatureTag value="kern"/>
         <Feature>
           <!-- LookupCount=2 -->
-          <LookupListIndex index="0" value="1"/>
-          <LookupListIndex index="1" value="0"/>
+          <LookupListIndex index="0" value="0"/>
+          <LookupListIndex index="1" value="1"/>
         </Feature>
       </FeatureRecord>
     </FeatureList>
\ No newline at end of file

The GPOS table built by fontmake does not change whether it was built in default or gftools mode.

ttx_diff only applies the sorting of the lookup indices to the font generated by fontmake (be in default or gftools mode), never to the font generated by fontc because the assumption was that those should already be sorted.

But they aren't somehow, and only when running fontc through gftools... 🤔

anthrotype commented 3 weeks ago

turns out this was because we weren't in fact invoking fontc for building static TTFs like this, but fontmake.. should be fixed now with https://github.com/googlefonts/gftools/commit/f14c7bc4e5e17b3262297c1f64d63a0ac717d4c0