capi: Added wrapper for tvg::Shape::scale
[platform/core/graphics/tizenvg.git] / src / bindings / capi / tvgCapi.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *               http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  */
17
18 #include <thorvg.h>
19 #include "thorvg_capi.h"
20
21 using namespace std;
22 using namespace tvg;
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 struct _Tvg_Canvas
29 {
30     //Dummy for Direct Casting
31 };
32
33 struct _Tvg_Paint
34 {
35     //Dummy for Direct Casting
36 };
37
38
39 /************************************************************************/
40 /* Engine API                                                           */
41 /************************************************************************/
42
43 TVG_EXPORT Tvg_Result tvg_engine_init(unsigned engine_method) {
44     Result ret = Result::Success;
45
46     if (engine_method & TVG_ENGINE_SW) ret = tvg::Initializer::init(tvg::CanvasEngine::Sw);
47     if (ret != Result::Success) return (Tvg_Result) ret;
48
49     if (engine_method & TVG_ENGINE_GL) ret = tvg::Initializer::init(tvg::CanvasEngine::Gl);
50     return (Tvg_Result) ret;
51 }
52
53
54 TVG_EXPORT Tvg_Result tvg_engine_term(unsigned engine_method) {
55     Result ret = Result::Success;
56
57     if (engine_method & TVG_ENGINE_SW) ret = tvg::Initializer::init(tvg::CanvasEngine::Sw);
58     if (ret != Result::Success) return (Tvg_Result) ret;
59
60     if (engine_method & TVG_ENGINE_GL) ret = tvg::Initializer::init(tvg::CanvasEngine::Gl);
61     return (Tvg_Result) ret;
62 }
63
64 /************************************************************************/
65 /* Canvas API                                                           */
66 /************************************************************************/
67
68 TVG_EXPORT Tvg_Canvas* tvg_swcanvas_create()
69 {
70     return (Tvg_Canvas*) SwCanvas::gen().release();
71 }
72
73
74 TVG_EXPORT Tvg_Result tvg_canvas_destroy(Tvg_Canvas* canvas)
75 {
76     delete(canvas);
77     return TVG_RESULT_SUCCESS;
78 }
79
80
81 TVG_EXPORT Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas* canvas, uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h)
82 {
83     return (Tvg_Result) reinterpret_cast<SwCanvas*>(canvas)->target(buffer, stride, w, h);
84 }
85
86
87 TVG_EXPORT Tvg_Result tvg_canvas_push(Tvg_Canvas* canvas, Tvg_Paint* paint)
88 {
89     return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->push(unique_ptr<Paint>((Paint*)paint));
90 }
91
92
93 TVG_EXPORT Tvg_Result tvg_canvas_reserve(Tvg_Canvas* canvas, uint32_t n)
94 {
95     return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->reserve(n);
96 }
97
98
99 TVG_EXPORT Tvg_Result tvg_canvas_clear(Tvg_Canvas* canvas)
100 {
101     return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->clear();
102 }
103
104
105 TVG_EXPORT Tvg_Result tvg_canvas_update(Tvg_Canvas* canvas)
106 {
107      return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->update();
108 }
109
110
111 TVG_EXPORT Tvg_Result tvg_canvas_update_paint(Tvg_Canvas* canvas, Tvg_Paint* paint)
112 {
113     return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->update((Paint*) paint);
114 }
115
116
117 TVG_EXPORT Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas, unsigned char async)
118 {
119     return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->draw(async);
120 }
121
122
123 TVG_EXPORT Tvg_Result tvg_canvas_sync(Tvg_Canvas* canvas)
124 {
125     return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->sync();
126 }
127
128
129 /************************************************************************/
130 /* Shape API                                                            */
131 /************************************************************************/
132
133 TVG_EXPORT Tvg_Paint* tvg_shape_new()
134 {
135     return (Tvg_Paint*) Shape::gen().release();
136 }
137
138
139 TVG_EXPORT Tvg_Result tvg_shape_del(Tvg_Paint* paint)
140 {
141     delete(paint);
142     return TVG_RESULT_SUCCESS;
143 }
144
145
146 TVG_EXPORT Tvg_Result tvg_shape_reset(Tvg_Paint* paint)
147 {
148     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->reset();
149 }
150
151
152 TVG_EXPORT Tvg_Result tvg_shape_move_to(Tvg_Paint* paint, float x, float y)
153 {
154     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->moveTo(x, y);
155 }
156
157
158 TVG_EXPORT Tvg_Result tvg_shape_line_to(Tvg_Paint* paint, float x, float y)
159 {
160     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->lineTo(x, y);
161 }
162
163
164 TVG_EXPORT Tvg_Result tvg_shape_cubic_to(Tvg_Paint* paint, float cx1, float cy1, float cx2, float cy2, float x, float y)
165 {
166     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->cubicTo(cx1, cy1, cx2, cy2, x, y);
167 }
168
169
170 TVG_EXPORT Tvg_Result tvg_shape_close(Tvg_Paint* paint)
171 {
172     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->close();
173 }
174
175
176 TVG_EXPORT Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y, float w, float h, float rx, float ry)
177 {
178     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendRect(x, y, w, h, rx, ry);
179 }
180
181
182 TVG_EXPORT Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry)
183 {
184     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendCircle(cx, cy, rx, ry);
185 }
186
187
188 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)
189 {
190     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendPath((PathCommand*)cmds, cmdCnt, (Point*)pts, ptsCnt);
191 }
192
193
194 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint* paint, float width)
195 {
196     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(width);
197 }
198
199
200 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
201 {
202     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(r, g, b, a);
203 }
204
205
206 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt)
207 {
208     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(dashPattern, cnt);
209 }
210
211
212 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap cap)
213 {
214     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke((StrokeCap)cap);
215 }
216
217
218 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join join)
219 {
220     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke((StrokeJoin)join);
221 }
222
223
224 TVG_EXPORT Tvg_Result tvg_shape_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
225 {
226     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill(r, g, b, a);
227 }
228
229 TVG_EXPORT Tvg_Result tvg_shape_scale(Tvg_Paint* paint, float factor)
230 {
231     return (Tvg_Result) reinterpret_cast<Shape*>(paint)->scale(factor);
232 }
233
234 #ifdef __cplusplus
235 }
236 #endif