From d96bba86f19f2cb212aaad5458e80132c598cecf Mon Sep 17 00:00:00 2001 From: Rasmus Andersson Date: Sun, 24 Sep 2017 19:19:39 -0700 Subject: Improvements to misc/rmglyph.py --- misc/rmglyph.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'misc') diff --git a/misc/rmglyph.py b/misc/rmglyph.py index f7b0489c4..3b5c41238 100755 --- a/misc/rmglyph.py +++ b/misc/rmglyph.py @@ -13,6 +13,7 @@ import cleanup_kerning dryRun = False +BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) def readLines(filename): @@ -291,6 +292,32 @@ def updateFeaturesFile(filename, rmnames): 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): argparser = ArgumentParser( @@ -320,7 +347,6 @@ def main(argv=None): args = argparser.parse_args(argv) global dryRun dryRun = args.dryRun - BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) srcDir = os.path.join(BASEDIR, 'src') # check if src font has modifications @@ -476,12 +502,35 @@ def main(argv=None): 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'+ 'Removed %d glyphs:\n %s' % ( len(rmnamesUnion), '\n '.join(sorted(rmnamesUnion)))) 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: print('You need to manually edit features.\n'+ '- git diff src/features.fea\n'+ -- cgit v1.2.3