def _optimize(self, otf, name, fmt): if fmt == Format.OTF: import cffsubr from fontTools.cffLib.specializer import specializeProgram logger.info(f"Optimizing {name}.{fmt.value}") topDict = otf["CFF "].cff.topDictIndex[0] charStrings = topDict.CharStrings for charString in charStrings.values(): charString.decompile() charString.program = specializeProgram(charString.program) logger.info(f"Subroutinizing {name}.{fmt.value}") cffsubr.subroutinize(otf, keep_glyph_names=False) return otf
def test_blend_round_trip(self): ttx_path = self.getpath('TestSparseCFF2VF.ttx') ttf_font = TTFont(recalcBBoxes=False, recalcTimestamp=False) ttf_font.importXML(ttx_path) fontGlyphList = ttf_font.getGlyphOrder() topDict = ttf_font['CFF2'].cff.topDictIndex[0] charstrings = topDict.CharStrings for glyphName in fontGlyphList: cs = charstrings[glyphName] cs.decompile() cmds = programToCommands(cs.program, getNumRegions=cs.getNumRegions) cmds_g = generalizeCommands(cmds) cmds = specializeCommands(cmds_g, generalizeFirst=False) program = commandsToProgram(cmds) self.assertEqual(program, cs.program) program = specializeProgram(program, getNumRegions=cs.getNumRegions) self.assertEqual(program, cs.program) program_g = generalizeProgram(program, getNumRegions=cs.getNumRegions) program = commandsToProgram(cmds_g) self.assertEqual(program, program_g)
def test_blend_round_trip(self): ttx_path = self.getpath('TestSparseCFF2VF.ttx') ttf_font = TTFont(recalcBBoxes=False, recalcTimestamp=False) ttf_font.importXML(ttx_path) fontGlyphList = ttf_font.getGlyphOrder() topDict = ttf_font['CFF2'].cff.topDictIndex[0] charstrings = topDict.CharStrings for glyphName in fontGlyphList: cs = charstrings[glyphName] cs.decompile() cmds = programToCommands(cs.program, getNumRegions=cs.getNumRegions) cmds_g = generalizeCommands(cmds) cmds = specializeCommands(cmds_g, generalizeFirst=False) program = commandsToProgram(cmds) self.assertEqual(program, cs.program) program = specializeProgram(program, getNumRegions=cs.getNumRegions) self.assertEqual(program, cs.program) program_g = generalizeProgram(program, getNumRegions=cs.getNumRegions) program = commandsToProgram(cmds_g) self.assertEqual(program, program_g)
def test_blend_round_trip(self): otfvf_path = self.get_test_input('TestSparseCFF2VF.otf') ttf_font = TTFont(otfvf_path) fontGlyphList = ttf_font.getGlyphOrder() topDict = ttf_font['CFF2'].cff.topDictIndex[0] charstrings = topDict.CharStrings for glyphName in fontGlyphList: print(glyphName) cs = charstrings[glyphName] cs.decompile() cmds = programToCommands(cs.program, getNumRegions=cs.getNumRegions) cmds_g = generalizeCommands(cmds) cmds = specializeCommands(cmds_g, generalizeFirst=False) program = commandsToProgram(cmds) self.assertEqual(program, cs.program) program = specializeProgram(program, getNumRegions=cs.getNumRegions) self.assertEqual(program, cs.program) program_g = generalizeProgram(program, getNumRegions=cs.getNumRegions) program = commandsToProgram(cmds_g) self.assertEqual(program, program_g)
def get_specialized_charstr(charstr, **kwargs): return programToString( specializeProgram(stringToProgram(charstr), **kwargs))
def get_specialized_charstr(charstr, **kwargs): return programToString(specializeProgram(stringToProgram(charstr), **kwargs))