This source file includes following definitions.
- buildGlobalAttributeList
- generateSVGCode_V3
#include "svggen.h"
void buildGlobalAttributeList(GF_List *svg_elements, GF_List *all_atts)
{
u32 i, j, k;
Bool added = 0;
for (i=0; i<gf_list_count(svg_elements); i++) {
SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
for (j = 0; j < gf_list_count(elt->generic_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);
}
}
}
{
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);
output = BeginFile(0);
fprintf(output, "#include <gpac/scenegraph_svg.h>\n\n\n");
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; i<gf_list_count(svg_elements); i++) {
SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
if (i == 0) {
fprintf(output, "\tTAG_SVG_%s = GF_NODE_RANGE_FIRST_SVG", elt->implementation_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");
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; i<gf_list_count(all_atts); i++) {
SVGGenAttribute *att = (SVGGenAttribute *)gf_list_get(all_atts, i);
if (i) fprintf(output, "\tTAG_SVG_ATT_%s,\n", att->implementation_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");
fprintf(output, "struct _all_atts {\n");
for (i=0; i<gf_list_count(all_atts); i++) {
SVGGenAttribute *att = (SVGGenAttribute *)gf_list_get(all_atts, i);
fprintf(output, "\t%s *%s;\n", att->impl_type, att->implementation_name);
}
fprintf(output, "};\n");
EndFile(output, 0);
output = BeginFile(1);
fprintf(output, "#ifndef GPAC_DISABLE_SVG\n\n");
fprintf(output, "#include <gpac/internal/scenegraph_dev.h>\n\n");
fprintf(output, "#include <gpac/nodes_svg_da.h>\n\n");
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; i<gf_list_count(all_atts); i++) {
SVGGenAttribute *att = (SVGGenAttribute *)gf_list_get(all_atts, i);
if (!strcmp(att->impl_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");
fprintf(output, "u32 gf_svg_get_attribute_type(u32 tag)\n{\n");
fprintf(output, "\tswitch(tag) {\n");
for (i=0; i<gf_list_count(all_atts); i++) {
SVGGenAttribute *att = (SVGGenAttribute *)gf_list_get(all_atts, i);
fprintf(output, "\t\tcase TAG_SVG_ATT_%s: return %s_datatype;\n", att->implementation_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");
fprintf(output, "const char*gf_svg_get_attribute_name(u32 tag)\n{\n");
fprintf(output, "\tswitch(tag) {\n");
for (i=0; i<gf_list_count(all_atts); i++) {
SVGGenAttribute *att = (SVGGenAttribute *)gf_list_get(all_atts, i);
fprintf(output, "\t\tcase TAG_SVG_ATT_%s: return \"%s\";\n", att->implementation_name, att->svg_name);
}
fprintf(output, "\t\tdefault: return \"unknown\";\n");
fprintf(output, "\t}\n");
fprintf(output, "}\n\n");
fprintf(output, "SVGAttribute *gf_svg_create_attribute(GF_Node *node, u32 tag)\n{\n\tswitch(tag) {\n");
for (i=0; i<gf_list_count(all_atts); i++) {
SVGGenAttribute *att = (SVGGenAttribute *)gf_list_get(all_atts, i);
fprintf(output, "\tcase TAG_SVG_ATT_%s: return gf_svg_create_attribute_from_datatype(%s_datatype, tag);\n", att->implementation_name, att->impl_type);
}
fprintf(output, "\tdefault: return NULL;\n\t}\n}\n\n");
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<gf_list_count(all_atts); i++) {
SVGGenAttribute *att = (SVGGenAttribute *)gf_list_get(all_atts, i);
fprintf(output, "\t\tcase TAG_SVG_ATT_%s: all_atts->%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");
fprintf(output, "u32 gf_svg_get_element_tag(const char *element_name)\n{\n\tif (!element_name) return TAG_UndefinedNode;\n");
for (i=0; i<gf_list_count(svg_elements); i++) {
SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
fprintf(output, "\tif (!stricmp(element_name, \"%s\")) return TAG_SVG_%s;\n", elt->svg_name, elt->implementation_name);
}
fprintf(output, "\treturn TAG_UndefinedNode;\n}\n\n");
fprintf(output, "const char *gf_svg_get_element_name(u32 tag)\n{\n\tswitch(tag) {\n");
for (i=0; i<gf_list_count(svg_elements); i++) {
SVGGenElement *elt = (SVGGenElement *)gf_list_get(svg_elements, i);
fprintf(output, "\tcase TAG_SVG_%s: return \"%s\";\n", elt->implementation_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);
}