createfont.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python
  2. import fontforge
  3. import argparse
  4. import sys
  5. import os
  6. parser = argparse.ArgumentParser()
  7. parser.add_argument('charmap')
  8. parser.add_argument('svgdir')
  9. parser.add_argument('--fontname')
  10. parser.add_argument('--fullname')
  11. parser.add_argument('--familyname')
  12. parser.add_argument('--width', type=int)
  13. parser.add_argument('--output-sfd')
  14. parser.add_argument('--output-woff')
  15. parser.add_argument('--output-ttf')
  16. args = parser.parse_args()
  17. font = fontforge.font()
  18. font.ascent = 1024 - 128
  19. font.descent = 128
  20. font.fontname = args.fontname
  21. font.fullname = args.fullname
  22. font.familyname = args.familyname
  23. font.copyright = "Created by Andy Teijelo with FontForge 2.0 (http://fontforge.sf.net)"
  24. f = open(args.charmap)
  25. for line in f:
  26. codepoint, msxcode = line.strip().split()
  27. codepoint = int(codepoint)
  28. msxcode = int(msxcode)
  29. glyph = font.createChar(codepoint)
  30. svgfile = "{}.svg".format(msxcode)
  31. glyph.importOutlines(os.path.join(args.svgdir, svgfile))
  32. glyph.width = args.width
  33. glyph.simplify()
  34. glyph.simplify(1.02, "forcelines")
  35. glyph.autoHint()
  36. font.save(args.output_sfd)
  37. font.generate(args.output_woff)
  38. font.generate(args.output_ttf)