Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make GlyphsBackend writable #76

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ollimeier
Copy link
Collaborator

Fixes #75

I added all missing 'put' methods from WritableFontBackend as stubs.

This is a draft PR for getting feedback early.

@justvanrossum
Copy link
Collaborator

All good so far 👍

@ollimeier
Copy link
Collaborator Author

@justvanrossum
As you said, I compared the fontra backend and the designspace backend. Therefore there are two options (also written in the code):

  1. option, similar to fontra backend: Convert the fontra glyph and replace the glyph in the rawGlyphsData and save it via openstep_plist.dump().
  2. option, similar to designspace backend: Instead of using fonttools for writing UFO use glyphsLib for writing to a GlyphsApp file

Would be great if we could talk about it tomorrow: c4efd49

        # 1. convert VariableGlyph to GSGlyph (but start with a copy of the original)
        # 2. serialize to text with glyphsLib.writer.Writer(), using io.StringIO or io.BytesIO
        # 3. parse stream into "raw" object
        # 4. replace original "raw" object with new "raw" object
        # 5. write whole file with openstep_plist
@ollimeier
Copy link
Collaborator Author

@justvanrossum So, the whole formatting with openstep_plist sucks even more. It's not just about formatting, even some parts are reordered, like in the following example the order of the kerning information:

Screenshot 2025-01-17 at 21 04 14

This is the reason why I implemented _findAndReplaceGlyph. This method finds the glyph 'chunk' via start and end row and replaces only this part, without openstep_plist. This is how a diff looks like then (I changed the name for every glyph, so we see a difference):

Screenshot 2025-01-17 at 21 07 29

Via glyphsLib.writer.Writer we get the right formatted text for GlyphsApp 2 or 3. Replacing a whole glyph of a glyphspackage is also very easy and very close to what we do in the fontra backend:

    def _findAndReplaceGlyph(self, glyphName, f):
        filePath = self.getGlyphFilePath(glyphName)
        filePath.write_text(f.getvalue(), encoding="utf=8")

I think this might be better and is probably closer to your original idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make GlyphsBackend writable
2 participants