/* * GPAC - Multimedia Framework C SDK * * Authors: Cyril Concolato * Copyright (c) Telecom ParisTech 2004-2012 * All rights reserved * * This file is part of GPAC / SVG Scene Graph Generator sub-project * * GPAC is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * GPAC is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include "svggen.h" void buildGlobalAttributeList(GF_List *svg_elements, GF_List *all_atts) { u32 i, j, k; Bool added = 0; for (i=0; igeneric_attributes); j++) { SVGGenAttribute *att = gf_list_get(elt->generic_attributes, j); added = 0; if (!strcmp(att->impl_type, "SMIL_Fill")) { strcpy(att->implementation_name, "smil_fill"); } else if (!strcmp(att->impl_type, "SVG_TransformType")) { strcpy(att->implementation_name, "transform_type"); } for (k = 0; k < gf_list_count(all_atts); k++) { SVGGenAttribute *a = gf_list_get(all_atts, k); if (!strcmp(a->implementation_name, att->implementation_name) && !strcmp(a->impl_type, att->impl_type)) { added = 1; break; } } if (!added) { gf_list_add(all_atts, att); } } for (j = 0; j < gf_list_count(elt->attributes); j++) { SVGGenAttribute *att = gf_list_get(elt->attributes, j); added = 0; if (!strcmp(elt->svg_name, "text")) { if (!strcmp(att->implementation_name, "x")) { strcpy(att->implementation_name, "text_x"); } else if (!strcmp(att->implementation_name, "y")) { strcpy(att->implementation_name, "text_y"); } else if (!strcmp(att->implementation_name, "rotate")) { strcpy(att->implementation_name, "text_rotate"); } } else if (!strcmp(elt->svg_name, "listener") && !strcmp(att->implementation_name, "target")) { strcpy(att->implementation_name, "listener_target"); } else if (!strcmp(elt->svg_name, "a") && !strcmp(att->implementation_name, "target")) { strcpy(att->impl_type, "SVG_String"); } else if (!strcmp(elt->svg_name, "cursorManager")) { if (!strcmp(att->implementation_name, "x")) { strcpy(att->implementation_name, "cursorManager_x"); } else if (!strcmp(att->implementation_name, "y")) { strcpy(att->implementation_name, "cursorManager_y"); } } for (k = 0; k < gf_list_count(all_atts); k++) { SVGGenAttribute *a = gf_list_get(all_atts, k); if (!strcmp(a->implementation_name, att->implementation_name) && !strcmp(a->impl_type, att->impl_type)) { added = 1; break; } } if (!added) { gf_list_add(all_atts, att); } } } /*motionTransform is not parsed in rng*/ { SVGGenAttribute *att = NewSVGGenAttribute(); strcpy(att->implementation_name, "motionTransform"); strcpy(att->impl_type, "SVG_Motion"); att->svg_name = "motionTransform"; att->svg_type = "SVG_Motion"; gf_list_add(all_atts, att); } } void generateSVGCode_V3(GF_List *svg_elements) { FILE *output; u32 i; GF_List *all_atts = gf_list_new(); buildGlobalAttributeList(svg_elements, all_atts); /***************************************************/ /***************************************************/ /*************** Creating .h file ******************/ /***************************************************/ /***************************************************/ output = BeginFile(0); fprintf(output, "#include \n\n\n"); /* Generation of ELEMENT tags */ fprintf(output, "/* Definition of SVG 3 Alternate element internal tags */\n"); fprintf(output, "/* TAG names are made of \"TAG_SVG\" + SVG element name (with - replaced by _) */\n"); fprintf(output, "enum {\n"); for (i=0; iimplementation_name); } else { fprintf(output, ",\n\tTAG_SVG_%s", elt->implementation_name); } } fprintf(output, ",\n\t/*undefined elements (when parsing) use this tag*/\n\tTAG_SVG_UndefinedElement\n};\n\n"); /* Generation of ATTRIBUTE tags */ fprintf(output, "/* Definition of SVG 3 attribute internal tags - %d defined */\n", gf_list_count(all_atts)); fprintf(output, "/* TAG names are made of \"TAG_SVG_ATT_\" + SVG attribute name (with - replaced by _) */\n"); fprintf(output, "enum {\n"); for (i=0; iimplementation_name); else fprintf(output, "\tTAG_SVG_ATT_%s = TAG_SVG_ATT_RANGE_FIRST,\n", att->implementation_name); } fprintf(output, "\t/*undefined attributes (when parsing) use this tag*/\n\tTAG_SVG_ATT_Unknown\n};\n\n"); /* Generation of the flatten structure pointing to all possible attributes in SVG */ fprintf(output, "struct _all_atts {\n"); for (i=0; iimpl_type, att->implementation_name); } fprintf(output, "};\n"); EndFile(output, 0); /***************************************************/ /***************************************************/ /*************** Creating .c file ******************/ /***************************************************/ /***************************************************/ output = BeginFile(1); fprintf(output, "#ifndef GPAC_DISABLE_SVG\n\n"); fprintf(output, "#include \n\n"); fprintf(output, "#include \n\n"); /****************************************************************/ /* u32 gf_svg_get_attribute_tag(u32 element_tag, const char *attribute_name) */ /****************************************************************/ fprintf(output, "u32 gf_svg_get_attribute_tag(u32 element_tag, const char *attribute_name)\n{\n\tif (!attribute_name) return TAG_SVG_ATT_Unknown;\n"); for (i=0; iimpl_type, "SMIL_Fill")) continue; if (!strcmp(att->impl_type, "SVG_ContentType")) continue; if (!strcmp(att->implementation_name, "text_x")) continue; if (!strcmp(att->implementation_name, "text_y")) continue; if (!strcmp(att->implementation_name, "text_rotate")) continue; if (!strcmp(att->implementation_name, "cursorManager_x")) continue; if (!strcmp(att->implementation_name, "cursorManager_y")) continue; if (!strcmp(att->svg_name, "x") || !strcmp(att->svg_name, "y")) { fprintf(output, "\tif (!stricmp(attribute_name, \"%s\")) {\n", att->svg_name); fprintf(output, "\t\tif (element_tag == TAG_SVG_text) return TAG_SVG_ATT_text_%s;\n", att->implementation_name); fprintf(output, "\t\telse if (element_tag == TAG_SVG_cursorManager) return TAG_SVG_ATT_cursorManager_%s;\n", att->implementation_name); fprintf(output, "\t\telse return TAG_SVG_ATT_%s;\n", att->implementation_name); fprintf(output, "\t}\n"); } else if (!strcmp(att->svg_name, "rotate")) { fprintf(output, "\tif (!stricmp(attribute_name, \"%s\")) {\n", att->svg_name); fprintf(output, "\t\tif (element_tag == TAG_SVG_text) return TAG_SVG_ATT_text_%s;\n", att->implementation_name); fprintf(output, "\t\telse return TAG_SVG_ATT_%s;\n", att->implementation_name); fprintf(output, "\t}\n"); } else if (!strcmp(att->svg_name, "type")) { fprintf(output, "\tif (!stricmp(attribute_name, \"%s\")) {\n", att->svg_name); fprintf(output, "\t\tif (element_tag == TAG_SVG_animateTransform) return TAG_SVG_ATT_transform_type;\n"); fprintf(output, "\t\telse return TAG_SVG_ATT_%s;\n", att->implementation_name); fprintf(output, "\t}\n"); } else if (!strcmp(att->svg_name, "fill")) { fprintf(output, "\tif (!stricmp(attribute_name, \"%s\")) {\n", att->svg_name); fprintf(output, "\t\tif (element_tag == TAG_SVG_animate || element_tag == TAG_SVG_animateColor || element_tag == TAG_SVG_animateMotion || element_tag == TAG_SVG_animateTransform || element_tag == TAG_SVG_animation || element_tag == TAG_SVG_audio || element_tag == TAG_SVG_video || element_tag == TAG_SVG_set) return TAG_SVG_ATT_smil_fill;\n"); fprintf(output, "\t\telse return TAG_SVG_ATT_%s;\n", att->implementation_name); fprintf(output, "\t}\n"); } else { fprintf(output, "\tif (!stricmp(attribute_name, \"%s\")) return TAG_SVG_ATT_%s;\n", att->svg_name, att->implementation_name); } } fprintf(output, "\treturn TAG_SVG_ATT_Unknown;\n}\n\n"); /****************************************************************/ /* u32 gf_svg_get_attribute_type(u32 tag) */ /****************************************************************/ fprintf(output, "u32 gf_svg_get_attribute_type(u32 tag)\n{\n"); fprintf(output, "\tswitch(tag) {\n"); for (i=0; iimplementation_name, att->impl_type); } fprintf(output, "\t\tdefault: return SVG_Unknown_datatype;\n"); fprintf(output, "\t}\n"); fprintf(output, "\treturn TAG_SVG_ATT_Unknown;\n}\n\n"); /****************************************************************/ /* const char* gf_svg_get_attribute_name(u32 tag) */ /****************************************************************/ fprintf(output, "const char*gf_svg_get_attribute_name(u32 tag)\n{\n"); fprintf(output, "\tswitch(tag) {\n"); for (i=0; iimplementation_name, att->svg_name); } fprintf(output, "\t\tdefault: return \"unknown\";\n"); fprintf(output, "\t}\n"); fprintf(output, "}\n\n"); /***************************************************/ /* SVGAttribute *gf_svg_create_attribute(GF_Node *node, u32 tag) */ /***************************************************/ fprintf(output, "SVGAttribute *gf_svg_create_attribute(GF_Node *node, u32 tag)\n{\n\tswitch(tag) {\n"); for (i=0; iimplementation_name, att->impl_type); } fprintf(output, "\tdefault: return NULL;\n\t}\n}\n\n"); /****************************************************************/ /* void gf_svg_flatten_attributes(SVG_Element *e, SVGAllAttributes *all_atts) */ /****************************************************************/ fprintf(output, "void gf_svg_flatten_attributes(SVG_Element *e, SVGAllAttributes *all_atts)\n"); fprintf(output, "{\n"); fprintf(output, "\tSVGAttribute *att;\n"); fprintf(output, "\tmemset(all_atts, 0, sizeof(SVGAllAttributes));\n"); fprintf(output, "\tif (e->sgprivate->tag <= GF_NODE_FIRST_DOM_NODE_TAG) return;\n"); fprintf(output, "\tatt = e->attributes;\n"); fprintf(output, "\twhile (att) {\n"); fprintf(output, "\t\tswitch(att->tag) {\n"); for (i=0; i%s = (%s *)att->data; break;\n", att->implementation_name, att->implementation_name, att->impl_type); } fprintf(output, "\t\t}\n"); fprintf(output, "\tatt = att->next;\n"); fprintf(output, "\t}\n"); fprintf(output, "}\n"); fprintf(output, "\n"); /****************************************************************/ /* u32 gf_svg_get_element_tag(const char *element_name) */ /****************************************************************/ fprintf(output, "u32 gf_svg_get_element_tag(const char *element_name)\n{\n\tif (!element_name) return TAG_UndefinedNode;\n"); for (i=0; isvg_name, elt->implementation_name); } fprintf(output, "\treturn TAG_UndefinedNode;\n}\n\n"); /***************************************************/ /* const char *gf_svg_get_element_name(u32 tag) */ /***************************************************/ fprintf(output, "const char *gf_svg_get_element_name(u32 tag)\n{\n\tswitch(tag) {\n"); for (i=0; iimplementation_name, elt->svg_name); } fprintf(output, "\tdefault: return \"TAG_SVG_UndefinedNode\";\n\t}\n}\n\n"); fprintf(output, "#endif /*GPAC_DISABLE_SVG*/\n\n"); EndFile(output, 1); generate_laser_tables_da(all_atts); gf_list_del(all_atts); }