def __init__ (self, filename) : XMLFileWriter.__init__(self,filename) doc = XMLElement(None,Document.DOCUMENT_NODE,"#document") comment = XMLElement(None,Document.COMMENT_NODE,"#comment") comment.set_attribute("data","created from python svgdraw module") doc.add_child(comment) self._svg_doc = doc
def save (self) : """Save SVG attributes as XML attributes """ self.set_attribute("x","%f" % self._x) self.set_attribute("y","%f" % self._y) self.set_attribute("xml:space","preserve") #text fragments self.clear_children() for txt,size in self._txt_fragments : #span span = XMLElement(None,ELEMENT_TYPE,"svg:tspan") self.add_child(span) span.set_attribute("x","%f" % self._x) span.set_attribute("y","%f" % self._y) span.set_attribute("sodipodi:role","line") span.set_attribute("style","font-size:%s" % write_float(size) ) #txt txtelm = XMLElement(None,TEXT_TYPE) span.add_child(txtelm) txtelm.set_attribute("data","%s" % txt) #save