1 #include <libcss/libcss.h>
4 #include "svgtiny_internal.h"
6 static css_error
node_name(void *pw
, void *node
, css_qname
*qname
);
7 static css_error
node_classes(void *pw
, void *node
,
8 lwc_string
***classes
, uint32_t *n_classes
);
12 * Resolve a relative URL to an absolute one by doing nothing. This is
13 * the simplest possible implementation of a URL resolver, needed for
16 css_error
svgtiny_resolve_url(void *pw
,
17 const char *base
, lwc_string
*rel
, lwc_string
**abs
)
22 /* Copy the relative URL to the absolute one (the return
24 *abs
= lwc_string_ref(rel
);
29 * Create a stylesheet with the default set of params.
31 * \param sheet A stylesheet pointer, passed in by reference, that
32 * we use to store the newly-created stylesheet.
33 * \param inline_style True if this stylesheet represents an inline
34 * style, and false otherwise.
36 * \return The return value from css_stylesheet_create() is returned.
38 css_error
svgtiny_create_stylesheet(css_stylesheet
**sheet
,
41 css_stylesheet_params params
;
43 params
.params_version
= CSS_STYLESHEET_PARAMS_VERSION_1
;
44 params
.level
= CSS_LEVEL_DEFAULT
;
45 params
.charset
= NULL
;
48 params
.allow_quirks
= false;
49 params
.inline_style
= inline_style
;
50 params
.resolve
= svgtiny_resolve_url
;
51 params
.resolve_pw
= NULL
;
53 params
.import_pw
= NULL
;
55 params
.color_pw
= NULL
;
57 params
.font_pw
= NULL
;
59 return css_stylesheet_create(¶ms
, sheet
);
63 /**************************/
64 /* libcss select handlers */
65 /**************************/
67 * From here on we implement the "select handler "API defined in
68 * libcss's include/libcss/select.h and discussed briefly in its
74 * Retrieve the given node's name
76 * \param pw Pointer to the current SVG parser state
77 * \param node Libdom SVG node
78 * \param qname Address at which to store the node name
80 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
82 css_error
node_name(void *pw
, void *node
, css_qname
*qname
)
86 struct svgtiny_parse_state
*state
;
88 err
= dom_node_get_node_name((dom_node
*)node
, &name
);
89 if (err
!= DOM_NO_ERR
) {
93 state
= (struct svgtiny_parse_state
*)pw
;
94 qname
->ns
= lwc_string_ref(state
->interned_svg_xmlns
);
96 err
= dom_string_intern(name
, &qname
->name
);
97 if (err
!= DOM_NO_ERR
) {
98 dom_string_unref(name
);
102 dom_string_unref(name
);
109 * Retrieve the given node's classes
111 * \param pw Pointer to the current SVG parser state
112 * \param node Libdom SVG node
113 * \param classes Address at which to store the class name array
114 * \param n_classes Address at which to store the length of the class
117 * \return CSS_OK on success, or CSS_NOMEM if anything goes wrong
119 * \note CSS_NOMEM is not possible in practice as of libdom-0.4.1,
120 * because the underlying libdom function never fails
122 css_error
node_classes(void *pw
, void *node
,
123 lwc_string
***classes
, uint32_t *n_classes
)
128 err
= dom_element_get_classes((dom_node
*)node
, classes
, n_classes
);
130 /* The implementation does not do it, but the documentation
131 for dom_element_get_classes() says that a DOM_NO_MEM_ERR is
132 possible here, so we handle it to be on the safe side. */
133 if (err
!= DOM_NO_ERR
) {