PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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