Source elements may not have a name attribute, but it is needed for for some processes afterwards.

If the element does not have one: create a new one with pattern "temp_master.%d"%(sourceCount).
The document writer then checks for source name attributes with this pattern so that is does not export.
This commit is contained in:
Erik van Blokland 2017-03-28 23:00:13 +02:00
parent 1b4106981e
commit 82e48b95b7

View File

@ -398,7 +398,9 @@ class BaseDocWriter(object):
if sourceObject.filename is not None:
sourceElement.attrib['filename'] = sourceObject.filename
if sourceObject.name is not None:
sourceElement.attrib['name'] = sourceObject.name
if sourceObject.name.find("temp_master")!=0:
# do not save temporary source names
sourceElement.attrib['name'] = sourceObject.name
if sourceObject.familyName is not None:
sourceElement.attrib['familyname'] = sourceObject.familyName
if sourceObject.styleName is not None:
@ -629,6 +631,7 @@ class BaseDocReader(object):
self.documentObject.axes.append(a)
def readSources(self):
sourceCount = 0
for sourceElement in self.root.findall(".sources/source"):
filename = sourceElement.attrib.get('filename')
if filename is not None and self.path is not None:
@ -636,6 +639,9 @@ class BaseDocReader(object):
else:
sourcePath = None
sourceName = sourceElement.attrib.get('name')
if sourceName is None:
# add a temporary source name
sourceName = "temp_master.%d"%(sourceCount)
sourceObject = self.sourceDescriptorClass()
sourceObject.path = sourcePath # absolute path to the ufo source
sourceObject.filename = filename # path as it is stored in the document
@ -671,6 +677,7 @@ class BaseDocReader(object):
if kerningElement.attrib.get('mute') == '1':
sourceObject.muteKerning = True
self.documentObject.sources.append(sourceObject)
sourceCount += 1
def locationFromElement(self, element):
elementLocation = None
@ -1092,7 +1099,7 @@ class DesignSpaceDocument(object):
a = None
if name in have:
if overwrite:
# we're making a new axis
# we have the axis,
a = self.getAxis(name)
else:
continue
@ -1767,7 +1774,9 @@ if __name__ == "__main__":
2
>>> new.checkAxes()
>>> len(new.axes)
4
2
>>> print([a.name for a in new.axes])
['snap', 'pop']
>>> new.write(testDocPath)
"""