SvgLoader: Supports case when only rx or ry is declared
authorJunsuChoi <jsuya.choi@samsung.com>
Wed, 9 Sep 2020 10:36:15 +0000 (19:36 +0900)
committerHermet Park <chuneon.park@samsung.com>
Thu, 10 Sep 2020 02:34:38 +0000 (11:34 +0900)
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.

Change-Id: Ibf1d258a093319ce21b2b907eee58f2a45f17352

src/loaders/svg/tvgSvgLoader.cpp
src/loaders/svg/tvgSvgLoaderCommon.h

index 76be7be..4ade095 100644 (file)
@@ -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: {
index 5b56532..91896bc 100644 (file)
@@ -196,6 +196,8 @@ struct SvgRectNode
     float h;
     float rx;
     float ry;
+    bool hasRx;
+    bool hasRy;
 };
 
 struct SvgLineNode