Does anyone know of a command-line tool that will convert both TTF and OTF fonts to SVG fonts?
4 Answers
You can use fontforge or batik to do this from the commandline.
With fontforge (see scripting documentation):
#!/usr/bin/fontforge
Open($1)
Generate($1:r + ".svg")
Save the above to convert2svgfont.pe
file, then invoke as:
convert2svgfont.pe myfont.ttf
For batik see this documentation, install and then invoke as:
java -jar batik-ttf2svg.jar myfont.ttf -o myfont.svg

- 4,229
- 4
- 32
- 42

- 59,452
- 12
- 120
- 139
-
Does batik-ttf2svg convert both otf (CFF-based OpenType) as well as ttf as the questioner asked? – djangodude Oct 27 '12 at 03:09
-
@djangodude hmm, I'm not 100% sure. – Erik Dahlström Oct 27 '12 at 09:22
-
Thanks @ErikDahlström, This is working, But the characters in SVG is mirrored/flipped. Is there any more function call I should add to avoid this inversion? – vimal1083 Jul 14 '17 at 11:28
-
No @Yashua, I couldn't. But I have got a workaround in CSS to flip the SVG. – vimal1083 Aug 07 '17 at 13:20
-
I ran into issues with flipping the svg using css/transforms (caused all transforms to deal with the flip) with this so I loaded the font in Fontographer, selected all, clicked rotate 180 and generated an inverted TTF file that did the trick. – cyberwombat Aug 14 '17 at 00:56
-
This fontforge recipe no longer works, because fontforge has switched to Python scripting. See my other answer for the new way. – Yitz May 07 '18 at 13:46
-
agree answer is unfortunately outdated, should have some way to mark an answer as outdated, and another one as being in date, as voting is not a good match for this scenario. – user254694 Jan 25 '19 at 11:11
-
Worked for me, but that documentation URL is broken, I found: "fontforge.org/docs/scripting/scripting.html" which I suspect is equivalent. – Robert Munafo Feb 17 '21 at 13:43
-
@Yitz - The script still works but you must specify the language to be fontforge (ff) and not python (py). `fontforge -lang ff -c 'Open($1); Generate($2)' wingdings.ttf wingdings.otf` [docs](https://fontforge.org/docs/techref/cliargs.html) – joematune Jan 19 '22 at 13:14
The fontforge recipe given previously by @Erik no longer works - fontforge has switched to Python scripting.
Here's how I converted a font from PFA to SVG on the command line - this will also work fine for TTF, etc.:
fontforge -c 'import fontforge;fontforge.open("/usr/share/fonts/X11/Type1/NachlieliCLM-Bold.pfa").generate("NachlieliCLM-Bold.svg")'

- 5,057
- 24
- 19
-
3Out of curiosity, is there a reason that you and apparently quite a few others still need SVG fonts, considering it's [no longer part of the spec](https://www.w3.org/TR/SVG2/changes.html#fonts) and browser support has been [dropped by all the major browsers](https://caniuse.com/#feat=svg-fonts)? What context are you using them in? – Hashim Aziz Sep 17 '19 at 16:10
-
6For myself, I want to open and edit certain glyphs in the font in Inkscape. Font's aren't only used on websites. – MacroMan Jan 13 '20 at 13:37
-
The initial script still works but you must specify the language to be fontforge (ff) and not python (py). `fontforge -lang ff -c 'Open($1); Generate($2)' wingdings.ttf wingdings.otf` [docs](https://fontforge.org/docs/techref/cliargs.html) – joematune Jan 19 '22 at 13:12
-
Can someone point me to a windows command line script that will take care of this? It's tiring switching to WSL to do this process. – fmotion1 Jun 23 '22 at 21:31
The batik part of this answer is also out of date because batik gives you an svg output using the deprecated glyph element.
If you run the latest version of batik on the nasa.ttf for example
java -jar batik-ttf2svg-1.10.jar nasa.ttf -o myfont.svg
you get an output that looks something like this
<font horiz-adv-x="1045" ><font-face
font-family="Nasa"
units-per-em="2048"
panose-1="2 11 5 0 0 0 0 0 0 0"
ascent="1507"
descent="-393"
alphabetic="0" />
....followed by much more code representing every glyph in font
the way to deal with this is represented in the answer at Use SVG glyph tag in HTML - turn glyphs into symbols and flip them.
As far as why the fonts are flipped on their X axis refer to the superseded part of spec https://www.w3.org/TR/SVG11/fonts.html#SVGFontsOverview
Unlike standard graphics in SVG, where the initial coordinate system has the y-axis pointing downward (see The initial coordinate system), the design grid for SVG fonts, along with the initial coordinate system for the glyphs, has the y-axis pointing upward for consistency with accepted industry practice for many popular font formats.

- 1,461
- 2
- 23
- 46
@Jay (I was unable to comment), on Window, this works :
"C:\Program Files (x86)\FontForgeBuilds\fontforge.bat" -lang py -c "import fontforge; fontforge.open('C:/Temp/myFont.ttf').generate('C:/Temp/myFont.svg')"

- 1
- 2