当前位置: 首页>>代码示例>>Python>>正文


Python subset.Options方法代码示例

本文整理汇总了Python中fontTools.subset.Options方法的典型用法代码示例。如果您正苦于以下问题:Python subset.Options方法的具体用法?Python subset.Options怎么用?Python subset.Options使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fontTools.subset的用法示例。


在下文中一共展示了subset.Options方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_timing_publishes_parts

# 需要导入模块: from fontTools import subset [as 别名]
# 或者: from fontTools.subset import Options [as 别名]
def test_timing_publishes_parts(self):
        _, fontpath = self.compile_font(self.getpath("TestTTF-Regular.ttx"), ".ttf")
        subsetpath = self.temp_path(".ttf")

        options = subset.Options()
        options.timing = True
        subsetter = subset.Subsetter(options)
        subsetter.populate(text='ABC')
        font = TTFont(fontpath)
        with CapturingLogHandler('fontTools.subset.timer', logging.DEBUG) as captor:
            captor.logger.propagate = False
            subsetter.subset(font)
            logs = captor.records
        captor.logger.propagate = True

        self.assertTrue(len(logs) > 5)
        self.assertEqual(len(logs), len([l for l in logs if 'msg' in l.args and 'time' in l.args]))
        # Look for a few things we know should happen
        self.assertTrue(filter(lambda l: l.args['msg'] == "load 'cmap'", logs))
        self.assertTrue(filter(lambda l: l.args['msg'] == "subset 'cmap'", logs))
        self.assertTrue(filter(lambda l: l.args['msg'] == "subset 'glyf'", logs)) 
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:23,代码来源:subset_test.py

示例2: decompress

# 需要导入模块: from fontTools import subset [as 别名]
# 或者: from fontTools.subset import Options [as 别名]
def decompress(ttFont, **kwargs):
    """ Use the FontTools Subsetter to desubroutinize the font's CFF table.
    Any keyword arguments are passed on as options to the Subsetter.
    Skip if the font contains no subroutines.
    """
    if not has_subrs(ttFont):
        log.debug('No subroutines found; skip decompress')
        return

    from fontTools import subset

    # The FontTools subsetter modifies many tables by default; here
    # we only want to desubroutinize, so we run the subsetter on a
    # temporary copy and extract the resulting CFF table from it
    make_temp = kwargs.pop('make_temp', True)
    if make_temp:
        from io import BytesIO
        from fontTools.ttLib import TTFont, newTable

        stream = BytesIO()
        ttFont.save(stream, reorderTables=None)
        stream.flush()
        stream.seek(0)
        tmpfont = TTFont(stream)
    else:
        tmpfont = ttFont  # run subsetter on the original font

    options = subset.Options(**kwargs)
    options.desubroutinize = True
    options.notdef_outline = True
    subsetter = subset.Subsetter(options=options)
    subsetter.populate(glyphs=tmpfont.getGlyphOrder())
    subsetter.subset(tmpfont)

    if make_temp:
        # copy modified CFF table to original font
        data = tmpfont['CFF '].compile(tmpfont)
        table = newTable('CFF ')
        table.decompile(data, ttFont)
        ttFont['CFF '] = table
        tmpfont.close() 
开发者ID:googlefonts,项目名称:compreffor,代码行数:43,代码来源:__init__.py

示例3: subset_ttf_font

# 需要导入模块: from fontTools import subset [as 别名]
# 或者: from fontTools.subset import Options [as 别名]
def subset_ttf_font(filepath: str) -> dict:
    options = subset.Options()
    font = subset.load_font(f'{filepath}.ttf', options)
    options.flavor = 'woff'
    subset.save_font(font, f'{filepath}.woff', options)
    options.flavor = 'woff2'
    subset.save_font(font, f'{filepath}.woff2', options)
    return {
        'woff': f'{filepath}.woff',
        'woff2': f'{filepath}.woff2'
    } 
开发者ID:solarhell,项目名称:fontObfuscator,代码行数:13,代码来源:utils.py

示例4: _get_default_options

