def execute_ufo_sfd(self, files, pipedata): _ = 'fontbakery-build-font2ttf.py %s %s' for filepath in files: ttfpath = os.path.basename(filepath)[:-4] + '.ttf' try: if self.bakery.config.get('compiler') == 'afdko': import time starttime = time.time() command = 'makeotf -f {0} {1} -o {2}.otf'.format(op.join(self.builddir, filepath), self.bakery.config.get('afdko', ''), op.join(self.builddir, filepath)[:-4]) self.bakery.logging_cmd(op.join(self.builddir, op.dirname(filepath))) run(command, op.join(self.builddir, op.dirname(filepath))) elapsedtime = time.time() - starttime self.bakery.logging_raw('Time elapsed: {}'.format(elapsedtime)) self.otf2ttf('{}.otf'.format(filepath[:-4]), pipedata) else: self.bakery.logging_cmd(_ % (filepath, ttfpath)) convert(op.join(self.builddir, filepath), op.join(self.builddir, ttfpath)) self.run_processes(op.basename(ttfpath), pipedata) except Exception as ex: self.bakery.logging_err(ex.message) raise
def execute_ufo_sfd(self, files, pipedata): _ = 'fontbakery-build-font2ttf.py %s %s' for filepath in files: ttfpath = os.path.basename(filepath)[:-4] + '.ttf' try: if self.bakery.config.get('compiler') == 'afdko': import time starttime = time.time() command = 'makeotf -f {0} {1} -o {2}.otf'.format( op.join(self.builddir, filepath), self.bakery.config.get('afdko', ''), op.join(self.builddir, filepath)[:-4]) self.bakery.logging_cmd( op.join(self.builddir, op.dirname(filepath))) run(command, op.join(self.builddir, op.dirname(filepath))) elapsedtime = time.time() - starttime self.bakery.logging_raw( 'Time elapsed: {}'.format(elapsedtime)) self.otf2ttf('{}.otf'.format(filepath[:-4]), pipedata) else: self.bakery.logging_cmd(_ % (filepath, ttfpath)) convert(op.join(self.builddir, filepath), op.join(self.builddir, ttfpath)) self.run_processes(op.basename(ttfpath), pipedata) except Exception as ex: self.bakery.logging_err(ex.message) raise
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): 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): 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
def bower_install(self, components=()): #TODO dependency on bower is temporary #cdn is preferred, if js can't be on cdn, it will be in static data print('Installing components') components_lst = components or [ 'angular-bootstrap', 'angular-sanitize', 'angular-moment --save', 'https://github.com/andriyko/ui-ace.git#bower', 'https://github.com/andriyko/angular-route-styles.git', 'ng-table' ] params = ' '.join(components_lst) log = run('bower install {}'.format(params), self.static_dir) print(log)
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
def git_info(config): """ If application is under git then return commit's hash and timestamp of the version running. Return None if application is not under git.""" params = "git log -n1" fmt = """ --pretty=format:'{"hash":"%h", "commit":"%H","date":"%cd"}'""" print("[%s]:%s" % (config['path'], params + fmt)) try: log = run(params + fmt, cwd=config['path']) return json.loads(log) except (ValueError, AttributeError): return {}
def bower_install(self, components=()): #TODO dependency on bower is temporary #cdn is preferred, if js can't be on cdn, it will be in static data print('Installing components') components_lst = components or ['angular-bootstrap', 'angular-sanitize', 'angular-moment --save', 'https://github.com/andriyko/ui-ace.git#bower', 'https://github.com/andriyko/angular-route-styles.git', 'ng-table'] params = ' '.join(components_lst) log = run('bower install {}'.format(params), self.static_dir) print(log)
def test_ots(self): """ Is TTF file correctly sanitized for Firefox and Chrome """ stdout = run('{0} {1}'.format('ot-sanitise', self.operator.path), os.path.dirname(self.operator.path), log=self.operator.logger) self.assertEqual('', stdout.strip())
def test_ots(self): """ Is TTF file correctly sanitized for Firefox and Chrome """ stdout = run('{0} {1}'.format('ot-sanitise', self.operator.path), os.path.dirname(self.operator.path)) self.assertEqual('', stdout.strip())