fix-dsig.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright 2013,2016 The Font Bakery Authors
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. # See AUTHORS.txt for the list of Authors and LICENSE.txt for the License.
  18. # Adapted for the Hack typeface build workflow by Chris Simpkins
  19. from __future__ import print_function, unicode_literals
  20. import sys
  21. import os
  22. from fontTools import ttLib
  23. def set_empty_dsig(ttFont):
  24. newDSIG = ttLib.newTable("DSIG")
  25. newDSIG.ulVersion = 1
  26. newDSIG.usFlag = 0
  27. newDSIG.usNumSigs = 0
  28. newDSIG.signatureRecords = []
  29. ttFont.tables["DSIG"] = newDSIG
  30. def main(argv):
  31. for path in argv:
  32. if not os.path.exists(path):
  33. sys.stderr.write("[fix-dsig.py] ERROR: " + path + " is not a valid path to a font file")
  34. sys.exit(1)
  35. else:
  36. font = ttLib.TTFont(path)
  37. set_empty_dsig(font)
  38. font.save(path)
  39. print(path + " - successful DSIG table fix")
  40. if __name__ == '__main__':
  41. main(sys.argv[1:])