Import and export from python

Is it possible to do batching using Glyphs? I’ve made a small script that removes unused characters from a font based on an input file, but i’d like to automate the process to automatically import, modify and export fonts for multiple languages, fonts, various options etc, instead of manually importing, running the script and exporting, which can be pretty time consuming.

Also, is there a way to reduce memory usage for very large fonts (fonts with asian languages). Fonts that I have to work with use a few GB of ram, and some won’t even load because I only have 4 GB. It also take very long for a font to load (tens of minutes).

You can write scripts that open a font, do some modifications and saves it again.

I will give you an example a bit later.

Even through Glyphs does not support chinese fonts, I can improve the memory usage and performance for big fonts a bit.

Thank you for the fast reply and I’m looking forward to the example.

btw, what version of Glyphs do you use?

I’m using 1.1.1

I can see that there is a memory leak fix in the updates. I hope it will help with my memory issues.

you can use a macro like this:

path = "/Users/georg/Desktop/MinionPro-Ana GS.glyphs"
doc = Glyphs.openDocumentWithContentsOfFile_display_(path, False)
del(doc.font.glyphs["A"])
print "__doc", doc
doc.writeToURL_ofType_error_(NSURL.fileURLWithPath_("/Users/georg/Desktop/MinionPro- Ana New.glyphs"), "com.schriftgestaltung.glyphs", None)

You can put it in the macro panel or in a .py file in the scripts folder.

Thank you very much for the example! However, is there a way to additionally export to otf? I’m not familiar with Objective-C and its python binding and don’t really know if there is an obvious way to this based on your example.

Glyphs is not a good choice to subset a existing font. You need to regenerate all opentype features and it does not support chinese font. So the fonts will not work the same way as the source fonts.

To write a .otf from script looks like this:
Exporter = GSExportInstanceOperation.alloc().initWithFont_instance_andURL_(doc.font,doc.font.ins tanceAtIndex_(0), NSURL.fileURLWithPath_("/Users/georg/Desktop/MinionPro-Ana New.otf"))
Exporter.main()

I will need to write a wrapper for that, because this function will not tell you about any error that happened during the export.

Thank you for taking the time to answer my questions. I’ll try your solution. I’ve had no problems in creating a subset of a font with Glyphs in the past, even with fonts with Chinese characters, but maybe we were just lucky and the problems you are talking about didn’t affect us.

Thank you again and have a good day.