dehint_composites.py 642 B

123456789101112131415161718192021
  1. import sys
  2. from fontTools.ttLib import TTFont
  3. filename = sys.argv[1]
  4. ttFont = TTFont(filename)
  5. modified = []
  6. for glyphname in ttFont['glyf'].keys():
  7. try:
  8. asm = ttFont['TSI1'].glyphPrograms[glyphname]
  9. if "OFFSET" in asm:
  10. asm = "USEMYMETRICS[]\r" + '\r'.join([line for line in asm.split('\r') if 'OFFSET' in line])
  11. ttFont['TSI1'].glyphPrograms[glyphname] = asm
  12. modified.append(glyphname)
  13. else:
  14. print(f"Skip '{glyphname}'")
  15. except:
  16. print(f"No program for '{glyphname}'")
  17. ttFont.save(filename.split('.ttf')[0] + "-alt.ttf")
  18. print(f"These glyphs were modified by the script:\n{', '.join(modified)}")