]> gitweb.michael.orlitzky.com - libsvgtiny.git/commitdiff
src/svgtiny_css.c: implement node_classes() select handler
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 11 Oct 2023 23:57:56 +0000 (19:57 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 20 Nov 2023 01:37:04 +0000 (20:37 -0500)
src/svgtiny_css.c

index 265204260f232b7f4326485713a8300597f38d0c..eb45ddf41aa53a27ec975a7d8986b1f260811896 100644 (file)
@@ -4,6 +4,8 @@
 #include "svgtiny_internal.h"
 
 static css_error node_name(void *pw, void *node, css_qname *qname);
+static css_error node_classes(void *pw, void *node,
+               lwc_string ***classes, uint32_t *n_classes);
 
 
 /**
@@ -101,3 +103,36 @@ css_error node_name(void *pw, void *node, css_qname *qname)
 
        return CSS_OK;
 }
+
+
+/**
+ * Retrieve the given node's classes
+ *
+ * \param pw         Pointer to the current SVG parser state
+ * \param node       Libdom SVG node
+ * \param classes    Address at which to store the class name array
+ * \param n_classes  Address at which to store the length of the class
+ *                   name array
+ *
+ * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
+ *
+ * \note CSS_NOMEM is not possible in practice as of libdom-0.4.1,
+ *       because the underlying libdom function never fails
+ */
+css_error node_classes(void *pw, void *node,
+               lwc_string ***classes, uint32_t *n_classes)
+{
+       UNUSED(pw);
+       dom_exception err;
+
+       err = dom_element_get_classes((dom_node *)node, classes, n_classes);
+
+       /* The implementation does not do it, but the documentation
+          for dom_element_get_classes() says that a DOM_NO_MEM_ERR is
+          possible here, so we handle it to be on the safe side. */
+       if (err != DOM_NO_ERR) {
+               return CSS_NOMEM;
+       }
+
+       return CSS_OK;
+}