Typophile

FontForge Quick Export OTF Script ?

Martin0 votes

Hi!

I'm relatively new to FontForge after I got some experience with FontLab Studio and so far I like it (especially going open source).
While testing a design I noticed that creating OTF fonts for testing in InDesign can be a tedious task. In FontLab I was used to a script that automatically created a copy of the file, removed overlaps and prompted the export dialog. So exporting OTF for testing was done in one click.

I bet there is something similar in the FontForge world, but I couldn't find anything...
How do you "quick export" test OTFs in FontForge?

Thanks!

Martin

I just export them. If your OS's font engine isn't hosed, it should deal with overlaps intelligently. YMMV of course.

I use so one script (saved as file in my /.FontForge/python/ directory) for tests.
Script : save copy of my font as temp.sfd, remove overlaps, corect direction etc., generate font (without hints), copy it (or overwrite) to my local fonts directory (on Linux) and remove temp files.

# -*- coding: utf-8 -*-
import shutil;
import os;

def genTestOTF(arg, ft):
localFontdir='/.local/share/fonts/';
fDir=os.path.expanduser("~")+localFontdir;
ftActive=fontforge.activeFont();
ftActive.save('temp.sfd');
ft=fontforge.open('temp.sfd');
aLayer=ft.layers[ft.activeLayer].name;
ft.encoding='UnicodeBMP';
ft.selection.all();
for g in ft.selection.byGlyphs:
g.removeOverlap();
g.correctDirection();
g.canonicalStart();
g.canonicalContours();
fontNazwa = ft.fontname;
plik=fontNazwa+'_test.otf';
ft.generate(plik, flags=('opentype','dummy-dsig','apple','no-hints','no-flex'),layer=aLayer)
shutil.copy(plik,fDir+plik);
ft.close();
os.remove(plik);
os.remove('temp.sfd');

fontforge.registerMenuItem(genTestOTF,None,None,"Font",None,"Generator","Quick test-otf");

Thank you gluk, this is exactly what I was looking for. I installed the script and commented out the parts obviously responsible for installing the font to the OS font library, but I run into an error:


File "/Applications/FontForge.app/Contents/Resources/opt/local/share/fontforge/python/test-otf.py" line 9, in genTestOTF
ftActive.save("temp.sfd")
EnvironmentError: Save As "test.sfd" failed

I'm under Mac OS 10.9.5 running FontForge version "04:18 AEST 7-Jan-2015".
I installed the script under /Applications/FontForge.app/Contents/Resources/opt/local/share/fontforge/python/ .

How could that be fixed?

another system, different FontForge version, most probably another Python version... :-)
Ok,
most simplest way to make it, and avoid saveAs:
script bellow first save your work, then remove overlaps etc., generate .otf and revert your original font file (ff should ask you).

# -*- coding: utf-8 -*-
import os;

def genTestOTF(arg, ft):
ft.save();
ft.encoding='UnicodeBMP';
ft.selection.all();
for g in ft.selection.byGlyphs:
g.removeOverlap();
g.correctDirection();
g.canonicalStart();
g.canonicalContours();
plik=ft.fontname+'_test.otf';
ft.generate(plik, flags=('opentype','dummy-dsig','apple','no-hints','no-flex'));
ft.selection.none();
ft.revert();

fontforge.registerMenuItem(genTestOTF,None,None,"Font",None,"Generator","Quick test-otf");

Great workaround, although I have to get used to do these actions on my working file.
I'll look into that!

BTW, is there a library / collection / community about FontForge scripts that I missed?

Captured from web.archive.org on 19 Jun 2019. view this capture