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