當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。