]> gitweb.michael.orlitzky.com - libsvgtiny.git/blobdiff - src/svgtiny_css.c
src/svgtiny_css.c: implement node_name() select handler
[libsvgtiny.git] / src / svgtiny_css.c
index f112ca30ed5e637a14968d2260eefe738372177e..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
@@ -19,3 +22,82 @@ css_error svgtiny_resolve_url(void *pw,
        *abs = lwc_string_ref(rel);
        return CSS_OK;
 }
+
+/**
+ * Create a stylesheet with the default set of params.
+ *
+ * \param sheet A stylesheet pointer, passed in by reference, that
+ * we use to store the newly-created stylesheet.
+ * \param inline_style True if this stylesheet represents an inline
+ * style, and false otherwise.
+ *
+ * \return The return value from css_stylesheet_create() is returned.
+ */
+css_error svgtiny_create_stylesheet(css_stylesheet **sheet,
+               bool inline_style)
+{
+       css_stylesheet_params params;
+
+       params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
+       params.level = CSS_LEVEL_DEFAULT;
+       params.charset = NULL;
+       params.url = "";
+       params.title = NULL;
+       params.allow_quirks = false;
+       params.inline_style = inline_style;
+       params.resolve = svgtiny_resolve_url;
+       params.resolve_pw = NULL;
+       params.import = NULL;
+       params.import_pw = NULL;
+       params.color = NULL;
+       params.color_pw = NULL;
+       params.font = NULL;
+       params.font_pw = NULL;
+
+       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;
+}