Created
June 10, 2025 23:02
-
-
Save futuremotiondev/7ca2241bb05af668992bdf8541359bab to your computer and use it in GitHub Desktop.
Convert TTF to SVG Font with FontForge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import fontforge | |
| import sys | |
| from os import path | |
| if len(sys.argv) < 2: | |
| print("Usage : {0} file.ttf".format(sys.argv[0])) | |
| exit(1) | |
| ttf_file = sys.argv[1] | |
| svg_file = "{0}.svg".format(ttf_file.split(".")[0]) | |
| def check_file(filePath): | |
| if path.exists(filePath): | |
| numb = 1 | |
| while True: | |
| newPath = "{0}_{2}{1}".format(*path.splitext(filePath) + (numb,)) | |
| if path.exists(newPath): | |
| numb += 1 | |
| else: | |
| return newPath | |
| return filePath | |
| safe_path = check_file(svg_file) | |
| font = fontforge.open(ttf_file) | |
| font.generate(safe_path) | |
| font.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment