本文整理汇总了Python中bakery_cli.ttfont.Font.get_ttfont方法的典型用法代码示例。如果您正苦于以下问题:Python Font.get_ttfont方法的具体用法?Python Font.get_ttfont怎么用?Python Font.get_ttfont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bakery_cli.ttfont.Font
的用法示例。
在下文中一共展示了Font.get_ttfont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fontname_is_equal_to_macstyle
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
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))
示例2: test_check_font_has_dsig_table
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
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')
示例3: test_metrics_descents_equal_bbox
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
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))
示例4: test_fontname_is_equal_to_macstyle
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
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))
示例5: test_check_italic_angle_agreement
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
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')
示例6: test_no_kern_table_exists
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
def test_no_kern_table_exists(self):
""" Check that no "KERN" table exists """
font = Font.get_ttfont(self.operator.path)
try:
font['KERN']
self.fail('Font does have "KERN" table')
except KeyError:
pass
示例7: test_check_upm_heigths_less_120
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
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)
示例8: test_suggested_subfamily_name
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
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'])
示例9: test_check_names_are_ascii_only
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
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))
示例10: test_check_names_are_ascii_only
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
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)
示例11: test_prep_magic_code
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
def test_prep_magic_code(self):
""" Font contains in PREP table magic code """
magiccode = '\xb8\x01\xff\x85\xb0\x04\x8d'
font = Font.get_ttfont(self.operator.path)
try:
bytecode = font.get_program_bytecode()
except KeyError:
bytecode = ''
self.assertTrue(bytecode == magiccode,
msg='PREP does not contain magic code')
示例12: test_check_hmtx_hhea_max_advance_width_agreement
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
def test_check_hmtx_hhea_max_advance_width_agreement(self):
""" Check if MaxAdvanceWidth agree in the Hmtx and Hhea tables """
font = Font.get_ttfont(self.operator.path)
hmtx_advance_width_max = font.get_hmtx_max_advanced_width()
hhea_advance_width_max = font.advance_width_max
error = ("AdvanceWidthMax mismatch: expected %s (from hmtx);"
" got %s (from hhea)") % (hmtx_advance_width_max,
hhea_advance_width_max)
self.assertEqual(hmtx_advance_width_max,
hhea_advance_width_max, error)
示例13: set
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
def set(fontpath, value):
ttfont = Font.get_ttfont(fontpath)
try:
ttfont['gasp']
except:
print('no table gasp', file=sys.stderr)
return
ttfont['gasp'].gaspRange[65535] = value
ttfont.save(fontpath + '.fix')
示例14: fix
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
def fix(fontpath):
ttfont = Font.get_ttfont(fontpath)
ot_namerecord = findOrCreateNameRecord(ttfont['name'].names, 16)
ot_namerecord.string = ttfont.familyname.encode("utf_16_be")
ot_namerecord = findOrCreateNameRecord(ttfont['name'].names, 17)
ot_namerecord.string = mapping.get(ttfont.stylename, 'Regular').encode("utf_16_be")
ot_namerecord = findOrCreateNameRecord(ttfont['name'].names, 18)
ot_namerecord.string = ttfont.fullname.encode("utf_16_be")
ttfont.save(fontpath + '.fix')
示例15: test_check_panose_identification
# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import get_ttfont [as 别名]
def test_check_panose_identification(self):
font = Font.get_ttfont(self.path)
if font['OS/2'].panose['bProportion'] == 9:
prev = 0
for g in font.glyphs():
if prev and font.advance_width(g) != prev:
link = ('http://www.thomasphinney.com/2013/01'
'/obscure-panose-issues-for-font-makers/')
self.fail(('Your font does not seem monospaced but PANOSE'
' bProportion set to monospace. It may have '
' a bug in windows. Details: %s' % link))
prev = font.advance_width(g)