summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitalii Vorobiov <vi.vorobiov@samsung.com>2017-11-07 11:41:36 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-11-07 11:54:09 +0900
commitee93543799fc4ccf72a0cbf43a2c3efe5c61d6d3 (patch)
treeaba6f64632b450ff67ef3fde881a757715b93ba7
parent66e0caccb7cfc15daf362c75f1b28689d2d2ab02 (diff)
evas_vg_load_svg: get rid of static Evas_SVG_Parsing
Summary: Refactoring. It is good to store values from that struct in a parsing/loading context static variable is a big NO NO: 1. Ugly code design, 2. Might not work when trying to load more than one SVG file. @fix Reviewers: jpeg, smohanty Subscribers: jenkins, cedric Differential Revision: https://phab.enlightenment.org/D5399
-rw-r--r--src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c400
1 files changed, 214 insertions, 186 deletions
diff --git a/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c b/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
index cec86e6eae..867d95c9df 100644
--- a/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
+++ b/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
@@ -13,9 +13,22 @@ static int _evas_vg_loader_svg_log_dom = -1;
13#endif 13#endif
14#define INF(...) EINA_LOG_DOM_INFO(_evas_vg_loader_svg_log_dom, __VA_ARGS__) 14#define INF(...) EINA_LOG_DOM_INFO(_evas_vg_loader_svg_log_dom, __VA_ARGS__)
15 15
16typedef Svg_Node *(*Factory_Method)(Svg_Node *parent, const char *buf, unsigned buflen); 16/* Global struct for working global cases during the parse */
17typedef struct _Evas_SVG_Parser Evas_SVG_Parser;
18struct _Evas_SVG_Parser {
19 struct {
20 int x, y, width, height;
21 } global;
22 struct {
23 Eina_Bool x1_percent, x2_percent, y1_percent, y2_percent;
24 Eina_Bool fx_parsed;
25 Eina_Bool fy_parsed;
26 } gradient;
17 27
18typedef Svg_Style_Gradient *(*Gradient_Factory_Method)(const char *buf, unsigned buflen); 28 Svg_Node *node;
29 Svg_Style_Gradient *style_grad;
30 Efl_Gfx_Gradient_Stop *grad_stop;
31};
19 32
20typedef struct _Evas_SVG_Loader Evas_SVG_Loader; 33typedef struct _Evas_SVG_Loader Evas_SVG_Loader;
21struct _Evas_SVG_Loader 34struct _Evas_SVG_Loader
@@ -24,10 +37,16 @@ struct _Evas_SVG_Loader
24 Svg_Node *doc; 37 Svg_Node *doc;
25 Svg_Node *def; 38 Svg_Node *def;
26 Svg_Style_Gradient *gradient; 39 Svg_Style_Gradient *gradient;
40 Evas_SVG_Parser *svg_parse;
27 int level; 41 int level;
28 Eina_Bool result:1; 42 Eina_Bool result:1;
29}; 43};
30 44
45
46typedef Svg_Node *(*Factory_Method)(Evas_SVG_Loader *loader, Svg_Node *parent, const char *buf, unsigned buflen);
47
48typedef Svg_Style_Gradient *(*Gradient_Factory_Method)(Evas_SVG_Loader *loader, const char *buf, unsigned buflen);
49
31/* length type to recalculate %, pt, pc, mm, cm etc*/ 50/* length type to recalculate %, pt, pc, mm, cm etc*/
32typedef enum { 51typedef enum {
33 SVG_PARSER_LENGTH_VERTICAL, 52 SVG_PARSER_LENGTH_VERTICAL,
@@ -36,19 +55,6 @@ typedef enum {
36 SVG_PARSER_LENGTH_OTHER 55 SVG_PARSER_LENGTH_OTHER
37} SVG_Parser_Length_Type; 56} SVG_Parser_Length_Type;
38 57
39/* Global struct for working global cases during the parse */
40typedef struct {
41 struct {
42 int x, y, width, height;
43 } global;
44 struct {
45 Eina_Bool x1_percent, x2_percent, y1_percent, y2_percent;
46 Eina_Bool fx_parsed;
47 Eina_Bool fy_parsed;
48 } gradient;
49} Evas_SVG_Parsing;
50static Evas_SVG_Parsing svg_parse;
51
52char * 58char *
53_skip_space(const char *str, const char *end) 59_skip_space(const char *str, const char *end)
54{ 60{
@@ -94,7 +100,7 @@ _parse_number(const char **content, double *number)
94 * is required, but for now default w3 constants would be used 100 * is required, but for now default w3 constants would be used
95 */ 101 */
96static inline double 102static inline double
97_to_double(const char *str, SVG_Parser_Length_Type type) 103_to_double(Evas_SVG_Parser *svg_parse, const char *str, SVG_Parser_Length_Type type)
98{ 104{
99 double parsed_value = strtod(str, NULL); 105 double parsed_value = strtod(str, NULL);
100 106
@@ -111,13 +117,13 @@ _to_double(const char *str, SVG_Parser_Length_Type type)
111 else if (strstr(str, "%")) 117 else if (strstr(str, "%"))
112 { 118 {
113 if (type == SVG_PARSER_LENGTH_VERTICAL) 119 if (type == SVG_PARSER_LENGTH_VERTICAL)
114 parsed_value = (parsed_value / 100.0) * svg_parse.global.height; 120 parsed_value = (parsed_value / 100.0) * svg_parse->global.height;
115 else if (type == SVG_PARSER_LENGTH_HORIZONTAL) 121 else if (type == SVG_PARSER_LENGTH_HORIZONTAL)
116 parsed_value = (parsed_value / 100.0) * svg_parse.global.width; 122 parsed_value = (parsed_value / 100.0) * svg_parse->global.width;
117 else // if other then it's radius 123 else // if other then it's radius
118 { 124 {
119 double max = svg_parse.global.width; 125 double max = svg_parse->global.width;
120 if (max < svg_parse.global.height) max = svg_parse.global.height; 126 if (max < svg_parse->global.height) max = svg_parse->global.height;
121 parsed_value = (parsed_value / 100.0) * max; 127 parsed_value = (parsed_value / 100.0) * max;
122 } 128 }
123 } 129 }
@@ -131,7 +137,7 @@ _to_double(const char *str, SVG_Parser_Length_Type type)
131 * Turn gradient variables into percentages 137 * Turn gradient variables into percentages
132 */ 138 */
133static inline double 139static inline double
134_gradient_to_double(const char *str, SVG_Parser_Length_Type type) 140_gradient_to_double(Evas_SVG_Parser *svg_parse, const char *str, SVG_Parser_Length_Type type)
135{ 141{
136 char *end = NULL; 142 char *end = NULL;
137 143
@@ -151,12 +157,12 @@ _gradient_to_double(const char *str, SVG_Parser_Length_Type type)
151 * https://www.w3.org/TR/2015/WD-SVG2-20150915/coords.html 157 * https://www.w3.org/TR/2015/WD-SVG2-20150915/coords.html
152 */ 158 */
153 if (type == SVG_PARSER_LENGTH_VERTICAL) 159 if (type == SVG_PARSER_LENGTH_VERTICAL)
154 max = svg_parse.global.height; 160 max = svg_parse->global.height;
155 else if (type == SVG_PARSER_LENGTH_HORIZONTAL) 161 else if (type == SVG_PARSER_LENGTH_HORIZONTAL)
156 max = svg_parse.global.width; 162 max = svg_parse->global.width;
157 else if (type == SVG_PARSER_LENGTH_OTHER) 163 else if (type == SVG_PARSER_LENGTH_OTHER)
158 max = sqrt(pow(svg_parse.global.height, 2) + 164 max = sqrt(pow(svg_parse->global.height, 2) +
159 pow(svg_parse.global.width, 2)) / sqrt(2.0); 165 pow(svg_parse->global.width, 2)) / sqrt(2.0);
160 166
161 if (strstr(str, "cm")) 167 if (strstr(str, "cm"))
162 parsed_value = parsed_value * 35.43307; 168 parsed_value = parsed_value * 35.43307;
@@ -763,7 +769,8 @@ static Eina_Bool _attr_style_node(void *data, const char *str);
763static Eina_Bool 769static Eina_Bool
764_attr_parse_svg_node(void *data, const char *key, const char *value) 770_attr_parse_svg_node(void *data, const char *key, const char *value)
765{ 771{
766 Svg_Node *node = data; 772 Evas_SVG_Loader *loader = data;
773 Svg_Node *node = loader->svg_parse->node;
767 Svg_Doc_Node *doc = &(node->node.doc); 774 Svg_Doc_Node *doc = &(node->node.doc);
768 Svg_Length_Type type; 775 Svg_Length_Type type;
769 776
@@ -785,13 +792,13 @@ _attr_parse_svg_node(void *data, const char *key, const char *value)
785 if (_parse_number(&value, &doc->vw)) 792 if (_parse_number(&value, &doc->vw))
786 { 793 {
787 _parse_number(&value, &doc->vh); 794 _parse_number(&value, &doc->vh);
788 svg_parse.global.height = doc->vh; 795 loader->svg_parse->global.height = doc->vh;
789 } 796 }
790 svg_parse.global.width = doc->vw; 797 loader->svg_parse->global.width = doc->vw;
791 } 798 }
792 svg_parse.global.y = doc->vy; 799 loader->svg_parse->global.y = doc->vy;
793 } 800 }
794 svg_parse.global.x = doc->vx; 801 loader->svg_parse->global.x = doc->vx;
795 } 802 }
796 else if (!strcmp(key, "preserveAspectRatio")) 803 else if (!strcmp(key, "preserveAspectRatio"))
797 { 804 {
@@ -800,18 +807,18 @@ _attr_parse_svg_node(void *data, const char *key, const char *value)
800 } 807 }
801 else if (!strcmp(key, "style")) 808 else if (!strcmp(key, "style"))
802 { 809 {
803 _attr_style_node(node, value); 810 _attr_style_node(loader, value);
804 } 811 }
805 else 812 else
806 { 813 {
807 _parse_style_attr(node, key, value); 814 _parse_style_attr(loader, key, value);
808 } 815 }
809 return EINA_TRUE; 816 return EINA_TRUE;
810} 817}
811 818
812//https://www.w3.org/TR/SVGTiny12/painting.html#SpecifyingPaint 819//https://www.w3.org/TR/SVGTiny12/painting.html#SpecifyingPaint
813static void 820static void
814_handle_paint_attr(Svg_Paint* paint, const char *value) 821_handle_paint_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Paint* paint, const char *value)
815{ 822{
816 if (!strcmp(value, "none")) 823 if (!strcmp(value, "none"))
817 { 824 {
@@ -829,78 +836,78 @@ _handle_paint_attr(Svg_Paint* paint, const char *value)
829} 836}
830 837
831static void 838static void
832_handle_color_attr(Svg_Node* node, const char *value) 839_handle_color_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node, const char *value)
833{ 840{
834 Svg_Style_Property *style = node->style; 841 Svg_Style_Property *style = node->style;
835 _to_color(value, &style->r, &style->g, &style->b, NULL); 842 _to_color(value, &style->r, &style->g, &style->b, NULL);
836} 843}
837 844
838static void 845static void
839_handle_fill_attr(Svg_Node* node, const char *value) 846_handle_fill_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node, const char *value)
840{ 847{
841 Svg_Style_Property *style = node->style; 848 Svg_Style_Property *style = node->style;
842 style->fill.flags |= SVG_FILL_FLAGS_PAINT; 849 style->fill.flags |= SVG_FILL_FLAGS_PAINT;
843 _handle_paint_attr(&style->fill.paint, value); 850 _handle_paint_attr(loader, &style->fill.paint, value);
844} 851}
845 852
846static void 853static void
847_handle_stroke_attr(Svg_Node* node, const char *value) 854_handle_stroke_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node, const char *value)
848{ 855{
849 Svg_Style_Property *style = node->style; 856 Svg_Style_Property *style = node->style;
850 style->stroke.flags |= SVG_STROKE_FLAGS_PAINT; 857 style->stroke.flags |= SVG_STROKE_FLAGS_PAINT;
851 _handle_paint_attr(&style->stroke.paint, value); 858 _handle_paint_attr(loader, &style->stroke.paint, value);
852} 859}
853 860
854static void 861static void
855_handle_stroke_opacity_attr(Svg_Node* node, const char *value) 862_handle_stroke_opacity_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node, const char *value)
856{ 863{
857 node->style->stroke.flags |= SVG_STROKE_FLAGS_OPACITY; 864 node->style->stroke.flags |= SVG_STROKE_FLAGS_OPACITY;
858 node->style->stroke.opacity = _to_opacity(value); 865 node->style->stroke.opacity = _to_opacity(value);
859} 866}
860 867
861static void 868static void
862_handle_stroke_width_attr(Svg_Node* node, const char *value) 869_handle_stroke_width_attr(Evas_SVG_Loader *loader, Svg_Node* node, const char *value)
863{ 870{
864 node->style->stroke.flags |= SVG_STROKE_FLAGS_WIDTH; 871 node->style->stroke.flags |= SVG_STROKE_FLAGS_WIDTH;
865 node->style->stroke.width = _to_double(value, SVG_PARSER_LENGTH_HORIZONTAL); 872 node->style->stroke.width = _to_double(loader->svg_parse, value, SVG_PARSER_LENGTH_HORIZONTAL);
866} 873}
867 874
868static void 875static void
869_handle_stroke_linecap_attr(Svg_Node* node, const char *value) 876_handle_stroke_linecap_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node, const char *value)
870{ 877{
871 node->style->stroke.flags |= SVG_STROKE_FLAGS_CAP; 878 node->style->stroke.flags |= SVG_STROKE_FLAGS_CAP;
872 node->style->stroke.cap = _to_line_cap(value); 879 node->style->stroke.cap = _to_line_cap(value);
873} 880}
874 881
875static void 882static void
876_handle_stroke_linejoin_attr(Svg_Node* node, const char *value) 883_handle_stroke_linejoin_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node, const char *value)
877{ 884{
878 node->style->stroke.flags |= SVG_STROKE_FLAGS_JOIN; 885 node->style->stroke.flags |= SVG_STROKE_FLAGS_JOIN;
879 node->style->stroke.join = _to_line_join(value); 886 node->style->stroke.join = _to_line_join(value);
880} 887}
881 888
882static void 889static void
883_handle_fill_rule_attr(Svg_Node* node, const char *value) 890_handle_fill_rule_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node, const char *value)
884{ 891{
885 node->style->fill.flags |= SVG_FILL_FLAGS_FILL_RULE; 892 node->style->fill.flags |= SVG_FILL_FLAGS_FILL_RULE;
886 node->style->fill.fill_rule = _to_fill_rule(value); 893 node->style->fill.fill_rule = _to_fill_rule(value);
887} 894}
888 895
889static void 896static void
890_handle_fill_opacity_attr(Svg_Node* node, const char *value) 897_handle_fill_opacity_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node, const char *value)
891{ 898{
892 node->style->fill.flags |= SVG_FILL_FLAGS_OPACITY; 899 node->style->fill.flags |= SVG_FILL_FLAGS_OPACITY;
893 node->style->fill.opacity = _to_opacity(value); 900 node->style->fill.opacity = _to_opacity(value);
894} 901}
895 902
896static void 903static void
897_handle_transform_attr(Svg_Node* node, const char *value) 904_handle_transform_attr(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node* node, const char *value)
898{ 905{
899 node->transform = _parse_transformation_matrix(value); 906 node->transform = _parse_transformation_matrix(value);
900} 907}
901 908
902 909
903typedef void (*Style_Method)(Svg_Node *node, const char *value); 910typedef void (*Style_Method)(Evas_SVG_Loader *loader, Svg_Node *node, const char *value);
904 911
905#define STYLE_DEF(Name, Name1) \ 912#define STYLE_DEF(Name, Name1) \
906 { #Name, sizeof (#Name), _handle_##Name1##_attr} 913 { #Name, sizeof (#Name), _handle_##Name1##_attr}
@@ -925,7 +932,8 @@ static const struct {
925static Eina_Bool 932static Eina_Bool
926_parse_style_attr(void *data, const char *key, const char *value) 933_parse_style_attr(void *data, const char *key, const char *value)
927{ 934{
928 Svg_Node* node = data; 935 Evas_SVG_Loader *loader = data;
936 Svg_Node* node = loader->svg_parse->node;
929 unsigned int i; 937 unsigned int i;
930 int sz; 938 int sz;
931 939
@@ -938,7 +946,7 @@ _parse_style_attr(void *data, const char *key, const char *value)
938 for (i = 0; i < sizeof (style_tags) / sizeof(style_tags[0]); i++) 946 for (i = 0; i < sizeof (style_tags) / sizeof(style_tags[0]); i++)
939 if (style_tags[i].sz - 1 == sz && !strncmp(style_tags[i].tag, key, sz)) 947 if (style_tags[i].sz - 1 == sz && !strncmp(style_tags[i].tag, key, sz))
940 { 948 {
941 style_tags[i].tag_handler(node, value); 949 style_tags[i].tag_handler(loader, node, value);
942 return EINA_TRUE; 950 return EINA_TRUE;
943 } 951 }
944 952
@@ -959,11 +967,12 @@ _attr_style_node(void *data, const char *str)
959static Eina_Bool 967static Eina_Bool
960_attr_parse_g_node(void *data, const char *key, const char *value) 968_attr_parse_g_node(void *data, const char *key, const char *value)
961{ 969{
962 Svg_Node *node = data; 970 Evas_SVG_Loader *loader = data;
971 Svg_Node* node = loader->svg_parse->node;
963 972
964 if (!strcmp(key, "style")) 973 if (!strcmp(key, "style"))
965 { 974 {
966 return _attr_style_node(node, value); 975 return _attr_style_node(loader, value);
967 } 976 }
968 else if (!strcmp(key, "transform")) 977 else if (!strcmp(key, "transform"))
969 { 978 {
@@ -975,7 +984,7 @@ _attr_parse_g_node(void *data, const char *key, const char *value)
975 } 984 }
976 else 985 else
977 { 986 {
978 _parse_style_attr(node, key, value); 987 _parse_style_attr(loader, key, value);
979 } 988 }
980 return EINA_TRUE; 989 return EINA_TRUE;
981} 990}
@@ -1024,7 +1033,7 @@ _create_node(Svg_Node *parent, Svg_Node_Type type)
1024} 1033}
1025 1034
1026static Svg_Node * 1035static Svg_Node *
1027_create_defs_node(Svg_Node *parent EINA_UNUSED, const char *buf EINA_UNUSED, unsigned buflen EINA_UNUSED) 1036_create_defs_node(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node *parent EINA_UNUSED, const char *buf EINA_UNUSED, unsigned buflen EINA_UNUSED)
1028{ 1037{
1029 Svg_Node *node = _create_node(NULL, SVG_NODE_DEFS); 1038 Svg_Node *node = _create_node(NULL, SVG_NODE_DEFS);
1030 eina_simple_xml_attributes_parse(buf, buflen, 1039 eina_simple_xml_attributes_parse(buf, buflen,
@@ -1033,29 +1042,30 @@ _create_defs_node(Svg_Node *parent EINA_UNUSED, const char *buf EINA_UNUSED, uns
1033} 1042}
1034 1043
1035static Svg_Node * 1044static Svg_Node *
1036_create_g_node(Svg_Node *parent, const char *buf, unsigned buflen) 1045_create_g_node(Evas_SVG_Loader *loader, Svg_Node *parent, const char *buf, unsigned buflen)
1037{ 1046{
1038 Svg_Node *node = _create_node(parent, SVG_NODE_G); 1047 loader->svg_parse->node = _create_node(parent, SVG_NODE_G);
1039 1048
1040 eina_simple_xml_attributes_parse(buf, buflen, 1049 eina_simple_xml_attributes_parse(buf, buflen,
1041 _attr_parse_g_node, node); 1050 _attr_parse_g_node, loader);
1042 return node; 1051 return loader->svg_parse->node;
1043} 1052}
1044 1053
1045static Svg_Node * 1054static Svg_Node *
1046_create_svg_node(Svg_Node *parent, const char *buf, unsigned buflen) 1055_create_svg_node(Evas_SVG_Loader *loader, Svg_Node *parent, const char *buf, unsigned buflen)
1047{ 1056{
1048 Svg_Node *node = _create_node(parent, SVG_NODE_DOC); 1057 loader->svg_parse->node = _create_node(parent, SVG_NODE_DOC);
1049 Svg_Doc_Node *doc = &(node->node.doc); 1058 Svg_Doc_Node *doc = &(loader->svg_parse->node->node.doc);
1050 1059
1051 doc->preserve_aspect = EINA_TRUE; 1060 doc->preserve_aspect = EINA_TRUE;
1052 eina_simple_xml_attributes_parse(buf, buflen, 1061 eina_simple_xml_attributes_parse(buf, buflen,
1053 _attr_parse_svg_node, node); 1062 _attr_parse_svg_node, loader);
1054 return node; 1063
1064 return loader->svg_parse->node;
1055} 1065}
1056 1066
1057static Svg_Node * 1067static Svg_Node *
1058_create_switch_node(Svg_Node *parent EINA_UNUSED, const char *buf EINA_UNUSED, unsigned buflen EINA_UNUSED) 1068_create_switch_node(Evas_SVG_Loader *loader EINA_UNUSED, Svg_Node *parent EINA_UNUSED, const char *buf EINA_UNUSED, unsigned buflen EINA_UNUSED)
1059{ 1069{
1060 return NULL; 1070 return NULL;
1061} 1071}
@@ -1063,7 +1073,8 @@ _create_switch_node(Svg_Node *parent EINA_UNUSED, const char *buf EINA_UNUSED, u
1063static Eina_Bool 1073static Eina_Bool
1064_attr_parse_path_node(void *data, const char *key, const char *value) 1074_attr_parse_path_node(void *data, const char *key, const char *value)
1065{ 1075{
1066 Svg_Node *node = data; 1076 Evas_SVG_Loader *loader = data;
1077 Svg_Node* node = loader->svg_parse->node;
1067 Svg_Path_Node *path = &(node->node.path); 1078 Svg_Path_Node *path = &(node->node.path);
1068 1079
1069 if (!strcmp(key, "d")) 1080 if (!strcmp(key, "d"))
@@ -1072,7 +1083,7 @@ _attr_parse_path_node(void *data, const char *key, const char *value)
1072 } 1083 }
1073 else if (!strcmp(key, "style")) 1084 else if (!strcmp(key, "style"))
1074 { 1085 {
1075 _attr_style_node(node, value); 1086 _attr_style_node(loader, value);
1076 } 1087 }
1077 else if (!strcmp(key, "id")) 1088 else if (!strcmp(key, "id"))
1078 { 1089 {
@@ -1080,19 +1091,20 @@ _attr_parse_path_node(void *data, const char *key, const char *value)
1080 } 1091 }
1081 else 1092 else
1082 { 1093 {
1083 _parse_style_attr(node, key, value); 1094 _parse_style_attr(loader, key, value);
1084 } 1095 }
1085 return EINA_TRUE; 1096 return EINA_TRUE;
1086} 1097}
1087 1098
1088static Svg_Node * 1099static Svg_Node *
1089_create_path_node(Svg_Node *parent, const char *buf, unsigned buflen) 1100_create_path_node(Evas_SVG_Loader *loader, Svg_Node *parent, const char *buf, unsigned buflen)
1090{ 1101{
1091 Svg_Node *node = _create_node(parent, SVG_NODE_PATH); 1102 loader->svg_parse->node = _create_node(parent, SVG_NODE_PATH);
1092 1103
1093 eina_simple_xml_attributes_parse(buf, buflen, 1104 eina_simple_xml_attributes_parse(buf, buflen,
1094 _attr_parse_path_node, node); 1105 _attr_parse_path_node, loader);
1095 return node; 1106
1107 return loader->svg_parse->node;
1096} 1108}
1097 1109
1098#define CIRCLE_DEF(Name, Field, Type) \ 1110#define CIRCLE_DEF(Name, Field, Type) \
@@ -1115,7 +1127,8 @@ static const struct {
1115static Eina_Bool 1127static Eina_Bool
1116_attr_parse_circle_node(void *data, const char *key, const char *value) 1128_attr_parse_circle_node(void *data, const char *key, const char *value)
1117{ 1129{
1118 Svg_Node *node = data; 1130 Evas_SVG_Loader *loader = data;
1131 Svg_Node* node = loader->svg_parse->node;
1119 Svg_Circle_Node *circle = &(node->node.circle); 1132 Svg_Circle_Node *circle = &(node->node.circle);
1120 unsigned int i; 1133 unsigned int i;
1121 unsigned char *array; 1134 unsigned char *array;
@@ -1125,13 +1138,14 @@ _attr_parse_circle_node(void *data, const char *key, const char *value)
1125 for (i = 0; i < sizeof (circle_tags) / sizeof(circle_tags[0]); i++) 1138 for (i = 0; i < sizeof (circle_tags) / sizeof(circle_tags[0]); i++)
1126 if (circle_tags[i].sz - 1 == sz && !strncmp(circle_tags[i].tag, key, sz)) 1139 if (circle_tags[i].sz - 1 == sz && !strncmp(circle_tags[i].tag, key, sz))
1127 { 1140 {
1128 *((double*) (array + circle_tags[i].offset)) = _to_double(value, circle_tags[i].type); 1141 *((double*) (array + circle_tags[i].offset)) =
1142 _to_double(loader->svg_parse, value, circle_tags[i].type);
1129 return EINA_TRUE; 1143 return EINA_TRUE;
1130 } 1144 }
1131 1145
1132 if (!strcmp(key, "style")) 1146 if (!strcmp(key, "style"))
1133 { 1147 {
1134 _attr_style_node(node, value); 1148 _attr_style_node(loader, value);
1135 } 1149 }
1136 else if (!strcmp(key, "id")) 1150 else if (!strcmp(key, "id"))
1137 { 1151 {
@@ -1139,19 +1153,19 @@ _attr_parse_circle_node(void *data, const char *key, const char *value)
1139 } 1153 }
1140 else 1154 else
1141 { 1155 {
1142 _parse_style_attr(node, key, value); 1156 _parse_style_attr(loader, key, value);
1143 } 1157 }
1144 return EINA_TRUE; 1158 return EINA_TRUE;
1145} 1159}
1146 1160
1147static Svg_Node * 1161static Svg_Node *
1148_create_circle_node(Svg_Node *parent, const char *buf, unsigned buflen) 1162_create_circle_node(Evas_SVG_Loader *loader, Svg_Node *parent, const char *buf, unsigned buflen)
1149{ 1163{
1150 Svg_Node *node = _create_node(parent, SVG_NODE_CIRCLE); 1164 loader->svg_parse->node = _create_node(parent, SVG_NODE_CIRCLE);
1151 1165
1152 eina_simple_xml_attributes_parse(buf, buflen, 1166 eina_simple_xml_attributes_parse(buf, buflen,
1153 _attr_parse_circle_node, node); 1167 _attr_parse_circle_node, loader);
1154 return node; 1168 return loader->svg_parse->node;
1155} 1169}
1156 1170
1157#define ELLIPSE_DEF(Name, Field, Type) \ 1171#define ELLIPSE_DEF(Name, Field, Type) \
@@ -1175,7 +1189,8 @@ static const struct {
1175static Eina_Bool 1189static Eina_Bool
1176_attr_parse_ellipse_node(void *data, const char *key, const char *value) 1190_attr_parse_ellipse_node(void *data, const char *key, const char *value)
1177{ 1191{
1178 Svg_Node *node = data; 1192 Evas_SVG_Loader *loader = data;
1193 Svg_Node* node = loader->svg_parse->node;
1179 Svg_Ellipse_Node *ellipse = &(node->node.ellipse); 1194 Svg_Ellipse_Node *ellipse = &(node->node.ellipse);
1180 unsigned int i; 1195 unsigned int i;
1181 unsigned char *array; 1196 unsigned char *array;
@@ -1185,7 +1200,8 @@ _attr_parse_ellipse_node(void *data, const char *key, const char *value)
1185 for (i = 0; i < sizeof (ellipse_tags) / sizeof(ellipse_tags[0]); i++) 1200 for (i = 0; i < sizeof (ellipse_tags) / sizeof(ellipse_tags[0]); i++)
1186 if (ellipse_tags[i].sz - 1 == sz && !strncmp(ellipse_tags[i].tag, key, sz)) 1201 if (ellipse_tags[i].sz - 1 == sz && !strncmp(ellipse_tags[i].tag, key, sz))
1187 { 1202 {
1188 *((double*) (array + ellipse_tags[i].offset)) = _to_double(value, ellipse_tags[i].type); 1203 *((double*) (array + ellipse_tags[i].offset)) =
1204 _to_double(loader->svg_parse, value, ellipse_tags[i].type);
1189 return EINA_TRUE; 1205 return EINA_TRUE;
1190 } 1206 }
1191 1207
@@ -1195,23 +1211,23 @@ _attr_parse_ellipse_node(void *data, const char *key, const char *value)
1195 } 1211 }
1196 else if (!strcmp(key, "style")) 1212 else if (!strcmp(key, "style"))
1197 { 1213 {
1198 _attr_style_node(node, value); 1214 _attr_style_node(loader, value);
1199 } 1215 }
1200 else 1216 else
1201 { 1217 {
1202 _parse_style_attr(node, key, value); 1218 _parse_style_attr(loader, key, value);
1203 } 1219 }
1204 return EINA_TRUE; 1220 return EINA_TRUE;
1205} 1221}
1206 1222
1207static Svg_Node * 1223static Svg_Node *
1208_create_ellipse_node(Svg_Node *parent, const char *buf, unsigned buflen) 1224_create_ellipse_node(Evas_SVG_Loader *loader, Svg_Node *parent, const char *buf, unsigned buflen)
1209{ 1225{
1210 Svg_Node *node = _create_node(parent, SVG_NODE_ELLIPSE); 1226 loader->svg_parse->node = _create_node(parent, SVG_NODE_ELLIPSE);
1211 1227
1212 eina_simple_xml_attributes_parse(buf, buflen, 1228 eina_simple_xml_attributes_parse(buf, buflen,
1213 _attr_parse_ellipse_node, node); 1229 _attr_parse_ellipse_node, loader);
1214 return node; 1230 return loader->svg_parse->node;
1215} 1231}
1216 1232
1217static void 1233static void
@@ -1260,7 +1276,8 @@ error_alloc:
1260static Eina_Bool 1276static Eina_Bool
1261_attr_parse_polygon_node(void *data, const char *key, const char *value) 1277_attr_parse_polygon_node(void *data, const char *key, const char *value)
1262{ 1278{
1263 Svg_Node *node = data; 1279 Evas_SVG_Loader *loader = data;
1280 Svg_Node *node = loader->svg_parse->node;
1264 Svg_Polygon_Node *polygon = NULL; 1281 Svg_Polygon_Node *polygon = NULL;
1265 1282
1266 if (node->type == SVG_NODE_POLYGON) 1283 if (node->type == SVG_NODE_POLYGON)
@@ -1275,7 +1292,7 @@ _attr_parse_polygon_node(void *data, const char *key, const char *value)
1275 } 1292 }
1276 else if (!strcmp(key, "style")) 1293 else if (!strcmp(key, "style"))
1277 { 1294 {
1278 _attr_style_node(node, value); 1295 _attr_style_node(loader, value);
1279 } 1296 }
1280 else if (!strcmp(key, "id")) 1297 else if (!strcmp(key, "id"))
1281 { 1298 {
@@ -1283,29 +1300,29 @@ _attr_parse_polygon_node(void *data, const char *key, const char *value)
1283 } 1300 }
1284 else 1301 else
1285 { 1302 {
1286 _parse_style_attr(node, key, value); 1303 _parse_style_attr(loader, key, value);
1287 } 1304 }
1288 return EINA_TRUE; 1305 return EINA_TRUE;
1289} 1306}
1290 1307
1291static Svg_Node * 1308static Svg_Node *
1292_create_polygon_node(Svg_Node *parent, const char *buf, unsigned buflen) 1309_create_polygon_node(Evas_SVG_Loader *loader, Svg_Node *parent, const char *buf, unsigned buflen)
1293{ 1310{
1294 Svg_Node *node = _create_node(parent, SVG_NODE_POLYGON); 1311 loader->svg_parse->node = _create_node(parent, SVG_NODE_POLYGON);
1295 1312
1296 eina_simple_xml_attributes_parse(buf, buflen, 1313 eina_simple_xml_attributes_parse(buf, buflen,
1297 _attr_parse_polygon_node, node); 1314 _attr_parse_polygon_node, loader);
1298 return node; 1315 return loader->svg_parse->node;
1299} 1316}
1300 1317
1301static Svg_Node * 1318static Svg_Node *
1302_create_polyline_node(Svg_Node *parent, const char *buf, unsigned buflen) 1319_create_polyline_node(Evas_SVG_Loader *loader, Svg_Node *parent, const char *buf, unsigned buflen)
1303{ 1320{
1304 Svg_Node *node = _create_node(parent, SVG_NODE_POLYLINE); 1321 loader->svg_parse->node = _create_node(parent, SVG_NODE_POLYLINE);
1305 1322
1306 eina_simple_xml_attributes_parse(buf, buflen, 1323 eina_simple_xml_attributes_parse(buf, buflen,
1307 _attr_parse_polygon_node, node); 1324 _attr_parse_polygon_node, loader);
1308 return node; 1325 return loader->svg_parse->node;
1309} 1326}
1310 1327
1311#define RECT_DEF(Name, Field, Type) \ 1328#define RECT_DEF(Name, Field, Type) \
@@ -1331,7 +1348,8 @@ static const struct {
1331static Eina_Bool 1348static Eina_Bool
1332_attr_parse_rect_node(void *data, const char *key, const char *value) 1349_attr_parse_rect_node(void *data, const char *key, const char *value)
1333{ 1350{
1334 Svg_Node *node = data; 1351 Evas_SVG_Loader *loader = data;
1352 Svg_Node *node = loader->svg_parse->node;
1335 Svg_Rect_Node *rect = & (node->node.rect); 1353 Svg_Rect_Node *rect = & (node->node.rect);
1336 unsigned int i; 1354 unsigned int i;
1337 unsigned char *array; 1355 unsigned char *array;
@@ -1341,7 +1359,7 @@ _attr_parse_rect_node(void *data, const char *key, const char *value)
1341 for (i = 0; i < sizeof (rect_tags) / sizeof(rect_tags[0]); i++) 1359 for (i = 0; i < sizeof (rect_tags) / sizeof(rect_tags[0]); i++)
1342 if (rect_tags[i].sz - 1 == sz && !strncmp(rect_tags[i].tag, key, sz)) 1360 if (rect_tags[i].sz - 1 == sz && !strncmp(rect_tags[i].tag, key, sz))
1343 { 1361 {
1344 *((double*) (array + rect_tags[i].offset)) = _to_double(value, rect_tags[i].type); 1362 *((double*) (array + rect_tags[i].offset)) = _to_double(loader->svg_parse, value, rect_tags[i].type);
1345 return EINA_TRUE; 1363 return EINA_TRUE;
1346 } 1364 }
1347 1365
@@ -1351,11 +1369,11 @@ _attr_parse_rect_node(void *data, const char *key, const char *value)
1351 } 1369 }
1352 else if (!strcmp(key, "style")) 1370 else if (!strcmp(key, "style"))
1353 { 1371 {
1354 _attr_style_node(node, value); 1372 _attr_style_node(loader, value);
1355 } 1373 }
1356 else 1374 else
1357 { 1375 {
1358 _parse_style_attr(node, key, value); 1376 _parse_style_attr(loader, key, value);
1359 } 1377 }
1360 1378
1361 if (!EINA_DBL_EQ(rect->rx, 0) && EINA_DBL_EQ(rect->ry, 0)) rect->ry = rect->rx; 1379 if (!EINA_DBL_EQ(rect->rx, 0) && EINA_DBL_EQ(rect->ry, 0)) rect->ry = rect->rx;
@@ -1365,13 +1383,13 @@ _attr_parse_rect_node(void *data, const char *key, const char *value)
1365} 1383}
1366 1384
1367static Svg_Node * 1385static Svg_Node *
1368_create_rect_node(Svg_Node *parent, const char *buf, unsigned buflen) 1386_create_rect_node(Evas_SVG_Loader *loader, Svg_Node *parent, const char *buf, unsigned buflen)
1369{ 1387{
1370 Svg_Node *node = _create_node(parent, SVG_NODE_RECT); 1388 loader->svg_parse->node = _create_node(parent, SVG_NODE_RECT);
1371 1389
1372 eina_simple_xml_attributes_parse(buf, buflen, 1390 eina_simple_xml_attributes_parse(buf, buflen,
1373 _attr_parse_rect_node, node); 1391 _attr_parse_rect_node, loader);
1374 return node; 1392 return loader->svg_parse->node;
1375} 1393}
1376 1394
1377#define LINE_DEF(Name, Field, Type) \ 1395#define LINE_DEF(Name, Field, Type) \
@@ -1395,7 +1413,8 @@ static const struct {
1395static Eina_Bool 1413static Eina_Bool
1396_attr_parse_line_node(void *data, const char *key, const char *value) 1414_attr_parse_line_node(void *data, const char *key, const char *value)
1397{ 1415{
1398 Svg_Node *node = data; 1416 Evas_SVG_Loader *loader = data;
1417 Svg_Node *node = loader->svg_parse->node;
1399 Svg_Line_Node *line = & (node->node.line); 1418 Svg_Line_Node *line = & (node->node.line);
1400 unsigned int i; 1419 unsigned int i;
1401 unsigned char *array; 1420 unsigned char *array;
@@ -1405,7 +1424,7 @@ _attr_parse_line_node(void *data, const char *key, const char *value)
1405 for (i = 0; i < sizeof (line_tags) / sizeof(line_tags[0]); i++) 1424 for (i = 0; i < sizeof (line_tags) / sizeof(line_tags[0]); i++)
1406 if (line_tags[i].sz - 1 == sz && !strncmp(line_tags[i].tag, key, sz)) 1425 if (line_tags[i].sz - 1 == sz && !strncmp(line_tags[i].tag, key, sz))
1407 { 1426 {
1408 *((double*) (array + line_tags[i].offset)) = _to_double(value, line_tags[i].type); 1427 *((double*) (array + line_tags[i].offset)) = _to_double(loader->svg_parse, value, line_tags[i].type);
1409 return EINA_TRUE; 1428 return EINA_TRUE;
1410 } 1429 }
1411 1430
@@ -1415,23 +1434,23 @@ _attr_parse_line_node(void *data, const char *key, const char *value)
1415 } 1434 }
1416 else if (!strcmp(key, "style")) 1435 else if (!strcmp(key, "style"))
1417 { 1436 {
1418 _attr_style_node(node, value); 1437 _attr_style_node(loader, value);
1419 } 1438 }
1420 else 1439 else
1421 { 1440 {
1422 _parse_style_attr(node, key, value); 1441 _parse_style_attr(loader, key, value);
1423 } 1442 }
1424 return EINA_TRUE; 1443 return EINA_TRUE;
1425} 1444}
1426 1445
1427static Svg_Node * 1446static Svg_Node *
1428_create_line_node(Svg_Node *parent, const char *buf, unsigned buflen) 1447_create_line_node(Evas_SVG_Loader *loader, Svg_Node *parent, const char *buf, unsigned buflen)
1429{ 1448{
1430 Svg_Node *node = _create_node(parent, SVG_NODE_LINE); 1449 loader->svg_parse->node = _create_node(parent, SVG_NODE_LINE);
1431 1450
1432 eina_simple_xml_attributes_parse(buf, buflen, 1451 eina_simple_xml_attributes_parse(buf, buflen,
1433 _attr_parse_line_node, node); 1452 _attr_parse_line_node, loader);
1434 return node; 1453 return loader->svg_parse->node;
1435} 1454}
1436 1455
1437static Eina_Stringshare * 1456static Eina_Stringshare *
@@ -1601,7 +1620,8 @@ _clone_node(Svg_Node *from, Svg_Node *parent)
1601static Eina_Bool 1620static Eina_Bool
1602_attr_parse_use_node(void *data, const char *key, const char *value) 1621_attr_parse_use_node(void *data, const char *key, const char *value)
1603{ 1622{
1604 Svg_Node *defs, *node_from, *node = data; 1623 Evas_SVG_Loader *loader = data;
1624 Svg_Node *defs, *node_from, *node = loader->svg_parse->node;
1605 Eina_Stringshare *id; 1625 Eina_Stringshare *id;
1606 1626
1607 if (!strcmp(key, "xlink:href")) 1627 if (!strcmp(key, "xlink:href"))
@@ -1620,13 +1640,13 @@ _attr_parse_use_node(void *data, const char *key, const char *value)
1620} 1640}
1621 1641
1622static Svg_Node * 1642static Svg_Node *
1623_create_use_node(Svg_Node *parent, const char *buf, unsigned buflen) 1643_create_use_node(Evas_SVG_Loader *loader, Svg_Node *parent, const char *buf, unsigned buflen)
1624{ 1644{
1625 Svg_Node *node = _create_node(parent, SVG_NODE_G); 1645 loader->svg_parse->node = _create_node(parent, SVG_NODE_G);
1626 1646
1627 eina_simple_xml_attributes_parse(buf, buflen, 1647 eina_simple_xml_attributes_parse(buf, buflen,
1628 _attr_parse_use_node, node); 1648 _attr_parse_use_node, loader);
1629 return node; 1649 return loader->svg_parse->node;
1630} 1650}
1631 1651
1632#define TAG_DEF(Name) \ 1652#define TAG_DEF(Name) \
@@ -1695,42 +1715,42 @@ _parse_spread_value(const char *value)
1695} 1715}
1696 1716
1697static void 1717static void
1698_handle_radial_cx_attr(Svg_Radial_Gradient* radial, const char *value) 1718_handle_radial_cx_attr(Evas_SVG_Loader *loader, Svg_Radial_Gradient* radial, const char *value)
1699{ 1719{
1700 radial->cx = _gradient_to_double(value, SVG_PARSER_LENGTH_HORIZONTAL); 1720 radial->cx = _gradient_to_double(loader->svg_parse, value, SVG_PARSER_LENGTH_HORIZONTAL);
1701 if (!svg_parse.gradient.fx_parsed) 1721 if (!loader->svg_parse->gradient.fx_parsed)
1702 radial->fx = radial->cx; 1722 radial->fx = radial->cx;
1703} 1723}
1704 1724
1705static void 1725static void
1706_handle_radial_cy_attr(Svg_Radial_Gradient* radial, const char *value) 1726_handle_radial_cy_attr(Evas_SVG_Loader *loader, Svg_Radial_Gradient* radial, const char *value)
1707{ 1727{
1708 radial->cy = _gradient_to_double(value, SVG_PARSER_LENGTH_VERTICAL); 1728 radial->cy = _gradient_to_double(loader->svg_parse, value, SVG_PARSER_LENGTH_VERTICAL);
1709 if (!svg_parse.gradient.fy_parsed) 1729 if (!loader->svg_parse->gradient.fy_parsed)
1710 radial->fy = radial->cy; 1730 radial->fy = radial->cy;
1711} 1731}
1712 1732
1713static void 1733static void
1714_handle_radial_fx_attr(Svg_Radial_Gradient* radial, const char *value) 1734_handle_radial_fx_attr(Evas_SVG_Loader *loader, Svg_Radial_Gradient* radial, const char *value)
1715{ 1735{
1716 radial->fx = _gradient_to_double(value, SVG_PARSER_LENGTH_HORIZONTAL); 1736 radial->fx = _gradient_to_double(loader->svg_parse, value, SVG_PARSER_LENGTH_HORIZONTAL);
1717 svg_parse.gradient.fx_parsed = EINA_TRUE; 1737 loader->svg_parse->gradient.fx_parsed = EINA_TRUE;
1718} 1738}
1719 1739
1720static void 1740static void
1721_handle_radial_fy_attr(Svg_Radial_Gradient* radial, const char *value) 1741_handle_radial_fy_attr(Evas_SVG_Loader *loader, Svg_Radial_Gradient* radial, const char *value)
1722{ 1742{
1723 radial->fy = _gradient_to_double(value, SVG_PARSER_LENGTH_VERTICAL); 1743 radial->fy = _gradient_to_double(loader->svg_parse, value, SVG_PARSER_LENGTH_VERTICAL);
1724 svg_parse.gradient.fy_parsed = EINA_TRUE; 1744 loader->svg_parse->gradient.fy_parsed = EINA_TRUE;
1725} 1745}
1726 1746
1727static void 1747static void
1728_handle_radial_r_attr(Svg_Radial_Gradient* radial, const char *value) 1748_handle_radial_r_attr(Evas_SVG_Loader *loader, Svg_Radial_Gradient* radial, const char *value)
1729{ 1749{
1730 radial->r = _gradient_to_double(value, SVG_PARSER_LENGTH_OTHER); 1750 radial->r = _gradient_to_double(loader->svg_parse, value, SVG_PARSER_LENGTH_OTHER);
1731} 1751}
1732 1752
1733typedef void (*Radial_Method)(Svg_Radial_Gradient *radial, const char *value); 1753typedef void (*Radial_Method)(Evas_SVG_Loader *loader, Svg_Radial_Gradient *radial, const char *value);
1734 1754
1735#define RADIAL_DEF(Name) \ 1755#define RADIAL_DEF(Name) \
1736 { #Name, sizeof (#Name), _handle_radial_##Name##_attr} 1756 { #Name, sizeof (#Name), _handle_radial_##Name##_attr}
@@ -1750,7 +1770,8 @@ static const struct {
1750static Eina_Bool 1770static Eina_Bool
1751_attr_parse_radial_gradient_node(void *data, const char *key, const char *value) 1771_attr_parse_radial_gradient_node(void *data, const char *key, const char *value)
1752{ 1772{
1753 Svg_Style_Gradient *grad = data; 1773 Evas_SVG_Loader *loader = data;
1774 Svg_Style_Gradient *grad = loader->svg_parse->style_grad;
1754 Svg_Radial_Gradient *radial = grad->radial; 1775 Svg_Radial_Gradient *radial = grad->radial;
1755 unsigned int i; 1776 unsigned int i;
1756 int sz = strlen(key); 1777 int sz = strlen(key);
@@ -1758,7 +1779,7 @@ _attr_parse_radial_gradient_node(void *data, const char *key, const char *value)
1758 for (i = 0; i < sizeof (radial_tags) / sizeof(radial_tags[0]); i++) 1779 for (i = 0; i < sizeof (radial_tags) / sizeof(radial_tags[0]); i++)
1759 if (radial_tags[i].sz - 1 == sz && !strncmp(radial_tags[i].tag, key, sz)) 1780 if (radial_tags[i].sz - 1 == sz && !strncmp(radial_tags[i].tag, key, sz))
1760 { 1781 {
1761 radial_tags[i].tag_handler(radial, value); 1782 radial_tags[i].tag_handler(loader, radial, value);
1762 return EINA_TRUE; 1783 return EINA_TRUE;
1763 } 1784 }
1764 1785
@@ -1783,9 +1804,10 @@ _attr_parse_radial_gradient_node(void *data, const char *key, const char *value)
1783} 1804}
1784 1805
1785static Svg_Style_Gradient * 1806static Svg_Style_Gradient *
1786_create_radialGradient(const char *buf, unsigned buflen) 1807_create_radialGradient(Evas_SVG_Loader *loader, const char *buf, unsigned buflen)
1787{ 1808{
1788 Svg_Style_Gradient *grad = calloc(1, sizeof(Svg_Style_Gradient)); 1809 Svg_Style_Gradient *grad = calloc(1, sizeof(Svg_Style_Gradient));
1810 loader->svg_parse->style_grad = grad;
1789 1811
1790 grad->type = SVG_RADIAL_GRADIENT; 1812 grad->type = SVG_RADIAL_GRADIENT;
1791 grad->user_space = EINA_TRUE; 1813 grad->user_space = EINA_TRUE;
@@ -1799,19 +1821,19 @@ _create_radialGradient(const char *buf, unsigned buflen)
1799 grad->radial->fy = 0.5; 1821 grad->radial->fy = 0.5;
1800 grad->radial->r = 0.5; 1822 grad->radial->r = 0.5;
1801 1823
1802 svg_parse.gradient.fx_parsed = EINA_FALSE; 1824 loader->svg_parse->gradient.fx_parsed = EINA_FALSE;
1803 svg_parse.gradient.fy_parsed = EINA_FALSE; 1825 loader->svg_parse->gradient.fy_parsed = EINA_FALSE;
1804 eina_simple_xml_attributes_parse(buf, buflen, 1826 eina_simple_xml_attributes_parse(buf, buflen,
1805 _attr_parse_radial_gradient_node, grad); 1827 _attr_parse_radial_gradient_node, loader);
1806
1807 return grad;
1808 1828
1829 return loader->svg_parse->style_grad;
1809} 1830}
1810 1831
1811static Eina_Bool 1832static Eina_Bool
1812_attr_parse_stops(void *data, const char *key, const char *value) 1833_attr_parse_stops(void *data, const char *key, const char *value)
1813{ 1834{
1814 Efl_Gfx_Gradient_Stop *stop = data; 1835 Evas_SVG_Loader *loader = data;
1836 Efl_Gfx_Gradient_Stop *stop = loader->svg_parse->grad_stop;
1815 1837
1816 if (!strcmp(key, "offset")) 1838 if (!strcmp(key, "offset"))
1817 { 1839 {
@@ -1835,89 +1857,89 @@ _attr_parse_stops(void *data, const char *key, const char *value)
1835} 1857}
1836 1858
1837static void 1859static void
1838_handle_linear_x1_attr(Svg_Linear_Gradient* linear, const char *value) 1860_handle_linear_x1_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, const char *value)
1839{ 1861{
1840 linear->x1 = _gradient_to_double(value, SVG_PARSER_LENGTH_HORIZONTAL); 1862 linear->x1 = _gradient_to_double(loader->svg_parse, value, SVG_PARSER_LENGTH_HORIZONTAL);
1841 if (strstr(value, "%")) 1863 if (strstr(value, "%"))
1842 svg_parse.gradient.x1_percent = EINA_TRUE; 1864 loader->svg_parse->gradient.x1_percent = EINA_TRUE;
1843} 1865}
1844 1866
1845static void 1867static void
1846_handle_linear_y1_attr(Svg_Linear_Gradient* linear, const char *value) 1868_handle_linear_y1_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, const char *value)
1847{ 1869{
1848 linear->y1 = _gradient_to_double(value, SVG_PARSER_LENGTH_VERTICAL); 1870 linear->y1 = _gradient_to_double(loader->svg_parse, value, SVG_PARSER_LENGTH_VERTICAL);
1849 if (strstr(value, "%")) 1871 if (strstr(value, "%"))
1850 svg_parse.gradient.y1_percent = EINA_TRUE; 1872 loader->svg_parse->gradient.y1_percent = EINA_TRUE;
1851} 1873}
1852 1874
1853static void 1875static void
1854_handle_linear_x2_attr(Svg_Linear_Gradient* linear, const char *value) 1876_handle_linear_x2_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, const char *value)
1855{ 1877{
1856 linear->x2 = _gradient_to_double(value, SVG_PARSER_LENGTH_HORIZONTAL); 1878 linear->x2 = _gradient_to_double(loader->svg_parse, value, SVG_PARSER_LENGTH_HORIZONTAL);
1857 /* checking if there are no percentage because x2 have default value 1879 /* checking if there are no percentage because x2 have default value
1858 * already set in percentages (100%) */ 1880 * already set in percentages (100%) */
1859 if (!strstr(value, "%")) 1881 if (!strstr(value, "%"))
1860 svg_parse.gradient.x2_percent = EINA_FALSE; 1882 loader->svg_parse->gradient.x2_percent = EINA_FALSE;
1861} 1883}
1862 1884
1863static void 1885static void
1864_handle_linear_y2_attr(Svg_Linear_Gradient* linear, const char *value) 1886_handle_linear_y2_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, const char *value)
1865{ 1887{
1866 linear->y2 = _gradient_to_double(value, SVG_PARSER_LENGTH_VERTICAL); 1888 linear->y2 = _gradient_to_double(loader->svg_parse, value, SVG_PARSER_LENGTH_VERTICAL);
1867 if (strstr(value, "%")) 1889 if (strstr(value, "%"))
1868 svg_parse.gradient.y2_percent = EINA_TRUE; 1890 loader->svg_parse->gradient.y2_percent = EINA_TRUE;
1869} 1891}
1870 1892
1871static void 1893static void
1872_recalc_linear_x1_attr(Svg_Linear_Gradient* linear, Eina_Bool user_space) 1894_recalc_linear_x1_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, Eina_Bool user_space)
1873{ 1895{
1874 if (!svg_parse.gradient.x1_percent && !user_space) 1896 if (!loader->svg_parse->gradient.x1_percent && !user_space)
1875 { 1897 {
1876 /* Since previous percentage is not required (it was already percent) 1898 /* Since previous percentage is not required (it was already percent)
1877 * so oops and make it all back */ 1899 * so oops and make it all back */
1878 linear->x1 = linear->x1 * svg_parse.global.width; 1900 linear->x1 = linear->x1 * loader->svg_parse->global.width;
1879 } 1901 }
1880 svg_parse.gradient.x1_percent = EINA_FALSE; 1902 loader->svg_parse->gradient.x1_percent = EINA_FALSE;
1881} 1903}
1882 1904
1883static void 1905static void
1884_recalc_linear_y1_attr(Svg_Linear_Gradient* linear, Eina_Bool user_space) 1906_recalc_linear_y1_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, Eina_Bool user_space)
1885{ 1907{
1886 if (!svg_parse.gradient.y1_percent && !user_space) 1908 if (!loader->svg_parse->gradient.y1_percent && !user_space)
1887 { 1909 {
1888 /* Since previous percentage is not required (it was already percent) 1910 /* Since previous percentage is not required (it was already percent)
1889 * so oops and make it all back */ 1911 * so oops and make it all back */
1890 linear->y1 = linear->y1 * svg_parse.global.height; 1912 linear->y1 = linear->y1 * loader->svg_parse->global.height;
1891 } 1913 }
1892 svg_parse.gradient.y1_percent = EINA_FALSE; 1914 loader->svg_parse->gradient.y1_percent = EINA_FALSE;
1893} 1915}
1894 1916
1895static void 1917static void
1896_recalc_linear_x2_attr(Svg_Linear_Gradient* linear, Eina_Bool user_space) 1918_recalc_linear_x2_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, Eina_Bool user_space)
1897{ 1919{
1898 if (!svg_parse.gradient.x2_percent && !user_space) 1920 if (!loader->svg_parse->gradient.x2_percent && !user_space)
1899 { 1921 {
1900 /* Since previous percentage is not required (it was already percent) 1922 /* Since previous percentage is not required (it was already percent)
1901 * so oops and make it all back */ 1923 * so oops and make it all back */
1902 linear->x2 = linear->x2 * svg_parse.global.width; 1924 linear->x2 = linear->x2 * loader->svg_parse->global.width;
1903 } 1925 }
1904 svg_parse.gradient.x2_percent = EINA_FALSE; 1926 loader->svg_parse->gradient.x2_percent = EINA_FALSE;
1905} 1927}
1906 1928
1907static void 1929static void
1908_recalc_linear_y2_attr(Svg_Linear_Gradient* linear, Eina_Bool user_space) 1930_recalc_linear_y2_attr(Evas_SVG_Loader *loader, Svg_Linear_Gradient* linear, Eina_Bool user_space)
1909{ 1931{
1910 if (!svg_parse.gradient.y2_percent && !user_space) 1932 if (!loader->svg_parse->gradient.y2_percent && !user_space)
1911 { 1933 {
1912 /* Since previous percentage is not required (it was already percent) 1934 /* Since previous percentage is not required (it was already percent)
1913 * so oops and make it all back */ 1935 * so oops and make it all back */
1914 linear->y2 = linear->y2 * svg_parse.global.height; 1936 linear->y2 = linear->y2 * loader->svg_parse->global.height;
1915 } 1937 }
1916 svg_parse.gradient.y2_percent = EINA_FALSE; 1938 loader->svg_parse->gradient.y2_percent = EINA_FALSE;
1917} 1939}
1918 1940
1919typedef void (*Linear_Method)(Svg_Linear_Gradient *linear, const char *value); 1941typedef void (*Linear_Method)(Evas_SVG_Loader *loader, Svg_Linear_Gradient *linear, const char *value);
1920typedef void (*Linear_Method_Recalc)(Svg_Linear_Gradient *linear, Eina_Bool user_space); 1942typedef void (*Linear_Method_Recalc)(Evas_SVG_Loader *loader, Svg_Linear_Gradient *linear, Eina_Bool user_space);
1921 1943
1922#define LINEAR_DEF(Name) \ 1944#define LINEAR_DEF(Name) \
1923 { #Name, sizeof (#Name), _handle_linear_##Name##_attr, _recalc_linear_##Name##_attr} 1945 { #Name, sizeof (#Name), _handle_linear_##Name##_attr, _recalc_linear_##Name##_attr}
@@ -1937,7 +1959,8 @@ static const struct {
1937static Eina_Bool 1959static Eina_Bool
1938_attr_parse_linear_gradient_node(void *data, const char *key, const char *value) 1960_attr_parse_linear_gradient_node(void *data, const char *key, const char *value)
1939{ 1961{
1940 Svg_Style_Gradient *grad = data; 1962 Evas_SVG_Loader *loader = data;
1963 Svg_Style_Gradient *grad = loader->svg_parse->style_grad;
1941 Svg_Linear_Gradient *linear = grad->linear; 1964 Svg_Linear_Gradient *linear = grad->linear;
1942 unsigned int i; 1965 unsigned int i;
1943 int sz = strlen(key); 1966 int sz = strlen(key);
@@ -1945,7 +1968,7 @@ _attr_parse_linear_gradient_node(void *data, const char *key, const char *value)
1945 for (i = 0; i < sizeof (linear_tags) / sizeof(linear_tags[0]); i++) 1968 for (i = 0; i < sizeof (linear_tags) / sizeof(linear_tags[0]); i++)
1946 if (linear_tags[i].sz - 1 == sz && !strncmp(linear_tags[i].tag, key, sz)) 1969 if (linear_tags[i].sz - 1 == sz && !strncmp(linear_tags[i].tag, key, sz))
1947 { 1970 {
1948 linear_tags[i].tag_handler(linear, value); 1971 linear_tags[i].tag_handler(loader, linear, value);
1949 return EINA_TRUE; 1972 return EINA_TRUE;
1950 } 1973 }
1951 1974
@@ -1970,9 +1993,11 @@ _attr_parse_linear_gradient_node(void *data, const char *key, const char *value)
1970} 1993}
1971 1994
1972static Svg_Style_Gradient * 1995static Svg_Style_Gradient *
1973_create_linearGradient(const char *buf, unsigned buflen) 1996_create_linearGradient(Evas_SVG_Loader *loader, const char *buf, unsigned buflen)
1974{ 1997{
1975 Svg_Style_Gradient *grad = calloc(1, sizeof(Svg_Style_Gradient)); 1998 Svg_Style_Gradient *grad = calloc(1, sizeof(Svg_Style_Gradient));
1999 loader->svg_parse->style_grad = grad;
2000
1976 unsigned int i; 2001 unsigned int i;
1977 2002
1978 grad->type = SVG_LINEAR_GRADIENT; 2003 grad->type = SVG_LINEAR_GRADIENT;
@@ -1982,14 +2007,14 @@ _create_linearGradient(const char *buf, unsigned buflen)
1982 * Default value of x2 is 100% 2007 * Default value of x2 is 100%
1983 */ 2008 */
1984 grad->linear->x2 = 1; 2009 grad->linear->x2 = 1;
1985 svg_parse.gradient.x2_percent = EINA_TRUE; 2010 loader->svg_parse->gradient.x2_percent = EINA_TRUE;
1986 eina_simple_xml_attributes_parse(buf, buflen, 2011 eina_simple_xml_attributes_parse(buf, buflen,
1987 _attr_parse_linear_gradient_node, grad); 2012 _attr_parse_linear_gradient_node, loader);
1988 2013
1989 for (i = 0; i < sizeof (linear_tags) / sizeof(linear_tags[0]); i++) 2014 for (i = 0; i < sizeof (linear_tags) / sizeof(linear_tags[0]); i++)
1990 linear_tags[i].tag_recalc(grad->linear, grad->user_space); 2015 linear_tags[i].tag_recalc(loader, grad->linear, grad->user_space);
1991 2016
1992 return grad; 2017 return loader->svg_parse->style_grad;
1993} 2018}
1994 2019
1995#define GRADIENT_DEF(Name) \ 2020#define GRADIENT_DEF(Name) \
@@ -2064,13 +2089,13 @@ _evas_svg_loader_xml_open_parser(Evas_SVG_Loader *loader,
2064 { 2089 {
2065 if (strcmp(tag_name, "svg")) 2090 if (strcmp(tag_name, "svg"))
2066 return; // Not a valid svg document 2091 return; // Not a valid svg document
2067 node = method(NULL, attrs, attrs_length); 2092 node = method(loader, NULL, attrs, attrs_length);
2068 loader->doc = node; 2093 loader->doc = node;
2069 } 2094 }
2070 else 2095 else
2071 { 2096 {
2072 parent = eina_array_data_get(loader->stack, eina_array_count(loader->stack) - 1); 2097 parent = eina_array_data_get(loader->stack, eina_array_count(loader->stack) - 1);
2073 node = method(parent, attrs, attrs_length); 2098 node = method(loader, parent, attrs, attrs_length);
2074 } 2099 }
2075 eina_array_push(loader->stack, node); 2100 eina_array_push(loader->stack, node);
2076 2101
@@ -2083,12 +2108,12 @@ _evas_svg_loader_xml_open_parser(Evas_SVG_Loader *loader,
2083 else if ((method = _find_graphics_factory(tag_name))) 2108 else if ((method = _find_graphics_factory(tag_name)))
2084 { 2109 {
2085 parent = eina_array_data_get(loader->stack, eina_array_count(loader->stack) - 1); 2110 parent = eina_array_data_get(loader->stack, eina_array_count(loader->stack) - 1);
2086 node = method(parent, attrs, attrs_length); 2111 node = method(loader, parent, attrs, attrs_length);
2087 } 2112 }
2088 else if ((gradient_method = _find_gradient_factory(tag_name))) 2113 else if ((gradient_method = _find_gradient_factory(tag_name)))
2089 { 2114 {
2090 Svg_Style_Gradient *gradient; 2115 Svg_Style_Gradient *gradient;
2091 gradient = gradient_method(attrs, attrs_length); 2116 gradient = gradient_method(loader, attrs, attrs_length);
2092 if (loader->doc->node.doc.defs) 2117 if (loader->doc->node.doc.defs)
2093 { 2118 {
2094 loader->def->node.defs.gradients = eina_list_append(loader->def->node.defs.gradients, gradient); 2119 loader->def->node.defs.gradients = eina_list_append(loader->def->node.defs.gradients, gradient);
@@ -2098,10 +2123,11 @@ _evas_svg_loader_xml_open_parser(Evas_SVG_Loader *loader,
2098 else if (!strcmp(tag_name, "stop")) 2123 else if (!strcmp(tag_name, "stop"))
2099 { 2124 {
2100 Efl_Gfx_Gradient_Stop *stop = calloc(1, sizeof(Efl_Gfx_Gradient_Stop)); 2125 Efl_Gfx_Gradient_Stop *stop = calloc(1, sizeof(Efl_Gfx_Gradient_Stop));
2126 loader->svg_parse->grad_stop = stop;
2101 /* default value for opacity */ 2127 /* default value for opacity */
2102 stop->a = 255; 2128 stop->a = 255;
2103 eina_simple_xml_attributes_parse(attrs, attrs_length, 2129 eina_simple_xml_attributes_parse(attrs, attrs_length,
2104 _attr_parse_stops, stop); 2130 _attr_parse_stops, loader);
2105 if (loader->gradient) 2131 if (loader->gradient)
2106 loader->gradient->stops = eina_list_append(loader->gradient->stops, stop); 2132 loader->gradient->stops = eina_list_append(loader->gradient->stops, stop);
2107 } 2133 }
@@ -2304,7 +2330,7 @@ static Vg_File_Data*
2304evas_vg_load_file_data_svg(const char *file, const char *key EINA_UNUSED, int *error EINA_UNUSED) 2330evas_vg_load_file_data_svg(const char *file, const char *key EINA_UNUSED, int *error EINA_UNUSED)
2305{ 2331{
2306 Evas_SVG_Loader loader = { 2332 Evas_SVG_Loader loader = {
2307 NULL, NULL, NULL, NULL, 0, EINA_FALSE 2333 NULL, NULL, NULL, NULL, NULL, 0, EINA_FALSE
2308 }; 2334 };
2309 const char *content; 2335 const char *content;
2310 unsigned int length; 2336 unsigned int length;
@@ -2318,6 +2344,7 @@ evas_vg_load_file_data_svg(const char *file, const char *key EINA_UNUSED, int *e
2318 return NULL; 2344 return NULL;
2319 } 2345 }
2320 2346
2347 loader.svg_parse = calloc(1, sizeof(Evas_SVG_Parser));
2321 length = eina_file_size_get(f); 2348 length = eina_file_size_get(f);
2322 content = eina_file_map_all(f, EINA_FILE_SEQUENTIAL); 2349 content = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
2323 if (content) 2350 if (content)
@@ -2343,7 +2370,8 @@ evas_vg_load_file_data_svg(const char *file, const char *key EINA_UNUSED, int *e
2343 { 2370 {
2344 *error = EVAS_LOAD_ERROR_GENERIC; 2371 *error = EVAS_LOAD_ERROR_GENERIC;
2345 } 2372 }
2346 return vg_common_create_vg_node(loader.doc); 2373 free(loader.svg_parse);
2374 return vg_common_create_vg_node(loader.doc);
2347} 2375}
2348 2376
2349static Evas_Vg_Load_Func evas_vg_load_svg_func = 2377static Evas_Vg_Load_Func evas_vg_load_svg_func =