chiark / gitweb /
Add name checking to compatcheck
authorBen Harris <bjh21@bjh21.me.uk>
Mon, 23 Dec 2024 23:22:45 +0000 (23:22 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 29 Dec 2024 18:50:52 +0000 (18:50 +0000)
This tries to ensure that sensible ways of specifying a font by name
continue to work across an upgrade.

compatcheck

index 9f1bb618d40059f1e88626a2f943421f5444b947..5b28cce5e64eca91066457cf07a16a8f7f91f563 100755 (executable)
 # continue to exist, and that any mapping through any 'cmap' should
 # continue to work.  As with glyph names, the script checks for the
 # existence of mappings, but not their content.
+#
+# Names.  Applications use a font's name to refer to it.  This script
+# checks that the subset of names for which this seems reasonable
+# match between the old and new fonts.
 
 from argparse import ArgumentParser
 from fontTools import ttLib
@@ -53,5 +57,32 @@ for cmapold in ttold['cmap'].tables:
              f"{(cmapold.platformID,cmapold.platEncID)}: "
              f"{set(cmapold.cmap.keys()) - set(cmapnew.cmap.keys())!r}")
 
+# Names that might be used to specify fonts.
+specnames = {
+    1,  # Font family name
+    2,  # Font subfamily name
+    4,  # Full font name
+    6,  # PostScript FontName
+    16, # Typographic family name
+    17, # Typographic subfamily name
+    18, # Compatible full name
+    20, # PostScript CID findfont name
+    21, # WWS family name
+    22, # WWS subfamily name
+    25, # Variations PostScript name prefix
+}
+for oldname in ttold['name'].names:
+    if oldname.nameID in specnames:
+        newname = ttnew['name'].getName(oldname.nameID, oldname.platformID,
+                                        oldname.platEncID, oldname.langID)
+        if newname == None:
+            fail("No name in new font for "
+                 f"nameID={oldname.nameID}, platformID={oldname.platformID}, "
+                 f"platEncID={oldname.platEncID}, langID={oldname.langID}")
+        if newname.string != oldname.string:
+            fail("Name mismatch for "
+                 f"nameID={oldname.nameID}, platformID={oldname.platformID}, "
+                 f"platEncID={oldname.platEncID}, langID={oldname.langID}")
+
 if failed:
     exit(1)