def process(self, useProductionNames=True, optimizeCff=True): if useProductionNames: self._rename_glyphs_from_ufo() if optimizeCff and 'CFF ' in self.otf: from compreffor import compress compress(self.otf) return self.otf
def main(args=None): log = compreffor.log timer = compreffor.timer timer.reset() options = parse_arguments(args) # consume kwargs that are not passed on to 'compress' function infile = options.pop('infile') outfile = options.pop('outfile') decompress = options.pop('decompress') generate_cff = options.pop('generate_cff') check = options.pop('check') verbose = options.pop('verbose') if verbose == 1: level = logging.INFO elif verbose > 1: level = logging.DEBUG else: level = logging.WARNING configLogger(logger=log, level=level) orig_size = os.path.getsize(infile) font = TTFont(infile) if decompress: log.info("Decompressing font with FontTools Subsetter") with timer("decompress the font"): compreffor.decompress(font) log.info("Compressing font through %s Compreffor", "pure-Python" if options['method_python'] else "C++") compreffor.compress(font, **options) with timer("compile and save compressed font"): font.save(outfile) if generate_cff: cff_file = os.path.splitext(outfile)[0] + ".cff" with open(cff_file, 'wb') as f: font['CFF '].cff.compile(f, None) log.info("Saved CFF data to '%s'" % os.path.basename(cff_file)) if check: log.info("Checking compression integrity and call depth") passed = compreffor.check(infile, outfile) if not passed: return 1 comp_size = os.path.getsize(outfile) log.info("Compressed to '%s' -- saved %s" % (os.path.basename(outfile), human_size(orig_size - comp_size))) log.debug("Total time: %gs", timer.time())
def _subroutinize_with_compreffor(cls, otf, cffVersion): from compreffor import compress if cls._get_cff_version(otf) != CFFVersion.CFF or cffVersion != CFFVersion.CFF: raise NotImplementedError( "Only 'CFF ' 1.0 is supported by compreffor; try using cffsubr" ) logger.info("Subroutinizing CFF table with compreffor") compress(otf)
def process(self, useProductionNames=None, optimizeCFF=True): """ useProductionNames: By default, when value is None, this will rename glyphs using the 'public.postscriptNames' in then UFO lib. If the mapping is not present, no glyph names are renamed. If the value is False, no glyphs are renamed whether or not the 'public.postscriptNames' mapping is present. If the value is True, but no 'public.postscriptNames' are present, then uniXXXX names are generated from the glyphs' unicode. The 'com.github.googlei18n.ufo2ft.useProductionNames' key can be set in the UFO lib to control this parameter (plist boolean value). For legacy reasons, an alias key (with an inverted meaning) is also supported: "com.schriftgestaltung.Don't use Production Names"; when this is present if the UFO lib and is set to True, this is equivalent to 'useProductionNames' set to False. optimizeCFF: Run compreffor to subroubtinize CFF table, if present. """ if useProductionNames is None: useProductionNames = self.ufo.lib.get( USE_PRODUCTION_NAMES, not self.ufo.lib.get(GLYPHS_DONT_USE_PRODUCTION_NAMES) and self._postscriptNames is not None, ) if useProductionNames: logger.info("Renaming glyphs to final production names") self._rename_glyphs_from_ufo() if optimizeCFF and "CFF " in self.otf: from compreffor import compress logger.info("Subroutinizing CFF table") compress(self.otf) return self.otf