Drop superflous Mac names option.
Remove mac names which not affect the functionality of mac applications. Fields
such as Manufacturer, URL Vender etc are dropped.
@@ -14,6 +14,49 @@ parser.add_argument('--csv', default=False, action='store_true',
" (CSV) file format")
parser.add_argument('--id', '-i', default='all')
parser.add_argument('--platform', '-p', type=int, default=3)
+parser.add_argument('--drop-superflous-mac-names', '-m', default=False,
+ action='store_true',
+ help='Drop superflous Mac names')
+
+
+def has_mac_names(ttfont):
+ """Check if a font has Mac names. Mac names have the following
+ field values:
+ platformID: 1, encodingID: 0, LanguageID: 0"""
+ for i in range(255):
+ if ttfont['name'].getName(i, 1, 0, 0):
+ return True
+ return False
+
+
+def drop_superflous_mac_names(ttfont):
+ """Drop superflous Mac nameIDs.
+
+ The following nameIDS are kept:
+ 1: Font Family name,
+ 2: Font Family Subfamily name,
+ 3: Unique font identifier,
+ 4: Full font name,
+ 5: Version string,
+ 6: Postscript name,
+ 16: Typographic family name,
+ 17: Typographic Subfamily name
+ 18: Compatible full (Macintosh only),
+ 20: PostScript CID,
+ 21: WWS Family Name,
+ 22: WWS Subfamily Name,
+ 25: Variations PostScript Name Prefix.
+
+ We keep these IDs in order for certain application to still function
+ such as Word 2011. IDs 1-6 are very common, > 16 are edge cases.
+
+ https://www.microsoft.com/typography/otspec/name.htm"""
+ keep_ids = [1, 2, 3, 4, 5, 6, 16, 17, 18, 20, 21, 22, 25]
+ for n in range(255):
+ if n not in keep_ids:
+ name = ttfont['name'].getName(n, 1, 0, 0)
+ if name:
+ ttfont['name'].names.remove(name)
def main():
@@ -64,6 +107,15 @@ def main():
if saveit:
font.save(path + ".fix")
+ if args.drop_superflous_mac_names:
+ for path in args.font:
+ font = ttLib.TTFont(path)
+ if has_mac_names(font):
+ drop_superflous_mac_names(font)
+ font.save(path + ".fix")
+ else:
+ print('font %s has no mac nametable' % path)
+
+
if __name__ == '__main__':
main()
-
