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


Python Font.get_ttfont_from_metadata方法代码示例

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


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

示例1: test_metrics_descents_equal_bbox

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_metrics_descents_equal_bbox(self):
        """ Check that descents values are same as min glyph point """
        contents = self.read_metadata_contents()
        family_metadata = Metadata.get_family_metadata(contents)

        fonts_descents_not_bbox = []
        ymin = 0

        _cache = {}
        for font_metadata in family_metadata.fonts:
            ttfont = Font.get_ttfont_from_metadata(self.path, font_metadata)

            ymin_, ymax_ = ttfont.get_bounding()
            ymin = min(ymin, ymin_)

            _cache[font_metadata.filename] = {
                'os2typo': abs(ttfont.descents.os2typo),
                'os2win': abs(ttfont.descents.os2win),
                'hhea': abs(ttfont.descents.hhea)
            }

        for filename, data in _cache.items():
            if [data['os2typo'], data['os2win'], data['hhea']] != [abs(ymin)] * 3:
                fonts_descents_not_bbox.append(filename)

        if fonts_descents_not_bbox:
            _ = '[%s] ascents differ to minimum value: %s'
            self.fail(_ % (', '.join(fonts_descents_not_bbox), ymin))
开发者ID:lowks,项目名称:fontbakery-cli,代码行数:30,代码来源:test_check_vertical_metrics.py

示例2: test_check_menu_contains_proper_glyphs

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
 def test_check_menu_contains_proper_glyphs(self):
     """ Check menu file contains proper glyphs """
     contents = self.read_metadata_contents()
     fm = Metadata.get_family_metadata(contents)
     for font_metadata in fm.fonts:
         tf = Font.get_ttfont_from_metadata(self.operator.path, font_metadata, is_menu=True)
         self.check_retrieve_glyphs(tf, font_metadata)
开发者ID:adrientetar,项目名称:fontbakery,代码行数:9,代码来源:test_metadata.py

示例3: test_check_normal_style_matches_names

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_check_normal_style_matches_names(self):
        """ Check metadata.json font.style `italic` matches font internal """
        contents = self.read_metadata_contents()
        family = Metadata.get_family_metadata(contents)

        for font_metadata in family.fonts:
            if font_metadata.style != 'normal':
                continue

            font = Font.get_ttfont_from_metadata(self.operator.path, font_metadata)

            if bool(font.macStyle & 0b10):
                self.fail(('Metadata style has been set to normal'
                           ' but font second bit (italic) in macStyle has'
                           ' been set'))

            style = font.familyname.split('-')[-1]
            if style.endswith('Italic'):
                self.fail(('macStyle second bit is not set but postScriptName "%s"'
                           ' is ended with "Italic"') % font.familyname)

            style = font.fullname.split('-')[-1]
            if style.endswith('Italic'):
                self.fail(('macStyle second bit is not set but fullName "%s"'
                           ' is ended with "Italic"') % font.fullname)
开发者ID:adrientetar,项目名称:fontbakery,代码行数:27,代码来源:test_metadata.py

示例4: test_font_name_matches_family

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_font_name_matches_family(self):
        """ METADATA.json fonts 'name' property should be
            same as font familyname """

        for font_metadata in self.metadata.fonts:
            font = Font.get_ttfont_from_metadata(self.operator.path, font_metadata)
            if font_metadata.name != font.familyname:
                msg = '"fonts.name" property is not the same as TTF familyname'
                self.fail(msg)
开发者ID:adrientetar,项目名称:fontbakery,代码行数:11,代码来源:test_metadata.py

示例5: test_the_same_number_of_glyphs_across_family

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_the_same_number_of_glyphs_across_family(self):
        """ The same number of glyphs across family? """
        glyphs_count = 0
        for font_metadata in self.familymetadata.fonts:
            ttfont = Font.get_ttfont_from_metadata(self.operator.path, font_metadata)
            if not glyphs_count:
                glyphs_count = len(ttfont.glyphs)

            if glyphs_count != len(ttfont.glyphs):
                self.fail('Family has a different glyphs\'s count in fonts')
