From: Ben Harris Date: Mon, 23 Dec 2024 23:22:45 +0000 (+0000) Subject: Add name checking to compatcheck X-Git-Tag: bedstead-3.251~58 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=698683b7fa7887e686c410a16700f125a92e4e46;p=bedstead.git Add name checking to compatcheck This tries to ensure that sensible ways of specifying a font by name continue to work across an upgrade. --- diff --git a/compatcheck b/compatcheck index 9f1bb61..5b28cce 100755 --- a/compatcheck +++ b/compatcheck @@ -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)