]> gitweb.michael.orlitzky.com - libsvgtiny.git/blobdiff - src/svgtiny_css.c
src/svgtiny_css.c: implement get_libcss_node_data() select handler
[libsvgtiny.git] / src / svgtiny_css.c
index 4e42888d59c83925d8ce3fa77eb30cb277525cdd..67f9fcddb48b38dd05baf0ffe2a592b9dc07d17c 100644 (file)
@@ -59,6 +59,10 @@ static css_error node_is_lang(void *pw, void *node,
                lwc_string *lang, bool *is_lang);
 static css_error ua_default_for_property(void *pw, uint32_t property,
        css_hint *hint);
+static css_error set_libcss_node_data(void *pw, void *node,
+               void *libcss_node_data);
+static css_error get_libcss_node_data(void *pw, void *node,
+               void **libcss_node_data);
 
 
 /**
@@ -1787,3 +1791,69 @@ css_error ua_default_for_property(void *pw, uint32_t property,
        UNUSED(hint);
        return CSS_INVALID;
 }
+
+
+/**
+ * Store libcss data on a node
+ *
+ * This is part of the libcss select handler API that we need to
+ * implement. It is essentially a thin dom_node_set_user_data()
+ * wrapper.
+ *
+ * \param pw                 Pointer to the current SVG parser state
+ * \param node               Libdom SVG node on which to store the data
+ * \param libcss_node_data   Pointer to the data to store
+ *
+ * \return Always returns CSS_OK
+ */
+css_error set_libcss_node_data(void *pw, void *node,
+               void *libcss_node_data)
+{
+       struct svgtiny_parse_state *state;
+       void *old_data;
+
+       /* A unique "userdata key" (a string) is used to identify this
+        * data. The fourth parameter (NULL) is a "user handler
+        * function." We will eventually have one, but for now we set
+        * it to NULL to avoid a circular reference mess that would
+        * break the build temporarily. */
+       state = (struct svgtiny_parse_state *)pw;
+       dom_node_set_user_data((dom_node *)node,
+                               state->interned_userdata_key,
+                               libcss_node_data,
+                               NULL,
+                               &old_data);
+
+       /* dom_node_set_user_data() always returns DOM_NO_ERR */
+       return CSS_OK;
+}
+
+
+/**
+ * Retrieve libcss data from a node
+ *
+ * This is part of the libcss select handler API that we need to
+ * implement. It is essentially a thin dom_node_get_user_data()
+ * wrapper.
+ *
+ * \param pw                 Pointer to the current SVG parser state
+ * \param node               Libdom SVG node from which to get the data
+ * \param libcss_node_data   Address at which to store a pointer to the data
+ *
+ * \return Always returns CSS_OK
+ */
+css_error get_libcss_node_data(void *pw, void *node,
+               void **libcss_node_data)
+{
+       struct svgtiny_parse_state *state;
+
+       /* A unique "userdata key" (a string) is used to identify this
+        * data. */
+       state = (struct svgtiny_parse_state *)pw;
+       dom_node_get_user_data((dom_node *)node,
+                               state->interned_userdata_key,
+                               libcss_node_data);
+
+       /* dom_node_get_user_data() always returns DOM_NO_ERR */
+       return CSS_OK;
+}