capi: correct interfaces.
authorHermet Park <chuneon.park@samsung.com>
Wed, 16 Sep 2020 08:53:24 +0000 (17:53 +0900)
committerHermet Park <chuneon.park@samsung.com>
Wed, 16 Sep 2020 08:59:09 +0000 (17:59 +0900)
put missing const parameter and correct set/get naming.

attention, these two apis are changed!

tvg_gradient_color_stops() => tvg_gradient_set_color_stops()
tvg_gradient_spread() = tvg_gradient_set_spread()

Change-Id: I309b973b8e88bdf33232f95e5da30061b9c2a22b

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

index a869639eff3156f2f88de2271a406338d5ac8a7c..8ec3f99bd5a63342cb6355644aba4c92058a94fb 100644 (file)
@@ -138,31 +138,31 @@ TVG_EXPORT Tvg_Result tvg_shape_append_path(Tvg_Paint* paint, const Tvg_Path_Com
 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_get_stroke_width(const 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);
-TVG_EXPORT Tvg_Result tvg_shape_get_stroke_color(Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a);
+TVG_EXPORT Tvg_Result tvg_shape_get_stroke_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a);
 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt);
-TVG_EXPORT Tvg_Result tvg_shape_get_stroke_dash(Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt);
+TVG_EXPORT Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt);
 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap cap);
-TVG_EXPORT Tvg_Result tvg_shape_get_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap* cap);
+TVG_EXPORT Tvg_Result tvg_shape_get_stroke_cap(const Tvg_Paint* paint, Tvg_Stroke_Cap* cap);
 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join join);
-TVG_EXPORT Tvg_Result tvg_shape_get_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join* join);
+TVG_EXPORT Tvg_Result tvg_shape_get_stroke_join(const Tvg_Paint* paint, Tvg_Stroke_Join* join);
 TVG_EXPORT Tvg_Result tvg_shape_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
-TVG_EXPORT Tvg_Result tvg_shape_get_fill_color(Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a);
+TVG_EXPORT Tvg_Result tvg_shape_get_fill_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a);
 TVG_EXPORT Tvg_Result tvg_shape_set_linear_gradient(Tvg_Paint* paint, Tvg_Gradient* grad);
 TVG_EXPORT Tvg_Result tvg_shape_set_radial_gradient(Tvg_Paint* paint, Tvg_Gradient* grad);
-TVG_EXPORT Tvg_Result tvg_shape_get_gradient(Tvg_Paint* paint, Tvg_Gradient** grad);
+TVG_EXPORT Tvg_Result tvg_shape_get_gradient(const Tvg_Paint* paint, Tvg_Gradient** grad);
 
 /************************************************************************/
 /* Gradient API                                                         */
 /************************************************************************/
 TVG_EXPORT Tvg_Gradient* tvg_linear_gradient_new();
 TVG_EXPORT Tvg_Gradient* tvg_radial_gradient_new();
-TVG_EXPORT Tvg_Result tvg_gradient_del(Tvg_Gradient* grad);
 TVG_EXPORT Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, float y1, float x2, float y2);
 TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, float cy, float radius);
-TVG_EXPORT Tvg_Result tvg_gradient_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt);
-TVG_EXPORT Tvg_Result tvg_gradient_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill);
+TVG_EXPORT Tvg_Result tvg_gradient_set_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt);
+TVG_EXPORT Tvg_Result tvg_gradient_set_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill);
+TVG_EXPORT Tvg_Result tvg_gradient_del(Tvg_Gradient* grad);
 
 
 /************************************************************************/
@@ -170,7 +170,7 @@ TVG_EXPORT Tvg_Result tvg_gradient_spread(Tvg_Gradient* grad, const Tvg_Stroke_F
 /************************************************************************/
 TVG_EXPORT Tvg_Paint* tvg_picture_new();
 TVG_EXPORT Tvg_Result tvg_picture_load(Tvg_Paint* paint, const char* path);
-TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(Tvg_Paint* paint, float* x, float* y, float* w, float* h);
+TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(const Tvg_Paint* paint, float* x, float* y, float* w, float* h);
 
 #ifdef __cplusplus
 }
index 0178e27ef6a124cc84fa8826ab877f2ef9dc58e1..2240223565b809bc2b2f7da76427d32518487b46 100644 (file)
@@ -26,6 +26,8 @@
 using namespace std;
 using namespace tvg;
 
+#define CCP(A) const_cast<Tvg_Paint*>(A)  //Const-Cast-Paint
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -279,10 +281,10 @@ 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_get_stroke_width(const Tvg_Paint* paint, float* width)
 {
     if (!paint || !width) return TVG_RESULT_INVALID_ARGUMENT;
-    *width = reinterpret_cast<Shape*>(paint)->strokeWidth();
+    *width = reinterpret_cast<Shape*>(CCP(paint))->strokeWidth();
     return TVG_RESULT_SUCCESS;
 }
 
@@ -294,10 +296,10 @@ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint* paint, uint8_t r, ui
 }
 
 
-TVG_EXPORT Tvg_Result tvg_shape_get_stroke_color(Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a)
+TVG_EXPORT Tvg_Result tvg_shape_get_stroke_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a)
 {
     if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
-    return (Tvg_Result) reinterpret_cast<Shape*>(paint)->strokeColor(r, g, b, a);
+    return (Tvg_Result) reinterpret_cast<Shape*>(CCP(paint))->strokeColor(r, g, b, a);
 }
 
 
@@ -308,10 +310,10 @@ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* d
 }
 
 
-TVG_EXPORT Tvg_Result tvg_shape_get_stroke_dash(Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt)
+TVG_EXPORT Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt)
 {
     if (!paint || !cnt || !dashPattern) return TVG_RESULT_INVALID_ARGUMENT;
-    *cnt = reinterpret_cast<Shape*>(paint)->strokeDash(dashPattern);
+    *cnt = reinterpret_cast<Shape*>(CCP(paint))->strokeDash(dashPattern);
     return TVG_RESULT_SUCCESS;
 }
 
@@ -323,10 +325,10 @@ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap
 }
 
 
-TVG_EXPORT Tvg_Result tvg_shape_get_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap* cap)
+TVG_EXPORT Tvg_Result tvg_shape_get_stroke_cap(const Tvg_Paint* paint, Tvg_Stroke_Cap* cap)
 {
     if (!paint || !cap) return TVG_RESULT_INVALID_ARGUMENT;
-    *cap = (Tvg_Stroke_Cap) reinterpret_cast<Shape*>(paint)->strokeCap();
+    *cap = (Tvg_Stroke_Cap) reinterpret_cast<Shape*>(CCP(paint))->strokeCap();
     return TVG_RESULT_SUCCESS;
 }
 
@@ -337,10 +339,10 @@ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Joi
 }
 
 
-TVG_EXPORT Tvg_Result tvg_shape_get_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join* join)
+TVG_EXPORT Tvg_Result tvg_shape_get_stroke_join(const Tvg_Paint* paint, Tvg_Stroke_Join* join)
 {
     if (!paint || !join) return TVG_RESULT_INVALID_ARGUMENT;
-    *join = (Tvg_Stroke_Join) reinterpret_cast<Shape*>(paint)->strokeJoin();
+    *join = (Tvg_Stroke_Join) reinterpret_cast<Shape*>(CCP(paint))->strokeJoin();
     return TVG_RESULT_SUCCESS;
 }
 
@@ -352,10 +354,10 @@ TVG_EXPORT Tvg_Result tvg_shape_set_fill_color(Tvg_Paint* paint, uint8_t r, uint
 }
 
 
-TVG_EXPORT Tvg_Result tvg_shape_get_fill_color(Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a)
+TVG_EXPORT Tvg_Result tvg_shape_get_fill_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a)
 {
     if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
-    return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill(r, g, b, a);
+    return (Tvg_Result) reinterpret_cast<Shape*>(CCP(paint))->fill(r, g, b, a);
 }
 
 
@@ -373,10 +375,10 @@ TVG_EXPORT Tvg_Result tvg_shape_set_radial_gradient(Tvg_Paint* paint, Tvg_Gradie
 }
 
 
-TVG_EXPORT Tvg_Result tvg_shape_get_gradient(Tvg_Paint* paint, Tvg_Gradient** gradient)
+TVG_EXPORT Tvg_Result tvg_shape_get_gradient(const Tvg_Paint* paint, Tvg_Gradient** gradient)
 {
    if (!paint || !gradient) return TVG_RESULT_INVALID_ARGUMENT;
-   *gradient = (Tvg_Gradient*)(reinterpret_cast<Shape*>(paint)->fill());
+   *gradient = (Tvg_Gradient*)(reinterpret_cast<Shape*>(CCP(paint))->fill());
    return TVG_RESULT_SUCCESS;
 }
 
@@ -398,10 +400,10 @@ TVG_EXPORT Tvg_Result tvg_picture_load(Tvg_Paint* paint, const char* path)
 }
 
 
-TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(Tvg_Paint* paint, float* x, float* y, float* w, float* h)
+TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(const Tvg_Paint* paint, float* x, float* y, float* w, float* h)
 {
     if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
-    return (Tvg_Result) reinterpret_cast<Picture*>(paint)->viewbox(x, y, w, h);
+    return (Tvg_Result) reinterpret_cast<Picture*>(CCP(paint))->viewbox(x, y, w, h);
 }
 
 
@@ -438,13 +440,13 @@ TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, floa
     return (Tvg_Result) reinterpret_cast<RadialGradient*>(grad)->radial(cx, cy, radius);
 }
 
-TVG_EXPORT Tvg_Result tvg_gradient_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt)
+TVG_EXPORT Tvg_Result tvg_gradient_set_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt)
 {
     if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
     return (Tvg_Result) reinterpret_cast<Fill*>(grad)->colorStops(reinterpret_cast<const Fill::ColorStop*>(color_stop), cnt);
 }
 
-TVG_EXPORT Tvg_Result tvg_gradient_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread)
+TVG_EXPORT Tvg_Result tvg_gradient_set_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread)
 {
     if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
     return (Tvg_Result) reinterpret_cast<Fill*>(grad)->spread((FillSpread)spread);
index c1fb9c9e0e0dcaa6216caf21b79e5638243601f5..ab405ffec4297d04f99ac121598d7e92afe4ae48 100644 (file)
@@ -53,7 +53,7 @@ void testCapi()
         {.offset=1, .r=255, .g=0, .b=0, .a=255},\r
     };\r
 \r
-    tvg_gradient_spread(grad2, TVG_STROKE_FILL_REPEAT);\r
+    tvg_gradient_set_spread(grad2, TVG_STROKE_FILL_REPEAT);\r
 \r
     Tvg_Paint* shape3 = tvg_shape_new();\r
     tvg_shape_append_rect(shape3, 0, 400, 400, 800, 20, 20);\r
@@ -65,12 +65,12 @@ void testCapi()
         {.offset=1, .r=0, .g=255, .b=0, .a=255},\r
     };\r
 \r
-    tvg_gradient_spread(grad3, TVG_STROKE_FILL_REFLECT);\r
+    tvg_gradient_set_spread(grad3, TVG_STROKE_FILL_REFLECT);\r
 \r
-    tvg_gradient_color_stops(grad, color_stops, 4);\r
-    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_gradient_set_color_stops(grad, color_stops, 4);\r
+    tvg_gradient_set_color_stops(grad1, color_stops1, 3);\r
+    tvg_gradient_set_color_stops(grad2, color_stops2, 2);\r
+    tvg_gradient_set_color_stops(grad3, color_stops3, 2);\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
@@ -90,7 +90,7 @@ void testCapi()
         {.offset=0.0, .r=0, .g=0, .b=0, .a=255},\r
         {.offset=1, .r=0, .g=255, .b=0, .a=255},\r
     };\r
-    tvg_gradient_color_stops(grad4, color_stops4, 2);\r
+    tvg_gradient_set_color_stops(grad4, color_stops4, 2);\r
     tvg_shape_set_linear_gradient(shape4, grad4);\r
 \r
     Tvg_Gradient* grad5 = tvg_linear_gradient_new();\r
@@ -100,7 +100,7 @@ void testCapi()
         {.offset=0.0, .r=0, .g=0, .b=255, .a=255},\r
         {.offset=1, .r=0, .g=255, .b=255, .a=255},\r
     };\r
-    tvg_gradient_color_stops(grad5, color_stops5, 2);\r
+    tvg_gradient_set_color_stops(grad5, color_stops5, 2);\r
     tvg_shape_set_linear_gradient(shape4, grad5);\r
     tvg_canvas_push(canvas, shape4);\r
 \r
@@ -111,7 +111,7 @@ void testCapi()
         {.offset=0.0, .r=0, .g=125, .b=0, .a=255},\r
         {.offset=1, .r=125, .g=0, .b=125, .a=255},\r
     };\r
-    tvg_gradient_color_stops(grad6, color_stops6, 2);\r
+    tvg_gradient_set_color_stops(grad6, color_stops6, 2);\r
     tvg_shape_set_radial_gradient(shape1, grad6);\r
     tvg_canvas_update(canvas);\r
 \r
@@ -126,14 +126,16 @@ void testCapi()
 \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
+    for(int i=0; i < cmdCnt; ++i) {\r
         printf("%d\n", cmds[i]);\r
+    }\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
+    for(int i=0; i < ptsCnt; ++i) {\r
         printf("(%.2lf, %.2lf)\n", pts[i].x, pts[i].y);\r
-        \r
+    }\r
+\r
     tvg_canvas_draw(canvas);\r
     tvg_canvas_sync(canvas);\r
 \r