# 需要导入模块: from fontTools import subset [as 别名]
# 或者: from fontTools.subset import Options [as 别名]
def _get_default_options():
    opt = subset.Options()
    opt.name_IDs = ["*"]
    opt.name_legacy = True
    opt.name_languages = ["*"]
    opt.layout_features = ["*"]
    opt.notdef_outline = True
    opt.recalc_bounds = True
    opt.recalc_timestamp = True
    opt.canonical_order = True
    return opt 
开发者ID:googlefonts,项目名称:nototools,代码行数:13,代码来源:subset_font_cmap.py

示例5: test_options

# 需要导入模块: from fontTools import subset [as 别名]
# 或者: from fontTools.subset import Options [as 别名]
def test_options(self):
        # https://github.com/behdad/fonttools/issues/413
        opt1 = subset.Options()
        self.assertTrue('Xyz-' not in opt1.layout_features)
        opt2 = subset.Options()
        opt2.layout_features.append('Xyz-')
        self.assertTrue('Xyz-' in opt2.layout_features)
        self.assertTrue('Xyz-' not in opt1.layout_features) 
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:10,代码来源:subset_test.py

示例6: makeKit

# 需要导入模块: from fontTools import subset [as 别名]
# 或者: from fontTools.subset import Options [as 别名]
def makeKit(font_path):
  # put the result into a directory named file_name.kit
  dest_dir = os.path.splitext(font_path)[0] + '.kit'
  if os.path.isdir(dest_dir):
    print 'FAILURE: dest %s already exists' % dest_dir
    return False
  os.makedirs(dest_dir)
  print 'Making a kit for %s in %s' % (font_path, dest_dir)

  # crack open the font
  # equivalent  pyftsubset /tmp/Lobster-Regular.ttf --unicodes='*' --obfuscate_names
  options = subset.Options()
  with contextlib.closing(subset.load_font(font_path, options)) as font:
    unicodes = []
    for t in font['cmap'].tables:
      if t.isUnicode():
        unicodes.extend(t.cmap.keys())
    options.unicodes = unicodes

    # mangle 'name' so the font can't be installed
    options.obfuscate_names

    # apply our subsetting, most notably trashing 'name'
    subsetter = subset.Subsetter(options=options)
    subsetter.populate()

    # write [ot]tf, woff, and woff2 editions with 'name' mangled
    font_name_noext = os.path.splitext(os.path.basename(font_path))[0]
    font_ext = os.path.splitext(os.path.basename(font_path))[1]
    for fmt in [font_ext, '.woff', '.woff2']:
      dest_file = os.path.join(dest_dir, font_name_noext + fmt)
      options.flavor = None
      if fmt.startswith('.woff'):
        options.flavor = fmt[1:]
      print 'Writing %s' % dest_file
      with open(dest_file, 'wb') as f:
        subset.save_font(font, f, options)

    # write a sample somewhat (no early Android, IE) bulletproof css
    dest_file = os.path.join(dest_dir, 'bulletproof.css')
    os2 = font['OS/2']
    font_style = 'normal'
    if os2.fsSelection & 1:
      font_style = 'italic'
    with open(dest_file, 'w') as f:
      f.write("@font-face {\n")
      f.write("  font-family: '%s';\n" % font_name_noext)
      f.write("  font-style: %s;\n" % font_style)
      f.write("  font-weight: %d;\n" % os2.usWeightClass)
      f.write("  src:\n")
      f.write("    url('./%s.woff2') format('woff2'),\n" % font_name_noext)
      f.write("    url('./%s.woff') format('woff'),\n" % font_name_noext)
      if font_ext == '.otf':
        f.write("    url('./%s.otf') format('opentype')" % font_name_noext)
      else:
        f.write("    url('./%s.ttf') format('truetype')" % font_name_noext)
      f.write(";\n")
      f.write("}\n")

  return True 
开发者ID:googlefonts,项目名称:gftools,代码行数:62,代码来源:make_kit.py

示例7: subset_font

