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