-
-
Save davelab6/4c63ee7ec18a6ab9da1681cb66bd53d2 to your computer and use it in GitHub Desktop.
Extract sbix strikes from font
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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