Work-Sans/sources/tools/makeGlyphsFileWithOnlyBraceGlyphs.py

51 lines
1.3 KiB
Python
Raw Normal View History

# Make a .glyphs file with only brace glyphs to export
import sys
import re
from glyphsLib import GSFont
from glyphsLib import GSGlyph
from glyphsLib import GSLayer
file = sys.argv[1]
2018-11-09 11:02:26 +03:00
font = GSFont(file)
2018-11-12 17:11:18 +03:00
print "\tPreparing %s" % file
2018-11-09 11:02:26 +03:00
# Append Italic to font family naame if Italics
style = sys.argv[2]
if style == "Italic":
font.familyName = "%s %s" % (font.familyName, style)
# Clear all features
font.features = []
font.classes = []
font.featurePrefixes = []
2018-11-09 11:02:26 +03:00
# Remove Rename Glyphs custom parameter
for instance in font.instances:
for customParam in instance.customParameters:
if customParam.name == "Rename Glyphs":
del customParam
# Find brace glyphs
listOfBraceGlyphs = []
for eachGlyph in font.glyphs:
for eachLayer in eachGlyph.layers:
if re.match('.*\d\}$', eachLayer.name):
listOfBraceGlyphs += [eachGlyph.name]
2018-11-12 17:11:18 +03:00
print "\tBrace glyphs found: ", listOfBraceGlyphs
listOfBraceGlyphs += ["space", ".notdef"]
2018-11-09 11:02:26 +03:00
listOfGlyphsNotToExport = [g.name for g in font.glyphs if g.name not in listOfBraceGlyphs]
for eachGlyph in listOfGlyphsNotToExport:
font.glyphs[eachGlyph].export = 0
# for eachGlyph in listOfBraceGlyphs:
# try:
# font.glyphs[eachGlyph].export = 1
# except:
# pass
newFileName = file.replace(".glyphs", "-onlyBraceGlyphs.glyphs")
font.save(newFileName)