Fontforge: Export a glyph to SVG with fontforge command line
Asked Answered
H

3

14

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.

Howling answered 20/12, 2017 at 9:37 Comment(0)
T
30

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).

Titi answered 2/5, 2018 at 5:50 Comment(11)
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.Janettajanette
Thanks @Kyle K for this answer, helped a lot! have a good day manImmoderate
Works great on windows, I just needed to start run_fontforge.exe with Admin permissions.Embargo
On MacOS it extracts it to your user home folderCattail
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;Nelidanelie
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?Blackcock
@Blackcock - i worked around by exporting all characters, moving them to a separate folder, selecting & clearing all uppercase, and running the export again for lowercase.Residence
@Blackcock You can specify a full address as argument to Export, so instead of Export("svg") do Export("/the/path/for/saving/glyph.svg").Interplay
@Interplay 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...Carricarriage
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.Residence
This will NOT export colored glyphs. Do you think it's possible?Betake
B
1

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.

Betake answered 3/10, 2022 at 19:39 Comment(0)
M
0

My PowerShell script for Windows 10 (execute from FontForge directory, i.e. C:\Program Files (x86)\FontForgeBuilds\bin):

.\fontforge -lang=ff -c 'Open($1); SelectWorthOutputting(); foreach Export($2); endloop;' 8bitlim.ttf '%n-%e.svg'

A version that reads all fonts from a subdirectory "fonts" and extracts glyphs:

$files = Get-ChildItem "fonts"

for ($i=0; $i -lt $files.Count; $i++) { $infile = "fonts" + $files[$i].Name .\fontforge -lang=ff -c 'Open($1); SelectWorthOutputting(); foreach Export($2); endloop;' $infile '%n-%e.svg' }

Mcfall answered 15/3 at 17:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.