fonttools/Scripts/RoboFabUFO/ExportOneGlyphToGlif.py
Erik van Blokland 2dcd36633c moving changes from robofab trunk rev 202 into the ufo3 branch
git-svn-id: http://svn.robofab.com/trunk@203 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c
2010-01-05 12:40:15 +00:00

40 lines
940 B
Python

#FLM: Glyph to Glif, not in UFO
"""
Dump the selected glyph to a Glif as a seperate, individual file.
This is not saved through a GlyphSet and any contents.plist in the
same directory will not be updated. If that's what you need use
DumpOneGlyphToUFO.py
"""
from robofab.glifLib import writeGlyphToString
from robofab.world import CurrentFont, CurrentGlyph
from robofab.interface.all.dialogs import PutFile
from robofab.tools.glyphNameSchemes import glyphNameToShortFileName
import os
f = CurrentFont()
g = CurrentGlyph()
if g is not None:
todo = [g.name]
else:
todo = f.selection
for c in todo:
g = f[c]
result = True
data = writeGlyphToString(g.name, g, g.drawPoints)
filename = glyphNameToShortFileName(g.name, None)
file = PutFile("Save this glif as:")
if file is not None:
path = os.path.join(os.path.dirname(file), filename)
print "saving to", path
f = open(path, "w")
f.write(data)
f.close()
print 'done'