Plugin importing data from a binary format when opened in Glyphs

I’m extending the MATH Plugin to read MATH table and import it into the data the plugin uses (some stored in master and glyph userData, others as anchors).

I already have a callback for DOCUMENTOPENED, so I open the font there using GSDocument.filePath and import the data into the GSFont.

All is good but I have some questions/issues:

  1. Is this the right approach or there is a better way?
  2. The causes the font and the affected glyphs to be Edited, but since everything is imported and the user didn’t manually change anything, I want to avoid this. Is there is away to revert the edited status of the font and the glyphs?
  1. Yes.
  2. You can clean up after yourself:
from AppKit import NSChangeCleared
for g in font.glyphs:
    g.undoManager().removeAllActions()
    g.updateChangeCount_(NSChangeCleared)
font.undoManager().removeAllActions()
font.parent.updateChangeCount_(NSChangeCleared)
3 Likes

This works, thanks.

Another question. If I’m opening a font collection file, Glyphs will ask the user to select a font from the collection. How do I know which font was selected to open it as well?

There is currently no way to do that directly. Maybe you can recognise it from the fontName?

I added the fontIndex to the font.tempData["TTCFontIndex"]

1 Like

I guess, but I wanted to check for a simpler solution first.

Thanks. That is enough for me, I don’t mind it working only in cutting edge for now.

Did this make it into release?

I only had it in the future branch. I just moved it into he 3 branch.

1 Like

Got it working now, thanks!