开发者ID:adrientetar,项目名称:fontbakery,代码行数:12,代码来源:test_metadata.py

示例6: test_the_same_names_of_glyphs_across_family

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_the_same_names_of_glyphs_across_family(self):
        """ The same names of glyphs across family? """
        glyphs = None
        for font_metadata in self.familymetadata.fonts:
            ttfont = Font.get_ttfont_from_metadata(self.operator.path, font_metadata)
            if not glyphs:
                glyphs = len(ttfont.glyphs)

            if glyphs != len(ttfont.glyphs):
                self.fail('Family has a different glyphs\'s names in fonts')
开发者ID:adrientetar,项目名称:fontbakery,代码行数:12,代码来源:test_metadata.py

示例7: test_postscriptname_contains_correct_weight

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_postscriptname_contains_correct_weight(self):
        """ Metadata weight matches postScriptName """
        contents = self.read_metadata_contents()
        fm = Metadata.get_family_metadata(contents)

        for font_metadata in fm.fonts:

            font = Font.get_ttfont_from_metadata(self.path, font_metadata)
            if font.OS2_usWeightClass != font_metadata.weight:
                msg = 'METADATA.JSON has weight %s but in TTF it is %s'
                self.fail(msg % (font_metadata.weight, font.OS2_usWeightClass))
开发者ID:lowks,项目名称:fontbakery-cli,代码行数:13,代码来源:test_check_canonical_weights.py

示例8: test_font_weight_same_as_in_metadata

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_font_weight_same_as_in_metadata(self):
        """ Font weight matches metadata.json value of key "weight" """
        contents = self.read_metadata_contents()
        fm = Metadata.get_family_metadata(contents)

        for font_metadata in fm.fonts:

            font = Font.get_ttfont_from_metadata(self.operator.path, font_metadata)
            if font.OS2_usWeightClass != font_metadata.weight:
                msg = 'METADATA.JSON has weight %s but in TTF it is %s'
                self.fail(msg % (font_metadata.weight, font.OS2_usWeightClass))
开发者ID:adrientetar,项目名称:fontbakery,代码行数:13,代码来源:test_metadata.py

示例9: test_check_metadata_matches_nametable

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_check_metadata_matches_nametable(self):
        contents = self.read_metadata_contents()
        fm = Metadata.get_family_metadata(contents)
        for font_metadata in fm.fonts:
            ttfont = Font.get_ttfont_from_metadata(self.path, font_metadata)

            report = '%s: Family name was supposed to be "%s" but is "%s"'
            report = report % (font_metadata.name, fm.name,
                               ttfont.familyname)
            self.assertEqual(ttfont.familyname, fm.name, report)
            self.assertEqual(ttfont.fullname, font_metadata.full_name)
开发者ID:lowks,项目名称:fontbakery-cli,代码行数:13,代码来源:test_check_metadata_matches_nametable.py

示例10: test_the_same_encodings_of_glyphs_across_family

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_the_same_encodings_of_glyphs_across_family(self):
        """ The same unicode encodings of glyphs across family? """
        encoding = None
        for font_metadata in self.familymetadata.fonts:
            ttfont = Font.get_ttfont_from_metadata(self.operator.path, font_metadata)
            cmap = ttfont.retrieve_cmap_format_4()

            if not encoding:
                encoding = cmap.platEncID

            if encoding != cmap.platEncID:
                self.fail('Family has different encoding across fonts')
开发者ID:adrientetar,项目名称:fontbakery,代码行数:14,代码来源:test_metadata.py

示例11: test_metadata_fonts_fields_have_fontname

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_metadata_fonts_fields_have_fontname(self):
        """ METADATA.json fonts items fields "name", "postScriptName",
            "fullName", "filename" contains font name right format """
        for x in self.metadata.fonts:
            font = Font.get_ttfont_from_metadata(self.operator.path, x)

            self.assertIn(font.familyname, x.name)
            self.assertIn(font.familyname, x.full_name)
            self.assertIn("".join(str(font.familyname).split()),
                          x.filename)
            self.assertIn("".join(str(font.familyname).split()),
                          x.post_script_name)
