Code

Rearrange to enable code that does not directly rely on lcms.
[inkscape.git] / src / dom / svgreader.cpp
index fb4b3c62ed7c3a78df869c19a6a514b7690d590f..ea4392f50fb494f0b1c0745956421690677dab03 100644 (file)
@@ -40,7 +40,6 @@
 
 #include <stdarg.h>
 
-#define SVG_NAMESPACE "http://www.w3.org/2000/svg"
 
 namespace org
 {
@@ -90,6 +89,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 +632,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();
@@ -762,8 +686,8 @@ SVGDocumentPtr SVGReader::parse(const DocumentPtr src)
     DOMImplementationImpl impl;
     doc = new SVGDocumentImpl(&impl, SVG_NAMESPACE, "svg" , NULL);
 
-    SVGElementImplPtr destElem = dynamic_cast<SVGElementImpl *>(doc->getRootElement().get());
-    ElementImplPtr    srcElem  = dynamic_cast<ElementImpl *>(src->getDocumentElement().get());
+    SVGElementImplPtr destElem = dynamic_pointer_cast<SVGElementImpl, SVGElement>(doc->getRootElement());
+    ElementImplPtr    srcElem  = dynamic_pointer_cast<ElementImpl, Element>(src->getDocumentElement());
     if (!parseElement(destElem, srcElem))
         {
         return NULL;