Skip to content

Make GlyphsBackend writable for glyph data - #76

Merged
justvanrossum merged 120 commits into
mainfrom
issue-75-make-GlyphsBackend-writable
Mar 13, 2025
Merged

justvanrossum merged 120 commits into
mainfrom
issue-75-make-GlyphsBackend-writable

Conversation

@ollimeier

@ollimeier ollimeier commented Jan 8, 2025 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member

All good so far 👍

@ollimeier

Copy link
Copy Markdown
Contributor 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: googlefonts/fontra-glyphs@c4efd49

@ollimeier

Copy link
Copy Markdown
Contributor 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
justvanrossum and others added 3 commits March 12, 2025 11:37
…File to include .glyphspackage

This includes some expected exceptions for 'kernTop', 'kernBottom' and 'rememberToMakeCoffee'
Comment thread src/fontra_glyphs/backend.py Outdated
@ollimeier

Copy link
Copy Markdown
Contributor Author

@justvanrossum I converted a .glyphs file with 3404 characters to a .glyphspackage and compared all glyph names with the glyphspackage glyphs file names and all were the same. It means that userNameToFileName just works fine.

@justvanrossum justvanrossum changed the title Make GlyphsBackend writable Make GlyphsBackend writable for glyph data Mar 13, 2025
@ollimeier

This comment was marked as resolved.

@justvanrossum
justvanrossum merged commit 8374341 into main Mar 13, 2025
@justvanrossum
justvanrossum deleted the issue-75-make-GlyphsBackend-writable branch March 13, 2025 12:04
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 for glyph data

2 participants