]> gitweb.michael.orlitzky.com - libsvgtiny.git/blob - src/svgtiny_css.c
src/svgtiny_css.c: implement node_name() select handler
[libsvgtiny.git] / src / svgtiny_css.c
1 #include <libcss/libcss.h>
2
3 #include "svgtiny.h"
4 #include "svgtiny_internal.h"
5
6 static css_error node_name(void *pw, void *node, css_qname *qname);
7
8
9 /**
10 * Resolve a relative URL to an absolute one by doing nothing. This is
11 * the simplest possible implementation of a URL resolver, needed for
12 * parsing CSS.
13 */
14 css_error svgtiny_resolve_url(void *pw,
15 const char *base, lwc_string *rel, lwc_string **abs)
16 {
17 UNUSED(pw);
18 UNUSED(base);
19
20 /* Copy the relative URL to the absolute one (the return
21 value) */
22 *abs = lwc_string_ref(rel);
23 return CSS_OK;
24 }
25
26 /**
27 * Create a stylesheet with the default set of params.
28 *
29 * \param sheet A stylesheet pointer, passed in by reference, that
30 * we use to store the newly-created stylesheet.
31 * \param inline_style True if this stylesheet represents an inline
32 * style, and false otherwise.
33 *
34 * \return The return value from css_stylesheet_create() is returned.
35 */
36 css_error svgtiny_create_stylesheet(css_stylesheet **sheet,
37 bool inline_style)
38 {
39 css_stylesheet_params params;
40
41 params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
42 params.level = CSS_LEVEL_DEFAULT;
43 params.charset = NULL;
44 params.url = "";
45 params.title = NULL;
46 params.allow_quirks = false;
47 params.inline_style = inline_style;
48 params.resolve = svgtiny_resolve_url;
49 params.resolve_pw = NULL;
50 params.import = NULL;
51 params.import_pw = NULL;
52 params.color = NULL;
53 params.color_pw = NULL;
54 params.font = NULL;
55 params.font_pw = NULL;
56
57 return css_stylesheet_create(&params, sheet);
58 }
59
60
61 /**************************/
62 /* libcss select handlers */
63 /**************************/
64 /*
65 * From here on we implement the "select handler "API defined in
66 * libcss's include/libcss/select.h and discussed briefly in its
67 * docs/API document.
68 */
69
70
71 /**
72 * Retrieve the given node's name
73 *
74 * \param pw Pointer to the current SVG parser state
75 * \param node Libdom SVG node
76 * \param qname Address at which to store the node name
77 *
78 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
79 */
80 css_error node_name(void *pw, void *node, css_qname *qname)
81 {
82 dom_string *name;
83 dom_exception err;
84 struct svgtiny_parse_state *state;
85
86 err = dom_node_get_node_name((dom_node *)node, &name);
87 if (err != DOM_NO_ERR) {
88 return CSS_NOMEM;
89 }
90
91 state = (struct svgtiny_parse_state *)pw;
92 qname->ns = lwc_string_ref(state->interned_svg_xmlns);
93
94 err = dom_string_intern(name, &qname->name);
95 if (err != DOM_NO_ERR) {
96 dom_string_unref(name);
97 return CSS_NOMEM;
98 }
99
100 dom_string_unref(name);
101
102 return CSS_OK;
103 }