]> gitweb.michael.orlitzky.com - libsvgtiny.git/blob - src/svgtiny_internal.h
src/svgtiny.c: use case-sensitive comparisons for SVG element names
[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 /* A libcss unit context. This is used to compute and compose
58 * styles, and is convenient to create once and pass along
59 * with the rest of the state. */
60 css_unit_ctx unit_ctx;
61
62 /* Keep track of the parent element's computed style so that
63 * we can compose its children's computed styles with it. */
64 css_computed_style *parent_style;
65
66 /* paint attributes */
67 svgtiny_colour fill;
68 svgtiny_colour stroke;
69 int stroke_width;
70
71 /* alpha */
72 float fill_opacity;
73 float stroke_opacity;
74
75 /* gradients */
76 struct svgtiny_parse_state_gradient fill_grad;
77 struct svgtiny_parse_state_gradient stroke_grad;
78
79 /* Interned strings */
80 #define SVGTINY_STRING_ACTION2(n,nn) dom_string *interned_##n;
81 #include "svgtiny_strings.h"
82 #undef SVGTINY_STRING_ACTION2
83
84 /* Where we store the interned copy of the SVG XML namespace,
85 *
86 * http://www.w3.org/2000/svg
87 *
88 * We handle it separately it has a different type
89 * (lwc_string) than those above (dom_string).
90 */
91 lwc_string *interned_svg_xmlns;
92 };
93
94 struct svgtiny_list;
95
96 /* svgtiny.c */
97 float svgtiny_parse_length(dom_string *s, int viewport_size,
98 const struct svgtiny_parse_state state);
99 void svgtiny_parse_color(dom_string *s, svgtiny_colour *c,
100 struct svgtiny_parse_state_gradient *grad,
101 struct svgtiny_parse_state *state);
102 void svgtiny_parse_transform(char *s, float *ma, float *mb,
103 float *mc, float *md, float *me, float *mf);
104 struct svgtiny_shape *svgtiny_add_shape(struct svgtiny_parse_state *state);
105 void svgtiny_transform_path(float *p, unsigned int n,
106 struct svgtiny_parse_state *state);
107 #if (defined(_GNU_SOURCE) && !defined(__APPLE__) || defined(__amigaos4__) || defined(__HAIKU__) || (defined(_POSIX_C_SOURCE) && ((_POSIX_C_SOURCE - 0) >= 200809L)))
108 #define HAVE_STRNDUP
109 #else
110 #undef HAVE_STRNDUP
111 char *svgtiny_strndup(const char *s, size_t n);
112 #define strndup svgtiny_strndup
113 #endif
114
115 /* svgtiny_css.c */
116 css_error svgtiny_create_stylesheet(css_stylesheet **sheet,
117 bool inline_style);
118 css_error svgtiny_select_style(struct svgtiny_parse_state *state,
119 dom_element *node,
120 const css_stylesheet *inline_sheet,
121 css_select_results **result);
122
123 /* svgtiny_gradient.c */
124 void svgtiny_find_gradient(const char *id,
125 struct svgtiny_parse_state_gradient *grad,
126 struct svgtiny_parse_state *state);
127 svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n,
128 struct svgtiny_parse_state *state);
129
130 /* svgtiny_list.c */
131 struct svgtiny_list *svgtiny_list_create(size_t item_size);
132 unsigned int svgtiny_list_size(struct svgtiny_list *list);
133 svgtiny_code svgtiny_list_resize(struct svgtiny_list *list,
134 unsigned int new_size);
135 void *svgtiny_list_get(struct svgtiny_list *list,
136 unsigned int i);
137 void *svgtiny_list_push(struct svgtiny_list *list);
138 void svgtiny_list_free(struct svgtiny_list *list);
139
140 #endif