⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 gaca源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
 *			GPAC - Multimedia Framework C SDK
 *
 *			Copyright (c) Cyril Concolato 2004-2005
 *					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 <stdio.h>
#include <string.h>
#include <time.h>

#include <gpac/list.h>

#include <libxml/tree.h>
#include <libxml/parser.h>

#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>


#define RNG_NS "http://relaxng.org/ns/structure/1.0"
#define RNGA_NS "http://relaxng.org/ns/compatibility/annotations/1.0"
#define SVGA_NS "http://www.w3.org/2005/02/svg-annotations"

#define RNG_PREFIX "rng"
#define RNGA_PREFIX "rnga"
#define SVGA_PREFIX "svg"

#define COPYRIGHT "/*\n *			GPAC - Multimedia Framework C SDK\n *\n *			Authors: Cyril Concolato - Jean Le Feuvre\n *    Copyright (c)2004-200X ENST - All rights reserved\n *\n *  This file is part of GPAC / SVG Scene Graph sub-project\n *\n *  GPAC is free software; you can redistribute it and/or modify\n *  it under the terms of the GNU Lesser General Public License as published by\n *  the Free Software Foundation; either version 2, or (at your option)\n *  any later version.\n *\n *  GPAC is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU Lesser General Public License for more details.	\n *\n *  You should have received a copy of the GNU Lesser General Public\n *  License along with this library; see the file COPYING.  If not, write to\n *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.\n *\n */\n"

static GF_List *globalAttrGrp;

/* SVG Generic */
static char *core[] = { "id", "class", "xml:id", "xml:base", "xml:lang", "xml:space", "externalResourceRequired" };

/* Properties Generic */
static char *properties[] = {
   /* media only*/
  "audio-level", "display", "image-rendering", "pointer-events", "shape-rendering", "text-rendering", 
  "viewport-fill", "viewport-fill-opacity", "visibility", 
  /* others */
  "color", "color-rendering", "display-align", "fill", "fill-opacity", "fill-rule", 
  "font-family", "font-size", "font-style", "font-weight", "line-increment", 
  "solid-color", "solid-opacity", "stop-color", "stop-opacity", 
  "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", 
   "stroke-opacity", "stroke-width", "text-anchor", "vector-effect", "opacity"
};

/* Focus */
static char *focus[] = { 
  "focusHighlight", "focusable", "nav-down", "nav-down-left", "nav-down-right", 
  "nav-left", "nav-next", "nav-prev", "nav-right", "nav-up", "nav-up-left", "nav-up-right"
};

/* Xlink */
static char *xlink[] = {
	"xlink:href", "xlink:show", "xlink:title", "xlink:actuate", "xlink:role", "xlink:arcrole", "xlink:type"
};

/* Timing */
static char *timing[] = {
	"begin", "end", "dur", "repeatCount", "repeatDur", "restart", "min", "max", "fill", "clipBegin", "clipEnd"
};

/* Sync */
static char *sync[] = {
	"syncBehavior", "syncBehaviorDefault", "syncTolerance", "syncToleranceDefault", "syncMaster", "syncReference"
};

/* Animation */
static char *anim[] = {
	"attributeName", "attributeType", "to", "from", "by", "values",
	"type", "calcMode", "keySplines", "keyTimes", "accumulate", "additive", "lsr:enabled"
};

/* Conditional Processing */
static char *conditional[] = {
	"requiredExtensions", "requiredFeatures", "requiredFonts", "requiredFormats", "systemLanguage"
};

typedef struct {
	int names_length; 
	char **names; // names of all the RNG definition to map
	int array_length;
	char **array; // mapping of constructs to the RNG definition
} _atts;

static char *svg_xml_generic_names[] = 
{ 
	"svg.Core.attr", 
	"svg.CorePreserve.attr", 
	"svg.External.attr" 
};

static char *properties_generic_names[] = 
{ 
	"svg.Properties.attr", 
	"svg.Media.attr",
	"svg.Opacity.attr" 
};

static char *focus_generic_names[] = { 
	"svg.FocusHighlight.attr", 
	"svg.Focus.attr"
};

static char *xlink_generic_names[] = { 
	"svg.AnimateCommon.attr", 
	"svg.XlinkEmbed.attr",
	"svg.XLinkRequired.attr", 
	"svg.XLinkReplace.attr", 
	"svg.ContentType.attr"
};

static char *timing_generic_names[] = { 
	"svg.MediaClip.attr",
	"svg.AnimateTiming.attr", 
	"svg.AnimateTimingNoMinMax.attr", 
	"svg.AnimateBegin.attr",
	"svg.AnimateTimingNoFillNoMinMax.attr" 
};

static char *sync_generic_names[] = { 
	"svg.AnimateSync.attr",
	"svg.AnimateSyncDefault.attr"
};

static char *animate_generic_names[] = { 
	"svg.AnimateAttributeCommon.attr",
	"svg.AnimateToCommon.attr",
	"svg.AnimateValueCommon.attr",
	"svg.AnimateAdditionCommon.attr", 
	"svg.AnimateTypeCommon.attr"
};

static char *conditional_generic_names[] = { "svg.Conditional.attr" };

static _atts generic_attributes[] = {
	{ 2, svg_xml_generic_names,		7, core },
	{ 3, properties_generic_names, 35, properties },
	{ 2, focus_generic_names,	   12, focus },
	{ 5, xlink_generic_names,		7, xlink },
	{ 5, timing_generic_names,		11, timing },
	{ 2, sync_generic_names,		6, sync },
	{ 5, animate_generic_names,	   13, anim },
	{ 1, conditional_generic_names,	5, conditional}
};

/* 
	type declarations 
*/

