4

I need to convert some ttf file to svg file I know I can use fontforge by script,but I wish I can do this in python I assume there is some protocols of the ttf file so I can parser it from binary to human readable svg,but I couldn't find the protocol any where(I use bing searched) Is there is some way I can do this?The protocol or a already made python lib would be ok

Tarjintor
  • 585
  • 4
  • 15

2 Answers2

0

I found a similar question for the command-line: Command-line tool for converting TTF/OTF fonts to SVG You could simply call it in a subprocess.

Community
  • 1
  • 1
0

Since this can be done with FontForge, you can simply use the fontforge library in Python. It can be installed using this command in Linux: (idk how to install it on other OSes)

sudo apt-get install python3-fontforge

Then, in pure Python:

import fontforge

def ttf2svg(i,o):
    font = fontforge.open(i)
    font.generate(o)
    font.close()

After this, just call the function like this:

ttf2svg([input filename], [output_filename])
HGStyle
  • 13
  • 5