Add name checking to compatcheck

This tries to ensure that sensible ways of specifying a font by name
continue to work across an upgrade.
This commit is contained in:
Ben Harris 2024-12-23 23:22:45 +00:00
parent 9c1ad469f5
commit 698683b7fa

View File

@ -19,6 +19,10 @@
# 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)