From 68ce2dc7d83b81bb42db0cbdbfcfbabd63bb6e51 Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Wed, 9 Sep 2020 19:36:15 +0900 Subject: [PATCH] SvgLoader: Supports case when only rx or ry is declared In relation to the declaration of rx and ry attribute of rect, the following three cases occur. rx="10" (or ry="10" rx="10" ry = "0" (or rx="0" ry = "10") rx="10" ry = "10" To cover these case, we check the rx and ry declarations. --- src/loaders/svg/tvgSvgLoader.cpp | 16 ++++++++++++---- src/loaders/svg/tvgSvgLoaderCommon.h | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/loaders/svg/tvgSvgLoader.cpp b/src/loaders/svg/tvgSvgLoader.cpp index 76be7be8..4ade0954 100644 --- a/src/loaders/svg/tvgSvgLoader.cpp +++ b/src/loaders/svg/tvgSvgLoader.cpp @@ -1270,11 +1270,17 @@ static bool _attrParseRectNode(void* data, const char* key, const char* value) for (i = 0; i < sizeof(rectTags) / sizeof(rectTags[0]); i++) { if (rectTags[i].sz - 1 == sz && !strncmp(rectTags[i].tag, key, sz)) { *((float*)(array + rectTags[i].offset)) = _toFloat(loader->svgParse, value, rectTags[i].type); + + //Case if only rx or ry is declared + if (!strncmp(rectTags[i].tag, "rx", sz)) rect->hasRx = true; + if (!strncmp(rectTags[i].tag, "ry", sz)) rect->hasRy = true; + + if ((rect->rx > FLT_EPSILON) && (rect->ry <= FLT_EPSILON) && rect->hasRx && !rect->hasRy) rect->ry = rect->rx; + if ((rect->ry > FLT_EPSILON) && (rect->rx <= FLT_EPSILON) && !rect->hasRx && rect->hasRy) rect->rx = rect->ry; return ret; } } - if (!strcmp(key, "id")) { node->id = _copyId(value); } else if (!strcmp(key, "style")) { @@ -1283,9 +1289,6 @@ static bool _attrParseRectNode(void* data, const char* key, const char* value) ret = _parseStyleAttr(loader, key, value); } - if (!(rect->rx - 0 <= FLT_EPSILON) && (rect->ry - 0 <= FLT_EPSILON)) rect->ry = rect->rx; - if (!(rect->ry - 0 <= FLT_EPSILON) && (rect->rx - 0 <= FLT_EPSILON)) rect->rx = rect->ry; - return ret; } @@ -1293,6 +1296,9 @@ static bool _attrParseRectNode(void* data, const char* key, const char* value) static SvgNode* _createRectNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength) { loader->svgParse->node = _createNode(parent, SvgNodeType::Rect); + if (loader->svgParse->node) { + loader->svgParse->node->node.rect.hasRx = loader->svgParse->node->node.rect.hasRy = false; + } simpleXmlParseAttributes(buf, bufLength, _attrParseRectNode, loader); return loader->svgParse->node; @@ -1459,6 +1465,8 @@ static void _copyAttr(SvgNode* to, SvgNode* from) to->node.rect.h = from->node.rect.h; to->node.rect.rx = from->node.rect.rx; to->node.rect.ry = from->node.rect.ry; + to->node.rect.hasRx = from->node.rect.hasRx; + to->node.rect.hasRy = from->node.rect.hasRy; break; } case SvgNodeType::Line: { diff --git a/src/loaders/svg/tvgSvgLoaderCommon.h b/src/loaders/svg/tvgSvgLoaderCommon.h index 5b56532a..91896bcc 100644 --- a/src/loaders/svg/tvgSvgLoaderCommon.h +++ b/src/loaders/svg/tvgSvgLoaderCommon.h @@ -196,6 +196,8 @@ struct SvgRectNode float h; float rx; float ry; + bool hasRx; + bool hasRy; }; struct SvgLineNode