Skip to content

Instantly share code, notes, and snippets.

@davelab6
Forked from Jolg42/extractSbixImages.py
Created March 15, 2017 12:38
Show Gist options
  • Save davelab6/bd82b5f628c4c2e3d93378d1d16e1cac to your computer and use it in GitHub Desktop.
Save davelab6/bd82b5f628c4c2e3d93378d1d16e1cac to your computer and use it in GitHub Desktop.
Extract sbix strikes from font
#!/usr/bin/env python
from fontTools.ttLib import TTFont
from os.path import exists, join
from os import mkdir, sys
# print 'Number of arguments:', len(sys.argv), 'arguments.'
# print 'Argument List:', str(sys.argv)
# print sys.argv[1]
def main():
f = TTFont(sys.argv[1])
if f.has_key("sbix"):
sbix = f["sbix"]
# print vars(sbix)
for bs in sbix.strikes.itervalues():
# print vars(bs), "\n"
print "Extracting ppem:", bs.ppem, "- Resolution:", bs.resolution
setpath = join("extracted", "set_%i" % bs.ppem)
if not exists(setpath):
mkdir(setpath)
print "Writing bitmap set to <%s>" % setpath
for bm in bs.glyphs.itervalues():
# print vars(bm), "\n"
if bm.graphicType is not None:
filename = join(setpath, "%s.png" % bm.glyphName)
pf = file(filename, "wb")
pf.write(bm.imageData)
pf.close()
else:
print "Font has no sbix table."
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment