Code

Fix drag & drop from swatches - patch by Adonis Papaderos
[inkscape.git] / src / dom / svgreader.cpp
index 1ec85bcca924381b32a5d986449e88b265d1962c..4584ba32f8d635d73f8433a1ea3e8913fdd194bd 100644 (file)
@@ -38,9 +38,9 @@
 #include "dom/ucd.h"
 #include "xmlreader.h"
 
+#include <cstdio>
 #include <stdarg.h>
 
-#define SVG_NAMESPACE "http://www.w3.org/2000/svg"
 
 namespace org
 {
@@ -90,6 +90,8 @@ void SVGReader::trace(char const *fmt, ...)
 //# P A R S I N G
 //#########################################################################
 
+
+
 /**
  *  Get the character at the position and record the fact
  */
@@ -631,96 +633,19 @@ bool SVGReader::parseElement(SVGElementImplPtr parent,
     //printf("namespaceURI:%s\n", namespaceURI.c_str());
     DOMString tagName      = sourceElem->getTagName();
     printf("tag name:%s\n", tagName.c_str());
-
-    ElementImplPtr newElement = NULL;
-    if (namespaceURI != SVG_NAMESPACE)
-        {
-        newElement = new SVGSVGElementImpl();
-        newElement->assign(*sourceElem);
-        parent->appendChild(newElement);
-        }
-    else //## SVG!!
+    ElementPtr newElement = doc->createElementNS(namespaceURI, tagName);
+    if (!newElement)
         {
+               return false;
+               }
+       NamedNodeMap &attrs = sourceElem->getAttributes();
+       for (unsigned int i=0 ; i<attrs.getLength() ; i++)
+           {
+           NodePtr n = attrs.item(i);
+           newElement->setAttribute(n->getNodeName(), n->getNodeValue());//should be exception here
+               }
+       parent->appendChild(newElement);
 
-        //####################################################
-        //## ATTRIBUTES
-        //####################################################
-        DOMString style = sourceElem->getAttribute("style");
-        if (style.size() > 0)
-            {
-            css::CssReader parser;
-            style.insert(0, "{");
-            style.append("}");
-            //printf("CSS:%s\n", style.c_str());
-            if (!parser.parse(style))
-                {
-                error("parsing style attribute");
-                }
-            else
-                {
-                //printf("##parsed!\n");
-                }
-            }
-
-        DOMString transform = sourceElem->getAttribute("transform");
-        if (transform.size() > 0)
-            {
-            if (!parseTransform(transform))
-                {
-                error("parsing transform attribute");
-                }
-            else
-                {
-                //printf("##parsed!\n");
-                }
-            }
-
-        //####################################################
-        //## ELEMENT - SPECIFIC
-        //####################################################
-        if (tagName == "svg")
-            {
-            newElement = new SVGSVGElementImpl();
-            newElement->assign(*sourceElem);
-            parent->appendChild(newElement);
-            }
-        else if (tagName == "title")
-            {
-            newElement = new SVGTitleElementImpl();
-            newElement->assign(*sourceElem);
-            parent->appendChild(newElement);
-            }
-        else if (tagName == "desc")
-            {
-            newElement = new SVGDescElementImpl();
-            newElement->assign(*sourceElem);
-            parent->appendChild(newElement);
-            }
-        else if (tagName == "defs")
-            {
-            newElement = new SVGDefsElementImpl();
-            newElement->assign(*sourceElem);
-            parent->appendChild(newElement);
-            }
-        else if (tagName == "style")
-            {
-            newElement = new SVGStyleElementImpl();
-            newElement->assign(*sourceElem);
-            parent->appendChild(newElement);
-            }
-        else if (tagName == "g")
-            {
-            newElement = new SVGGElementImpl();
-            newElement->assign(*sourceElem);
-            parent->appendChild(newElement);
-            }
-        else if (tagName == "path")
-            {
-            newElement = new SVGPathElementImpl();
-            newElement->assign(*sourceElem);
-            parent->appendChild(newElement);
-            }
-        }
 
     NodeList children = sourceElem->getChildNodes();
     int nodeCount = children.getLength();