log SvgLoader: Enhance log message

- Change tag name "Doc" to "Svg"
- Fix "Mask" tag name.
- Add element to skip output
 - title
- Add attribute to skip output
 - id, data-name, version, overflow=visible, xmlns*, xml:space
This commit is contained in:
JunsuChoi 2021-04-26 15:25:45 +09:00 committed by Hermet Park
parent dc637d0beb
commit f8f90f3f34
4 changed files with 56 additions and 8 deletions

View file

@ -36,8 +36,6 @@ typedef SvgNode* (*FactoryMethod)(SvgLoaderData* loader, SvgNode* parent, const
typedef SvgStyleGradient* (*GradientFactoryMethod)(SvgLoaderData* loader, const char* buf, unsigned bufLength);
static char* _skipSpace(const char* str, const char* end)
{
while (((end && str < end) || (!end && *str != '\0')) && isspace(*str)) {
@ -739,8 +737,8 @@ static bool _attrParseSvgNode(void* data, const char* key, const char* value)
return simpleXmlParseW3CAttribute(value, _parseStyleAttr, loader);
}
#ifdef THORVG_LOG_ENABLED
else if (!strcmp(key, "xmlns") || !strcmp(key, "xmlns:xlink") || !strcmp(key, "xmlns:svg")) {
//No action
else if (!strcmp(key, "x") || !strcmp(key, "y")) {
if (0.0f == _parseLength(value, &type)) printf("SVG: Unsupported attributes used [Elements type: Svg][Attribute: %s][Value: %s]\n", key, value);
}
#endif
else {
@ -1080,7 +1078,7 @@ static SvgNode* _createSvgNode(SvgLoaderData* loader, SvgNode* parent, const cha
static SvgNode* _createMaskNode(SvgLoaderData* loader, SvgNode* parent, TVG_UNUSED const char* buf, TVG_UNUSED unsigned bufLength)
{
loader->svgParse->node = _createNode(parent, SvgNodeType::Unknown);
loader->svgParse->node = _createNode(parent, SvgNodeType::Mask);
if (!loader->svgParse->node) return nullptr;
simpleXmlParseAttributes(buf, bufLength, _attrParseMaskNode, loader);
@ -2207,7 +2205,7 @@ static void _svgLoaderParserXmlOpen(SvgLoaderData* loader, const char* content,
}
#ifdef THORVG_LOG_ENABLED
else {
printf("SVG: Unsupported elements used [Elements: %s]\n", tagName);
if (!isIgnoreUnsupportedLogElements(tagName)) printf("SVG: Unsupported elements used [Elements: %s]\n", tagName);
}
#endif
}

View file

@ -47,6 +47,7 @@ enum class SvgNodeType
Use,
Video,
ClipPath,
Mask,
//Custome_command, //Not support
Unknown
};

View file

@ -42,7 +42,7 @@
string simpleXmlNodeTypeToString(SvgNodeType type)
{
switch (type) {
case SvgNodeType::Doc: return "Doc";
case SvgNodeType::Doc: return "Svg";
case SvgNodeType::G: return "G";
case SvgNodeType::Defs: return "Defs";
case SvgNodeType::Animation: return "Animation";
@ -61,10 +61,55 @@ string simpleXmlNodeTypeToString(SvgNodeType type)
case SvgNodeType::Use: return "Use";
case SvgNodeType::Video: return "Video";
case SvgNodeType::ClipPath: return "ClipPath";
case SvgNodeType::Mask: return "Mask";
default: return "Unknown";
}
return "Unknown";
}
bool isIgnoreUnsupportedLogElements(const char* tagName)
{
const auto elementsNum = 1;
const char* const elements[] = { "title" };
for (unsigned int i = 0; i < elementsNum; ++i) {
if (!strncmp(tagName, elements[i], strlen(tagName))) {
return true;
}
}
return false;
}
bool _isIgnoreUnsupportedLogAttributes(const char* tagAttribute, const char* tagValue)
{
const auto attributesNum = 6;
const struct
{
const char* tag;
bool tagWildcard; //If true, it is assumed that a wildcard is used after the tag. (ex: tagName*)
const char* value;
} attributes[] = {
{"id", false, nullptr},
{"data-name", false, nullptr},
{"overflow", false, "visible"},
{"version", false, nullptr},
{"xmlns", true, nullptr},
{"xml:space", false, nullptr},
};
for (unsigned int i = 0; i < attributesNum; ++i) {
if (!strncmp(tagAttribute, attributes[i].tag, attributes[i].tagWildcard ? strlen(attributes[i].tag) : strlen(tagAttribute))) {
if (attributes[i].value && tagValue) {
if (!strncmp(tagValue, attributes[i].value, strlen(tagValue))) {
return true;
} else continue;
}
return true;
}
}
return false;
}
#endif
static const char* _simpleXmlFindWhiteSpace(const char* itr, const char* itrEnd)
@ -267,7 +312,9 @@ bool simpleXmlParseAttributes(const char* buf, unsigned bufLength, simpleXMLAttr
tval[i] = '\0';
#ifdef THORVG_LOG_ENABLED
if (!func((void*)data, tmpBuf, tval)) printf("SVG: Unsupported attributes used [Elements type: %s][Attribute: %s]\n", simpleXmlNodeTypeToString(((SvgLoaderData*)data)->svgParse->node->type).c_str(), tmpBuf);
if (!func((void*)data, tmpBuf, tval)) {
if (!_isIgnoreUnsupportedLogAttributes(tmpBuf, tval)) printf("SVG: Unsupported attributes used [Elements type: %s][Id : %s][Attribute: %s][Value: %s]\n", simpleXmlNodeTypeToString(((SvgLoaderData*)data)->svgParse->node->type).c_str(), ((SvgLoaderData*)data)->svgParse->node->id ? ((SvgLoaderData*)data)->svgParse->node->id->c_str() : "NO_ID", tmpBuf, tval ? tval : "NONE");
}
#else
func((void*)data, tmpBuf, tval);
#endif

View file

@ -54,6 +54,8 @@ const char *simpleXmlFindAttributesTag(const char* buf, unsigned buflen);
#ifdef THORVG_LOG_ENABLED
string simpleXmlNodeTypeToString(SvgNodeType type);
bool isIgnoreUnsupportedLogElements(const char* tagName);
#endif
#endif //_TVG_SIMPLE_XML_PARSER_H_