chiark / gitweb /
Extend compatcheck 'GSUB' checks to handle renamed glyphs
authorBen Harris <bjh21@bjh21.me.uk>
Wed, 1 Jan 2025 23:53:51 +0000 (23:53 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Wed, 1 Jan 2025 23:53:51 +0000 (23:53 +0000)
We do this by pulling out the CFF charstring for old and new glyph
names from the new font and seeing if they're the same.

compatcheck

index c119693ee1bf4d2793350ee4acc6f517e7a57647..a1acf61453e3bb2fa1cd8de2e80b2911b395eb6a 100755 (executable)
 # depend on the behaviour of particular inputs to these lookups, and
 # that they should thus be consistent within major versions.  Unlike
 # for most features above, we'd like to check that the semantics of
-# the chosen glyphs haven't changed.  For now, we do that by checking
-# glyph names.  The only feature currently handled by this is 'aalt'
-# (Access All Alternates).
+# the chosen glyphs haven't changed.  This is made tricky by the fact
+# the Bedstead 3.251 changed some glyph names while keeping the same
+# semantics, and also changed the shape of some glyphs.  Our approach
+# is to look up both old and new glyph names in the new font and check
+# that they have the same outline there.  The only feature currently
+# handled by this is 'aalt' (Access All Alternates).
 
 from argparse import ArgumentParser
 from fontTools import ttLib
@@ -116,11 +119,15 @@ def feat_to_dict(gsub, tag):
             for st in lookup.SubTable:
                 return st.alternates
 
+def charstring(glyphname):
+    return ttnew['CFF '].cff[0].CharStrings[glyphname].bytecode
+
 for feat in ['aalt']:
     oldalt = feat_to_dict(ttold['GSUB'], feat)
     newalt = feat_to_dict(ttnew['GSUB'], feat)
     for k in sorted(set(oldalt.keys()) & set(newalt.keys())):
-        if newalt[k][:len(oldalt[k])] != oldalt[k]:
+        if ([charstring(x) for x in newalt[k][:len(oldalt[k])]] !=
+            [charstring(x) for x in oldalt[k]]):
             fail(f"new '{feat}' lookup for {k} is not a prefix of old one")
 
 if failed: