def execute(self, pipedata, prefix=""): self.stdout_pipe.write('Optimizing TTF', prefix='### %s ' % prefix) for filename in pipedata['bin_files']: # convert the ttf to a ttx file - this may fail font = fontforge.open(op.join(self.builddir, filename)) glyphs = [] for g in font.glyphs(): if not g.codepoint: continue glyphs.append(g.codepoint) from fontTools import subset args = [op.join(self.builddir, filename)] + glyphs args += ['--layout-features="*"'] subset.main(args) self.stdout_pipe.write('$ pyftsubset %s' % ' '.join(args)) # compare filesizes TODO print analysis of this :) comment = "# look at the size savings of that subset process" cmd = "ls -l '%s'* %s" % (filename, comment) run(cmd, cwd=self.builddir, log=self.stdout_pipe) # move ttx files to src shutil.move(op.join(self.builddir, filename + '.subset'), op.join(self.builddir, filename), log=self.stdout_pipe)
def optimize_ttx(self, builddir): filename = self.postscript_fontname # convert the ttf to a ttx file - this may fail font = fontforge.open(op.join(builddir, filename) + '.ttf') glyphs = [] for g in font.glyphs(): if not g.codepoint: continue glyphs.append(g.codepoint) from fontTools import subset args = [op.join(builddir, filename) + '.ttf'] + glyphs # args += ['--notdef-outline', '--name-IDs="*"', '--hinting'] subset.main(args) self.stdout_pipe.write(' '.join(args)) # compare filesizes TODO print analysis of this :) cmd = "ls -l '%s.ttf'*" % filename run(cmd, cwd=builddir, log=self.stdout_pipe) # move ttx files to src shutil.move(op.join(builddir, filename + '.ttf.subset'), op.join(builddir, filename + '.ttf'), log=self.stdout_pipe)
def optimize(self, builddir): filename = self.postscript_fontname # convert the ttf to a ttx file - this may fail font = fontforge.open(op.join(builddir, filename) + '.ttf') glyphs = [] for g in font.glyphs(): if not g.codepoint: continue glyphs.append(g.codepoint) from fontTools import subset args = [op.join(builddir, filename) + '.ttf'] + glyphs args += ['--layout-features="*"'] subset.main(args) self.stdout_pipe.write('$ pyftsubset %s' % ' '.join(args)) # compare filesizes TODO print analysis of this :) comment = "# look at the size savings of that subset process" cmd = "ls -l '%s.ttf'* %s" % (filename, comment) run(cmd, cwd=builddir, log=self.stdout_pipe) # move ttx files to src shutil.move(op.join(builddir, filename + '.ttf.subset'), op.join(builddir, filename + '.ttf'), log=self.stdout_pipe)
def execute(self, pipedata, prefix=""): """ Run ttfautohint with project command line settings For each ttf file in result src folder, outputting them in the _out root, or just copy the ttfs there. """ # $ ttfautohint -l 7 -r 28 -G 0 -x 13 -w "" \ # -W -c original_font.ttf final_font.ttf params = pipedata.get('ttfautohint', '') if not params: return pipedata self.stdout_pipe.write('Autohint TTFs (ttfautohint)\n', prefix='### %s ' % prefix) if 'autohinting_sizes' not in pipedata: pipedata['autohinting_sizes'] = [] for filepath in pipedata['bin_files']: filepath = op.join(self.project_root, self.builddir, filepath) cmd = ("ttfautohint {params} {source}" " '{name}.autohint.ttf'").format(params=params.strip(), name=filepath[:-4], source=filepath) try: run(cmd, cwd=self.builddir, log=self.stdout_pipe) except: self.stdout_pipe.write('TTFAutoHint is not available\n', prefix="### Error:") break pipedata['autohinting_sizes'].append({ 'fontname': op.basename(filepath), 'origin': op.getsize(filepath), 'processed': op.getsize(filepath[:-4] + '.autohint.ttf') }) # compare filesizes TODO print analysis of this :) comment = "# look at the size savings of that subset process" cmd = "ls -l %s.*ttf %s" % (filepath[:-4], comment) run(cmd, cwd=self.builddir, log=self.stdout_pipe) shellutil.move(filepath[:-4] + '.autohint.ttf', filepath, log=self.stdout_pipe) return pipedata
def compile_ttx(self, builddir): run("ttx {}.ttx".format(self.postscript_fontname), cwd=op.join(builddir, 'sources'), log=self.stdout_pipe)