def vtt_dump(infile, outfile=None, **kwargs):
if not os.path.exists(infile):
raise VTTLibArgumentError("'%s' not found" % infile)
font = TTFont(infile)
if font.sfntVersion not in ("\x00\x01\x00\x00", "true"):
raise VTTLibArgumentError("Not a TrueType font (bad sfntVersion)")
for table_tag in VTT_TABLES:
if table_tag not in font:
raise VTTLibArgumentError(
"Table '%s' not found in input font" % table_tag)
if not outfile:
ufo = os.path.splitext(infile)[0] + ".ufo"
else:
ufo = outfile
if not os.path.exists(ufo) or not os.path.isdir(ufo):
raise VTTLibArgumentError("No such directory: '%s'" % ufo)
check_ufo_version(ufo)
folder = os.path.join(ufo, "data", TTX_DATA_FOLDER)
# create data sub-folder if it doesn't exist already
try:
os.makedirs(folder)
except OSError as e:
if e.errno != errno.EEXIST or not os.path.isdir(folder):
raise
normalize_vtt_programs(font)
ufo_contents = read_ufo_contents(ufo)
subset_vtt_glyph_programs(font, list(ufo_contents))
for tag in VTT_TABLES:
# dump each table individually instead of using 'splitTables'
# to avoid creating an extra index file
outfile = os.path.join(folder, tagToIdentifier(tag) + '.ttx')
# always use Unix LF newlines
font.saveXML(outfile, tables=[tag], newlinestr='\n')
write_maxp_data(font, ufo)
评论列表
文章目录