Automate process of SVG to TTF/OTF in FontForge

Updated september 2021 as I have learned more about OTF:

I’ve been creating SVG-fonts using Inkscape and the Custom Stroke Font extension. The single line fonts work best as SVG, but I will convert the fonts to TTF or OTF when creating regular outline fonts or stickfonts (zero width fonts looking like single line fonts) or temporary closed single line fonts. With trial and error I have found the steps that is needed to get the best results most effectively.

The steps in FontForge

The TTF format expect the em size to be 1024 (or 2048). OTF expect em size of 1000. So if the SVG font units-per-em is different is should be changed. The TTF format also expect a certain direction of the paths, the paths should be defined as quadratic bezier curves and the nodes should be whole numbers. I have previously described the manual steps for this (see last paragraph of this post). Now I have found a way to script these steps (except for the quadratic conversion part, but it seems like my results are fine without this step – the convert to quadratic seem to happen during generating the font). OTF do not need to be converted to integers.

The steps automated

Paste the code below into Notepad or similar and save as svg2ttf.pe

#!/usr/local/bin/fontforge
SelectAll()
ScaleToEm(1024)
CorrectDirection()
RoundToInt()

When you want to use the font for cutting or plotting I highly prefer the OTF format as explained in another post. Then use this code instead and save as svg2otf.pe:

#!/usr/local/bin/fontforge
SelectAll()
ScaleToEm(1000)
CorrectDirection()

In FontForge go to File – > Preferences … and find the Script Menu. Locate the .pe file you just created and in Menu Name write the text you want to recognize it with. Now the script(s) should appear in File -> Script Menu (you might have to restart FontForge first).

Add the .pe script to the Script Menu from the Preferenses window.

Use the script

Now you can open your SVG-font in FontForge, go to File -> Script Menu, select the script you want and watch it work.

It’s recommended to add your copyright info (Go to Element -> Font info).

To create your TTF or OTF font file: File -> Generat Fonts and select file format TrueType or Open Type (CFF).

Leave a Reply

Your email address will not be published. Required fields are marked *