Improve misc/gen-glyphinfo.py and gen-metrics-and-svgs.py by ignoring glyphs listed in "delete" of fontbuild.cfg

This commit is contained in:
Rasmus Andersson 2017-09-24 19:38:30 -07:00
parent d513973d3c
commit b47572cc05
3 changed files with 44 additions and 12 deletions

View file

@ -151,11 +151,11 @@ glyphinfo: docs/lab/glyphinfo.json docs/glyphs/metrics.json
src/glyphorder.txt: src/Inter-UI-Regular.ufo/lib.plist src/Inter-UI-Black.ufo/lib.plist src/diacritics.txt misc/gen-glyphorder.py src/glyphorder.txt: src/Inter-UI-Regular.ufo/lib.plist src/Inter-UI-Black.ufo/lib.plist src/diacritics.txt misc/gen-glyphorder.py
misc/gen-glyphorder.py src/Inter-UI-*.ufo > src/glyphorder.txt misc/gen-glyphorder.py src/Inter-UI-*.ufo > src/glyphorder.txt
docs/lab/glyphinfo.json: _local/UnicodeData.txt src/glyphorder.txt misc/gen-glyphinfo.py docs/lab/glyphinfo.json: _local/UnicodeData.txt src/glyphorder.txt src/fontbuild.cfg misc/gen-glyphinfo.py
misc/gen-glyphinfo.py -ucd _local/UnicodeData.txt \ misc/gen-glyphinfo.py -ucd _local/UnicodeData.txt \
src/Inter-UI-*.ufo > docs/lab/glyphinfo.json src/Inter-UI-*.ufo > docs/lab/glyphinfo.json
docs/glyphs/metrics.json: src/glyphorder.txt misc/gen-metrics-and-svgs.py $(Regular_ufo_d) docs/glyphs/metrics.json: src/glyphorder.txt src/fontbuild.cfg misc/gen-metrics-and-svgs.py $(Regular_ufo_d)
misc/gen-metrics-and-svgs.py -f src/Inter-UI-Regular.ufo misc/gen-metrics-and-svgs.py -f src/Inter-UI-Regular.ufo

View file

@ -9,6 +9,10 @@ from argparse import ArgumentParser
from robofab.objects.objectsRF import OpenFont from robofab.objects.objectsRF import OpenFont
from collections import OrderedDict from collections import OrderedDict
from unicode_util import parseUnicodeDataFile from unicode_util import parseUnicodeDataFile
from ConfigParser import RawConfigParser
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
# Regex matching "default" glyph names, like "uni2043" and "u01C5" # Regex matching "default" glyph names, like "uni2043" and "u01C5"
@ -156,6 +160,17 @@ def main():
args = argparser.parse_args() args = argparser.parse_args()
markLibKey = 'com.typemytype.robofont.mark' markLibKey = 'com.typemytype.robofont.mark'
srcDir = os.path.join(BASEDIR, 'src')
# load fontbuild config
config = RawConfigParser(dict_type=OrderedDict)
configFilename = os.path.join(srcDir, 'fontbuild.cfg')
config.read(configFilename)
deleteNames = set()
for sectionName, value in config.items('glyphs'):
if sectionName == 'delete':
deleteNames = set(value.split())
fontPaths = [] fontPaths = []
for fontPath in args.fontPaths: for fontPath in args.fontPaths:
fontPath = fontPath.rstrip('/ ') fontPath = fontPath.rstrip('/ ')
@ -166,8 +181,8 @@ def main():
fonts = [OpenFont(fontPath) for fontPath in args.fontPaths] fonts = [OpenFont(fontPath) for fontPath in args.fontPaths]
agl = loadAGL('src/glyphlist.txt') # { 2126: 'Omega', ... } agl = loadAGL(os.path.join(srcDir, 'glyphlist.txt')) # { 2126: 'Omega', ... }
diacriticComps = loadGlyphCompositions('src/diacritics.txt') diacriticComps = loadGlyphCompositions(os.path.join(srcDir, 'diacritics.txt'))
uc2names, name2ucs, allNames = loadLocalNamesDB(fonts, agl, diacriticComps) uc2names, name2ucs, allNames = loadLocalNamesDB(fonts, agl, diacriticComps)
ucd = {} ucd = {}
@ -189,6 +204,8 @@ def main():
for font in fonts: for font in fonts:
for name, v in glyphorder.iteritems(): for name, v in glyphorder.iteritems():
if name in deleteNames:
continue
if name in visitedGlyphNames: if name in visitedGlyphNames:
continue continue

