I am aware that it is possible to write an export format plugin using GlyphsSDK, but I am wondering whether it is also possible to write a custom file format plugin for Glyphs 3, that would enable saving and opening files of that format. Ideally I would like to store my projects in a compressed binary format (.bglyphs or something of the kind). If this is not possible, could it be considered in a future release?
Version control systems can save only the differences for text files but typically have to save the entire file for every revision when using binary files. That should give you much improved disk space utilization for text files over binary files.
You might also want to look into using .glyphspackage files where each glyph is stored as its own file. Depending on the version control system you are using, that might reduce space usage significantly.
Regardless of whether somebody else finds this useful or sensible, I would just like to know whether a custom file plugin with open and save capabilities is possible. An alternative to .glyphs, .glyphspackage, and .ufo file formats, if you will.
You have to setup yourself as an “Editor” (CFBundleTypeRole = Editor) for your file type and implement - (BOOL)writeFont:(GSFont *)font toURL:(NSURL *)URL error:(out NSError **)error or in python: def writeFont_toURL_error_(self, font, URL, None)
And: - (GSFont *)fontFromURL:(NSURL *)URL ofType:(NSString *)type error:(out NSError **)error; or python: def fontFromURL_ofType_error_(self, URL, type, NONE)
But if you just need a binary format, Glyphs has one build in. I didn’t use if for some time so it is actually broken right now. But I should be able to fix it.
But, as Florian already pointed out, there are no real benefits to that format. Yes, the files will be a bit smaller but the size of the repository will be much bigger very quickly with binary files.
Thank you. I will try that. Is there perhaps an open-source plugin that does that already? Or an example of it?
That may be very true for git, but not for subversion or any other centralized VCS that employs a binary delta. In such cases the repository can be an efficient storage for binaries. Of course these files render diff and merge useless, but as much as I like the .glyphs format, I would not be resolving merge conflicts by hand, or looking at diffs anyway.
I have added writeFont_toURL_error_ and fontFromURL_ofType_error_ functions to the BDF file format plugin, but the format does not show up in the ‘Save As…’ dialog. Should the BDFFileFormat class inherit from GeneralPlugin instead? It says here that file format plug-ins provide only font export functionality through the Export dialog, and not the Save and Open functionalities.
Does the Info.plist in the BDF plugin require any additional modifications as well? CFBundleTypeRole is already set to Editor.
You were right. I fixed it that you can add a new file type to Glyphs with a plugin.
If you write in python, you need implement those two methods:
def read(self, filepath, fileType):
font = GSFont()
# read the file into that font object here
def export(self, font, filepath=None):
# write the file here
The thing is GetSaveFile inside the export function (where I presume NSSavePanel would be called, since I am not calling it anywhere else explicitly) is not even getting invoked. In fact, I think this exception happens before the export function is entered. I believe this to be so, because a File > Export, instead of a File > Save As which is what I am trying to do, is successful and I get NSLog messages from the export function.