source-foundry / Hack

A typeface designed for source code
http://sourcefoundry.org/hack/
Other
16.49k stars 616 forks source link

Source cleanliness: remove com.schriftgestaltung.Glyphs.lastChange glyph lib keys #459

Open madig opened 6 years ago

madig commented 6 years ago

These are just noise if you're using Git. You can keep Glyphs from inserting them by setting the "Disable Last Change" parameter in the font or inserting the com.schriftgestaltung.customParameter.GSFont.lastChange lib key.

chrissimpkins commented 6 years ago

I got this far on automated removal of this glif file library key across all source files and need some guidance on an appropriate pointPen to use in order to capture the contours for the write back to the *.glif source. Thoughts?

from ufoLib import UFOReader

class GlyphObj(object):
    def __init__(self):
        pass

ufo = UFOReader("Test-Regular.ufo")
glyphset = ufo.getGlyphSet()

for glyphname in glyphset.contents:
    gobj = GlyphObj()
    glyph = glyphset.readGlyph(glyphname, gobj, POINTPEN) # <--- HERE

    if hasattr(gobj, "lib"):
        gobj.lib.pop("com.schriftgestaltung.Glyphs.lastChange", None)
        glyphset.writeGlyph(glyphname, gobj, POINTPEN) # <--- AND HERE
chrissimpkins commented 6 years ago

And by the following comment:

inserting the com.schriftgestaltung.customParameter.GSFont.lastChange lib key.

what do you set this key to in order to eliminate Glyphs app time stamps of the *.glif files?

madig commented 6 years ago

Try

from pathlib import Path
import defcon

for ufo in Path("src").glob("*.ufo"):
    u = defcon.Font(ufo)
    u.lib["com.schriftgestaltung.customParameter.GSFont.lastChange"] = False
    for layer in u.layers:
        for glyph in layer:
            if "com.schriftgestaltung.Glyphs.lastChange" in glyph.lib:
                del glyph.lib["com.schriftgestaltung.Glyphs.lastChange"]
chrissimpkins commented 6 years ago

Thank you!

madig commented 6 years ago

Round-trip through Glyphs.app to make sure stuff doesn't sneak back in.