View file

@ -9,6 +9,10 @@ from math import ceil, floor
from robofab.objects.objectsRF import OpenFont from robofab.objects.objectsRF import OpenFont
from collections import OrderedDict from collections import OrderedDict
from fontbuild.generateGlyph import generateGlyph from fontbuild.generateGlyph import generateGlyph
from ConfigParser import RawConfigParser
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
font = None # RFont font = None # RFont
ufopath = '' ufopath = ''
@ -337,6 +341,17 @@ argparser.add_argument('glyphs', metavar='<glyphname>', type=str, nargs='*',
args = argparser.parse_args() args = argparser.parse_args()
srcDir = os.path.join(BASEDIR, 'src')
# load fontbuild config
config = RawConfigParser(dict_type=OrderedDict)
configFilename = os.path.join(srcDir, 'fontbuild.cfg')
config.read(configFilename)
deleteNames = set()
for sectionName, value in config.items('glyphs'):
if sectionName == 'delete':
deleteNames = set(value.split())
if len(args.scale): if len(args.scale):
scale = float(args.scale) scale = float(args.scale)
@ -345,26 +360,26 @@ ufopath = args.ufopath.rstrip('/')
font = OpenFont(ufopath) font = OpenFont(ufopath)
effectiveAscender = max(font.info.ascender, font.info.unitsPerEm) effectiveAscender = max(font.info.ascender, font.info.unitsPerEm)
srcdir = os.path.abspath(os.path.join(__file__, '..', '..'))
# print('\n'.join(font.keys())) # print('\n'.join(font.keys()))
# sys.exit(0) # sys.exit(0)
agl = loadAGL(os.path.join(srcdir, 'src', 'glyphlist.txt')) # { 2126: 'Omega', ... } agl = loadAGL(os.path.join(srcDir, 'glyphlist.txt')) # { 2126: 'Omega', ... }
deleteNames.add('.notdef')
deleteNames.add('.null')
ignoreGlyphs = set(['.notdef', '.null'])
glyphnames = args.glyphs if len(args.glyphs) else font.keys() glyphnames = args.glyphs if len(args.glyphs) else font.keys()
glyphnameSet = set(glyphnames) glyphnameSet = set(glyphnames)
generatedGlyphNames = set() generatedGlyphNames = set()
diacriticComps = loadGlyphCompositions(os.path.join(srcdir, 'src', 'diacritics.txt')) diacriticComps = loadGlyphCompositions(os.path.join(srcDir, 'diacritics.txt'))
for glyphName, comp in diacriticComps.iteritems(): for glyphName, comp in diacriticComps.iteritems():
if glyphName not in glyphnameSet: if glyphName not in glyphnameSet:
generatedGlyphNames.add(glyphName) generatedGlyphNames.add(glyphName)
glyphnames.append(glyphName) glyphnames.append(glyphName)
glyphnameSet.add(glyphName) glyphnameSet.add(glyphName)
glyphnames = [gn for gn in glyphnames if gn not in ignoreGlyphs] glyphnames = [gn for gn in glyphnames if gn not in deleteNames]
glyphnames.sort() glyphnames.sort()
nameToIdMap, idToNameMap = genGlyphIDs(glyphnames) nameToIdMap, idToNameMap = genGlyphIDs(glyphnames)
@ -387,7 +402,7 @@ for glyphname in glyphnames:
svgtext = '\n'.join(svgLines) svgtext = '\n'.join(svgLines)
# print(svgtext) # print(svgtext)
glyphsHtmlFilename = os.path.join(srcdir, 'docs', 'glyphs', 'index.html') glyphsHtmlFilename = os.path.join(BASEDIR, 'docs', 'glyphs', 'index.html')
html = '' html = ''
with open(glyphsHtmlFilename, 'r') as f: with open(glyphsHtmlFilename, 'r') as f:
@ -425,7 +440,7 @@ with open(glyphsHtmlFilename, 'w') as f:
f.write(html) f.write(html)
# JSON # JSON
jsonFilename = os.path.join(srcdir, 'docs', 'glyphs', 'metrics.json') jsonFilename = os.path.join(BASEDIR, 'docs', 'glyphs', 'metrics.json')
jsonFilenameRel = os.path.relpath(jsonFilename, os.getcwd()) jsonFilenameRel = os.path.relpath(jsonFilename, os.getcwd())
print('write', jsonFilenameRel) print('write', jsonFilenameRel)
with open(jsonFilename, 'w') as f: with open(jsonFilename, 'w') as f: