Created
April 6, 2020 04:54
-
-
Save tobywf/6c313982c43da272698375bd1b41617f to your computer and use it in GitHub Desktop.
Extract SBIX glyphs from a 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
# 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