Improvements to misc/rmglyph.py

This commit is contained in:
Rasmus Andersson 2017-09-24 19:19:39 -07:00
parent 958c0a58fd
commit d96bba86f1

View file

@ -13,6 +13,7 @@ import cleanup_kerning
dryRun = False dryRun = False
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
def readLines(filename): def readLines(filename):
@ -291,6 +292,32 @@ def updateFeaturesFile(filename, rmnames):
return didChange return didChange
def grep(filename, names):
hasPrintedFilename = False
relFilename = os.path.relpath(os.path.abspath(filename), BASEDIR)
findCount = 0
with open(filename, 'r') as f:
lineno = 1
for line in f:
foundNames = []
for name in names:
col = line.find(name)
if col != -1:
foundNames.append((name, lineno, col, line))
findCount += 1
if len(foundNames):
if not hasPrintedFilename:
print('%s:' % relFilename)
hasPrintedFilename = True
for name, lineno, col, line in foundNames:
line = line.strip()
if len(line) > 50:
line = line[:47] + '...'
print(' %s\t%d:%d\t%s' % (name, lineno, col, line))
lineno += 1
return findCount
def main(argv=None): def main(argv=None):
argparser = ArgumentParser( argparser = ArgumentParser(
@ -320,7 +347,6 @@ def main(argv=None):
args = argparser.parse_args(argv) args = argparser.parse_args(argv)
global dryRun global dryRun
dryRun = args.dryRun dryRun = args.dryRun
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
srcDir = os.path.join(BASEDIR, 'src') srcDir = os.path.join(BASEDIR, 'src')
# check if src font has modifications # check if src font has modifications
@ -476,12 +502,35 @@ def main(argv=None):
featuresChanged = updateFeaturesFile(featuresFile, rmnamesUnion) featuresChanged = updateFeaturesFile(featuresFile, rmnamesUnion)
# TMP for testing fuzzy
# rmnamesUnion = set()
# featuresChanged = False
# with open('_local/rmlog') as f:
# for line in f:
# line = line.strip()
# if len(line):
# rmnamesUnion.add(line)
print('\n————————————————————————————————————————————————————\n'+ print('\n————————————————————————————————————————————————————\n'+
'Removed %d glyphs:\n %s' % ( 'Removed %d glyphs:\n %s' % (
len(rmnamesUnion), '\n '.join(sorted(rmnamesUnion)))) len(rmnamesUnion), '\n '.join(sorted(rmnamesUnion))))
print('\n————————————————————————————————————————————————————\n') print('\n————————————————————————————————————————————————————\n')
# find possibly-missed instances
print('Fuzzy matches:')
fuzzyMatchCount = 0
fuzzyMatchCount += grep(diacriticsFile, rmnamesUnion)
fuzzyMatchCount += grep(configFilename, rmnamesUnion)
fuzzyMatchCount += grep(featuresFile, rmnamesUnion)
for fontPath in fontPaths:
fuzzyMatchCount += grep(os.path.join(fontPath, 'lib.plist'), rmnamesUnion)
if fuzzyMatchCount == 0:
print(' (none)\n')
else:
print('You may want to look into those ^\n')
if featuresChanged: if featuresChanged:
print('You need to manually edit features.\n'+ print('You need to manually edit features.\n'+
'- git diff src/features.fea\n'+ '- git diff src/features.fea\n'+