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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update: check if we have any results before passing the xml to readGlyphFromString.