dev-versioner.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # ------------------------------------------------------------------------------
  4. # dev-versioner.py
  5. # Copyright 2016 Christopher Simpkins
  6. # MIT license
  7. # ------------------------------------------------------------------------------
  8. import sys
  9. from fontTools import ttLib
  10. VERSION_STRING="Version 2.020;DEV-03192016;"
  11. def main(argv):
  12. success_indicator = 0
  13. for font_variant_path in argv:
  14. tt = ttLib.TTFont(font_variant_path)
  15. namerecord_list = tt['name'].__dict__['names']
  16. path_list = font_variant_path.split(".")
  17. outfile_path = path_list[0] + "-DEV." + path_list[1]
  18. for record in namerecord_list:
  19. if record.__dict__['langID'] == 0 and record.__dict__['nameID'] == 5:
  20. record.__dict__['string'] = VERSION_STRING
  21. tt.save(outfile_path)
  22. success_indicator += 1
  23. elif record.__dict__['langID'] == 1033 and record.__dict__['nameID'] == 5:
  24. record.__dict__['string'] = VERSION_STRING.encode('utf_16_be') # UTF-16 big endian encoding for the Microsoft tables
  25. tt.save(outfile_path)
  26. success_indicator += 1
  27. if success_indicator == 0:
  28. print("[ERROR] Unable to complete the name table update for " + font_variant_path)
  29. elif success_indicator == 1: # should equal 2 if both name tables were successfully updated
  30. print("[ERROR] Incomplete name table update for " + font_variant_path)
  31. success_indicator = 0 # reset success indicator
  32. if __name__ == '__main__':
  33. main(sys.argv[1:])