]> gitweb.michael.orlitzky.com - libsvgtiny.git/blob - src/svgtiny_internal.h
src/svgtiny_css.c: use our userdata handler in set_libcss_node_data()
[libsvgtiny.git] / src / svgtiny_internal.h
1 /*
2 * This file is part of Libsvgtiny
3 * Licensed under the MIT License,
4 * http://opensource.org/licenses/mit-license.php
5 * Copyright 2008 James Bursa <james@semichrome.net>
6 */
7
8 #ifndef SVGTINY_INTERNAL_H
9 #define SVGTINY_INTERNAL_H
10
11 #include <stdbool.h>
12
13 #include <dom/dom.h>
14 #include <libcss/libcss.h>
15
16 #ifndef UNUSED
17 #define UNUSED(x) ((void) (x))
18 #endif
19
20 struct svgtiny_gradient_stop {
21 float offset;
22 svgtiny_colour color;
23 };
24
25 #define svgtiny_MAX_STOPS 10
26 #define svgtiny_LINEAR_GRADIENT 0x2000000
27
28 struct svgtiny_parse_state_gradient {
29 unsigned int linear_gradient_stop_count;
30 dom_string *gradient_x1, *gradient_y1, *gradient_x2, *gradient_y2;
31 struct svgtiny_gradient_stop gradient_stop[svgtiny_MAX_STOPS];
32 bool gradient_user_space_on_use;
33 struct {
34 float a, b, c, d, e, f;
35 } gradient_transform;
36 };
37
38 struct svgtiny_parse_state {
39 struct svgtiny_diagram *diagram;
40 dom_document *document;
41
42 float viewport_width;
43 float viewport_height;
44
45 /* current transformation matrix */
46 struct {
47 float a, b, c, d, e, f;
48 } ctm;
49
50 /* A libcss context to hold any stylesheets that are present
51 * in the SVG document. This should be pre-populated rather
52 * than on-the-fly, because, for example, a <style> sheet at
53 * the end of the document should affect the SVG elements that
54 * precede it. */
55 css_select_ctx *select_ctx;
56
57 /* paint attributes */
58 svgtiny_colour fill;
59 svgtiny_colour stroke;
60 int stroke_width;
61
62 /* gradients */
63 struct svgtiny_parse_state_gradient fill_grad;
64 struct svgtiny_parse_state_gradient stroke_grad;
65
66 /* Interned strings */
67 #define SVGTINY_STRING_ACTION2(n,nn) dom_string *interned_##n;
68 #include "svgtiny_strings.h"
69 #undef SVGTINY_STRING_ACTION2
70
71 /* Where we store the interned copy of the SVG XML namespace,
72 *
73 * http://www.w3.org/2000/svg
74 *
75 * We handle it separately it has a different type
76 * (lwc_string) than those above (dom_string).
77 */
78 lwc_string *interned_svg_xmlns;
79 };
80
81 struct svgtiny_list;
82
83 /* svgtiny.c */
84 float svgtiny_parse_length(dom_string *s, int viewport_size,
85 const struct svgtiny_parse_state state);
86 void svgtiny_parse_color(dom_string *s, svgtiny_colour *c,
87 struct svgtiny_parse_state_gradient *grad,
88 struct svgtiny_parse_state *state);
89 void svgtiny_parse_transform(char *s, float *ma, float *mb,
90 float *mc, float *md, float *me, float *mf);
91 struct svgtiny_shape *svgtiny_add_shape(struct svgtiny_parse_state *state);
92 void svgtiny_transform_path(float *p, unsigned int n,
93 struct svgtiny_parse_state *state);
94 #if (defined(_GNU_SOURCE) && !defined(__APPLE__) || defined(__amigaos4__) || defined(__HAIKU__) || (defined(_POSIX_C_SOURCE) && ((_POSIX_C_SOURCE - 0) >= 200809L)))
95 #define HAVE_STRNDUP
96 #else
97 #undef HAVE_STRNDUP
98 char *svgtiny_strndup(const char *s, size_t n);
99 #define strndup svgtiny_strndup
100 #endif
101
102 /* svgtiny_css.c */
103 css_error svgtiny_create_stylesheet(css_stylesheet **sheet,
104 bool inline_style);
105
106 /* svgtiny_gradient.c */
107 void svgtiny_find_gradient(const char *id,
108 struct svgtiny_parse_state_gradient *grad,
109 struct svgtiny_parse_state *state);
110 svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
111 struct svgtiny_parse_state *state);
112
113 /* svgtiny_list.c */
114 struct svgtiny_list *svgtiny_list_create(size_t item_size);
115 unsigned int svgtiny_list_size(struct svgtiny_list *list);
116 svgtiny_code svgtiny_list_resize(struct svgtiny_list *list,
117 unsigned int new_size);
118 void *svgtiny_list_get(struct svgtiny_list *list,
119 unsigned int i);
120 void *svgtiny_list_push(struct svgtiny_list *list);
121 void svgtiny_list_free(struct svgtiny_list *list);
122
123 #endif