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

index 9faf8180f7bbd3d3d646ba5639acb0cd6edb0410..265204260f232b7f4326485713a8300597f38d0c 100644 (file)
@@ -3,6 +3,9 @@
 #include "svgtiny.h"
 #include "svgtiny_internal.h"
 
+static css_error node_name(void *pw, void *node, css_qname *qname);
+
+
 /**
  * Resolve a relative URL to an absolute one by doing nothing. This is
  * the simplest possible implementation of a URL resolver, needed for
@@ -53,3 +56,48 @@ css_error svgtiny_create_stylesheet(css_stylesheet **sheet,
 
        return css_stylesheet_create(&params, sheet);
 }
+
+
+/**************************/
+/* libcss select handlers */
+/**************************/
+/*
+ * From here on we implement the "select handler "API defined in
+ * libcss's include/libcss/select.h and discussed briefly in its
+ * docs/API document.
+ */
+
+
+/**
+ * Retrieve the given node's name
+ *
+ * \param pw     Pointer to the current SVG parser state
+ * \param node   Libdom SVG node
+ * \param qname  Address at which to store the node name
+ *
+ * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
+ */
+css_error node_name(void *pw, void *node, css_qname *qname)
+{
+       dom_string *name;
+       dom_exception err;
+       struct svgtiny_parse_state *state;
+
+       err = dom_node_get_node_name((dom_node *)node, &name);
+       if (err != DOM_NO_ERR) {
+               return CSS_NOMEM;
+       }
+
+       state = (struct svgtiny_parse_state *)pw;
+       qname->ns = lwc_string_ref(state->interned_svg_xmlns);
+
+       err = dom_string_intern(name, &qname->name);
+       if (err != DOM_NO_ERR) {
+               dom_string_unref(name);
+               return CSS_NOMEM;
+       }
+
+       dom_string_unref(name);
+
+       return CSS_OK;
+}