SvgLoader: Support x,y rounded rect 68/237868/2
authorJunsuChoi <jsuya.choi@samsung.com>
Mon, 6 Jul 2020 08:01:56 +0000 (17:01 +0900)
committerHermet Park <chuneon.park@samsung.com>
Tue, 7 Jul 2020 02:37:27 +0000 (02:37 +0000)
Change-Id: I45d8f7ff3604da0a80c09e2495ed8c0301310094

src/loaders/svg_loader/tvgSvgSceneBuilder.cpp
test/svgs/rect.svg [new file with mode: 0644]

index 66b3593..2451103 100644 (file)
@@ -150,11 +150,28 @@ unique_ptr<tvg::Shape> _shapeBuildHelper(SvgNode* node)
             break;
         }
         case SvgNodeType::Rect: {
-            if (node->node.rect.rx == node->node.rect.ry) {
+            if (node->node.rect.rx == node->node.rect.ry || (node->node.rect.rx == 0 || node->node.rect.ry == 0)) {
                  shape->appendRect(node->node.rect.x, node->node.rect.y, node->node.rect.w, node->node.rect.h, node->node.rect.rx);
             }
             else {
-                //TODO: Support rounded rectangle
+                float x = node->node.rect.x;
+                float y = node->node.rect.y;
+                float w = node->node.rect.w;
+                float h = node->node.rect.h;
+                float rx = node->node.rect.rx;
+                float ry = node->node.rect.ry;
+                float rhx = rx / 2;
+                float rhy = ry / 2;
+                shape->moveTo(x + rx, y);
+                shape->lineTo(x + w - rx, y);
+                shape->cubicTo(x + w - rx + rhx, y, x + w, y + ry - rhy, x + w, y + ry);
+                shape->lineTo(x + w, y + h - ry);
+                shape->cubicTo(x + w, y + h - ry + rhy, x + w - rx + rhx, y + h, x + w - rx, y + h);
+                shape->lineTo(x + rx, y + h);
+                shape->cubicTo(x + rx - rhx, y + h, x, y + h - ry + rhy, x, y + h - ry);
+                shape->lineTo(x, y + ry);
+                shape->cubicTo(x, y + ry - rhy, x + rx - rhx, y, x + rx, y);
+                shape->close();
             }
             break;
         }
diff --git a/test/svgs/rect.svg b/test/svgs/rect.svg
new file mode 100644 (file)
index 0000000..2e82905
--- /dev/null
@@ -0,0 +1,7 @@
+<svg viewBox="0 0 220 100" xmlns="http://www.w3.org/2000/svg">
+  <!-- Simple rectangle -->
+  <rect width="100" height="100" />
+
+  <!-- Rounded corner rectangle -->
+  <rect x="120" width="100" height="100" rx="15" ry="30"/>
+</svg>