Skip to content

Instantly share code, notes, and snippets.

@starrhorne
Created January 19, 2012 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save starrhorne/1637310 to your computer and use it in GitHub Desktop.
Save starrhorne/1637310 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys
from fontTools import ttLib
FONT_SPECIFIER_NAME_ID = 4
FONT_SPECIFIER_FAMILY_ID = 1
def shortName( font ):
"""Get the short name from the font's names table"""
name = ""
family = ""
for record in font['name'].names:
if record.nameID == FONT_SPECIFIER_NAME_ID and not name:
if '\000' in record.string:
name = unicode(record.string, 'utf-16-be').encode('utf-8')
else:
name = record.string
elif record.nameID == FONT_SPECIFIER_FAMILY_ID and not family:
if '\000' in record.string:
family = unicode(record.string, 'utf-16-be').encode('utf-8')
else:
family = record.string
if name and family:
break
return name, family
tt = ttLib.TTFont(sys.argv[1])
print shortName(tt)[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment