def run_processes(self, filename, pipedata): from bakery_cli.pipe.fontlint import FontLint from bakery_cli.pipe.pyftsubset import PyFtSubset from bakery_cli.pipe.optimize import Optimize from bakery_cli.pipe.ttfautohint import TTFAutoHint from bakery_cli.pipe.font_crunch import FontCrunch from bakery_cli.utils import ProcessedFile processedfile = ProcessedFile() processedfile.filepath = filename fontlint = FontLint(self.bakery) fontlint.run(pipedata) optimize = Optimize(self.bakery) optimize.run(pipedata) ttfautohint = TTFAutoHint(self.bakery) ttfautohint.run(pipedata) pyftsubset = PyFtSubset(self.bakery) pyftsubset.run(pipedata) fontcrunch = FontCrunch(self.bakery) fontcrunch.run(pipedata)
def run(self, pipedata): # create menu subset with glyph for text of family name if pipedata.get('pyftsubset') is False: return from bakery_cli.utils import ProcessedFile name = ProcessedFile() self.bakery.logging_raw( '### Subset TTFs (pyftsubset) {}\n'.format(name)) ttfont = ttLib.TTFont(op.join(self.builddir, name)) L = map(lambda X: (X.nameID, X.string), ttfont['name'].names) D = dict(L) string = bin2unistring(D.get(16) or D.get(1)) menu_glyphs = '\n'.join(['U+%04x' % ord(c) for c in string]) for subset in pipedata.get('subset', []): glyphs = SubsetExtension.get_glyphs(subset) # The every subsets must include the "latin" subset if subset != 'latin': glyphs += '\n{}'.format(SubsetExtension.get_glyphs('latin')) self.execute_pyftsubset(pipedata, subset, name, glyphs=glyphs) # If any subset other than latin or latin-ext has been # generated when the subsetting is done, this string should # additionally include some characters corresponding to each # of those subsets. G = SubsetExtension.get_glyphs(subset + '-menu') if G: menu_glyphs += '\n{}'.format(G) self.execute_pyftsubset(pipedata, 'menu', name, glyphs=menu_glyphs)
def fix(self): newfilename = self.validate() new_targetpath = os.path.join(os.path.dirname(self.fontpath), newfilename) shutil.move(self.fontpath, new_targetpath) from bakery_cli.logger import logger logger.info('$ mv {} {}'.format(self.fontpath, os.path.basename(new_targetpath))) self.testcase.operator.path = new_targetpath from bakery_cli.utils import ProcessedFile f = ProcessedFile() f.filepath = newfilename self.save_after_fix = False return True
def run(self, pipedata): if 'optimize' in pipedata and not pipedata['optimize']: return from bakery_cli.utils import ProcessedFile filename = ProcessedFile() self.bakery.logging_raw('### Optimize TTF {}'.format(filename)) # copied from https://code.google.com/p/noto/source/browse/nototools/subset.py from fontTools.subset import Options, Subsetter, load_font, save_font options = Options() options.layout_features = ["*"] options.name_IDs = ["*"] options.hinting = True options.legacy_kern = True options.notdef_outline = True options.no_subset_tables += ['DSIG'] options.drop_tables = list( set(options._drop_tables_default) - set(['DSIG'])) cmd_options = ('--glyphs=*' ' --layout-features=*' ' --name-IDs=*' ' --hinting' ' --legacy-kern --notdef-outline' ' --no-subset-tables+=DSIG' ' --drop-tables-=DSIG') font = load_font(op.join(self.builddir, filename), options) cmdline = 'pyftsubset {1} {0}'.format(cmd_options, op.join(self.builddir, filename)) self.bakery.logging_cmd(cmdline) subsetter = Subsetter(options=options) subsetter.populate(glyphs=font.getGlyphOrder()) subsetter.subset(font) save_font(font, op.join(self.builddir, filename + '.fix'), options) # compare filesizes TODO print analysis of this :) comment = "# look at the size savings of that subset process" self.bakery.logging_cmd(comment) run(u"ls -la {0} {0}.fix | awk '{{ print $5 \"\t\" $9 }}'".format( unicode(op.join(self.builddir, filename)))) comment = "# copy back optimized ttf to original filename" self.bakery.logging_cmd(comment) shutil.move(op.join(self.builddir, filename + '.fix'), op.join(self.builddir, filename))
def run(self, pipedata): try: from fontcrunch import fontcrunch except ImportError: self.bakery.logging_raw( 'Fontcruch is not installed. Please `pip install fontcrunch`') return if not pipedata.get('fontcrunch'): return # run fontcrunch only if user set flag in config from bakery_cli.utils import ProcessedFile filename = ProcessedFile() filename = os.path.join(self.builddir, filename) self.bakery.logging_raw('### Fontcrunch {}\n'.format(filename)) fontcrunch.optimize(filename, '{}.crunched'.format(filename)) shutil.move('{}.crunched'.format(filename), filename) return 1
def run(self, pipedata): if not pipedata.get('ttfautohint', '') or not ttfautohint_installed(): return False from bakery_cli.utils import ProcessedFile filepath = ProcessedFile() self.bakery.logging_raw( '### Autohint TTFs (ttfautohint) {}\n'.format(filepath)) params = pipedata['ttfautohint'] filepath = op.join(self.project_root, self.builddir, filepath) cmd = ("ttfautohint {params} {name}" " '{name}.fix'").format(params=params.strip(), name=filepath) try: run(cmd, cwd=self.builddir) except: return False if 'autohinting_sizes' not in pipedata: pipedata['autohinting_sizes'] = [] origsize = op.getsize(filepath) autohintsize = op.getsize(filepath + '.fix') pipedata['autohinting_sizes'].append({ 'fontname': op.basename(filepath), 'origin': origsize, 'processed': autohintsize }) # compare filesizes TODO print analysis of this :) comment = "# look at the size savings of that subset process" run("ls -la {0} {0}.fix | awk '{{ print $5 \"\t\" $9 }}'".format( filepath)) comment = "# copy back optimized ttf to original filename" self.bakery.logging_cmd(comment) shutil.move(filepath + '.fix', filepath) return 1