···
22
-
if isinstance(v, defs.DrawingDef):
23
-
v = 'url(#{})'.format(v.id)
22
+
if isinstance(v, defs.DrawingElement):
23
+
if k == 'xlink:href':
24
+
v = '#{}'.format(v.id)
26
+
v = 'url(#{})'.format(v.id)
outputFile.write(' {}="{}"'.format(k,v))
···
def writeSvgDefs(self, idGen, isDuplicate, outputFile):
for defn in self.getSvgDefs():
if isDuplicate(defn): continue
41
+
defn.writeSvgDefs(idGen, isDuplicate, outputFile)
defn.writeSvgElement(outputFile)
···
tags. This will not be called if hasContent is False. '''
raise RuntimeError('This element has no content')
74
-
return [v for v in self.args.values() if isinstance(v, defs.DrawingDef)]
78
+
return [v for v in self.args.values()
79
+
if isinstance(v, defs.DrawingElement)]
if isinstance(other, type(self)):
return (self.TAG_NAME == other.TAG_NAME and
···
class Use(DrawingBasicElement):
''' A copy of another element
135
-
Specify the other element by its id: href='#otherElemId'. '''
140
+
The other element becomes an SVG def shared between all Use elements
141
+
that reference it. '''
def __init__(self, otherElem, x, y, **kwargs):
139
-
if isinstance(otherElem, str):
140
-
otherElemId = otherElem
142
-
if otherElem.id is None:
143
-
raise ValueError('otherElem must have an id')
144
-
otherElemId = otherElem.id
145
-
href = '#{}'.format(otherElemId)
146
-
super().__init__(xlink__href=href, x=x, y=y, **kwargs)
145
+
if isinstance(otherElem, str) and not otherElem.startswith('#'):
146
+
otherElem = '#' + otherElem
147
+
super().__init__(xlink__href=otherElem, x=x, y=y, **kwargs)
class Image(DrawingBasicElement):
''' A linked or embedded raster image '''