mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 22:23:27 +00:00
svg_loader: code refactoring.
clean up about logging before replacing it with TVGLOG()
This commit is contained in:
parent
02b0f6cfc9
commit
5024e7f952
4 changed files with 76 additions and 65 deletions
|
@ -2484,49 +2484,50 @@ static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* paren
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void _inefficientNodeCheck(TVG_UNUSED SvgNode* node){
|
||||||
#ifdef THORVG_LOG_ENABLED
|
#ifdef THORVG_LOG_ENABLED
|
||||||
static void _inefficientNodeCheck(SvgNode* node){
|
auto type = simpleXmlNodeTypeToString(node->type);
|
||||||
if (!node->display && node->type != SvgNodeType::ClipPath) printf("SVG: Inefficient elements used [Display is none][Node Type : %s]\n", simpleXmlNodeTypeToString(node->type).c_str());
|
|
||||||
if (node->style->opacity == 0) printf("SVG: Inefficient elements used [Opacity is zero][Node Type : %s]\n", simpleXmlNodeTypeToString(node->type).c_str());
|
if (!node->display && node->type != SvgNodeType::ClipPath) printf("SVG: Inefficient elements used [Display is none][Node Type : %s]\n", type);
|
||||||
if (node->style->fill.opacity == 0 && node->style->stroke.opacity == 0) printf("SVG: Inefficient elements used [Fill opacity and stroke opacity are zero][Node Type : %s]\n", simpleXmlNodeTypeToString(node->type).c_str());
|
if (node->style->opacity == 0) printf("SVG: Inefficient elements used [Opacity is zero][Node Type : %s]\n", type);
|
||||||
|
if (node->style->fill.opacity == 0 && node->style->stroke.opacity == 0) printf("SVG: Inefficient elements used [Fill opacity and stroke opacity are zero][Node Type : %s]\n", type);
|
||||||
|
|
||||||
switch (node->type) {
|
switch (node->type) {
|
||||||
case SvgNodeType::Path: {
|
case SvgNodeType::Path: {
|
||||||
if (!node->node.path.path || node->node.path.path->empty()) printf("SVG: Inefficient elements used [Empty path][Node Type : %s]\n", simpleXmlNodeTypeToString(node->type).c_str());
|
if (!node->node.path.path || node->node.path.path->empty()) printf("SVG: Inefficient elements used [Empty path][Node Type : %s]\n", type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SvgNodeType::Ellipse: {
|
case SvgNodeType::Ellipse: {
|
||||||
if (node->node.ellipse.rx == 0 && node->node.ellipse.ry == 0) printf("SVG: Inefficient elements used [Size is zero][Node Type : %s]\n", simpleXmlNodeTypeToString(node->type).c_str());
|
if (node->node.ellipse.rx == 0 && node->node.ellipse.ry == 0) printf("SVG: Inefficient elements used [Size is zero][Node Type : %s]\n", type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SvgNodeType::Polygon:
|
case SvgNodeType::Polygon:
|
||||||
case SvgNodeType::Polyline: {
|
case SvgNodeType::Polyline: {
|
||||||
if (node->node.polygon.pointsCount < 2) printf("SVG: Inefficient elements used [Invalid Polygon][Node Type : %s]\n", simpleXmlNodeTypeToString(node->type).c_str());
|
if (node->node.polygon.pointsCount < 2) printf("SVG: Inefficient elements used [Invalid Polygon][Node Type : %s]\n", type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SvgNodeType::Circle: {
|
case SvgNodeType::Circle: {
|
||||||
if (node->node.circle.r == 0) printf("SVG: Inefficient elements used [Size is zero][Node Type : %s]\n", simpleXmlNodeTypeToString(node->type).c_str());
|
if (node->node.circle.r == 0) printf("SVG: Inefficient elements used [Size is zero][Node Type : %s]\n", type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SvgNodeType::Rect: {
|
case SvgNodeType::Rect: {
|
||||||
if (node->node.rect.w == 0 && node->node.rect.h) printf("SVG: Inefficient elements used [Size is zero][Node Type : %s]\n", simpleXmlNodeTypeToString(node->type).c_str());
|
if (node->node.rect.w == 0 && node->node.rect.h) printf("SVG: Inefficient elements used [Size is zero][Node Type : %s]\n", type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SvgNodeType::Line: {
|
case SvgNodeType::Line: {
|
||||||
if (node->node.line.x1 == node->node.line.x2 && node->node.line.y1 == node->node.line.y2) printf("SVG: Inefficient elements used [Size is zero][Node Type : %s]\n", simpleXmlNodeTypeToString(node->type).c_str());
|
if (node->node.line.x1 == node->node.line.x2 && node->node.line.y1 == node->node.line.y2) printf("SVG: Inefficient elements used [Size is zero][Node Type : %s]\n", type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void _updateStyle(SvgNode* node, SvgStyleProperty* parentStyle)
|
static void _updateStyle(SvgNode* node, SvgStyleProperty* parentStyle)
|
||||||
{
|
{
|
||||||
_styleInherit(node->style, parentStyle);
|
_styleInherit(node->style, parentStyle);
|
||||||
#ifdef THORVG_LOG_ENABLED
|
|
||||||
_inefficientNodeCheck(node);
|
_inefficientNodeCheck(node);
|
||||||
#endif
|
|
||||||
|
|
||||||
auto child = node->child.data;
|
auto child = node->child.data;
|
||||||
for (uint32_t i = 0; i < node->child.count; ++i, ++child) {
|
for (uint32_t i = 0; i < node->child.count; ++i, ++child) {
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
struct SvgNode;
|
struct SvgNode;
|
||||||
struct SvgStyleGradient;
|
struct SvgStyleGradient;
|
||||||
|
|
||||||
|
//NOTE: Please update simpleXmlNodeTypeToString() as well.
|
||||||
enum class SvgNodeType
|
enum class SvgNodeType
|
||||||
{
|
{
|
||||||
Doc,
|
Doc,
|
||||||
|
|
|
@ -36,50 +36,6 @@
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
#ifdef THORVG_LOG_ENABLED
|
#ifdef THORVG_LOG_ENABLED
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
string simpleXmlNodeTypeToString(SvgNodeType type)
|
|
||||||
{
|
|
||||||
switch (type) {
|
|
||||||
case SvgNodeType::Doc: return "Svg";
|
|
||||||
case SvgNodeType::G: return "G";
|
|
||||||
case SvgNodeType::Defs: return "Defs";
|
|
||||||
case SvgNodeType::Animation: return "Animation";
|
|
||||||
case SvgNodeType::Arc: return "Arc";
|
|
||||||
case SvgNodeType::Circle: return "Circle";
|
|
||||||
case SvgNodeType::Ellipse: return "Ellipse";
|
|
||||||
case SvgNodeType::Image: return "Image";
|
|
||||||
case SvgNodeType::Line: return "Line";
|
|
||||||
case SvgNodeType::Path: return "Path";
|
|
||||||
case SvgNodeType::Polygon: return "Polygon";
|
|
||||||
case SvgNodeType::Polyline: return "Polyline";
|
|
||||||
case SvgNodeType::Rect: return "Rect";
|
|
||||||
case SvgNodeType::Text: return "Text";
|
|
||||||
case SvgNodeType::TextArea: return "TextArea";
|
|
||||||
case SvgNodeType::Tspan: return "Tspan";
|
|
||||||
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)
|
bool _isIgnoreUnsupportedLogAttributes(const char* tagAttribute, const char* tagValue)
|
||||||
{
|
{
|
||||||
const auto attributesNum = 6;
|
const auto attributesNum = 6;
|
||||||
|
@ -109,9 +65,9 @@ bool _isIgnoreUnsupportedLogAttributes(const char* tagAttribute, const char* tag
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static const char* _simpleXmlFindWhiteSpace(const char* itr, const char* itrEnd)
|
static const char* _simpleXmlFindWhiteSpace(const char* itr, const char* itrEnd)
|
||||||
{
|
{
|
||||||
for (; itr < itrEnd; itr++) {
|
for (; itr < itrEnd; itr++) {
|
||||||
|
@ -253,6 +209,55 @@ static const char* _simpleXmlFindDoctypeChildEndTag(const char* itr, const char*
|
||||||
/* External Class Implementation */
|
/* External Class Implementation */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
|
const char* simpleXmlNodeTypeToString(TVG_UNUSED SvgNodeType type)
|
||||||
|
{
|
||||||
|
#ifdef THORVG_LOG_ENABLED
|
||||||
|
static const char* TYPE_NAMES[] = {
|
||||||
|
"Svg",
|
||||||
|
"G",
|
||||||
|
"Defs",
|
||||||
|
"Animation",
|
||||||
|
"Arc",
|
||||||
|
"Circle",
|
||||||
|
"Ellipse",
|
||||||
|
"Image",
|
||||||
|
"Line",
|
||||||
|
"Path",
|
||||||
|
"Polygon",
|
||||||
|
"Polyline",
|
||||||
|
"Rect",
|
||||||
|
"Text",
|
||||||
|
"TextArea",
|
||||||
|
"Tspan",
|
||||||
|
"Use",
|
||||||
|
"Video",
|
||||||
|
"ClipPath",
|
||||||
|
"Mask",
|
||||||
|
"Unknown",
|
||||||
|
};
|
||||||
|
return TYPE_NAMES[(int) type];
|
||||||
|
#endif
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool isIgnoreUnsupportedLogElements(TVG_UNUSED const char* tagName)
|
||||||
|
{
|
||||||
|
#ifdef THORVG_LOG_ENABLED
|
||||||
|
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;
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool simpleXmlParseAttributes(const char* buf, unsigned bufLength, simpleXMLAttributeCb func, const void* data)
|
bool simpleXmlParseAttributes(const char* buf, unsigned bufLength, simpleXMLAttributeCb func, const void* data)
|
||||||
{
|
{
|
||||||
|
@ -313,7 +318,11 @@ bool simpleXmlParseAttributes(const char* buf, unsigned bufLength, simpleXMLAttr
|
||||||
|
|
||||||
#ifdef THORVG_LOG_ENABLED
|
#ifdef THORVG_LOG_ENABLED
|
||||||
if (!func((void*)data, tmpBuf, tval)) {
|
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");
|
if (!_isIgnoreUnsupportedLogAttributes(tmpBuf, tval)) {
|
||||||
|
auto type = simpleXmlNodeTypeToString(((SvgLoaderData*)data)->svgParse->node->type);
|
||||||
|
auto id = ((SvgLoaderData*)data)->svgParse->node->id ? ((SvgLoaderData*)data)->svgParse->node->id->c_str() : "NO_ID";
|
||||||
|
printf("SVG: Unsupported attributes used [Elements type: %s][Id : %s][Attribute: %s][Value: %s]\n", type, id, tmpBuf, tval ? tval : "NONE");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
func((void*)data, tmpBuf, tval);
|
func((void*)data, tmpBuf, tval);
|
||||||
|
@ -510,7 +519,11 @@ bool simpleXmlParseW3CAttribute(const char* buf, simpleXMLAttributeCb func, cons
|
||||||
|
|
||||||
#ifdef THORVG_LOG_ENABLED
|
#ifdef THORVG_LOG_ENABLED
|
||||||
if (!func((void*)data, key, val)) {
|
if (!func((void*)data, key, val)) {
|
||||||
if (!_isIgnoreUnsupportedLogAttributes(key, val)) 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", key, val ? val : "NONE");
|
if (!_isIgnoreUnsupportedLogAttributes(key, val)) {
|
||||||
|
auto type = simpleXmlNodeTypeToString(((SvgLoaderData*)data)->svgParse->node->type);
|
||||||
|
auto id = ((SvgLoaderData*)data)->svgParse->node->id ? ((SvgLoaderData*)data)->svgParse->node->id->c_str() : "NO_ID";
|
||||||
|
printf("SVG: Unsupported attributes used [Elements type: %s][Id : %s][Attribute: %s][Value: %s]\n", type, id, key, val ? val : "NONE");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
func((void*)data, key, val);
|
func((void*)data, key, val);
|
||||||
|
|
|
@ -51,11 +51,7 @@ bool simpleXmlParseAttributes(const char* buf, unsigned buflen, simpleXMLAttribu
|
||||||
bool simpleXmlParse(const char* buf, unsigned buflen, bool strip, simpleXMLCb func, const void* data);
|
bool simpleXmlParse(const char* buf, unsigned buflen, bool strip, simpleXMLCb func, const void* data);
|
||||||
bool simpleXmlParseW3CAttribute(const char* buf, simpleXMLAttributeCb func, const void* data);
|
bool simpleXmlParseW3CAttribute(const char* buf, simpleXMLAttributeCb func, const void* data);
|
||||||
const char *simpleXmlFindAttributesTag(const char* buf, unsigned buflen);
|
const char *simpleXmlFindAttributesTag(const char* buf, unsigned buflen);
|
||||||
|
|
||||||
#ifdef THORVG_LOG_ENABLED
|
|
||||||
string simpleXmlNodeTypeToString(SvgNodeType type);
|
|
||||||
|
|
||||||
bool isIgnoreUnsupportedLogElements(const char* tagName);
|
bool isIgnoreUnsupportedLogElements(const char* tagName);
|
||||||
#endif
|
const char* simpleXmlNodeTypeToString(SvgNodeType type);
|
||||||
|
|
||||||
#endif //_TVG_SIMPLE_XML_PARSER_H_
|
#endif //_TVG_SIMPLE_XML_PARSER_H_
|
||||||
|
|
Loading…
Add table
Reference in a new issue