Make it possible to rename the default layer.
git-svn-id: http://svn.robofab.com/branches/ufo3k@386 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c
This commit is contained in:
parent
145902c57a
commit
91b7ba0e72
@ -952,14 +952,24 @@ class UFOWriter(object):
|
||||
"""
|
||||
if self._formatVersion < 3:
|
||||
raise UFOLibError("Renaming a glyph set is not allowed in UFO %d." % self._formatVersion)
|
||||
# make sure the new layer name doesn't already exist
|
||||
if newLayerName is None:
|
||||
newLayerName = DEFAULT_LAYER_NAME
|
||||
if newLayerName in self.layerContents:
|
||||
raise UFOLibError("A layer named %s already exists." % newLayerName)
|
||||
# make sure the default layer doesn't already exist
|
||||
if defaultLayer and DEFAULT_GLYPHS_DIRNAME in self.layerContents.values():
|
||||
raise UFOLibError("A default layer already exists.")
|
||||
# the new and old names can be the same
|
||||
# as long as the default is being switched
|
||||
if layerName == newLayerName:
|
||||
# if the default is off and the layer is already not the default, skip
|
||||
if self.layerContents[layerName] != DEFAULT_GLYPHS_DIRNAME and not defaultLayer:
|
||||
return
|
||||
# if the default is on and the layer is already the default, skip
|
||||
if self.layerContents[layerName] == DEFAULT_GLYPHS_DIRNAME and defaultLayer:
|
||||
return
|
||||
else:
|
||||
# make sure the new layer name doesn't already exist
|
||||
if newLayerName is None:
|
||||
newLayerName = DEFAULT_LAYER_NAME
|
||||
if newLayerName in self.layerContents:
|
||||
raise UFOLibError("A layer named %s already exists." % newLayerName)
|
||||
# make sure the default layer doesn't already exist
|
||||
if defaultLayer and DEFAULT_GLYPHS_DIRNAME in self.layerContents.values():
|
||||
raise UFOLibError("A default layer already exists.")
|
||||
# get the paths
|
||||
oldDirectory = self._findDirectoryForLayerName(layerName)
|
||||
if defaultLayer:
|
||||
|
@ -3998,6 +3998,30 @@ class UFO3WriteLayersTestCase(unittest.TestCase):
|
||||
result = readPlist(path)
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def testRenameLayerDefault(self):
|
||||
self.makeUFO()
|
||||
writer = UFOWriter(self.ufoPath)
|
||||
writer.renameGlyphSet("public.default", u"layer xxx")
|
||||
writer.renameGlyphSet("layer 1", u"layer 1", defaultLayer=True)
|
||||
writer.writeLayerContents(["layer xxx", "layer 1", "layer 2"])
|
||||
path = os.path.join(self.ufoPath, "glyphs")
|
||||
exists = os.path.exists(path)
|
||||
self.assertEqual(True, exists)
|
||||
path = os.path.join(self.ufoPath, "glyphs.layer 1")
|
||||
exists = os.path.exists(path)
|
||||
self.assertEqual(False, exists)
|
||||
path = os.path.join(self.ufoPath, "glyphs.layer 2")
|
||||
exists = os.path.exists(path)
|
||||
self.assertEqual(True, exists)
|
||||
path = os.path.join(self.ufoPath, "glyphs.layer xxx")
|
||||
exists = os.path.exists(path)
|
||||
self.assertEqual(True, exists)
|
||||
# layer contents
|
||||
path = os.path.join(self.ufoPath, "layercontents.plist")
|
||||
expected = [['layer xxx', 'glyphs.layer xxx'], ['layer 1', 'glyphs'], ['layer 2', 'glyphs.layer 2']]
|
||||
result = readPlist(path)
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
# rename duplicate name
|
||||
|
||||
def testRenameLayerDuplicateName(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user