开发者ID:adrientetar,项目名称:fontbakery,代码行数:14,代码来源:test_metadata.py

示例12: test_metrics_linegaps_are_zero

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_metrics_linegaps_are_zero(self):
        """ Check that linegaps in tables are zero """
        contents = self.read_metadata_contents()
        family_metadata = Metadata.get_family_metadata(contents)

        fonts_gaps_are_not_zero = []
        for font_metadata in family_metadata.fonts:
            ttfont = Font.get_ttfont_from_metadata(self.path, font_metadata)
            if bool(ttfont.linegaps.os2typo) or bool(ttfont.linegaps.hhea):
                fonts_gaps_are_not_zero.append(font_metadata.filename)

        if fonts_gaps_are_not_zero:
            _ = '[%s] have not zero linegaps'
            self.fail(_ % ', '.join(fonts_gaps_are_not_zero))
开发者ID:lowks,项目名称:fontbakery-cli,代码行数:16,代码来源:test_check_vertical_metrics.py

示例13: test_postscriptname_in_metadata_equal_to_font_on_disk

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_postscriptname_in_metadata_equal_to_font_on_disk(self):
        """ Checks METADATA.json 'postScriptName' matches TTF 'postScriptName' """
        contents = self.read_metadata_contents()
        metadata = Metadata.get_family_metadata(contents)

        for font_metadata in metadata.fonts:
            try:
                font = Font.get_ttfont_from_metadata(self.operator.path, font_metadata)
            except IOError:
                continue
            if font.post_script_name != font_metadata.post_script_name:

                msg = 'In METADATA postScriptName="{0}", but in TTF "{1}"'
                self.fail(msg.format(font.post_script_name,
                                     font_metadata.post_script_name))
开发者ID:adrientetar,项目名称:fontbakery,代码行数:17,代码来源:test_metadata.py

示例14: test_check_nbsp_width_matches_sp_width

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_check_nbsp_width_matches_sp_width(self):
        """ Check NO-BREAK SPACE advanceWidth is the same as SPACE """
        contents = self.read_metadata_contents()
        fm = Metadata.get_family_metadata(contents)
        for font_metadata in fm.fonts:
            tf = Font.get_ttfont_from_metadata(self.path, font_metadata)
            space_advance_width = tf.advance_width('space')
            nbsp_advance_width = tf.advance_width('uni00A0')

            _ = "%s: The font does not contain a sp glyph"
            self.assertTrue(space_advance_width, _ % font_metadata.filename)
            _ = "%s: The font does not contain a nbsp glyph"
            self.assertTrue(nbsp_advance_width, _ % font_metadata.filename)

            _ = ("%s: The nbsp advance width does not match "
                 "the sp advance width") % font_metadata.filename
            self.assertEqual(space_advance_width, nbsp_advance_width, _)
开发者ID:lowks,项目名称:fontbakery-cli,代码行数:19,代码来源:test_check_nbsp_width_matches_sp_width.py

示例15: test_font_on_disk_family_equal_in_metadata_json

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont_from_metadata [as 别名]
    def test_font_on_disk_family_equal_in_metadata_json(self):
        """ Font on disk and in METADATA.json have the same family name """
        contents = self.read_metadata_contents()
        metadata = Metadata.get_family_metadata(contents)

        unmatched_fonts = []
        for font_metadata in metadata.fonts:
            try:
                font = Font.get_ttfont_from_metadata(self.operator.path,
                                                     font_metadata)
            except IOError:
                continue
            if font.familyname != font_metadata.name:
                unmatched_fonts.append(font_metadata.filename)

        if unmatched_fonts:
            msg = 'Unmatched family name are in fonts: {}'
            self.fail(msg.format(', '.join(unmatched_fonts)))
开发者ID:adrientetar,项目名称:fontbakery,代码行数:20,代码来源:test_metadata.py


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