2
0

dev-versioner.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. SUCCESS_INDICATOR = 0
  12. def main(argv):
  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:])