def fix_name_ascii(font_path, log=None): """ Replacing non ascii names in copyright """ SCRIPTPATH = os.path.join(app.config['ROOT'], 'scripts', 'ascii.py') command = "{0} {1} {2}".format(PYPATH, SCRIPTPATH, font_path) logging(log, command) fix_name_table(font_path) shutil.move(font_path + '.fix', font_path, log=log)
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 fix_fstype_to_zero(font_path, log=None): """ Fix fsType to zero """ SCRIPTPATH = os.path.join(app.config['ROOT'], 'scripts', 'fstype.py') command = "{0} {1} --autofix {2}".format(PYPATH, SCRIPTPATH, font_path) logging(log, command) reset_fstype(font_path) shutil.move(font_path + '.fix', font_path, log=log)
def movebin_to_builddir(self, builddir, files): result = [] for a in files: d = op.join(builddir, op.basename(a)[:-4] + '.ttf') s = op.join(builddir, a[:-4] + '.ttf') shellutil.move(s, d, log=self.stdout_pipe) result.append(op.basename(a)[:-4] + '.ttf') return result
def fix_ttf_stylenames(font_path, log=None): """ Fix style names """ SCRIPTPATH = os.path.join(app.config['ROOT'], 'scripts', 'stylenames.py') command = "{0} {1} --autofix {2}".format(PYPATH, SCRIPTPATH, font_path) logging(log, command) fix_style_names(font_path) shutil.move(font_path + '.fix', font_path, log=log)
def fix_nbsp(font_path, log=None): """ Fix width for space and nbsp """ SCRIPTPATH = os.path.join(app.config['ROOT'], 'scripts', 'nbsp.py') command = "{0} {1} {2}".format(PYPATH, SCRIPTPATH, font_path) logging(log, command) checkAndFix(font_path) command = "mv {0}.fix {0}".format(font_path) logging(log, command) shutil.move(font_path + '.fix', font_path, log=log)
def after_copy(self, builddir): out_name = self.postscript_fontname + '.ttf' self.compile_ttx(builddir) if self.source.sfntVersion == 'OTTO': # OTF self.convert_otf2ttf(builddir) # If TTF already, move it up else: try: shutil.move(op.join(builddir, 'sources', out_name), op.join(builddir, out_name), log=self.stdout_pipe) except (OSError, IOError): pass
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 execute_pyftsubset(self, pipedata, subsetname, name, glyphs="", args=""): from fontTools import subset argv = [op.join(self.builddir, name)] + glyphs.split() # argv += ['--notdef-outline', '--name-IDs="*"', '--hinting'] override_argv = [] if pipedata.get('pyftsubset'): override_argv = pipedata['pyftsubset'].split() if pipedata.get('pyftsubset.%s' % subsetname): override_argv = pipedata['pyftsubset.%s' % subsetname].split() argv = argv + override_argv subset.main(argv) self.stdout_pipe.write('$ pyftsubset %s' % ' '.join(argv)) # need to move result .subset file to avoid overwrite with # next subset shutil.move(op.join(self.builddir, name) + '.subset', op.join(self.builddir, name)[:-4] + '.' + subsetname, log=self.stdout_pipe)
def execute(self, pipedata, prefix=""): rename_executed = False newfiles = [] for i, filepath in enumerate(pipedata['bin_files']): path = op.join(self.builddir, filepath) font = ttLib.TTFont(path) psname = self.get_psname(font) if psname: if op.basename(path) != psname: if not rename_executed: self.stdout_pipe.write('Rename built files with PS Naming', prefix='### %s ' % prefix) rename_executed = True shutil.move(path, op.join(op.dirname(path), psname), log=self.stdout_pipe) newfiles.append(filepath.replace(op.basename(filepath), psname)) else: newfiles.append(filepath) pipedata['bin_files'] = newfiles return pipedata
def fix_metrics(path, log=None): """ Fix vmet table with actual min and max values """ SCRIPTPATH = os.path.join(app.config['ROOT'], 'scripts', 'vmet.py') from checker.metadata import FamilyMetadata family_metadata = FamilyMetadata(json.load(open(path))) paths = [] for f in family_metadata.fonts: path = op.join(op.dirname(path), f.filename) paths.append(path) command = "{0} {1} --autofix {2}" command = command.format(PYPATH, SCRIPTPATH, ' '.join(paths)) logging(log, command) metricfix(paths) for font_path in paths: shutil.move(font_path + '.fix', font_path, log=log) command = "{0} {1} {2}".format(PYPATH, SCRIPTPATH, ' '.join(paths)) logging(log, command) log.write(metricview(paths))