def processFont(self, filepath): # extension = filepath[filepath.rindex('.'):] ftFont = None print print 'filepath', filepath leftSideBearings = [] rightSideBearings = [] try: ftFont = TFFreetypeFont(filepath) postscript_name = ftFont.postscriptName if postscript_name in self.processedPostscriptNames: return glyphIndexToCharacterMap = ftFont.getGlyphIndexToCharacterMap() # print '\t', 'postscript_name', postscript_name self.processedPostscriptNames.add(postscript_name) # characterToGlyphIndexMap = ftFont.getCharacterToGlyphIndexMap() for glyphIndex in ftFont.getGlyphIndices(): if glyphIndex not in glyphIndexToCharacterMap: continue unicode = glyphIndexToCharacterMap[glyphIndex] if unicode > 0x7f: ''' ignore code points not in first code block. ''' continue contours, xAdvance = ftFont.getGlyphContours(glyphIndex) if len(contours) < 1: ''' Ignore empty glyphs. ''' continue minmax = minmaxPaths(contours) leftSideBearing = minmax.minX rightSideBearing = xAdvance - minmax.maxX leftSideBearings.append(leftSideBearing) rightSideBearings.append(rightSideBearing) except Exception, e: print 'error filepath', filepath print e.message traceback.print_exc() del ftFont return
def convertFont(self): ftFont = TFFreetypeFont(self.src_file) ufoFont = self.createUfo(ftFont) ufoFont = TFSFont(ufoFont) glyphInfos = ftFont.getGlyphInfos() convertedGlyphIndices = set() for glyphInfo in glyphInfos: self.convertGlyph(ftFont, ufoFont, glyphInfo) convertedGlyphIndices.add(glyphInfo.glyphIndex) for glyphIndex in ftFont.getGlyphIndices(): if glyphIndex not in convertedGlyphIndices: print 'Could not convert glyph', glyphIndex self.convertKerning(ftFont, ufoFont, glyphInfos) ufoFont.update() ufoFont.save(self.dst_file) ufoFont.close()