Some initial, broken support for layerinfo.plist.
git-svn-id: http://svn.robofab.com/branches/ufo3k@307 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c
This commit is contained in:
parent
0b7abcfc96
commit
8d7d861e19
@ -31,6 +31,8 @@ else:
|
|||||||
WRITE_MODE = "w"
|
WRITE_MODE = "w"
|
||||||
READ_MODE = "r"
|
READ_MODE = "r"
|
||||||
|
|
||||||
|
LAYERINFO_FILENAME = "layercontents.plist"
|
||||||
|
|
||||||
|
|
||||||
class Glyph(object):
|
class Glyph(object):
|
||||||
|
|
||||||
@ -81,7 +83,7 @@ class GlyphSet(object):
|
|||||||
|
|
||||||
glyphClass = Glyph
|
glyphClass = Glyph
|
||||||
|
|
||||||
def __init__(self, dirName, glyphNameToFileNameFunc=None):
|
def __init__(self, dirName, glyphNameToFileNameFunc=None, ufoFormatVersion=3):
|
||||||
"""'dirName' should be a path to an existing directory.
|
"""'dirName' should be a path to an existing directory.
|
||||||
|
|
||||||
The optional 'glyphNameToFileNameFunc' argument must be a callback
|
The optional 'glyphNameToFileNameFunc' argument must be a callback
|
||||||
@ -91,6 +93,7 @@ class GlyphSet(object):
|
|||||||
a file name is created for a given glyph name.
|
a file name is created for a given glyph name.
|
||||||
"""
|
"""
|
||||||
self.dirName = dirName
|
self.dirName = dirName
|
||||||
|
self.ufoFormatVersion = ufoFormatVersion
|
||||||
if glyphNameToFileNameFunc is None:
|
if glyphNameToFileNameFunc is None:
|
||||||
glyphNameToFileNameFunc = glyphNameToFileName
|
glyphNameToFileNameFunc = glyphNameToFileName
|
||||||
self.glyphNameToFileName = glyphNameToFileNameFunc
|
self.glyphNameToFileName = glyphNameToFileNameFunc
|
||||||
@ -133,6 +136,45 @@ class GlyphSet(object):
|
|||||||
f.write(plist)
|
f.write(plist)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
# layer info
|
||||||
|
|
||||||
|
def readLayerInfo(self, info):
|
||||||
|
path = os.path.join(self.dirName, LAYERINFO_FILENAME)
|
||||||
|
if not os.path.exists(path):
|
||||||
|
return
|
||||||
|
infoDict = readPlist(path)
|
||||||
|
infoDict = validateLayerInfoData(infoDict)
|
||||||
|
# populate the object
|
||||||
|
for attr, value in infoDataToSet.items():
|
||||||
|
try:
|
||||||
|
setattr(info, attr, value)
|
||||||
|
except AttributeError:
|
||||||
|
raise GlifLibError("The supplied layer info object does not support setting a necessary attribute (%s)." % attr)
|
||||||
|
|
||||||
|
def writeLayerInfo(self, info):
|
||||||
|
if self.ufoFormatVersion < 3:
|
||||||
|
raise GlifLibError("layerinfo.plist is not allowed in UFO %d." % self.ufoFormatVersion)
|
||||||
|
# gather data
|
||||||
|
infoData = {}
|
||||||
|
for attr in layerInfoVersion3ValueData.keys():
|
||||||
|
if hasattr(info, attr):
|
||||||
|
try:
|
||||||
|
value = getattr(info, attr)
|
||||||
|
except AttributeError:
|
||||||
|
raise GlifLibError("The supplied info object does not support getting a necessary attribute (%s)." % attr)
|
||||||
|
if value is None:
|
||||||
|
continue
|
||||||
|
infoData[attr] = value
|
||||||
|
# validate
|
||||||
|
infoData = validateLayerInfoVersion3Data(infoData)
|
||||||
|
# write file
|
||||||
|
path = os.path.join(self.dirName, LAYERINFO_FILENAME)
|
||||||
|
plist = writePlistToString(infoData)
|
||||||
|
f = open(path, WRITE_MODE)
|
||||||
|
f.write(plist)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
# read caching
|
# read caching
|
||||||
|
|
||||||
def getGLIF(self, glyphName):
|
def getGLIF(self, glyphName):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user