Skip to content

Instantly share code, notes, and snippets.

@Jolg42
Created March 14, 2017 15:34
Show Gist options
  • Save Jolg42/f22676fdfba6dbfe4589aa30f0326fb4 to your computer and use it in GitHub Desktop.
Save Jolg42/f22676fdfba6dbfe4589aa30f0326fb4 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()
@liudanking
Copy link

It's great. But how can I naming png file by code points?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment