PageRenderTime 119ms CodeModel.GetById 20ms app.highlight 71ms RepoModel.GetById 19ms app.codeStats 1ms

/applications/generators/SVG/v1.c

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