I’ve written a Python2 script with fontforge library does the following:
- Accepts a source font
- Accepts a file containing all characters to be used. It can be a translation file, string asset file, HTML file, etc.
- Output a font with characters that aren’t shown in the file removed
Here is the code:
#!/usr/bin/python2
import sys
import fontforge
if len(sys.argv) == 4:
font = fontforge.open(sys.argv[1])
with open(sys.argv[2], "r") as f:
for i in f.read().decode("UTF-8"):
font.selection[ord(i)] = True
font.selection.invert()
for i in font.selection.byGlyphs:
font.removeGlyph(i)
font.generate(sys.argv[3])
else:
print "WARNING: Check the license of the source font\nbefore distributing the output font generated by this script.\nI'm not responsible for any legal issue caused by\ninappropriate use of this script!\n"
print "Usage: {} [source font] [file with glyphs NOT to be removed] [output]".format(sys.argv[0])
print "Example: {} /path/to/ukai.ttc chineseTranslation.txt ukaiStripped.ttf".format(sys.argv[0])
Please notice that it may not be legal to use this script on certain fonts. Ensure to checkout the license of the source font. I’m not responsible for any legal issue caused by using any font generated by this script.