Last active
July 4, 2019 08:25
-
-
Save LettError/960eb6863bfdbc6ad512 to your computer and use it in GitHub Desktop.
RoboFont: copy glif from git repo to layer in current glyph.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Assuming you have | |
a UFO open in RoboFont | |
a current glyph selected | |
and furthermore that | |
this glyph is part of a git repository | |
and that you have done some work on it | |
and would like to compare the current state in robofont | |
with the version in git | |
then | |
this script will get the .glif xml for the right file | |
and write it to a layer named "prev" | |
By running this script you agree that | |
you understand that any data in the prev layer might be forfeit, | |
you need to run the ufo3 version of robofab as you need the ufoLib, | |
and that | |
the author of this script is not responsible for any loss of data. | |
""" | |
import os | |
import subprocess | |
from ufoLib import UFOReader | |
from ufoLib.glifLib import readGlyphFromString | |
from defcon.objects.glyph import Glyph | |
f = CurrentFont() | |
g = CurrentGlyph() | |
cwd = os.getcwd() | |
if f is not None: | |
targetPrev = g.getLayer('prev') | |
targetPrev.clear() | |
prevPen = targetPrev.getPointPen() | |
reader = UFOReader(f.path) | |
gs = reader.getGlyphSet() | |
glifName = gs.contents.get(g.name) | |
glyphsDir = os.path.join(f.path, "glyphs") | |
if glifName is not None: | |
path = os.path.join(glyphsDir, glifName) | |
os.chdir(glyphsDir) | |
cmd = "HEAD:./%s"%glifName | |
p = subprocess.Popen(['git', 'show', cmd], stdout=subprocess.PIPE) | |
glifXML = p.stdout.read() | |
if len(glifXML)>0: | |
readGlyphFromString(glifXML, targetPrev, prevPen) | |
print "Updated %s from %s"%(g.name, glifName) | |
else: | |
print "No data found for %s"%g.name | |
os.chdir(cwd) |
pretty cool!
shouldn't you recommend to use the stand-alone ufoLib instead of the by-now-dead robofab/ufo3k branch?
https://github.com/unified-font-object/ufoLib
@anthrotype Good point, edited, thanks!
On the other hand, RoboFont uses robofab.ufoLib, so using that would take away an external dependency.
(defcon''s Glyph doesn't appear to be used here.)
@justvanrossum: updated! Next step: RoboFont could sniff at the *.ufo/glyphs and check for possible conflicts. If there is a conflicting version of a glyph in git, RF could pull it and store it in a separate layer. Data is preserved and the user can choose either version to go to the foreground layer.
Update: check if we have any results before passing the xml to readGlyphFromString.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, sorry for the two unnecessary prints