def extractUFO(pathOrFile, destination, doGlyphs=True, doInfo=True, doKerning=True, format=None, customFunctions={}): if format is None: format = extractFormat(pathOrFile) if format not in _extractFunctions: raise ExtractorError("Unknown file format.") func = _extractFunctions[format] # wrap the extraction in a try: except: so that # callers don't need to worry about lower level # (fontTools, etc.) errors. if an error # occurs, print the traceback for debugging and # raise an ExtractorError. try: func(pathOrFile, destination, doGlyphs=doGlyphs, doInfo=doInfo, doKerning=doKerning, customFunctions=customFunctions.get(format, [])) except: import sys import traceback traceback.print_exc(file=sys.stdout) raise ExtractorError("There was an error reading the %s file." % format)
def _validateClasses(classes): """ Check to make sure that a glyph is not part of more than one class. If this is found, an ExtractorError is raised. """ glyphToClass = {} for className, glyphList in classes.items(): for glyphName in glyphList: if glyphName not in glyphToClass: glyphToClass[glyphName] = set() glyphToClass[glyphName].add(className) for glyphName, groupList in glyphToClass.items(): if len(groupList) > 1: raise ExtractorError( "Kerning classes are in an conflicting state.")
def _extractOpenTypeKerningFromKern(source): kern = source["kern"] kerning = {} for subtable in kern.kernTables: if subtable.version != 0: raise ExtractorError("Unknown kern table formst: %d" % subtable.version) # XXX the spec defines coverage values for # kerning direction (horizontal or vertical) # minimum (some sort of kerning restriction) # cross-stream (direction of the kerns within the direction of the table. odd.) # override (if the values in this subtable should override the values of others) # however, it is vague about how these should be stored. # as such, we just assume that the direction is horizontal, # that the values of all subtables are additive and that # there are no minimum values. kerning.update(subtable.kernTable) return kerning
def _validateClasses(classes): """ Check to make sure that a glyph is not part of more than one class. If this is found, an ExtractorError is raised. """ glyphToClass = {} for className, glyphList in classes.items(): for glyphName in glyphList: if glyphName not in glyphToClass: glyphToClass[glyphName] = set() glyphToClass[glyphName].add(className) conflicts = 0 for glyphName, groupList in glyphToClass.items(): if len(groupList) > 1: print('Conflicting kerning classes for %s:' % glyphName) for groupId in groupList: group = classes[groupId] print(' %r => %s' % (groupId, ', '.join(group))) conflicts += 1 if conflicts > 0: raise ExtractorError("Kerning classes are in an conflicting state")