Code

Fix version check for wheel selector.
[inkscape.git] / src / sp-style-elem.cpp
index ff27f3de0e77508a416b15e3ee7d9718ce7187e8..5a57d548b83e9e0d772e5f17c6d8be5f355fe720 100644 (file)
@@ -4,6 +4,7 @@
 #include "document.h"
 #include "sp-style-elem.h"
 #include "attributes.h"
+#include "style.h"
 using Inkscape::XML::TEXT_NODE;
 
 static void sp_style_elem_init(SPStyleElem *style_elem);
@@ -11,7 +12,7 @@ static void sp_style_elem_class_init(SPStyleElemClass *klass);
 static void sp_style_elem_build(SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr);
 static void sp_style_elem_set(SPObject *object, unsigned const key, gchar const *const value);
 static void sp_style_elem_read_content(SPObject *);
-static Inkscape::XML::Node *sp_style_elem_write(SPObject *, Inkscape::XML::Node *, guint flags);
+static Inkscape::XML::Node *sp_style_elem_write(SPObject *, Inkscape::XML::Document *, Inkscape::XML::Node *, guint flags);
 
 static SPObjectClass *parent_class;
 
@@ -119,10 +120,10 @@ child_order_changed_cb(Inkscape::XML::Node *, Inkscape::XML::Node *,
 }
 
 static Inkscape::XML::Node *
-sp_style_elem_write(SPObject *const object, Inkscape::XML::Node *repr, guint const flags)
+sp_style_elem_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint const flags)
 {
     if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
-        repr = sp_repr_new("svg:style");
+        repr = xml_doc->createElement("svg:style");
     }
 
     g_return_val_if_fail(object, repr);
@@ -130,7 +131,7 @@ sp_style_elem_write(SPObject *const object, Inkscape::XML::Node *repr, guint con
     if (flags & SP_OBJECT_WRITE_BUILD) {
         g_warning("nyi: Forming <style> content for SP_OBJECT_WRITE_BUILD.");
         /* fixme: Consider having the CRStyleSheet be a member of SPStyleElem, and then
-           pretty-print to a string s, then repr->addChild(sp_repr_new_text(s), NULL). */
+           pretty-print to a string s, then repr->addChild(xml_doc->createTextNode(s), NULL). */
     }
     if (style_elem.is_css) {
         repr->setAttribute("type", "text/css");
@@ -138,7 +139,7 @@ sp_style_elem_write(SPObject *const object, Inkscape::XML::Node *repr, guint con
     /* todo: media */
 
     if (((SPObjectClass *) parent_class)->write)
-        ((SPObjectClass *) parent_class)->write(object, repr, flags);
+        ((SPObjectClass *) parent_class)->write(object, xml_doc, repr, flags);
 
     return repr;
 }
@@ -357,6 +358,17 @@ sp_style_elem_read_content(SPObject *const object)
     }
     cr_parser_destroy(parser);
     //object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+
+    // Style references via class= do not, and actually cannot, use autoupdating URIReferences.
+    // Therefore, if an object refers to a stylesheet which has not yet loaded when the object is being loaded
+    // (e.g. if the stylesheet is below or inside the object in XML), its class= has no effect (bug 1491639).
+    // Below is a partial hack that fixes this for a single case: when the <style> is a child of the object
+    // that uses a style from it. It just forces the parent of <style> to reread its style as soon as the stylesheet
+    // is fully loaded. Naturally, this won't work if the user of the stylesheet is its grandparent or precedent.
+    SPObject *parent = SP_OBJECT_PARENT (object);
+    if ( parent ) {
+        sp_style_read_from_object(parent->style, parent);
+    }
 }
 
 /**
@@ -404,4 +416,4 @@ sp_style_elem_build(SPObject *object, SPDocument *document, Inkscape::XML::Node
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :