예제 #1
0
 def execute_bin(self, files, pipedata):
     for p in files:
         if p.endswith('.otf'):
             self.otf2ttf(p, pipedata)
         else:
             shellutil.move(op.join(self.builddir, 'sources', p),
                            op.join(self.builddir, p))
             self.run_processes(p, pipedata)
예제 #2
0
 def execute_bin(self, files, pipedata):
     for p in files:
         if p.endswith('.otf'):
             self.otf2ttf(p, pipedata)
         else:
             shellutil.move(op.join(self.builddir, 'sources', p),
                            op.join(self.builddir, p))
             self.run_processes(p, pipedata)
예제 #3
0
    def run(self, filename, pipedata):
        if not pipedata.get('fontcrunch'):
            return  # run fontcrunch only if user set flag in config
        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
예제 #4
0
    def movebin_to_builddir(self, files):
        result = []
        for a in files:
            d = op.join(self.builddir, op.basename(a)[:-4] + '.ttf')
            s = op.join(self.builddir, a[:-4] + '.ttf')

            try:
                shellutil.move(s, d)
                result.append(op.basename(a)[:-4] + '.ttf')
            except:
                pass
        return result
예제 #5
0
    def movebin_to_builddir(self, files):
        result = []
        for a in files:
            d = op.join(self.builddir, op.basename(a)[:-4] + '.ttf')
            s = op.join(self.builddir, a[:-4] + '.ttf')

            try:
                shellutil.move(s, d)
                result.append(op.basename(a)[:-4] + '.ttf')
            except:
                pass
        return result
예제 #6
0
    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))
예제 #7
0
    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))
예제 #8
0
    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
예제 #9
0
    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
예제 #10
0
    def otf2ttf(self, filepath, pipedata):
        fontname = filepath[:-4]

        ttfpath = '{}.ttf'.format(op.basename(fontname))

        path = '{}.otf'.format(op.basename(fontname))

        if op.exists(op.join(self.builddir, 'sources', path)):
            _ = 'fontbakery-build-font2ttf.py {0}.otf {1}\n'
            self.bakery.logging_cmd(_.format(fontname, ttfpath))
            try:
                convert(op.join(self.builddir, 'sources', path),
                        op.join(self.builddir, 'sources', ttfpath))
                os.remove(op.join(self.builddir, 'sources', path))
            except Exception as ex:
                self.bakery.logging_err(ex.message)
                raise

        shellutil.move(op.join(self.builddir, 'sources', ttfpath),
                       op.join(self.builddir, ttfpath))
        self.run_processes(ttfpath, pipedata)
예제 #11
0
    def otf2ttf(self, filepath, pipedata):
        fontname = filepath[:-4]

        ttfpath = '{}.ttf'.format(op.basename(fontname))

        path = '{}.otf'.format(op.basename(fontname))

        if op.exists(op.join(self.builddir, 'sources', path)):
            _ = 'fontbakery-build-font2ttf.py {0}.otf {1}\n'
            self.bakery.logging_cmd(_.format(fontname, ttfpath))
            try:
                convert(op.join(self.builddir, 'sources', path),
                        op.join(self.builddir, 'sources', ttfpath))
                os.remove(op.join(self.builddir, 'sources', path))
            except Exception as ex:
                self.bakery.logging_err(ex.message)
                raise

        shellutil.move(op.join(self.builddir, 'sources', ttfpath),
                       op.join(self.builddir, ttfpath))
        self.run_processes(ttfpath, pipedata)
예제 #12
0
    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