Skip to content

Instantly share code, notes, and snippets.

@tobywf
Created April 6, 2020 04:54
Show Gist options
  • Save tobywf/6c313982c43da272698375bd1b41617f to your computer and use it in GitHub Desktop.
Save tobywf/6c313982c43da272698375bd1b41617f to your computer and use it in GitHub Desktop.
Extract SBIX glyphs from a font
# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6sbix.html
# requires fonttools lib (`pip install fonttools>=4.7.0`)
import sys
from fontTools.ttLib import TTFont
font = TTFont(sys.argv[1])
sbix = font["sbix"]
max_ppem = max(sbix.strikes.keys())
strike = sbix.strikes[max_ppem]
for bitmap in strike.glyphs.values():
if bitmap.graphicType == "png ":
filename = f"glyph-{bitmap.glyphName}.png"
with open(filename, "wb") as f:
f.write(bitmap.imageData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment