Code

Added simplistic test cases
[inkscape.git] / src / xml / repr-css.cpp
index afa0ca2ef36a8b439443cc36a8f58886eca162f0..be125f45358481f40259bb75bbc6ad297897872f 100644 (file)
@@ -8,6 +8,7 @@
 #include <glibmm/ustring.h>
 
 #include "xml/repr.h"
+#include "xml/simple-document.h"
 #include "xml/simple-node.h"
 #include "style.h"
 #include "libcroco/cr-sel-eng.h"
@@ -21,20 +22,28 @@ using Inkscape::XML::Document;
 
 struct SPCSSAttrImpl : public SimpleNode, public SPCSSAttr {
 public:
-    SPCSSAttrImpl() : SimpleNode(g_quark_from_static_string("css")) {}
+    SPCSSAttrImpl(Document *doc)
+    : SimpleNode(g_quark_from_static_string("css"), doc) {}
+    SPCSSAttrImpl(SPCSSAttrImpl const &other, Document *doc)
+    : SimpleNode(other, doc) {}
 
     NodeType type() const { return Inkscape::XML::ELEMENT_NODE; }
 
 protected:
-    SimpleNode *_duplicate(Document* /*doc*/) const { return new SPCSSAttrImpl(*this); }
+    SimpleNode *_duplicate(Document* doc) const { return new SPCSSAttrImpl(*this, doc); }
 };
 
 static void sp_repr_css_add_components(SPCSSAttr *css, Node *repr, gchar const *attr);
 
+
 SPCSSAttr *
 sp_repr_css_attr_new()
 {
-    return new SPCSSAttrImpl();
+    static Inkscape::XML::Document *attr_doc=NULL;
+    if (!attr_doc) {
+        attr_doc = new Inkscape::XML::SimpleDocument();
+    }
+    return new SPCSSAttrImpl(attr_doc);
 }
 
 void
@@ -120,7 +129,7 @@ sp_repr_css_set_property(SPCSSAttr *css, gchar const *name, gchar const *value)
     g_assert(css != NULL);
     g_assert(name != NULL);
 
-    sp_repr_set_attr((Node *) css, name, value);
+    ((Node *) css)->setAttribute(name, value, false);
 }
 
 void
@@ -129,7 +138,7 @@ sp_repr_css_unset_property(SPCSSAttr *css, gchar const *name)
     g_assert(css != NULL);
     g_assert(name != NULL);
 
-    sp_repr_set_attr((Node *) css, name, "inkscape:unset");
+    ((Node *) css)->setAttribute(name, "inkscape:unset", false);
 }
 
 double
@@ -219,7 +228,7 @@ sp_repr_css_merge_from_decl(SPCSSAttr *css, CRDeclaration const *const decl)
     guchar *const str_value_unsigned = cr_term_to_string(decl->value);
     gchar *const str_value = reinterpret_cast<gchar *>(str_value_unsigned);
     gchar *value_unquoted = attribute_unquote (str_value); // libcroco returns strings quoted in ""
-    sp_repr_set_attr((Node *) css, decl->property->stryng->str, value_unquoted);
+    ((Node *) css)->setAttribute(decl->property->stryng->str, value_unquoted, false);
     g_free(value_unquoted);
     g_free(str_value);
 }