PageRenderTime 1148ms CodeModel.GetById 433ms app.highlight 515ms RepoModel.GetById 177ms app.codeStats 0ms

/ext/gpac/applications/generators/SVG/v1.c

https://github.com/paulcbetts/yikes
C | 612 lines | 475 code | 63 blank | 74 comment | 107 complexity | 1afda8dd1b490c42c4cc1cd23e2bd87f MD5 | raw file
  1/*
  2 *			GPAC - Multimedia Framework C SDK
  3 *
  4 *			Copyright (c) Cyril Concolato 2004-2005
  5 *					All rights reserved
  6 *
  7 *  This file is part of GPAC / SVG Scene Graph Generator sub-project
  8 *
  9 *  GPAC is free software; you can redistribute it and/or modify
 10 *  it under the terms of the GNU Lesser General Public License as published by
 11 *  the Free Software Foundation; either version 2, or (at your option)
 12 *  any later version.
 13 *   
 14 *  GPAC is distributed in the hope that it will be useful,
 15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17 *  GNU Lesser General Public License for more details.
 18 *   
 19 *  You should have received a copy of the GNU Lesser General Public
 20 *  License along with this library; see the file COPYING.  If not, write to
 21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 22 *
 23 */
 24
 25#include "svggen.h"
 26
 27void generateNode(FILE *output, SVGGenElement* svg_elt) 
 28{
 29	fprintf(output, "typedef struct _tagSVG_SA_%sElement\n{\n", svg_elt->implementation_name);
 30
 31	if (svg_elt->has_transform) {
 32		fprintf(output, "\tTRANSFORMABLE_SVG_ELEMENT\n");
 33	} else {
 34		fprintf(output, "\tBASE_SVG_ELEMENT\n");
 35	}
 36
 37	if (!strcmp(svg_elt->implementation_name, "conditional")) {
 38		fprintf(output, "\tSVGCommandBuffer updates;\n");
 39	} 
 40
 41	generateAttributes(output, svg_elt->attributes, 0);
 42
 43	/*special case for handler node*/
 44	if (!strcmp(svg_elt->implementation_name, "handler")) {
 45		fprintf(output, "\tvoid (*handle_event)(GF_Node *hdl, GF_DOM_Event *event);\n");
 46	}
 47	fprintf(output, "} SVG_SA_%sElement;\n\n\n", svg_elt->implementation_name);
 48}
 49
 50
 51void generateAttributeInfo(FILE *output, char * elt_imp_name, SVGGenAttribute *att, u32 i)
 52{
 53	fprintf(output, "\t\tcase %d:\n", i);
 54	fprintf(output, "\t\t\tinfo->name = \"%s\";\n", att->svg_name);
 55	fprintf(output, "\t\t\tinfo->fieldType = %s_datatype;\n", att->impl_type);
 56	fprintf(output, "\t\t\tinfo->far_ptr = & ((SVG_SA_%sElement *)node)->%s;\n", elt_imp_name, att->implementation_name);
 57	fprintf(output, "\t\t\treturn GF_OK;\n");
 58}
 59
 60u32 generateCoreInfo(FILE *output, SVGGenElement *elt, u32 start)
 61{
 62	u32 i = start;
 63
 64	fprintf(output, "\t\tcase %d:\n", i);
 65	fprintf(output, "\t\t\tinfo->name = \"id\";\n");
 66	fprintf(output, "\t\t\tinfo->fieldType = SVG_ID_datatype;\n");
 67	fprintf(output, "\t\t\tinfo->far_ptr = gf_node_get_name_address(node);\n");
 68	fprintf(output, "\t\t\treturn GF_OK;\n");
 69	i++;
 70
 71	fprintf(output, "\t\tcase %d:\n", i);
 72	fprintf(output, "\t\t\tinfo->name = \"xml:id\";\n");
 73	fprintf(output, "\t\t\tinfo->fieldType = SVG_ID_datatype;\n");
 74	fprintf(output, "\t\t\tinfo->far_ptr = gf_node_get_name_address(node);\n");
 75	fprintf(output, "\t\t\treturn GF_OK;\n");
 76	i++;
 77
 78	fprintf(output, "\t\tcase %d:\n", i);
 79	fprintf(output, "\t\t\tinfo->name = \"class\";\n");
 80	fprintf(output, "\t\t\tinfo->fieldType = SVG_String_datatype;\n");
 81	fprintf(output, "\t\t\tinfo->far_ptr = &((SVG_SA_Element *)node)->core->_class;\n");
 82	fprintf(output, "\t\t\treturn GF_OK;\n");
 83	i++;
 84
 85	fprintf(output, "\t\tcase %d:\n", i);
 86	fprintf(output, "\t\t\tinfo->name = \"xml:lang\";\n");
 87	fprintf(output, "\t\t\tinfo->fieldType = SVG_LanguageID_datatype;\n");
 88	fprintf(output, "\t\t\tinfo->far_ptr = &((SVG_SA_Element *)node)->core->lang;\n");
 89	fprintf(output, "\t\t\treturn GF_OK;\n");
 90	i++;
 91
 92	fprintf(output, "\t\tcase %d:\n", i);
 93	fprintf(output, "\t\t\tinfo->name = \"xml:base\";\n");
 94	fprintf(output, "\t\t\tinfo->fieldType = SVG_String_datatype;\n");
 95	fprintf(output, "\t\t\tinfo->far_ptr = &((SVG_SA_Element *)node)->core->base;\n");
 96	fprintf(output, "\t\t\treturn GF_OK;\n");
 97	i++;
 98
 99	fprintf(output, "\t\tcase %d:\n", i);
100	fprintf(output, "\t\t\tinfo->name = \"xml:space\";\n");
101	fprintf(output, "\t\t\tinfo->fieldType = XML_Space_datatype;\n");
102	fprintf(output, "\t\t\tinfo->far_ptr = &((SVG_SA_Element *)node)->core->space;\n");
103	fprintf(output, "\t\t\treturn GF_OK;\n");
104	i++;
105
106	fprintf(output, "\t\tcase %d:\n", i);
107	fprintf(output, "\t\t\tinfo->name = \"externalResourcesRequired\";\n");
108	fprintf(output, "\t\t\tinfo->fieldType = SVG_Boolean_datatype;\n");
109	fprintf(output, "\t\t\tinfo->far_ptr = &((SVG_SA_Element *)node)->core->eRR;\n");
110	fprintf(output, "\t\t\treturn GF_OK;\n");
111	i++;
112
113	return i;
114}
115
116void generateAttributeInfoFlat(FILE *output, char *pointer, char *name, char *type, u32 i)
117{
118	fprintf(output, "\t\tcase %d:\n", i);
119	fprintf(output, "\t\t\tinfo->name = \"%s\";\n", name);
120	fprintf(output, "\t\t\tinfo->fieldType = %s_datatype;\n", type);
121	fprintf(output, "\t\t\tinfo->far_ptr = &%s;\n", pointer);
122	fprintf(output, "\t\t\treturn GF_OK;\n");
123}
124
125u32 generateTransformInfo(FILE *output, SVGGenElement *elt, u32 start)
126{
127	u32 i = start;
128
129	fprintf(output, "\t\tcase %d:\n", i);
130	fprintf(output, "\t\t\tinfo->name = \"transform\";\n");
131	fprintf(output, "\t\t\tinfo->fieldType = SVG_Transform_datatype;\n");
132	fprintf(output, "\t\t\tinfo->far_ptr = &((SVGTransformableElement *)node)->transform;\n");
133	fprintf(output, "\t\t\treturn GF_OK;\n");
134	i++;
135	return i;
136}
137
138u32 generateMotionTransformInfo(FILE *output, SVGGenElement *elt, u32 start)
139{
140	u32 i = start;
141
142	fprintf(output, "\t\tcase %d:\n", i);
143	fprintf(output, "\t\t\tinfo->name = \"motionTransform\";\n");
144	fprintf(output, "\t\t\tinfo->fieldType = SVG_Motion_datatype;\n");
145	fprintf(output, "\t\t\tinfo->far_ptr = ((SVGTransformableElement *)node)->motionTransform;\n");
146	fprintf(output, "\t\t\treturn GF_OK;\n");
147	i++;
148	return i;
149}
150
151u32 generateXYInfo(FILE *output, SVGGenElement *elt, u32 start)
152{
153	u32 i = start;
154
155	fprintf(output, "\t\tcase %d:\n", i);
156	fprintf(output, "\t\t\tinfo->name = \"x\";\n");
157	fprintf(output, "\t\t\tinfo->fieldType = SVG_Coordinate_datatype;\n");
158	fprintf(output, "\t\t\tinfo->far_ptr = &((SVGTransformableElement *)node)->xy.x;\n");
159	fprintf(output, "\t\t\treturn GF_OK;\n");
160	i++;
161
162	fprintf(output, "\t\tcase %d:\n", i);
163	fprintf(output, "\t\t\tinfo->name = \"y\";\n");
164	fprintf(output, "\t\t\tinfo->fieldType = SVG_Coordinate_datatype;\n");
165	fprintf(output, "\t\t\tinfo->far_ptr = &((SVGTransformableElement *)node)->xy.y;\n");
166	fprintf(output, "\t\t\treturn GF_OK;\n");
167	i++;
168	return i;
169}
170
171u32 generateGenericInfo(FILE *output, SVGGenElement *elt, u32 index, char *pointer_root, u32 start)
172{
173	u32 i = start;
174	int k;
175	for (k=0; k < generic_attributes[index].array_length; k++) {
176		char *att_name = generic_attributes[index].array[k];
177		SVGGenAttribute *a = findAttribute(elt, att_name);
178		if (a) {
179			char pointer[500];
180			if (strstr(att_name, "xlink:")) {
181				sprintf(pointer, "%s%s", pointer_root, att_name+6);
182			} else if (strstr(att_name, "xml:")) {
183				sprintf(pointer, "%s%s", pointer_root, att_name+4);
184			} else {
185				char imp_name[50];
186				svgNameToImplementationName(att_name, imp_name);
187				sprintf(pointer, "%s%s", pointer_root, imp_name);
188			}
189			generateAttributeInfoFlat(output, pointer, a->svg_name, a->impl_type, i);
190			i++;
191		}
192	}
193	return i;
194}
195
196u32 generateIndexInfo(FILE *output, SVGGenElement *elt, u32 index, u32 start)
197{
198	u32 i = start;
199	int k;
200	for (k=0; k < generic_attributes[index].array_length; k++) {
201		char *att_name = generic_attributes[index].array[k];
202		SVGGenAttribute *a = findAttribute(elt, att_name);
203		if (a) {
204			fprintf(output, "\tif(!strcmp(\"%s\", name)) return %d;\n", att_name, i); 
205			i++;
206		}
207	}
208	return i;
209}
210
211void generateNodeImpl(FILE *output, SVGGenElement* svg_elt) 
212{
213	u32 i;	
214
215	/***************************************************/	
216	/*				Constructor						   */
217	/***************************************************/	
218	fprintf(output, "void *gf_svg_new_%s()\n{\n\tSVG_SA_%sElement *p;\n", svg_elt->implementation_name,svg_elt->implementation_name);
219	fprintf(output, "\tGF_SAFEALLOC(p, SVG_SA_%sElement);\n\tif (!p) return NULL;\n\tgf_node_setup((GF_Node *)p, TAG_SVG_%s);\n\tgf_sg_parent_setup((GF_Node *) p);\n",svg_elt->implementation_name,svg_elt->implementation_name);
220	fprintf(output, "#ifdef GF_NODE_USE_POINTERS\n");
221	fprintf(output, "\t((GF_Node *p)->sgprivate->name = \"%s\";\n", svg_elt->implementation_name);
222	fprintf(output, "\t((GF_Node *p)->sgprivate->node_del = gf_svg_sa_%s_del;\n", svg_elt->implementation_name);
223	fprintf(output, "\t((GF_Node *p)->sgprivate->get_field = gf_svg_sa_%s_get_attribute;\n", svg_elt->implementation_name);
224	fprintf(output, "#endif\n");
225
226	fprintf(output, "\tgf_svg_sa_init_core((SVG_SA_Element *)p);\n");		
227	if (svg_elt->has_properties || 
228		svg_elt->has_media_properties || 
229		svg_elt->has_opacity_properties) {
230		fprintf(output, "\tgf_svg_sa_init_properties((SVG_SA_Element *)p);\n");		
231	} 
232	if (svg_elt->has_focus) {
233		fprintf(output, "\tgf_svg_sa_init_focus((SVG_SA_Element *)p);\n");		
234	} 
235	if (svg_elt->has_xlink) {
236		fprintf(output, "\tgf_svg_sa_init_xlink((SVG_SA_Element *)p);\n");		
237	} 
238	if (svg_elt->has_timing) {
239		fprintf(output, "\tgf_svg_sa_init_timing((SVG_SA_Element *)p);\n");		
240	} 
241	if (svg_elt->has_sync) {
242		fprintf(output, "\tgf_svg_sa_init_sync((SVG_SA_Element *)p);\n");		
243	}
244	if (svg_elt->has_animation){
245		fprintf(output, "\tgf_svg_sa_init_anim((SVG_SA_Element *)p);\n");		
246	} 
247	if (svg_elt->has_conditional) {
248		fprintf(output, "\tgf_svg_sa_init_conditional((SVG_SA_Element *)p);\n");		
249	} 
250
251	if (svg_elt->has_transform) {
252		fprintf(output, "\tgf_mx2d_init(p->transform.mat);\n");
253	} 
254
255	if (!strcmp(svg_elt->implementation_name, "conditional")) {
256		fprintf(output, "\tgf_svg_sa_init_lsr_conditional(&p->updates);\n");
257		fprintf(output, "\tgf_svg_sa_init_timing((SVG_SA_Element *)p);\n");		
258
259	} 
260
261	for (i = 0; i < gf_list_count(svg_elt->attributes); i++) {
262		SVGGenAttribute *att = gf_list_get(svg_elt->attributes, i);
263		/* Initialization of complex types */
264		if ( !strcmp("SVG_Points", att->impl_type) || 
265			 !strcmp("SVG_Coordinates", att->impl_type) ||
266			 !strcmp("SMIL_KeyPoints", att->impl_type)) {
267			fprintf(output, "\tp->%s = gf_list_new();\n", att->implementation_name);
268		} else if (!strcmp("SVG_PathData", att->impl_type) && !strcmp(svg_elt->svg_name, "animateMotion")) {
269			fprintf(output, "#ifdef USE_GF_PATH\n");
270			fprintf(output, "\tgf_path_reset(&p->path);\n");
271			fprintf(output, "#else\n");
272			fprintf(output, "\tp->path.commands = gf_list_new();\n");
273			fprintf(output, "\tp->path.points = gf_list_new();\n");
274			fprintf(output, "#endif\n");
275		} else if (!strcmp("SVG_PathData", att->impl_type)) {
276			fprintf(output, "#ifdef USE_GF_PATH\n");
277			fprintf(output, "\tgf_path_reset(&p->d);\n");
278			fprintf(output, "#else\n");
279			fprintf(output, "\tp->d.commands = gf_list_new();\n");
280			fprintf(output, "\tp->d.points = gf_list_new();\n");
281			fprintf(output, "#endif\n");
282		} else if (!strcmp(att->svg_name, "lsr:enabled")) {
283			fprintf(output, "\tp->lsr_enabled = 1;\n");
284		} 
285	}
286	/*some default values*/
287	if (!strcmp(svg_elt->svg_name, "svg")) {
288		fprintf(output, "\tp->width.type = SVG_NUMBER_PERCENTAGE;\n");
289		fprintf(output, "\tp->width.value = INT2FIX(100);\n");
290		fprintf(output, "\tp->height.type = SVG_NUMBER_PERCENTAGE;\n");
291		fprintf(output, "\tp->height.value = INT2FIX(100);\n");
292	}
293	else if (!strcmp(svg_elt->svg_name, "solidColor")) {
294		fprintf(output, "\tp->properties->solid_opacity.value = FIX_ONE;\n");
295	}
296	else if (!strcmp(svg_elt->svg_name, "stop")) {
297		fprintf(output, "\tp->properties->stop_opacity.value = FIX_ONE;\n");
298	}
299	else if (!strcmp(svg_elt->svg_name, "linearGradient")) {
300		fprintf(output, "\tp->x2.value = FIX_ONE;\n");
301		fprintf(output, "\tgf_mx2d_init(p->gradientTransform.mat);\n");
302	}
303	else if (!strcmp(svg_elt->svg_name, "radialGradient")) {
304		fprintf(output, "\tp->cx.value = FIX_ONE/2;\n");
305		fprintf(output, "\tp->cy.value = FIX_ONE/2;\n");
306		fprintf(output, "\tp->r.value = FIX_ONE/2;\n");
307		fprintf(output, "\tgf_mx2d_init(p->gradientTransform.mat);\n");
308		fprintf(output, "\tp->fx.value = FIX_ONE/2;\n");
309		fprintf(output, "\tp->fy.value = FIX_ONE/2;\n");
310	}
311	else if (!strcmp(svg_elt->svg_name, "video") || !strcmp(svg_elt->svg_name, "audio") || !strcmp(svg_elt->svg_name, "animation")) {
312		fprintf(output, "\tp->timing->dur.type = SMIL_DURATION_MEDIA;\n");
313	}
314	fprintf(output, "\treturn p;\n}\n\n");
315
316	/***************************************************/	
317	/*                     Destructor                  */
318	/***************************************************/	
319	fprintf(output, "static void gf_svg_sa_%s_del(GF_Node *node)\n{\n", svg_elt->implementation_name);
320	fprintf(output, "\tSVG_SA_%sElement *p = (SVG_SA_%sElement *)node;\n", svg_elt->implementation_name, svg_elt->implementation_name);
321
322	fprintf(output, "\tgf_svg_sa_reset_base_element((SVG_SA_Element *)p);\n");
323
324	if (!strcmp(svg_elt->implementation_name, "conditional")) {
325		fprintf(output, "\tgf_svg_sa_reset_lsr_conditional(&p->updates);\n");
326	} 
327	else if (!strcmp(svg_elt->implementation_name, "a")) {
328		fprintf(output, "\tif (p->target) free(p->target);\n");
329	} 
330
331	for (i = 0; i < gf_list_count(svg_elt->attributes); i++) {
332		SVGGenAttribute *att = gf_list_get(svg_elt->attributes, i);
333		if (!strcmp("SMIL_KeyPoints", att->impl_type)) {
334			fprintf(output, "\tgf_smil_delete_key_types(p->%s);\n", att->implementation_name);
335		} else if (!strcmp("SVG_Coordinates", att->impl_type)) {
336			fprintf(output, "\tgf_svg_delete_coordinates(p->%s);\n", att->implementation_name);
337		} else if (!strcmp("SVG_Points", att->impl_type)) {
338			fprintf(output, "\tgf_svg_delete_points(p->%s);\n", att->implementation_name);
339		} else if (!strcmp("SVG_PathData", att->impl_type)) {
340			if (!strcmp(svg_elt->svg_name, "animateMotion")) {
341				fprintf(output, "\tgf_svg_reset_path(p->path);\n");
342			} else {
343				fprintf(output, "\tgf_svg_reset_path(p->d);\n");
344			}
345		} else if (!strcmp("XMLRI", att->impl_type)) {
346			fprintf(output, "\tgf_svg_reset_iri(node->sgprivate->scenegraph, &p->%s);\n", att->implementation_name);
347		} else if (!strcmp("SVG_FontFamily", att->impl_type)) {
348			fprintf(output, "\tif (p->%s.value) free(p->%s.value);\n", att->implementation_name, att->implementation_name);
349		} else if (!strcmp("SVG_String", att->impl_type) || !strcmp("SVG_ContentType", att->impl_type)) {
350			fprintf(output, "\tfree(p->%s);\n", att->implementation_name);
351		}
352	}
353	if (svg_elt->has_transform) {
354		fprintf(output, "\tif (p->motionTransform) free(p->motionTransform);\n");
355	} 
356
357	fprintf(output, "\tgf_sg_parent_reset((GF_Node *) p);\n");
358	fprintf(output, "\tgf_node_free((GF_Node *)p);\n");
359	fprintf(output, "}\n\n");
360	
361	/***************************************************/	
362	/*				Attribute Access				   */
363	/***************************************************/	
364	fprintf(output, "static GF_Err gf_svg_sa_%s_get_attribute(GF_Node *node, GF_FieldInfo *info)\n{\n", svg_elt->implementation_name);
365	fprintf(output, "\tswitch (info->fieldIndex) {\n");
366	svg_elt->nb_atts = 0;
367	svg_elt->nb_atts = generateCoreInfo(output, svg_elt, svg_elt->nb_atts);
368
369	if (svg_elt->has_media_properties) 
370		svg_elt->nb_atts = generateGenericInfo(output, svg_elt, 2, "((SVG_SA_Element *)node)->properties->", svg_elt->nb_atts);
371	if (svg_elt->has_properties) 
372		svg_elt->nb_atts = generateGenericInfo(output, svg_elt, 1, "((SVG_SA_Element *)node)->properties->", svg_elt->nb_atts);
373	if (svg_elt->has_opacity_properties) 
374		svg_elt->nb_atts = generateGenericInfo(output, svg_elt, 3, "((SVG_SA_Element *)node)->properties->", svg_elt->nb_atts);
375	if (svg_elt->has_focus) 
376		svg_elt->nb_atts = generateGenericInfo(output, svg_elt, 4, "((SVG_SA_Element *)node)->focus->", svg_elt->nb_atts);
377	if (svg_elt->has_xlink) 
378		svg_elt->nb_atts = generateGenericInfo(output, svg_elt, 5, "((SVG_SA_Element *)node)->xlink->", svg_elt->nb_atts);
379	if (svg_elt->has_timing) 
380		svg_elt->nb_atts = generateGenericInfo(output, svg_elt, 6, "((SVG_SA_Element *)node)->timing->", svg_elt->nb_atts);
381	if (svg_elt->has_sync) 
382		svg_elt->nb_atts = generateGenericInfo(output, svg_elt, 7, "((SVG_SA_Element *)node)->sync->", svg_elt->nb_atts);
383	if (svg_elt->has_animation) 
384		svg_elt->nb_atts = generateGenericInfo(output, svg_elt, 8, "((SVG_SA_Element *)node)->anim->", svg_elt->nb_atts);
385	if (svg_elt->has_conditional) 
386		svg_elt->nb_atts = generateGenericInfo(output, svg_elt, 9, "((SVG_SA_Element *)node)->conditional->", svg_elt->nb_atts);
387	if (svg_elt->has_transform) {
388		svg_elt->nb_atts = generateTransformInfo(output, svg_elt, svg_elt->nb_atts);
389		svg_elt->nb_atts = generateMotionTransformInfo(output, svg_elt, svg_elt->nb_atts);
390	}
391	if (svg_elt->has_xy) 
392		svg_elt->nb_atts = generateXYInfo(output, svg_elt, svg_elt->nb_atts);
393
394	for (i = 0; i < gf_list_count(svg_elt->attributes); i++) {
395		SVGGenAttribute *att = gf_list_get(svg_elt->attributes, i);
396		generateAttributeInfo(output, svg_elt->implementation_name, att, svg_elt->nb_atts++);
397	}
398	fprintf(output, "\t\tdefault: return GF_BAD_PARAM;\n\t}\n}\n\n");
399
400	/***************************************************/	
401	/*	gf_svg_sa_%s_get_attribute_index_from_name		   */
402	/***************************************************/	
403	fprintf(output, "s32 gf_svg_sa_%s_get_attribute_index_from_name(char *name)\n{\n", svg_elt->implementation_name);
404	{
405		u32 att_index = 0;
406		fprintf(output, "\tif(!strcmp(\"id\", name)) return %d;\n", att_index); 
407		att_index++;
408		fprintf(output, "\tif(!strcmp(\"xml:id\", name)) return %d;\n", att_index); 
409		att_index++;
410		fprintf(output, "\tif(!strcmp(\"class\", name)) return %d;\n", att_index); 
411		att_index++;
412		fprintf(output, "\tif(!strcmp(\"xml:lang\", name)) return %d;\n", att_index); 
413		att_index++;
414		fprintf(output, "\tif(!strcmp(\"xml:base\", name)) return %d;\n", att_index); 
415		att_index++;
416		fprintf(output, "\tif(!strcmp(\"xml:space\", name)) return %d;\n", att_index); 
417		att_index++;
418		fprintf(output, "\tif(!strcmp(\"externalResourcesRequired\", name)) return %d;\n", att_index); 
419		att_index++;
420		if (svg_elt->has_media_properties) 
421			att_index = generateIndexInfo(output, svg_elt, 2, att_index);
422		if (svg_elt->has_properties) 
423			att_index = generateIndexInfo(output, svg_elt, 1, att_index);
424		if (svg_elt->has_opacity_properties) 
425			att_index = generateIndexInfo(output, svg_elt, 3, att_index);
426		if (svg_elt->has_focus) 
427			att_index = generateIndexInfo(output, svg_elt, 4, att_index);
428		if (svg_elt->has_xlink) 
429			att_index = generateIndexInfo(output, svg_elt, 5, att_index);
430		if (svg_elt->has_timing) 
431			att_index = generateIndexInfo(output, svg_elt, 6, att_index);
432		if (svg_elt->has_sync) 
433			att_index = generateIndexInfo(output, svg_elt, 7, att_index);
434		if (svg_elt->has_animation) 
435			att_index = generateIndexInfo(output, svg_elt, 8, att_index);
436		if (svg_elt->has_conditional) 
437			att_index = generateIndexInfo(output, svg_elt, 9, att_index);
438		if (svg_elt->has_transform) {
439			fprintf(output, "\tif(!strcmp(\"transform\", name)) return %d;\n", att_index); 
440			att_index++;
441			/*motionTransform*/
442			fprintf(output, "\tif(!strcmp(\"motionTransform\", name)) return %d;\n", att_index); 
443			att_index++;
444		}
445		if (svg_elt->has_xy) {
446			fprintf(output, "\tif(!strcmp(\"x\", name)) return %d;\n", att_index); 
447			att_index++;
448			fprintf(output, "\tif(!strcmp(\"y\", name)) return %d;\n", att_index); 
449			att_index++;
450		}
451
452		for (i = 0; i < gf_list_count(svg_elt->attributes); i++) {
453			SVGGenAttribute *att = gf_list_get(svg_elt->attributes, i);
454			fprintf(output, "\tif(!strcmp(\"%s\", name)) return %d;\n", att->svg_name, att_index); 
455			att_index++;
456		}
457	}
458	fprintf(output, "\treturn -1;\n}\n\n");
459}
460
461void generateSVGCode_V1(GF_List *svg_elements) 
462{
463	FILE *output;
464	u32 i;
465
466	/***************************************************/	
467	/***************************************************/	
468	/*************** Creating .h file ******************/	
469	/***************************************************/	
470	/***************************************************/	
471	output = BeginFile(0);
472	fprintf(output, "#include <gpac/scenegraph_svg.h>\n\n\n");
473	fprintf(output, "/* Definition of SVG element internal tags */\n");
474	fprintf(output, "/* TAG names are made of \"TAG_SVG\" + SVG element name (with - replaced by _) */\n");
475
476	/* write all tags */
477	fprintf(output, "enum {\n");
478	for (i=0; i<gf_list_count(svg_elements); i++) {
479		SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
480		if (i == 0) {
481			fprintf(output, "\tTAG_SVG_%s = GF_NODE_RANGE_FIRST_SVG_SA", elt->implementation_name);
482		} else {
483			fprintf(output, ",\n\tTAG_SVG_%s", elt->implementation_name);
484		}
485	}
486	
487	fprintf(output, ",\n\t/*undefined elements (when parsing) use this tag*/\n\tTAG_SVG_UndefinedElement\n};\n\n");
488	
489	fprintf(output, "/******************************************\n");
490 	fprintf(output, "*   SVG Elements structure definitions    *\n");
491 	fprintf(output, "*******************************************/\n");
492	for (i=0; i<gf_list_count(svg_elements); i++) {
493		SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
494		generateNode(output, elt);
495	}
496	fprintf(output, "/******************************************\n");
497 	fprintf(output, "*  End SVG Elements structure definitions *\n");
498 	fprintf(output, "*******************************************/\n");
499	EndFile(output, 0);
500
501	/***************************************************/	
502	/***************************************************/	
503	/*************** Creating .c file ******************/	
504	/***************************************************/	
505	/***************************************************/	
506	output = BeginFile(1);
507	fprintf(output, "#include <gpac/nodes_svg_sa.h>\n\n");
508	
509	fprintf(output, "#ifndef GPAC_DISABLE_SVG\n\n");
510	fprintf(output, "#include <gpac/internal/scenegraph_dev.h>\n\n");
511	fprintf(output, "#ifdef GPAC_ENABLE_SVG_SA\n\n");
512	for (i=0; i<gf_list_count(svg_elements); i++) {
513		SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
514		generateNodeImpl(output, elt);
515	}
516
517	/***************************************************/	
518	/* SVG_SA_Element *gf_svg_sa_create_node(u32 ElementTag)  */
519	/***************************************************/	
520	fprintf(output, "SVG_SA_Element *gf_svg_sa_create_node(u32 ElementTag)\n");
521	fprintf(output, "{\n");
522	fprintf(output, "\tswitch (ElementTag) {\n");
523	for (i=0; i<gf_list_count(svg_elements); i++) {
524		SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
525		fprintf(output, "\t\tcase TAG_SVG_%s: return (SVG_SA_Element*) gf_svg_new_%s();\n",elt->implementation_name,elt->implementation_name);
526	}
527	fprintf(output, "\t\tdefault: return NULL;\n\t}\n}\n\n");
528	
529	/***************************************************/	
530	/* void gf_svg_sa_element_del(SVG_SA_Element *elt)        */
531	/***************************************************/	
532	fprintf(output, "void gf_svg_sa_element_del(SVG_SA_Element *elt)\n{\n");
533	fprintf(output, "\tGF_Node *node = (GF_Node *)elt;\n");
534	fprintf(output, "\tswitch (node->sgprivate->tag) {\n");
535	for (i=0; i<gf_list_count(svg_elements); i++) {
536		SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
537		fprintf(output, "\t\tcase TAG_SVG_%s: gf_svg_sa_%s_del(node); return;\n", elt->implementation_name, elt->implementation_name);
538	}
539	fprintf(output, "\t\tdefault: return;\n\t}\n}\n\n");
540
541	/***************************************************/	
542	/* u32 gf_svg_sa_get_attribute_count(SVG_SA_Element *elt) */
543	/***************************************************/	
544	fprintf(output, "u32 gf_svg_sa_get_attribute_count(GF_Node *node)\n{\n");
545	fprintf(output, "\tswitch (node->sgprivate->tag) {\n");
546	for (i=0; i<gf_list_count(svg_elements); i++) {
547		SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
548		fprintf(output, "\t\tcase TAG_SVG_%s: return %i;\n", elt->implementation_name, elt->nb_atts);
549	}
550	fprintf(output, "\t\tdefault: return 0;\n\t}\n}\n\n");
551	
552	/***********************************************************************/	
553	/* GF_Err gf_svg_sa_get_attribute_info(GF_Node *node, GF_FieldInfo *info) */
554	/***********************************************************************/	
555	fprintf(output, "GF_Err gf_svg_sa_get_attribute_info(GF_Node *node, GF_FieldInfo *info)\n{\n");
556	fprintf(output, "\tswitch (node->sgprivate->tag) {\n");
557	for (i=0; i<gf_list_count(svg_elements); i++) {
558		SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
559		fprintf(output, "\t\tcase TAG_SVG_%s: return gf_svg_sa_%s_get_attribute(node, info);\n", elt->implementation_name, elt->implementation_name);
560	}
561	fprintf(output, "\t\tdefault: return GF_BAD_PARAM;\n\t}\n}\n\n");
562
563	/****************************************************************/	
564	/* u32 gf_svg_sa_node_type_by_class_name(const char *element_name) */
565	/****************************************************************/	
566	fprintf(output, "u32 gf_svg_sa_node_type_by_class_name(const char *element_name)\n{\n\tif (!element_name) return TAG_UndefinedNode;\n");
567	for (i=0; i<gf_list_count(svg_elements); i++) {
568		SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
569		fprintf(output, "\tif (!stricmp(element_name, \"%s\")) return TAG_SVG_%s;\n", elt->svg_name, elt->implementation_name);
570	}
571	fprintf(output, "\treturn TAG_UndefinedNode;\n}\n\n");
572
573
574	/***************************************************/	
575	/* const char *gf_svg_sa_get_element_name(u32 tag) */
576	/***************************************************/	
577	fprintf(output, "const char *gf_svg_sa_get_element_name(u32 tag)\n{\n\tswitch(tag) {\n");
578	for (i=0; i<gf_list_count(svg_elements); i++) {
579		SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
580		fprintf(output, "\tcase TAG_SVG_%s: return \"%s\";\n", elt->implementation_name, elt->svg_name);
581	}
582	fprintf(output, "\tdefault: return \"UndefinedNode\";\n\t}\n}\n\n");
583
584	/***************************************************/	
585	/* const char *gf_svg_sa_get_attribute_index_by_name(u32 tag) */
586	/***************************************************/	
587	fprintf(output, "s32 gf_svg_sa_get_attribute_index_by_name(GF_Node *node, char *name)\n{\n\tswitch(node->sgprivate->tag) {\n");
588	for (i=0; i<gf_list_count(svg_elements); i++) {
589		SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
590		fprintf(output, "\tcase TAG_SVG_%s: return gf_svg_sa_%s_get_attribute_index_from_name(name);\n", elt->implementation_name, elt->implementation_name);
591	}
592	fprintf(output, "\tdefault: return -1;\n\t}\n}\n\n");
593
594	/***************************************************/	
595	/* Bool gf_svg_is_element_transformable(u32 tag) */
596	/***************************************************/	
597	fprintf(output, "Bool gf_svg_is_element_transformable(u32 tag)\n{\n\tswitch(tag) {\n");
598	for (i=0; i<gf_list_count(svg_elements); i++) {
599		SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
600		fprintf(output, "\tcase TAG_SVG_%s:", elt->implementation_name);
601		if (elt->has_transform) fprintf(output, "return 1;\n");
602		else fprintf(output, "return 0;\n");
603	}
604	fprintf(output, "\tdefault: return 0;\n\t}\n}\n");
605
606	fprintf(output, "#endif /*GPAC_ENABLE_SVG_SA*/\n");
607	fprintf(output, "#endif /*GPAC_DISABLE_SVG*/\n\n");
608	EndFile(output, 1); 
609
610	generate_laser_tables(svg_elements);
611}
612