Convert in command line an sfd file (fontforge) to ttf, otf, woff, svg

command lineconversionfonts

I search a way to automatically convert an sfd file (The work format of Fontforge) to the main font format (at least otf, ttf, woof, svg).

But I need to do it in command line, I don’t need to do it from GUI.

Unfortunately it seams that the Fontforge application don’t support it (I read the manpage and there is no mention of this usage). Anyway, I need to do it from command line but it’s not necessary to do it from Fontforge. Any other application who can convert the Fontforge work format “SFD” to the main font format.

So, how can I get a commands like this:

sfd2ttf input.sfd output.ttf
sfd2otf input.sfd output.otf
sfd2woff input.sfd output.woff
sfd2svg input.sfd output.svg

Best Answer

You can do it with Fontforge, see here:

-c script-string

If FontForge's first (or second, if the first is -lang) argument is "-c" then the argument that follows will be treated as a string containing scripting commands, and those commands will be executed. All remaining arguments will be passed to the script.

$ fontforge -c 'Open($1); Generate($2)' foo.sfd foo.ttf

Will read a font from "foo.sfd" and then generate a truetype font from it called "foo.ttf"

In your case you can create a script, say convertsfd, like this

#!/bin/bash
fontforge -lang=ff -c 'Open($1); Generate($2)' "$1" "$2"

make it executable, and call it like this:

$ ./convertsfd foo.sfd foo.ttf

Change the second argument to foo.otf or to other formats as needed, I only tested with ttf and otf.

To call the script from anywhere, just place it in your ~/.local/bin, or some other directory in your PATH.