# 需要导入模块: from fontTools import subset [as 别名]
# 或者: from fontTools.subset import Options [as 别名]
def subset_font(source_file, target_file, include=None, exclude=None, options=None):
    """Subsets a font file.

    Subsets a font file based on a specified character set. If only include is
    specified, only characters from that set would be included in the output
    font.  If only exclude is specified, all characters except those in that
    set will be included.  If neither is specified, the character set will
    remain the same, but inaccessible glyphs will be removed.

    Args:
      source_file: Input file name.
      target_file: Output file name
      include: The list of characters to include from the source font.
      exclude: The list of characters to exclude from the source font.
      options: A dictionary listing which options should be different from the
          default.

    Raises:
      NotImplementedError: Both include and exclude were specified.
    """
    opt = subset.Options()

    opt.name_IDs = ["*"]
    opt.name_legacy = True
    opt.name_languages = ["*"]
    opt.layout_features = ["*"]
    opt.notdef_outline = True
    opt.recalc_bounds = True
    opt.recalc_timestamp = True
    opt.canonical_order = True
    opt.drop_tables = ["+TTFA"]

    if options is not None:
        for name, value in options.items():
            setattr(opt, name, value)

    if include is not None:
        if exclude is not None:
            raise NotImplementedError(
                "Subset cannot include and exclude a set at the same time."
            )
        target_charset = include
    else:
        if exclude is None:
            exclude = []
        source_charset = coverage.character_set(source_file)
        target_charset = source_charset - set(exclude)

    font = subset.load_font(source_file, opt)
    subsetter = subset.Subsetter(options=opt)
    subsetter.populate(unicodes=target_charset)
    subsetter.subset(font)
    subset.save_font(font, target_file, opt) 
开发者ID:googlefonts,项目名称:nototools,代码行数:55,代码来源:subset.py

示例8: subset_otf_from_ufo

# 需要导入模块: from fontTools import subset [as 别名]
# 或者: from fontTools.subset import Options [as 别名]
def subset_otf_from_ufo(self, otf_path, ufo):
        """Subset a font using "Keep Glyphs" custom parameter and export flags as set
        by glyphsLib.

        "Export Glyphs" and "Remove Glyphs" are currently not supported:
        https://github.com/googlei18n/glyphsLib/issues/295.
        """
        from fontTools import subset

        # we must exclude from the final UFO glyphOrder all the glyphs that were not
        # exported to OTF because included in 'public.skipExportGlyphs'
        skip_export_glyphs = set(ufo.lib.get("public.skipExportGlyphs", ()))
        exported_glyphs = dict.fromkeys(
            g for g in ufo.keys() if g not in skip_export_glyphs
        )
        ufo_order = makeOfficialGlyphOrder(exported_glyphs, glyphOrder=ufo.glyphOrder)
        # ufo2ft always inserts a ".notdef" glyph as the first glyph
        if ".notdef" not in exported_glyphs:
            ufo_order.insert(0, ".notdef")
        ot_order = TTFont(otf_path).getGlyphOrder()
        assert ot_order[0] == ".notdef"
        assert len(ufo_order) == len(ot_order)

        for key in (KEEP_GLYPHS_NEW_KEY, KEEP_GLYPHS_OLD_KEY):
            keep_glyphs_list = ufo.lib.get(key)
            if keep_glyphs_list is not None:
                keep_glyphs = set(keep_glyphs_list)
                break
        else:
            keep_glyphs = None

        include = []
        for source_name, binary_name in zip(ufo_order, ot_order):
            if keep_glyphs and source_name not in keep_glyphs:
                continue

            if source_name in ufo:
                exported = ufo[source_name].lib.get(GLYPH_EXPORT_KEY, True)
                if not exported:
                    continue

            include.append(binary_name)

        # copied from nototools.subset
        opt = subset.Options()
        opt.name_IDs = ["*"]
        opt.name_legacy = True
        opt.name_languages = ["*"]
        opt.layout_features = ["*"]
        opt.notdef_outline = True
        opt.recalc_bounds = True
        opt.recalc_timestamp = True
        opt.canonical_order = True

        opt.glyph_names = True

        font = subset.load_font(otf_path, opt, lazy=False)
        subsetter = subset.Subsetter(options=opt)
        subsetter.populate(glyphs=include)
        subsetter.subset(font)
        subset.save_font(font, otf_path, opt) 
开发者ID:googlefonts,项目名称:fontmake,代码行数:63,代码来源:font_project.py


注:本文中的fontTools.subset.Options方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。