X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fsvgtiny_css.c;h=eb45ddf41aa53a27ec975a7d8986b1f260811896;hb=0812d2a5244107a57eed9a4e82f05e75c88143fa;hp=9faf8180f7bbd3d3d646ba5639acb0cd6edb0410;hpb=7631bb4f5133b45639b71280864c4099c50400db;p=libsvgtiny.git diff --git a/src/svgtiny_css.c b/src/svgtiny_css.c index 9faf818..eb45ddf 100644 --- a/src/svgtiny_css.c +++ b/src/svgtiny_css.c @@ -3,6 +3,11 @@ #include "svgtiny.h" #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); + + /** * 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 +58,81 @@ css_error svgtiny_create_stylesheet(css_stylesheet **sheet, return css_stylesheet_create(¶ms, 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; +} + + +/** + * 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; +}