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:
parent
d513973d3c
commit
b47572cc05
3 changed files with 44 additions and 12 deletions
4
Makefile
4
Makefile
|
|
@ -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
|
||||
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 \
|
||||
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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@ from argparse import ArgumentParser
|
|||
from robofab.objects.objectsRF import OpenFont
|
||||
from collections import OrderedDict
|
||||
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"
|
||||
|
|
@ -156,6 +160,17 @@ def main():
|
|||
args = argparser.parse_args()
|
||||
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 = []
|
||||
for fontPath in args.fontPaths:
|
||||
fontPath = fontPath.rstrip('/ ')
|
||||
|
|
@ -166,8 +181,8 @@ def main():
|
|||
|
||||
fonts = [OpenFont(fontPath) for fontPath in args.fontPaths]
|
||||
|
||||
agl = loadAGL('src/glyphlist.txt') # { 2126: 'Omega', ... }
|
||||
diacriticComps = loadGlyphCompositions('src/diacritics.txt')
|
||||
agl = loadAGL(os.path.join(srcDir, 'glyphlist.txt')) # { 2126: 'Omega', ... }
|
||||
diacriticComps = loadGlyphCompositions(os.path.join(srcDir, 'diacritics.txt'))
|
||||
uc2names, name2ucs, allNames = loadLocalNamesDB(fonts, agl, diacriticComps)
|
||||
|
||||
ucd = {}
|
||||
|
|
@ -189,6 +204,8 @@ def main():
|
|||
|
||||
for font in fonts:
|
||||
for name, v in glyphorder.iteritems():
|
||||
if name in deleteNames:
|
||||
continue
|
||||
if name in visitedGlyphNames:
|
||||
continue
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@ from math import ceil, floor
|
|||
from robofab.objects.objectsRF import OpenFont
|
||||
from collections import OrderedDict
|
||||
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
|
||||
ufopath = ''
|
||||
|
|
@ -337,6 +341,17 @@ argparser.add_argument('glyphs', metavar='<glyphname>', type=str, nargs='*',
|
|||
|
||||
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):
|
||||
scale = float(args.scale)
|
||||
|
||||
|
|
@ -345,26 +360,26 @@ ufopath = args.ufopath.rstrip('/')
|
|||
font = OpenFont(ufopath)
|
||||
effectiveAscender = max(font.info.ascender, font.info.unitsPerEm)
|
||||
|
||||
srcdir = os.path.abspath(os.path.join(__file__, '..', '..'))
|
||||
|
||||
# print('\n'.join(font.keys()))
|
||||
# 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()
|
||||
glyphnameSet = set(glyphnames)
|
||||
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():
|
||||
if glyphName not in glyphnameSet:
|
||||
generatedGlyphNames.add(glyphName)
|
||||
glyphnames.append(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()
|
||||
|
||||
nameToIdMap, idToNameMap = genGlyphIDs(glyphnames)
|
||||
|
|
@ -387,7 +402,7 @@ for glyphname in glyphnames:
|
|||
svgtext = '\n'.join(svgLines)
|
||||
# print(svgtext)
|
||||
|
||||
glyphsHtmlFilename = os.path.join(srcdir, 'docs', 'glyphs', 'index.html')
|
||||
glyphsHtmlFilename = os.path.join(BASEDIR, 'docs', 'glyphs', 'index.html')
|
||||
|
||||
html = ''
|
||||
with open(glyphsHtmlFilename, 'r') as f:
|
||||
|
|
@ -425,7 +440,7 @@ with open(glyphsHtmlFilename, 'w') as f:
|
|||
f.write(html)
|
||||
|
||||
# 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())
|
||||
print('write', jsonFilenameRel)
|
||||
with open(jsonFilename, 'w') as f:
|
||||
|
|
|
|||
Reference in a new issue