typedef struct
{
	xmlChar *svg_name;
	char implementation_name[50];

	Bool has_svg_generic;
	Bool has_xml_generic;
	Bool has_media_properties;
	Bool has_properties;
	Bool has_focus;
	Bool has_xlink;
	Bool has_timing;
	Bool has_sync;
	Bool has_animation;
	Bool has_conditional;
	Bool has_transform;
	Bool has_xy;

	GF_List *attributes;
	GF_List *generic_attributes;

	u32 nb_atts;
} SVGElement;

typedef struct {
	xmlChar *svg_name; 
	char implementation_name[50];
	xmlChar *svg_type; 
	char impl_type[50]; 
	u8 animatable; 
	u8 inheritable; 
	Bool optional;
	xmlChar *default_value;
} SVGAttribute;

typedef struct {
	char *name;
	char imp_name[50];
	GF_List *attrs;
	GF_List *attrgrps;
} SVGAttrGrp;

SVGAttribute *NewSVGAttribute()
{
	SVGAttribute *att;
	GF_SAFEALLOC(att, sizeof(SVGAttribute))
	return att;
}

void deleteSVGAttribute(SVGAttribute **p)
{
	xmlFree((*p)->svg_name);
	xmlFree((*p)->svg_type);
	free(*p);
	*p = NULL;
}

SVGAttrGrp *NewAttrGrp()
{
	SVGAttrGrp *tmp;
	GF_SAFEALLOC(tmp, sizeof(SVGAttrGrp))
	tmp->attrs = gf_list_new();
	tmp->attrgrps = gf_list_new();
	return tmp;
}

SVGElement *NewSVGElement() 
{
	SVGElement *elt;
	GF_SAFEALLOC(elt, sizeof(SVGElement));
	if (elt) {
		elt->attributes = gf_list_new();
		elt->generic_attributes = gf_list_new();
	}
	return elt;
}

void deleteSVGElement(SVGElement **p)
{
	u32 i;
	xmlFree((*p)->svg_name);
	for (i = 0; i < gf_list_count((*p)->attributes); i++) {
		SVGAttribute *a = gf_list_get((*p)->attributes, i);
		deleteSVGAttribute(&a);
	}
	gf_list_del((*p)->attributes);
	free(*p);
	*p = NULL;
}

static GF_List *sortElements(GF_List *elements)
{
	u32 i, j;
	GF_List *sorted_elements = gf_list_new();

	for (i = 0; i< gf_list_count(elements); i++) {
		u8 is_added = 0;
		SVGElement *elt = gf_list_get(elements, i);
		for (j = 0; j < gf_list_count(sorted_elements); j++) {
			SVGElement *selt = gf_list_get(sorted_elements, j);
			if (strcmp(elt->svg_name, selt->svg_name) < 0) {
				gf_list_insert(sorted_elements, elt, j);
				is_added = 1;
				break;
			}
		}
		if (!is_added) gf_list_add(sorted_elements, elt);
	}

	gf_list_del(elements);
	return sorted_elements;
}

static GF_List *sortAttrGrp(GF_List *attgrps)
{
	u32 i, j;
	GF_List *sorted_attgrps = gf_list_new();

	for (i = 0; i< gf_list_count(attgrps); i++) {
		u8 is_added = 0;
		SVGAttrGrp *grp = gf_list_get(attgrps, i);
		for (j = 0; j < gf_list_count(sorted_attgrps); j++) {
			SVGAttrGrp *sgrp = gf_list_get(sorted_attgrps, j);
			if (strcmp(grp->name, sgrp->name) < 0) {
				gf_list_insert(sorted_attgrps, grp, j);
				is_added = 1;
				break;
			}
		}
		if (!is_added) gf_list_add(sorted_attgrps, grp);
	}

	gf_list_del(attgrps);
	return sorted_attgrps;
}

static GF_List *sortAttr(GF_List *atts)
{
	u32 i, j;
	GF_List *sorted_atts = gf_list_new();

	for (i = 0; i< gf_list_count(atts); i++) {
		u8 is_added = 0;
		SVGAttribute *att = gf_list_get(atts, i);
		for (j = 0; j < gf_list_count(sorted_atts); j++) {
			SVGAttribute *satt = gf_list_get(sorted_atts, j);
			if (strcmp(att->svg_name, satt->svg_name) < 0) {
				gf_list_insert(sorted_atts, att, j);
				is_added = 1;
				break;
			}
		}
		if (!is_added) gf_list_add(sorted_atts, att);
	}

	gf_list_del(atts);
	return sorted_atts;
}

void svgNameToImplementationName(xmlChar *svg_name, char implementation_name[50]) {
	char *tmp;
	strcpy(implementation_name, svg_name);
	tmp = implementation_name;
	while ( (tmp = strchr(tmp, '.')) ) { *tmp='_'; tmp++; }
	tmp = implementation_name;
	while ( (tmp = strchr(tmp, '-')) ) { *tmp='_'; tmp++; }
	tmp = implementation_name;
	while ( (tmp = strchr(tmp, ':')) ) { *tmp='_'; tmp++; }
}

static Bool isGenericAttributesGroup(char *name) 
{
	if (!strcmp(name, "svg.Core.attr") ||
		!strcmp(name, "svg.CorePreserve.attr") ||
		!strcmp(name, "svg.External.attr") ||
		!strcmp(name, "svg.Properties.attr") ||
		!strcmp(name, "svg.Media.attr") ||
		!strcmp(name, "svg.MediaClip.attr") ||
		!strcmp(name, "svg.Opacity.attr") ||
		!strcmp(name, "svg.FocusHighlight.attr") || 
		!strcmp(name, "svg.Focus.attr") ||

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -