From eaa0cd3b00ff2bb70ffc5756903fe66b6070f9cd Mon Sep 17 00:00:00 2001
From: Piotr Kalota
Date: Tue, 15 Sep 2020 14:06:05 +0200
Subject: [PATCH] bindings/capi: Added path getters + test in testCapi.c
Change-Id: I5ce453509d16c06f5649f08fcd2d16414e7e0f18
---
inc/thorvg_capi.h | 2 ++
src/bindings/capi/tvgCapi.cpp | 17 +++++++++++++++++
test/testCapi.c | 29 ++++++++++++++++++++++-------
3 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/inc/thorvg_capi.h b/inc/thorvg_capi.h
index 8b09036..a869639 100644
--- a/inc/thorvg_capi.h
+++ b/inc/thorvg_capi.h
@@ -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);
diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp
index 059a4c0..0178e27 100644
--- a/src/bindings/capi/tvgCapi.cpp
+++ b/src/bindings/capi/tvgCapi.cpp
@@ -254,6 +254,23 @@ TVG_EXPORT Tvg_Result tvg_shape_append_path(Tvg_Paint* paint, const Tvg_Path_Com
return (Tvg_Result) reinterpret_cast(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(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(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)
{
diff --git a/test/testCapi.c b/test/testCapi.c
index e31db67..c1fb9c9 100644
--- a/test/testCapi.c
+++ b/test/testCapi.c
@@ -71,10 +71,10 @@ void testCapi()
tvg_gradient_color_stops(grad1, color_stops1, 3);
tvg_gradient_color_stops(grad2, color_stops2, 2);
tvg_gradient_color_stops(grad3, color_stops3, 2);
- tvg_shape_linear_gradient_set(shape, grad);
- tvg_shape_radial_gradient_set(shape1, grad1);
- tvg_shape_linear_gradient_set(shape2, grad2);
- tvg_shape_linear_gradient_set(shape3, grad3);
+ tvg_shape_set_linear_gradient(shape, grad);
+ tvg_shape_set_radial_gradient(shape1, grad1);
+ tvg_shape_set_linear_gradient(shape2, grad2);
+ tvg_shape_set_linear_gradient(shape3, grad3);
tvg_canvas_push(canvas, shape);
tvg_canvas_push(canvas, shape1);
@@ -91,7 +91,7 @@ void testCapi()
{.offset=1, .r=0, .g=255, .b=0, .a=255},
};
tvg_gradient_color_stops(grad4, color_stops4, 2);
- tvg_shape_linear_gradient_set(shape4, grad4);
+ tvg_shape_set_linear_gradient(shape4, grad4);
Tvg_Gradient* grad5 = tvg_linear_gradient_new();
tvg_linear_gradient_set(grad5, 700, 700, 800, 800);
@@ -101,7 +101,7 @@ void testCapi()
{.offset=1, .r=0, .g=255, .b=255, .a=255},
};
tvg_gradient_color_stops(grad5, color_stops5, 2);
- tvg_shape_linear_gradient_set(shape4, grad5);
+ tvg_shape_set_linear_gradient(shape4, grad5);
tvg_canvas_push(canvas, shape4);
Tvg_Gradient* grad6 = tvg_radial_gradient_new();
@@ -112,13 +112,28 @@ void testCapi()
{.offset=1, .r=125, .g=0, .b=125, .a=255},
};
tvg_gradient_color_stops(grad6, color_stops6, 2);
- tvg_shape_radial_gradient_set(shape1, grad6);
+ tvg_shape_set_radial_gradient(shape1, grad6);
tvg_canvas_update(canvas);
tvg_shape_set_stroke_width(shape,3);
tvg_shape_set_stroke_color(shape, 125, 0, 125, 255);
tvg_canvas_update_paint(canvas, shape);
+ const Tvg_Path_Command* cmds;
+ uint32_t cmdCnt;
+ const Tvg_Point* pts;
+ uint32_t ptsCnt;
+
+ tvg_shape_get_path_commands(shape, &cmds, &cmdCnt);
+ printf("---- First Shape Commands(%u) ----\n", cmdCnt);
+ for(int i=0; i