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>
8 #ifndef SVGTINY_INTERNAL_H
9 #define SVGTINY_INTERNAL_H
14 #include <libcss/libcss.h>
17 #define UNUSED(x) ((void) (x))
20 struct svgtiny_gradient_stop
{
25 #define svgtiny_MAX_STOPS 10
26 #define svgtiny_LINEAR_GRADIENT 0x2000000
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
;
34 float a
, b
, c
, d
, e
, f
;
38 struct svgtiny_parse_state
{
39 struct svgtiny_diagram
*diagram
;
40 dom_document
*document
;
43 float viewport_height
;
45 /* current transformation matrix */
47 float a
, b
, c
, d
, e
, f
;
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
55 css_select_ctx
*select_ctx
;
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
;
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
;
66 /* paint attributes */
68 svgtiny_colour stroke
;
76 struct svgtiny_parse_state_gradient fill_grad
;
77 struct svgtiny_parse_state_gradient stroke_grad
;
79 /* Interned strings */
80 #define SVGTINY_STRING_ACTION2(n,nn) dom_string *interned_##n;
81 #include "svgtiny_strings.h"
82 #undef SVGTINY_STRING_ACTION2
84 /* Where we store the interned copy of the SVG XML namespace,
86 * http://www.w3.org/2000/svg
88 * We handle it separately it has a different type
89 * (lwc_string) than those above (dom_string).
91 lwc_string
*interned_svg_xmlns
;
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)))
111 char *svgtiny_strndup(const char *s
, size_t n
);
112 #define strndup svgtiny_strndup
116 css_error
svgtiny_create_stylesheet(css_stylesheet
**sheet
,
118 css_error
svgtiny_select_style(struct svgtiny_parse_state
*state
,
120 const css_stylesheet
*inline_sheet
,
121 css_select_results
**result
);
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
);
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
,
137 void *svgtiny_list_push(struct svgtiny_list
*list
);
138 void svgtiny_list_free(struct svgtiny_list
*list
);