patch_dotted_zero.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. This patch replaces the dotted zero with a regular zero without dot.
  5. You will need Python and the Python FontTools
  6. from <https://github.com/fonttools/fonttools/> to run this.
  7. """
  8. try:
  9. from fontTools.ttLib import TTFont
  10. have_fonttools = True
  11. except:
  12. have_fonttools = False
  13. from os.path import join
  14. files = [
  15. "Sudo.ttf",
  16. "Sudo-Italic.ttf",
  17. "Sudo-Bold.ttf",
  18. "Sudo-BoldItalic.ttf",
  19. #join(r"Web Fonts", "SudoWeb.woff"),
  20. #join(r"Web Fonts", "SudoWeb-Italic.woff"),
  21. #join(r"Web Fonts", "SudoWeb-Bold.woff"),
  22. #join(r"Web Fonts", "SudoWeb-BoldItalic.woff"),
  23. ]
  24. def patch_cmap(font):
  25. #print " Patching CMAP ..."
  26. c = font["cmap"]
  27. for table in c.tables:
  28. #print " Patching format %i subtable ..." % table.format,
  29. if 0x30 in table.cmap:
  30. table.cmap[0x30] = "zero.zero"
  31. #print "OK."
  32. else:
  33. pass
  34. #print "glyph not found."
  35. def patch(filepath):
  36. print "Patching '%s' ..." % filepath,
  37. base, ext = filepath.rsplit(".", 1)
  38. font = TTFont(filepath)
  39. patch_cmap(font)
  40. font.save("%s_patch.%s" % (base, ext))
  41. font.close()
  42. print "OK"
  43. if have_fonttools:
  44. for f in files:
  45. patch(f)
  46. print "\nThe web fonts were not patched. For the web fonts, please activate the OpenType 'zero' feature in your CSS:"
  47. print ' font-feature-settings: "zero";'
  48. else:
  49. print "Please install the Python FontTools from <https://github.com/fonttools/fonttools/> first."