From 2a24349fd32731d90e13877876f9fca804f99b8a Mon Sep 17 00:00:00 2001 From: Michal Wolny Date: Fri, 8 Jan 2021 15:00:00 +0100 Subject: [dev-iconfont-generation] fix svg outline stroke directions during iconfont generation --- generate.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 generate.py (limited to 'generate.py') diff --git a/generate.py b/generate.py new file mode 100644 index 00000000..d763ed16 --- /dev/null +++ b/generate.py @@ -0,0 +1,28 @@ +import os +import fontforge + +# svg2ttf library does not support fill-rule="evenodd" so after converting icons to outlineStroke we fix path directions to work with "nonzero" +# more: https://github.com/tabler/tabler-icons/issues/13 - thanks for awesome suggestions in the issue + + +print ("Running fontforge to fix svg outline directions!") + +def files(path): + for file in os.listdir(path): + if os.path.isfile(os.path.join(path, file)): + yield file + +# refer to https://fontforge.org/docs/scripting/python/fontforge.html for documentation +# inspiration from https://github.com/FontCustom/fontcustom/blob/master/lib/fontcustom/scripts/generate.py + +font = fontforge.font() +for file in files("./icons-outlined"): + print (f"Correcting outline for {file}") + glyph = font.createChar(123, file) + glyph.importOutlines("./icons-outlined/" + file) + glyph.correctDirection() + glyph.export("./icons-outlined/" + file) + glyph.clear() + + +print ("Finished fixing svg outline directions!") -- cgit v1.2.1