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

Function main

misc/tools/restore-diacritics-kerning.py:219–429  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

217
218
219def main():
220 argparser = ArgumentParser(description='Restore lost kerning')
221
222 argparser.add_argument(
223 '-dry', dest='dryRun', action='store_const', const=True, default=False,
224 help='Do not modify anything, but instead just print what would happen.')
225
226 argparser.add_argument(
227 'srcFont', metavar='<fontfile>', type=str,
228 help='TrueType, OpenType or UFO fonts to gather glyph info from')
229
230 argparser.add_argument(
231 'diffFile', metavar='<diffile>', type=str, help='Diff file')
232
233 args = argparser.parse_args()
234
235 dryRun = args.dryRun
236
237 agl = parseAGL('src/glyphlist.txt')
238 diacriticComps = loadGlyphCompositions('src/diacritics.txt')
239
240 altUc2names, altName2ucs = loadAltNamesDB(agl, args.srcFont)
241 localUc2Names, localName2ucs = loadLocalNamesDB(agl, diacriticComps)
242
243 canonicalGlyphName = lambda name: _canonicalGlyphName(
244 name, localName2ucs, localUc2Names, altName2ucs)
245
246 deletedNames = loadNamesFromDiff(args.diffFile) # 10e15297b.diff
247 deletedDiacriticNames = OrderedDict()
248
249 for glyphName, comp in diacriticComps.iteritems():
250 if glyphName in deletedNames:
251 deletedDiacriticNames[glyphName] = comp
252
253
254 for fontPath in srcFontPaths:
255 addedGroupNames = set()
256
257 oldFilenamePrefix = 'regular'
258 if fontPath.find('Bold') != -1:
259 oldFilenamePrefix = 'bold'
260 oldGroups, oldNameToGroups = loadGroups(
261 oldFilenamePrefix + '-groups.plist')
262 oldKerning, oldLIndex, oldRIndex, oldRGroupIndex = loadKerning(
263 oldFilenamePrefix + '-kerning.plist')
264 # lIndex : { name => <ref to plist right-hand side dict> }
265 # rIndex : { name => [(left-hand-side-name, kernVal), ...] }
266
267 currGroupFilename = os.path.join(fontPath, 'groups.plist')
268 currKerningFilename = os.path.join(fontPath, 'kerning.plist')
269 currGroups, currNameToGroups = loadGroups(currGroupFilename)
270 currKerning, currLIndex, currRIndex, currRGroupIndex = loadKerning(currKerningFilename)
271
272 for glyphName, comp in deletedDiacriticNames.iteritems():
273 oldGroupMemberships = oldNameToGroups.get(glyphName)
274 localGlyphName, localUc = canonicalGlyphName(glyphName)
275
276 # if glyphName != 'dcaron':

Callers 1

Calls 11

loadAltNamesDBFunction · 0.85
_canonicalGlyphNameFunction · 0.85
loadNamesFromDiffFunction · 0.85
loadGroupsFunction · 0.85
loadKerningFunction · 0.85
addMethod · 0.80
parseAGLFunction · 0.70
loadGlyphCompositionsFunction · 0.70
loadLocalNamesDBFunction · 0.70
canonicalGlyphNameFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…