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

Open
wants to merge 48 commits into
base: main
Choose a base branch
from

Conversation

ollimeier
Copy link
Collaborator

@ollimeier ollimeier commented Jan 8, 2025

This fixes #75.
This also fixes #79.

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

@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?

        # 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 ollimeier force-pushed the issue-75-make-GlyphsBackend-writable branch from ee36016 to 6d8e783 Compare January 22, 2025 15:18
@ollimeier ollimeier marked this pull request as ready for review January 23, 2025 17:31
@justvanrossum
Copy link
Collaborator

Our openstep-plist fork now also fixes the binary data formatting, so the last regex-based workaround can be removed.

Justs openstep-plist takes care of binary_spaces, so need of extra function.
GlyphsApp will add an empty layer if one is missing.
@justvanrossum
Copy link
Collaborator

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.

Issue with editing axes, if raised an error Make GlyphsBackend writable
2 participants