bindings/capi: Added path getters + test in testCapi.c
authorPiotr Kalota <p.kalota@samsung.com>
Tue, 15 Sep 2020 12:06:05 +0000 (14:06 +0200)
committerHermet Park <chuneon.park@samsung.com>
Wed, 16 Sep 2020 07:56:22 +0000 (16:56 +0900)
Change-Id: I5ce453509d16c06f5649f08fcd2d16414e7e0f18

inc/thorvg_capi.h
src/bindings/capi/tvgCapi.cpp
test/testCapi.c

index 8b09036..a869639 100644 (file)
@@ -135,6 +135,8 @@ TVG_EXPORT Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y,
 TVG_EXPORT Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry);
 TVG_EXPORT Tvg_Result tvg_shape_append_arc(Tvg_Paint* paint, float cx, float cy, float radius, float startAngle, float sweep, uint8_t pie);
 TVG_EXPORT Tvg_Result tvg_shape_append_path(Tvg_Paint* paint, const Tvg_Path_Command* cmds, uint32_t cmdCnt, const Tvg_Point* pts, uint32_t ptsCnt);
+TVG_EXPORT Tvg_Result tvg_shape_get_path_coords(const Tvg_Paint* paint, const Tvg_Point** pts, uint32_t* cnt);
+TVG_EXPORT Tvg_Result tvg_shape_get_path_commands(const Tvg_Paint* paint, const Tvg_Path_Command** cmds, uint32_t* cnt);
 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint* paint, float width);
 TVG_EXPORT Tvg_Result tvg_shape_get_stroke_width(Tvg_Paint* paint, float* width);
 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
index 059a4c0..0178e27 100644 (file)
@@ -254,6 +254,23 @@ TVG_EXPORT Tvg_Result tvg_shape_append_path(Tvg_Paint* paint, const Tvg_Path_Com
     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendPath((PathCommand*)cmds, cmdCnt, (Point*)pts, ptsCnt);
 }
 
+TVG_EXPORT Tvg_Result tvg_shape_get_path_coords(const Tvg_Paint* paint, const Tvg_Point** pts, uint32_t* cnt)
+{
+    if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
+    auto ret = reinterpret_cast<const Shape*>(paint)->pathCoords((const Point**)pts);
+    if (cnt) *cnt = ret;
+    return TVG_RESULT_SUCCESS;
+}
+
+
+TVG_EXPORT Tvg_Result tvg_shape_get_path_commands(const Tvg_Paint* paint, const Tvg_Path_Command** cmds, uint32_t* cnt)
+{
+    if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
+    auto ret = reinterpret_cast<const Shape*>(paint)->pathCommands((const PathCommand**)cmds);
+    if (cnt) *cnt = ret;
+    return TVG_RESULT_SUCCESS;
+}
+
 
 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint* paint, float width)
 {
index e31db67..c1fb9c9 100644 (file)
@@ -71,10 +71,10 @@ void testCapi()
     tvg_gradient_color_stops(grad1, color_stops1, 3);\r
     tvg_gradient_color_stops(grad2, color_stops2, 2);\r
     tvg_gradient_color_stops(grad3, color_stops3, 2);\r
-    tvg_shape_linear_gradient_set(shape, grad);\r
-    tvg_shape_radial_gradient_set(shape1, grad1);\r
-    tvg_shape_linear_gradient_set(shape2, grad2);\r
-    tvg_shape_linear_gradient_set(shape3, grad3);\r
+    tvg_shape_set_linear_gradient(shape, grad);\r
+    tvg_shape_set_radial_gradient(shape1, grad1);\r
+    tvg_shape_set_linear_gradient(shape2, grad2);\r
+    tvg_shape_set_linear_gradient(shape3, grad3);\r
 \r
     tvg_canvas_push(canvas, shape);\r
     tvg_canvas_push(canvas, shape1);\r
@@ -91,7 +91,7 @@ void testCapi()
         {.offset=1, .r=0, .g=255, .b=0, .a=255},\r
     };\r
     tvg_gradient_color_stops(grad4, color_stops4, 2);\r
-    tvg_shape_linear_gradient_set(shape4, grad4);\r
+    tvg_shape_set_linear_gradient(shape4, grad4);\r
 \r
     Tvg_Gradient* grad5 = tvg_linear_gradient_new();\r
     tvg_linear_gradient_set(grad5, 700, 700, 800, 800);\r
@@ -101,7 +101,7 @@ void testCapi()
         {.offset=1, .r=0, .g=255, .b=255, .a=255},\r
     };\r
     tvg_gradient_color_stops(grad5, color_stops5, 2);\r
-    tvg_shape_linear_gradient_set(shape4, grad5);\r
+    tvg_shape_set_linear_gradient(shape4, grad5);\r
     tvg_canvas_push(canvas, shape4);\r
 \r
     Tvg_Gradient* grad6 = tvg_radial_gradient_new();\r
@@ -112,13 +112,28 @@ void testCapi()
         {.offset=1, .r=125, .g=0, .b=125, .a=255},\r
     };\r
     tvg_gradient_color_stops(grad6, color_stops6, 2);\r
-    tvg_shape_radial_gradient_set(shape1, grad6);\r
+    tvg_shape_set_radial_gradient(shape1, grad6);\r
     tvg_canvas_update(canvas);\r
 \r
     tvg_shape_set_stroke_width(shape,3);\r
     tvg_shape_set_stroke_color(shape, 125, 0, 125, 255);\r
     tvg_canvas_update_paint(canvas, shape);\r
 \r
+    const Tvg_Path_Command* cmds;\r
+    uint32_t cmdCnt;\r
+    const Tvg_Point* pts;\r
+    uint32_t ptsCnt;\r
+\r
+    tvg_shape_get_path_commands(shape, &cmds, &cmdCnt);\r
+    printf("---- First Shape Commands(%u) ----\n", cmdCnt);\r
+    for(int i=0; i<cmdCnt; ++i)\r
+        printf("%d\n", cmds[i]);\r
+\r
+    tvg_shape_get_path_coords(shape, &pts, &ptsCnt);\r
+    printf("---- First Shape Points(%u) ----\n", ptsCnt);\r
+    for(int i=0; i<ptsCnt; ++i)\r
+        printf("(%.2lf, %.2lf)\n", pts[i].x, pts[i].y);\r
+        \r
     tvg_canvas_draw(canvas);\r
     tvg_canvas_sync(canvas);\r
 \r