MCPcopy
hub / github.com/rsms/inter / main

Function main

misc/tools/gen-glyphorder.py:39–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37
38
39def main():
40 argparser = ArgumentParser(description='Generate glyph order list from UFO files')
41 argparser.add_argument('fontPaths', metavar='<ufofile>', type=str, nargs='+', help='UFO files')
42 args = argparser.parse_args()
43
44 srcDir = os.path.join(BASEDIR, 'src')
45
46 # load fontbuild config
47 config = RawConfigParser(dict_type=OrderedDict)
48 config.read(os.path.join(srcDir, 'fontbuild.cfg'))
49 deleteNames = set(config.get('glyphs', 'delete').split())
50
51 fontPaths = []
52 for fontPath in args.fontPaths:
53 if 'regular' or 'Regular' in fontPath:
54 fontPaths = [fontPath] + fontPaths
55 else:
56 fontPaths.append(fontPath)
57
58 fontPath0 = args.fontPaths[0]
59 libPlist = plistlib.readPlist(os.path.join(fontPath, 'lib.plist'))
60 glyphOrder = libPlist['public.glyphOrder']
61 glyphNameSet = set(glyphOrder)
62
63 nameLists = []
64 indexOffset = 0
65 index = -1
66
67 for fontPath in fontPaths[1:]:
68 libPlist = plistlib.readPlist(os.path.join(fontPath, 'lib.plist'))
69 if 'public.glyphOrder' in libPlist:
70 names = libPlist['public.glyphOrder']
71 numInserted = 0
72 for i in range(len(names)):
73 name = names[i]
74 if name not in glyphNameSet:
75 if i > 0 and names[i-1] in glyphNameSet:
76 # find position of prev glyph
77 index = glyphOrder.index(names[i-1]) + 1
78 elif index != -1:
79 index += 1
80 else:
81 index = min(len(glyphOrder), i - indexOffset)
82
83 glyphOrder.insert(index, name)
84 numInserted += 1
85 glyphNameSet.add(name)
86
87 indexOffset += numInserted
88
89 # add any composed glyphs to the end
90 diacriticComps = loadGlyphCompositions(os.path.join(srcDir, 'diacritics.txt'))
91 for name in diacriticComps.keys():
92 if name not in glyphNameSet:
93 glyphOrder.append(name)
94
95 # filter out deleted glyphs
96 glyphOrder = [n for n in glyphOrder if n not in deleteNames]

Callers 1

gen-glyphorder.pyFile · 0.70

Calls 3

addMethod · 0.80
loadGlyphCompositionsFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…