font2svg.py 750 B

123456789101112131415161718
  1. import sys
  2. if len(sys.argv) < 2:
  3. print 'Usage: python {} webfont-file.svg'.format(sys.argv[0])
  4. sys.exit()
  5. with open(sys.argv[1], 'r') as r:
  6. lines = r.read().split('\n')
  7. glyphs = [x for x in lines if '<glyph' in x]
  8. # for every glyph element in the file
  9. for i in range(0, len(glyphs)):
  10. with open(str(i + 1).rjust(3, '0') + '.svg', 'w') as w:
  11. w.write('<?xml version="1.0" standalone="no"?>\n')
  12. w.write('<svg width="1500px" height="1500px" version="1.1" xmlns="http://www.w3.org/2000/svg">\n')
  13. # replace 'glyph' with 'path' and flip vertically
  14. w.write(glyphs[i].replace('<glyph', '<path transform="scale(1, -1) translate(0, -1500)"') + '\n')
  15. w.write('</svg>')