Beispiel #1
0
    def execute_pyftsubset(self,
                           pipedata,
                           subsetname,
                           name,
                           glyphs="",
                           args=""):
        from fontTools.subset import Subsetter, Options, load_font, save_font
        target_file = '{0}.{1}'.format(
            op.join(self.builddir, name)[:-4], subsetname)

        options = Options()
        cmd_options = ''
        if pipedata.get('pyftsubset'):
            cmd_options = pipedata['pyftsubset']
            options.parse_opts(pipedata['pyftsubset'].split())

        if pipedata.get('pyftsubset.%s' % subsetname):
            cmd_options = pipedata['pyftsubset.%s' % subsetname]
            options.parse_opts(pipedata['pyftsubset.%s' % subsetname].split())

        font = load_font(op.join(self.builddir, name), options)

        unicodes = re_range(
            [int(g.replace('U+', ''), 16) for g in glyphs.split()])
        self.bakery.logging_cmd('pyftsubset --unicodes="{0}" {2} {1}'.format(
            unicodes, name, cmd_options))

        subsetter = Subsetter(options=options)
        subsetter.populate(
            unicodes=[int(g.replace('U+', ''), 16) for g in glyphs.split()])
        subsetter.subset(font)

        self.bakery.logging_cmd('mv {0}.subset {1}'.format(name, target_file))
        save_font(font, target_file, options)
Beispiel #2
0
    def execute_pyftsubset(self, pipedata, subsetname, name, glyphs="", args=""):
        from fontTools.subset import Subsetter, Options, load_font, save_font
        target_file = '{0}.{1}'.format(op.join(self.builddir, name)[:-4],
                                       subsetname)

        options = Options()
        cmd_options = ''
        if pipedata.get('pyftsubset'):
            cmd_options = pipedata['pyftsubset']
            options.parse_opts(pipedata['pyftsubset'].split())

        if pipedata.get('pyftsubset.%s' % subsetname):
            cmd_options = pipedata['pyftsubset.%s' % subsetname]
            options.parse_opts(pipedata['pyftsubset.%s' % subsetname].split())

        font = load_font(op.join(self.builddir, name), options)

        unicodes = re_range([int(g.replace('U+', ''), 16) for g in glyphs.split()])
        self.bakery.logging_cmd('pyftsubset --unicodes="{0}" {2} {1}'.format(unicodes, name,
                                                                             cmd_options))

        subsetter = Subsetter(options=options)
        subsetter.populate(unicodes=[int(g.replace('U+', ''), 16) for g in glyphs.split()])
        subsetter.subset(font)

        self.bakery.logging_cmd('mv {0}.subset {1}'.format(name, target_file))
        save_font(font, target_file, options)
Beispiel #3
0
def generate_subset(unicode_range, flavor, font_file, output_dir):
    """
    Generate font subset.
    You can do the same with the following command.
    $ pyftsubset YOUR_FONT.otf \
    --unicodes=U+943a-943b \
    --layout-features='*' \
    --flavor=woff \
    --name-IDs='*' \
    --output-file=style/font-subsets/YOUR_FONT-subset-1.woff
    """
    args = ["--layout-features='*'", "--flavor=%s" % flavor]
    options = Options()
    options.parse_opts(args)
    subsetter = Subsetter(options)
    font = load_font(font_file, options)

    subsetter.populate(unicodes=parse_unicodes(unicode_range))
    subsetter.subset(font)

    font_path = Path(font_file)
    name = font_path.stem
    unicode_range_hash = _get_unicode_range_hash(unicode_range)
    outfile = "%s/%s/%s-subset-%s.%s" % (
        output_dir,
        FONT_DIR,
        name,
        unicode_range_hash,
        flavor,
    )
    save_font(font, outfile, options)
    font.close()
Beispiel #4
0
def main(args):
  """Main program to run preprocessing of the font Arguments:

    font-file
    --hinting=(False|True)  ,default is false
  """
  options = Options()
  args = options.parse_opts(args, ignore_unknown=True)
  if len(args) < 1:
    print('usage: ./pyprepfnt font-file [--option=value]...', file=sys.stderr)
    sys.exit(1)

  fontfile = args[0]
  args = args[1:]

  filename, extension = os.path.splitext(fontfile)

  cleanfile = filename + '_clean' + extension
  cleanup.cleanup(fontfile, False, cleanfile)

  closure.dump_closure_map(cleanfile, '.')

  preprocess = Preprocess(cleanfile, '.')
  preprocess.base_font()
  preprocess.cmap_dump()
  preprocess.serial_glyphs()