Skip to content

Instantly share code, notes, and snippets.

@futuremotiondev
Created June 10, 2025 23:02
Show Gist options
  • Select an option

  • Save futuremotiondev/7ca2241bb05af668992bdf8541359bab to your computer and use it in GitHub Desktop.

Select an option

Save futuremotiondev/7ca2241bb05af668992bdf8541359bab to your computer and use it in GitHub Desktop.
Convert TTF to SVG Font with FontForge
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