Question

Does anyone know of a command-line tool that will convert both TTF and OTF fonts to SVG fonts?

Was it helpful?

Solution

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

OTHER TIPS

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")'

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top