12

How to export a glyph (from its unicode) to SVG with Fontforge command line ?

I also need to specify the font size and keep the original margins it has in the font.

DevonDahon
  • 7,460
  • 6
  • 69
  • 114

2 Answers2

27

You may have found your answer already, but I just had to do this with the latest build of FontForge. The old answer of this command:

fontforge -lang=ff -c 'Open($1); SelectWorthOutputting(); foreach Export("svg"); endloop;' font.ttf 

From a command prompt didn't want to work on Windows10 (I assume a permission issue), but you could give it a try. A quick work-around is to do it via the GUI Execute Script.

  • Run FontForge (For Windows10 installed in the Program Files (x86) directory, you may need to right-click "run_fontforge.exe" --> Run As Administrator).

  • Open the font you want to export.

  • Go to File > Execute Script

  • Paste: SelectWorthOutputting(); foreach Export("svg"); endloop;
  • Select "FF" radial button.
  • Hit OK

It'll save to the FontForge folder (where run_fontforge.exe is located).

Kyle K.
  • 306
  • 4
  • 3
  • Thank you Kyle! I am an Ubuntu user and your modification still worked for me. I have Python scripting enabled too but I haven't gotten around to writing a script when this works perfectly well :). Only thing I have to figure out how to do next is to specify the save location for all the svg files. – Hee Jin Nov 15 '18 at 18:17
  • 1
    Thanks @Kyle K for this answer, helped a lot! have a good day man – Kresimir Pendic May 09 '19 at 10:13
  • 1
    Works great on windows, I just needed to start run_fontforge.exe with Admin permissions. – Nick Oct 07 '19 at 17:00
  • On MacOS it extracts it to your user home folder – Shardul Nov 28 '19 at 11:36
  • On Linux, specifying a destination folder is quite simple. Assuming you have a file "font.ttf" in a specific folder and a subfolder "svg" in which you want to extract all the individual characters, you can use a Bash script of the type: `cd ~/mydir/svg; fontforge -lang=ff -c 'Open($1); SelectWorthOutputting(); foreach Export("svg"); endloop;' ../font.ttf;` – Francesco Galgani Sep 19 '20 at 10:16
  • 2
    Is there anyway to select a location for saving the SVGs in Win 10? Also, in Windows, small letters are getting overwritten by cap letters while saving. Any workaround for that? – Clicker Oct 01 '20 at 17:29
  • @Clicker - i worked around by exporting all characters, moving them to a separate folder, selecting & clearing all uppercase, and running the export again for lowercase. – ashleedawg Jan 12 '21 at 11:46
  • 1
    @Clicker You can specify a full address as argument to Export, so instead of `Export("svg")` do `Export("/the/path/for/saving/glyph.svg")`. – Student Jan 21 '21 at 22:37
  • @Student Can you please show an example of using a custom path? For some reason it doesn't work for me... It created a single file, and I want a file per each glyph... – android developer Oct 03 '21 at 07:21
  • Manually select the glyphs for export (drag mouse to select consecutive, or hold Shift to select non-consecutive), then `File`>`Execute Script`, click **`FF`** radio button, and paste code: `foreach Export("/myDestinationFolder/%n-%e.svg"); endloop;` to export with filenames like `A-65.svg`. – ashleedawg Feb 08 '22 at 01:36
  • This will NOT export colored glyphs. Do you think it's possible? – Berry Tsakala Oct 03 '22 at 19:40
0

On Windows os (Tested on win10)

this is from inside a BATCH file:

c:\Programs\FontForge\bin\fontforge.exe -lang=ff -c "Open($1); SelectWorthOutputting(); foreach Export('%%e_%%f_%%n_%%u.eps'); endloop;" %1

this is directly on the command line:

c:\Programs\FontForge\bin\fontforge.exe -lang=ff -c "Open($1); SelectWorthOutputting(); foreach Export('%e_%f_%n_%u.eps'); endloop;" font-file.ttf

note - the color is not exported. And I don't know if it's unimplemented, or a bug.

Berry Tsakala
  • 15,313
  • 12
  • 57
  • 80