Fontforge: Export all glyphs as individual SVGs to a specific location

Created on 30 Sep 2020  路  4Comments  路  Source: fontforge/fontforge

Is there any way to export all glyphs from a font as individual SVGs to a specific location in Windows 10?

Most helpful comment

1) Do some copy of your SFD file, because for correct output you need unlink references in the glyphs.

2) Do some subdirectory in the directory where you have SFD file
-for example your SFD file is in d:\myfonts\myfont.sfd, so do subdirectory d:\myfonts\svg for script output, this subdirectory you will need put to the script

3) Open your SFD file - you have two choices, better is first
a) by doubleclick from some File manager or Windows Explorer
b) From FontForge menu: File/ Open

4) Use File/ Execute script, check radiobox FF, and put there:

SelectAll()
UnlinkReference()
Export("svg/%n-%e.svg")
font-forge-script

This FontForge script select all glyphs, then unlink references in glyphs, and then export glyphs to the SVG subdirectory. %n means the file name will be the glyph name, and %e adds glyph encoding to the file name -> it is important, if you don't use %e then glyphs with the same names differs only with lowercase/uppercase will be rewrites only to one file. For example if you have glyphs "a" and "A", then Export only with %n do only one file -> "a.svg". Export with %n-%e will do correctly two files, for example something like "a-12.svg" and "A-38.svg".

If you opened your SFD file from File menu, you must add path to the Export command like: Export("d:/myfonts/svg/%n-%e.svg") else you will see message "Save failed".

When i tried this script, FontForge exported some glyphs with limited viewbox, there is examples for arabic letter Ha'.
Ha

It is possible to correct viewbox for example in InkScape, but batch process is better. I use program Find and Replace http://findandreplace.io for batch replacing by regular expressions in the files. I had viebow in exported files 2048px high
poznblok

so I changed it with Find and Replace to the 2500px:
fnr

All 4 comments

I'm not positive but I'm pretty sure you need a python script for this

I'm not positive but I'm pretty sure you need a python script for this

I found this from Stack Overflow: SelectWorthOutputting(); foreach Export("svg"); endloop;
But SVGs are getting saved to a default location. Also, some glyphs are not getting saved. For e.g., small letters. I don't have experience in coding. So, any help would be appreciated. Thanks in advance.

1) Do some copy of your SFD file, because for correct output you need unlink references in the glyphs.

2) Do some subdirectory in the directory where you have SFD file
-for example your SFD file is in d:\myfonts\myfont.sfd, so do subdirectory d:\myfonts\svg for script output, this subdirectory you will need put to the script

3) Open your SFD file - you have two choices, better is first
a) by doubleclick from some File manager or Windows Explorer
b) From FontForge menu: File/ Open

4) Use File/ Execute script, check radiobox FF, and put there:

SelectAll()
UnlinkReference()
Export("svg/%n-%e.svg")
font-forge-script

This FontForge script select all glyphs, then unlink references in glyphs, and then export glyphs to the SVG subdirectory. %n means the file name will be the glyph name, and %e adds glyph encoding to the file name -> it is important, if you don't use %e then glyphs with the same names differs only with lowercase/uppercase will be rewrites only to one file. For example if you have glyphs "a" and "A", then Export only with %n do only one file -> "a.svg". Export with %n-%e will do correctly two files, for example something like "a-12.svg" and "A-38.svg".

If you opened your SFD file from File menu, you must add path to the Export command like: Export("d:/myfonts/svg/%n-%e.svg") else you will see message "Save failed".

When i tried this script, FontForge exported some glyphs with limited viewbox, there is examples for arabic letter Ha'.
Ha

It is possible to correct viewbox for example in InkScape, but batch process is better. I use program Find and Replace http://findandreplace.io for batch replacing by regular expressions in the files. I had viebow in exported files 2048px high
poznblok

so I changed it with Find and Replace to the 2500px:
fnr

@KamilLanda It worked! Thanks a lot for this detailed explanation. Learned a lot today. Thanks again.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ilius picture ilius  路  9Comments

dimitre picture dimitre  路  7Comments

typedesigner picture typedesigner  路  5Comments

zoghal picture zoghal  路  9Comments

Shawali picture Shawali  路  3Comments