def add_image_glyphs(in_file, out_file, pairs, verbosity=1): """Add images from pairs (glyphstr, filename) to .ttx file in_file and write to .ttx file out_file.""" quiet = verbosity < 2 font = ttx.TTFont(quiet=quiet) font.importXML(in_file, quiet=quiet) sort_glyphstr_tuples(pairs) font_builder = FontBuilder(font) # we've already sorted by length, so the longest glyphstrs are at the end. To see if # we have ligatures, we just need to check the last one. if len(pairs[-1][0]) > 1: font_builder.init_gsub() img_builder = svg_builder.SvgBuilder(font_builder) for glyphstr, filename in pairs: if verbosity > 1: print "Adding glyph for U+%s" % ",".join( ["%04X" % ord(char) for char in glyphstr]) img_builder.add_from_filename(glyphstr, filename) font.saveXML(out_file, quiet=quiet) if verbosity: print "added %s images to %s" % (len(pairs), out_file)
def add_image_glyphs(in_file, out_file, pairs): """Add images from pairs (glyphstr, filename) to .ttx file in_file and write to .ttx file out_file.""" font = ttx.TTFont() font.importXML(in_file) sort_glyphstr_tuples(pairs) font_builder = FontBuilder(font) # we've already sorted by length, so the longest glyphstrs are at the end. To # see if we have ligatures, we just need to check the last one. if len(pairs[-1][0]) > 1: font_builder.init_gsub() img_builder = svg_builder.SvgBuilder(font_builder) for glyphstr, filename in pairs: logging.debug("Adding glyph for U+%s", ",".join(["%04X" % ord(char) for char in glyphstr])) img_builder.add_from_filename(glyphstr, filename) font.saveXML(out_file) logging.info("Added %s images to %s", len(pairs), out_file)