示例#1
0
class SvgXmlToolTest(unittest.TestCase):
    def setUp(self):
        self.xmlTool = SvgXmlTool()
        self.tool = SvgTool()

    def test_copyAttrSvgTag(self):
        svg1 = minidom.parseString('<svg a="0" b="1" c="2"/>')
        svg2 = minidom.parseString('<svg new="0"/>')
        self.xmlTool.copyAttrSvgTag(svg1, svg2)
        self.assertTrue(svg2.documentElement.attributes.get("a"))
        self.assertTrue(svg2.documentElement.attributes.get("b"))
        self.assertTrue(svg2.documentElement.attributes.get("c"))
        self.assertTrue(svg1.documentElement.attributes.get("a"))
        self.assertTrue(svg1.documentElement.attributes.get("b"))
        self.assertTrue(svg1.documentElement.attributes.get("c"))

    def test_copyMetadataTag(self):
        svg1 = minidom.parseString('<svg><metadata a="0" b="1" c="2"/></svg>')
        svg2 = minidom.parseString("<svg/>")
        self.xmlTool.copyTag(svg1, svg2, "metadata")
        self.assertTrue(svg2.documentElement.getElementsByTagName("metadata"))
        self.assertTrue(svg1.documentElement.getElementsByTagName("metadata"))

    def test_copyDefs(self):
        svg1 = minidom.parseString('<svg><defs a="0"/></svg>')
        svg2 = minidom.parseString("<svg/>")
        self.xmlTool.copyTag(svg1, svg2, "defs")
        self.assertTrue(svg2.documentElement.getElementsByTagName("defs"))
        self.assertTrue(svg1.documentElement.getElementsByTagName("defs"))
示例#2
0
 def copySvgHead(self, svg_code, new_code = None):
     """
         TODO
     """
     xml_tool = SvgXmlTool()
     
     new_code = xml_tool.copyAttrSvgTag(svg_code, \
                                       new_code or self.makeNewSvgImage().getCode())
     new_code = xml_tool.copyTag( svg_code, new_code, 'defs' )
     new_code = xml_tool.copyTag( svg_code, new_code, 'metadata' )
     new_code = xml_tool.copyTag( svg_code, new_code, 'sodipodi:namedview' )
     return new_code