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:
Tal Leming 2011-10-06 17:50:53 +00:00
parent 145902c57a
commit 91b7ba0e72
2 changed files with 42 additions and 8 deletions

View File

@ -952,6 +952,16 @@ class UFOWriter(object):
"""
if self._formatVersion < 3:
raise UFOLibError("Renaming a glyph set is not allowed in UFO %d." % self._formatVersion)
# 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

View File

@ -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):