#include <stdbool.h>
#include <dom/dom.h>
+#include <libcss/libcss.h>
#ifndef UNUSED
#define UNUSED(x) ((void) (x))
#define svgtiny_MAX_STOPS 10
#define svgtiny_LINEAR_GRADIENT 0x2000000
+struct svgtiny_parse_state_gradient {
+ unsigned int linear_gradient_stop_count;
+ dom_string *gradient_x1, *gradient_y1, *gradient_x2, *gradient_y2;
+ struct svgtiny_gradient_stop gradient_stop[svgtiny_MAX_STOPS];
+ bool gradient_user_space_on_use;
+ struct {
+ float a, b, c, d, e, f;
+ } gradient_transform;
+};
+
struct svgtiny_parse_state {
struct svgtiny_diagram *diagram;
dom_document *document;
float a, b, c, d, e, f;
} ctm;
- /*struct css_style style;*/
+ /* A libcss context to hold any stylesheets that are present
+ * in the SVG document. This should be pre-populated rather
+ * than on-the-fly, because, for example, a <style> sheet at
+ * the end of the document should affect the SVG elements that
+ * precede it. */
+ css_select_ctx *select_ctx;
+
+ /* A libcss unit context. This is used to compute and compose
+ * styles, and is convenient to create once and pass along
+ * with the rest of the state. */
+ css_unit_ctx unit_ctx;
+
+ /* Keep track of the parent element's computed style so that
+ * we can compose its children's computed styles with it. */
+ css_computed_style *parent_style;
/* paint attributes */
svgtiny_colour fill;
svgtiny_colour stroke;
int stroke_width;
+ /* alpha */
+ float fill_opacity;
+ float stroke_opacity;
+
/* gradients */
- unsigned int linear_gradient_stop_count;
- const char *gradient_x1, *gradient_y1, *gradient_x2, *gradient_y2;
- struct svgtiny_gradient_stop gradient_stop[svgtiny_MAX_STOPS];
- bool gradient_user_space_on_use;
- struct {
- float a, b, c, d, e, f;
- } gradient_transform;
+ struct svgtiny_parse_state_gradient fill_grad;
+ struct svgtiny_parse_state_gradient stroke_grad;
/* Interned strings */
-#define SVGTINY_STRING_ACTION(n) dom_string *interned_##n;
+#define SVGTINY_STRING_ACTION2(n,nn) dom_string *interned_##n;
#include "svgtiny_strings.h"
-#undef SVGTINY_STRING_ACTION
-
+#undef SVGTINY_STRING_ACTION2
+
+ /* Where we store the interned copy of the SVG XML namespace,
+ *
+ * http://www.w3.org/2000/svg
+ *
+ * We handle it separately it has a different type
+ * (lwc_string) than those above (dom_string).
+ */
+ lwc_string *interned_svg_xmlns;
};
struct svgtiny_list;
/* svgtiny.c */
-float svgtiny_parse_length(const char *s, int viewport_size,
+float svgtiny_parse_length(dom_string *s, int viewport_size,
const struct svgtiny_parse_state state);
-void svgtiny_parse_color(const char *s, svgtiny_colour *c,
+void svgtiny_parse_color(dom_string *s, svgtiny_colour *c,
+ struct svgtiny_parse_state_gradient *grad,
struct svgtiny_parse_state *state);
void svgtiny_parse_transform(char *s, float *ma, float *mb,
float *mc, float *md, float *me, float *mf);
struct svgtiny_shape *svgtiny_add_shape(struct svgtiny_parse_state *state);
void svgtiny_transform_path(float *p, unsigned int n,
struct svgtiny_parse_state *state);
-#if defined(_GNU_SOURCE)
+#if (defined(_GNU_SOURCE) && !defined(__APPLE__) || defined(__amigaos4__) || defined(__HAIKU__) || (defined(_POSIX_C_SOURCE) && ((_POSIX_C_SOURCE - 0) >= 200809L)))
#define HAVE_STRNDUP
#else
#undef HAVE_STRNDUP
#define strndup svgtiny_strndup
#endif
+/* svgtiny_css.c */
+css_error svgtiny_create_stylesheet(css_stylesheet **sheet,
+ bool inline_style);
+css_error svgtiny_select_style(struct svgtiny_parse_state *state,
+ dom_element *node,
+ const css_stylesheet *inline_sheet,
+ css_select_results **result);
+
/* svgtiny_gradient.c */
-void svgtiny_find_gradient(const char *id, struct svgtiny_parse_state *state);
+void svgtiny_find_gradient(const char *id,
+ struct svgtiny_parse_state_gradient *grad,
+ struct svgtiny_parse_state *state);
svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
struct svgtiny_parse_state *state);
-dom_node *svgtiny_find_element_by_id(dom_node *node, const char *id);
/* svgtiny_list.c */
struct svgtiny_list *svgtiny_list_create(size_t item_size);
void *svgtiny_list_push(struct svgtiny_list *list);
void svgtiny_list_free(struct svgtiny_list *list);
-/* colors.gperf */
-const struct svgtiny_named_color *
- svgtiny_color_lookup(register const char *str,
- register unsigned int len);
-
#endif