fix-outline.py 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import os
  2. import fontforge
  3. # svg2ttf library does not support fill-rule="evenodd" so after converting icons to outlineStroke we fix path directions to work with "nonzero"
  4. # more: https://github.com/tabler/tabler-icons/issues/13 - thanks for awesome suggestions in the issue
  5. print ("Running fontforge to fix svg outline directions!")
  6. def files(path):
  7. for file in os.listdir(path):
  8. if os.path.isfile(os.path.join(path, file)):
  9. yield file
  10. # refer to https://fontforge.org/docs/scripting/python/fontforge.html for documentation
  11. # inspiration from https://github.com/FontCustom/fontcustom/blob/master/lib/fontcustom/scripts/generate.py
  12. font = fontforge.font()
  13. for file in files("./icons-outlined"):
  14. print (f"Correcting outline for {file}")
  15. glyph = font.createChar(123, file)
  16. glyph.importOutlines("./icons-outlined/" + file)
  17. glyph.round()
  18. glyph.simplify()
  19. glyph.simplify()
  20. glyph.correctDirection()
  21. glyph.export("./icons-outlined/" + file)
  22. glyph.clear()
  23. print ("Finished fixing svg outline directions!")