本文整理汇总了Python中bakery_cli.ttfont.Font类的典型用法代码示例。如果您正苦于以下问题:Python Font类的具体用法?Python Font怎么用?Python Font使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Font类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reset_fstype
def reset_fstype(fontpath):
from bakery_cli.ttfont import Font
try:
font = Font(fontpath)
except TTLibError as ex:
print("ERROR: %s" % ex, file=sys.stderr)
return
font['OS/2'].fsType = 0
font.save(fontpath + '.fix')
示例2: test_check_names_are_ascii_only
def test_check_names_are_ascii_only(self):
""" NAME and CFF tables must not contain non-ascii characters """
font = Font.get_ttfont(self.operator.path)
for name in font.names:
string = Font.bin2unistring(name)
marks = CharacterSymbolsFixer.unicode_marks(string)
if marks:
self.fail('Contains {}'.format(marks))
示例3: fix_style_names
def fix_style_names(fontpath):
from bakery_cli.ttfont import Font
try:
font = Font(fontpath)
except TTLibError as ex:
print("ERROR: %s" % ex)
return
# font['name'].fsType = 0
font.save(fontpath + '.fix')
示例4: test_check_names_are_ascii_only
def test_check_names_are_ascii_only(self):
""" NAME and CFF tables must not contain non-ascii characters """
font = Font.get_ttfont(self.path)
for name_record in font.names:
string = Font.bin2unistring(name_record)
try:
string.encode('ascii')
except UnicodeEncodeError:
self.fail("%s contain non-ascii chars" % name_record.nameID)
示例5: test_check_normal_style_matches_names
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)
示例6: test_check_menu_contains_proper_glyphs
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)
示例7: test_fontname_is_equal_to_macstyle
def test_fontname_is_equal_to_macstyle(self):
""" Check that fontname is equal to macstyle flags """
font = Font.get_ttfont(self.operator.path)
macStyle = font.macStyle
try:
fontname_style = font.fullname.split('-')[1]
except IndexError:
fontname_style = ''
expected_style = ''
if macStyle & 0b01:
expected_style += 'Bold'
if macStyle & 0b10:
expected_style += 'Italic'
if not bool(macStyle & 0b11):
expected_style = 'Regular'
if fontname_style != expected_style:
_ = 'macStyle ({0}) supposed style ended with "{1}"'
if fontname_style:
_ += ' but ends with "{2}"'
self.fail(_.format(bin(macStyle)[-2:], expected_style, fontname_style))
示例8: test_check_names_same_across_platforms
def test_check_names_same_across_platforms(self):
""" Font names are same across specific-platforms """
font = Font.get_ttfont(self.operator.path)
for name in font.names:
for name2 in font.names:
if name.nameID != name2.nameID:
continue
if self.diff_platform(name, name2) or self.diff_platform(name2, name):
_name = Font.bin2unistring(name)
_name2 = Font.bin2unistring(name2)
if _name != _name2:
msg = ('Names in "name" table are not the same'
' across specific-platforms')
self.fail(msg)
示例9: test_metrics_descents_equal_bbox
def test_metrics_descents_equal_bbox(self):
""" Check that descents values are same as min glyph point """
dirname = os.path.dirname(self.operator.path)
directory = UpstreamDirectory(dirname)
fonts_descents_not_bbox = []
ymin = 0
_cache = {}
for filename in directory.get_binaries():
ttfont = Font.get_ttfont(os.path.join(dirname, filename))
ymin_, _ = ttfont.get_bounding()
ymin = min(ymin, ymin_)
_cache[filename] = {
'os2typo': abs(ttfont.descents.os2typo),
'os2win': abs(ttfont.descents.os2win),
'hhea': abs(ttfont.descents.hhea)
}
for filename, data in _cache.items():
datas = [data['os2typo'], data['os2win'], data['hhea']]
if datas != [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))
示例10: test_check_italic_angle_agreement
def test_check_italic_angle_agreement(self):
""" Check italicangle property zero or negative """
font = Font.get_ttfont(self.operator.path)
if font.italicAngle > 0:
self.fail('italicAngle must be less or equal zero')
if abs(font.italicAngle) > 20:
self.fail('italicAngle can\'t be larger than 20 degrees')
示例11: test_metrics_descents_equal_bbox
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))
示例12: test_check_font_has_dsig_table
def test_check_font_has_dsig_table(self):
""" Check that font has DSIG table """
font = Font.get_ttfont(self.operator.path)
try:
font['DSIG']
except KeyError:
self.fail('Font does not have "DSIG" table')
示例13: test_fontname_is_equal_to_macstyle
def test_fontname_is_equal_to_macstyle(self):
""" Check that fontname is equal to macstyle flags """
font = Font.get_ttfont(self.path)
fontname = font.fullname
macStyle = font.macStyle
try:
fontname_style = fontname.split('-')[1]
except IndexError:
self.fail(('Fontname is not canonical. Expected it contains '
'style. eg.: Italic, BoldItalic, Regular'))
style = ''
if macStyle & 0b01:
style += 'Bold'
if macStyle & 0b10:
style += 'Italic'
if not bool(macStyle & 0b11):
style = 'Regular'
if not fontname_style.endswith(style):
_ = 'macStyle (%s) supposed style ended with "%s" but ends with "%s"'
self.fail(_ % (bin(macStyle)[-2:], style, fontname_style))
示例14: test_check_upm_heigths_less_120
def test_check_upm_heigths_less_120(self):
""" Check if UPM Heights NOT more than 120% """
ttfont = Font.get_ttfont(self.path)
value = ttfont.ascents.get_max() + abs(ttfont.descents.get_min())
value = value * 100 / float(ttfont.get_upm_height())
if value > 120:
_ = "UPM:Height is %d%%, consider redesigning to 120%% or less"
self.fail(_ % value)
示例15: test_suggested_subfamily_name
def test_suggested_subfamily_name(self):
""" Family does not contain subfamily in `name` table """
# Currently we just look that family does not contain any spaces
# in its name. This prevent us from incorrect suggestions of names
font = Font.get_ttfont(self.operator.path)
suggestedvalues = getSuggestedFontNameValues(font.ttfont)
self.assertEqual(font.familyname, suggestedvalues['family'])
self.assertEqual(font.stylename, suggestedvalues['subfamily'])