def generateTTFs(self): """Build TTF for each font generated since last call to generateTTFs.""" fonts = [OpenFont(ufo) for ufo in self.generatedFonts] self.generatedFonts = [] log(">> Converting curves to quadratic") # using a slightly higher max error (e.g. 0.0025 em), dots will have # fewer control points and look noticeably different max_err = 0.002 if self.compatible: fonts_to_quadratic(fonts, max_err_em=max_err, dump_stats=True) else: for font in fonts: fonts_to_quadratic([font], max_err_em=max_err, dump_stats=True) log(">> Generating TTF files") for font in fonts: ttfName = self.generateOutputPath(font, "ttf") log(os.path.basename(ttfName)) for glyph in font: for contour in glyph: contour.reverseContour() saveOTF( font, ttfName, self.thinGlyphOrder if "Thin" in ttfName else self.glyphOrder, truetype=True)
def run_all( self, glyphs_path, preprocess=True, interpolate=False, compatible=False, remove_overlaps=True, use_mti=False, gdef_path=None, gpos_path=None, gsub_path=None): """Run toolchain from Glyphs source to OpenType binaries.""" is_italic = 'Italic' in glyphs_path mti_feafiles = None if use_mti: mti_feafiles = { 'GDEF': gdef_path, 'GPOS': gpos_path, 'GSUB': gsub_path} if preprocess: print '>> Checking Glyphs source for illegal glyph names' glyphs_source = self.preprocess(glyphs_path) glyphs_path = 'tmp.glyphs' with open(glyphs_path, 'w') as fp: fp.write(glyphs_source) if interpolate: print '>> Interpolating master UFOs from Glyphs source' ufos = self.build_instances(glyphs_path, is_italic) else: print '>> Loading master UFOs from Glyphs source' ufos = self.build_masters(glyphs_path, is_italic) if preprocess: os.remove(glyphs_path) if remove_overlaps and not compatible: for ufo in ufos: print '>> Removing overlaps for ' + ufo.info.postscriptFullName self.remove_overlaps(ufo) for ufo in ufos: print '>> Saving OTF for ' + ufo.info.postscriptFullName self.save_otf( ufo, is_instance=interpolate, mti_feafiles=mti_feafiles, kern_writer=GlyphsKernWriter) start_t = time() if compatible: print '>> Converting curves to quadratic' fonts_to_quadratic(ufos, dump_stats=True) else: for ufo in ufos: print '>> Converting curves for ' + ufo.info.postscriptFullName fonts_to_quadratic([ufo], dump_stats=True) t = time() - start_t print '[took %f seconds]' % t for ufo in ufos: print '>> Saving TTF for ' + ufo.info.postscriptFullName self.save_ttf( ufo, is_instance=interpolate, mti_feafiles=mti_feafiles, kern_writer=GlyphsKernWriter)
def run_all(self, glyphs_path, interpolate=False, compatible=False, remove_overlaps=True, preprocess=True): """Run toolchain from Glyphs source to OpenType binaries.""" is_italic = 'Italic' in glyphs_path if preprocess: print '>> Checking Glyphs source for illegal glyph names' glyphs_source = self.preprocess(glyphs_path) glyphs_path = 'tmp.glyphs' with open(glyphs_path, 'w') as fp: fp.write(glyphs_source) if interpolate: print '>> Interpolating master UFOs from Glyphs source' ufos = self.build_instances(glyphs_path, is_italic) else: print '>> Loading master UFOs from Glyphs source' ufos = self.build_masters(glyphs_path, is_italic) if preprocess: os.remove(glyphs_path) if remove_overlaps and not compatible: for ufo in ufos: print '>> Removing overlaps for ' + ufo.info.postscriptFullName self.remove_overlaps(ufo) for ufo in ufos: print '>> Saving OTF for ' + ufo.info.postscriptFullName self.save_otf(ufo, is_instance=interpolate, kern_writer=GlyphsKernWriter) start_t = time() if compatible: print '>> Converting curves to quadratic' fonts_to_quadratic(ufos, dump_stats=True) else: for ufo in ufos: print '>> Converting curves for ' + ufo.info.postscriptFullName fonts_to_quadratic([ufo], dump_stats=True) t = time() - start_t print '[took %f seconds]' % t for ufo in ufos: print '>> Saving TTF for ' + ufo.info.postscriptFullName self.save_ttf(ufo, is_instance=interpolate, kern_writer=GlyphsKernWriter)
def run_from_ufos( self, ufos, compatible=False, remove_overlaps=True, mti_source=None, **kwargs): """Run toolchain from UFO sources to OpenType binaries.""" if isinstance(ufos, str): ufos = glob.glob(ufos) if isinstance(ufos[0], str): ufos = [OpenUfo(ufo) for ufo in ufos] if remove_overlaps and not compatible: for ufo in ufos: print '>> Removing overlaps for ' + self._font_name(ufo) self.remove_overlaps(ufo) mti_paths = {} if mti_source: mti_paths = plistlib.readPlist(mti_source) src_dir = os.path.dirname(mti_source) for paths in mti_paths.values(): for table in ('GDEF', 'GPOS', 'GSUB'): paths[table] = os.path.join(src_dir, paths[table]) for ufo in ufos: name = self._font_name(ufo) print '>> Saving OTF for ' + name self.save_otf(ufo, mti_feafiles=mti_paths.get(name), **kwargs) start_t = time() if compatible: print '>> Converting curves to quadratic' fonts_to_quadratic(ufos, dump_stats=True) else: for ufo in ufos: print '>> Converting curves for ' + self._font_name(ufo) fonts_to_quadratic([ufo], dump_stats=True) t = time() - start_t print '[took %f seconds]' % t for ufo in ufos: name = self._font_name(ufo) print '>> Saving TTF for ' + name self.save_otf( ufo, ttf=True, mti_feafiles=mti_paths.get(name), **kwargs)