2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "thorvg_capi.h"
30 //Dummy for Direct Casting
35 //Dummy for Direct Casting
40 //Dummy for Direct Casting
44 /************************************************************************/
46 /************************************************************************/
48 TVG_EXPORT Tvg_Result tvg_engine_init(unsigned engine_method) {
49 Result ret = Result::Success;
51 if (engine_method & TVG_ENGINE_SW) ret = tvg::Initializer::init(tvg::CanvasEngine::Sw);
52 if (ret != Result::Success) return (Tvg_Result) ret;
54 if (engine_method & TVG_ENGINE_GL) ret = tvg::Initializer::init(tvg::CanvasEngine::Gl);
55 return (Tvg_Result) ret;
59 TVG_EXPORT Tvg_Result tvg_engine_term(unsigned engine_method) {
60 Result ret = Result::Success;
62 if (engine_method & TVG_ENGINE_SW) ret = tvg::Initializer::init(tvg::CanvasEngine::Sw);
63 if (ret != Result::Success) return (Tvg_Result) ret;
65 if (engine_method & TVG_ENGINE_GL) ret = tvg::Initializer::init(tvg::CanvasEngine::Gl);
66 return (Tvg_Result) ret;
69 /************************************************************************/
71 /************************************************************************/
73 TVG_EXPORT Tvg_Canvas* tvg_swcanvas_create()
75 return (Tvg_Canvas*) SwCanvas::gen().release();
79 TVG_EXPORT Tvg_Result tvg_canvas_destroy(Tvg_Canvas* canvas)
82 return TVG_RESULT_SUCCESS;
86 TVG_EXPORT Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas* canvas, uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h)
88 return (Tvg_Result) reinterpret_cast<SwCanvas*>(canvas)->target(buffer, stride, w, h);
92 TVG_EXPORT Tvg_Result tvg_canvas_push(Tvg_Canvas* canvas, Tvg_Paint* paint)
94 return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->push(unique_ptr<Paint>((Paint*)paint));
98 TVG_EXPORT Tvg_Result tvg_canvas_reserve(Tvg_Canvas* canvas, uint32_t n)
100 return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->reserve(n);
104 TVG_EXPORT Tvg_Result tvg_canvas_clear(Tvg_Canvas* canvas)
106 return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->clear();
110 TVG_EXPORT Tvg_Result tvg_canvas_update(Tvg_Canvas* canvas)
112 return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->update(nullptr);
116 TVG_EXPORT Tvg_Result tvg_canvas_update_paint(Tvg_Canvas* canvas, Tvg_Paint* paint)
118 return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->update((Paint*) paint);
122 TVG_EXPORT Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas)
124 return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->draw();
128 TVG_EXPORT Tvg_Result tvg_canvas_sync(Tvg_Canvas* canvas)
130 return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->sync();
134 /************************************************************************/
136 /************************************************************************/
138 TVG_EXPORT Tvg_Result tvg_paint_del(Tvg_Paint* paint)
141 return TVG_RESULT_SUCCESS;
145 TVG_EXPORT Tvg_Result tvg_paint_scale(Tvg_Paint* paint, float factor)
147 return (Tvg_Result) reinterpret_cast<Paint*>(paint)->scale(factor);
151 TVG_EXPORT Tvg_Result tvg_paint_rotate(Tvg_Paint* paint, float degree)
153 return (Tvg_Result) reinterpret_cast<Paint*>(paint)->rotate(degree);
157 TVG_EXPORT Tvg_Result tvg_paint_translate(Tvg_Paint* paint, float x, float y)
159 return (Tvg_Result) reinterpret_cast<Paint*>(paint)->translate(x, y);
163 TVG_EXPORT Tvg_Result tvg_paint_transform(Tvg_Paint* paint, const Tvg_Matrix* m)
165 return (Tvg_Result) reinterpret_cast<Paint*>(paint)->transform(*(reinterpret_cast<const Matrix*>(m)));
169 /************************************************************************/
171 /************************************************************************/
173 TVG_EXPORT Tvg_Paint* tvg_shape_new()
175 return (Tvg_Paint*) Shape::gen().release();
179 TVG_EXPORT Tvg_Result tvg_shape_reset(Tvg_Paint* paint)
181 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->reset();
185 TVG_EXPORT Tvg_Result tvg_shape_move_to(Tvg_Paint* paint, float x, float y)
187 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->moveTo(x, y);
191 TVG_EXPORT Tvg_Result tvg_shape_line_to(Tvg_Paint* paint, float x, float y)
193 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->lineTo(x, y);
197 TVG_EXPORT Tvg_Result tvg_shape_cubic_to(Tvg_Paint* paint, float cx1, float cy1, float cx2, float cy2, float x, float y)
199 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->cubicTo(cx1, cy1, cx2, cy2, x, y);
203 TVG_EXPORT Tvg_Result tvg_shape_close(Tvg_Paint* paint)
205 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->close();
209 TVG_EXPORT Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y, float w, float h, float rx, float ry)
211 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendRect(x, y, w, h, rx, ry);
214 TVG_EXPORT Tvg_Result tvg_shape_append_arc(Tvg_Paint* paint, float cx, float cy, float radius, float startAngle, float sweep, uint8_t pie)
216 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendArc(cx, cy, radius, startAngle, sweep, pie);
219 TVG_EXPORT Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry)
221 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendCircle(cx, cy, rx, ry);
225 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)
227 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendPath((PathCommand*)cmds, cmdCnt, (Point*)pts, ptsCnt);
231 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint* paint, float width)
233 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(width);
237 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
239 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(r, g, b, a);
243 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt)
245 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(dashPattern, cnt);
249 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap cap)
251 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke((StrokeCap)cap);
255 TVG_EXPORT Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join join)
257 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke((StrokeJoin)join);
261 TVG_EXPORT Tvg_Result tvg_shape_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
263 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill(r, g, b, a);
267 TVG_EXPORT Tvg_Result tvg_shape_linear_gradient_set(Tvg_Paint* paint, Tvg_Gradient *gradient)
269 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill(unique_ptr<LinearGradient>((LinearGradient*)(gradient)));
273 TVG_EXPORT Tvg_Result tvg_shape_radial_gradient_set(Tvg_Paint* paint, Tvg_Gradient *gradient)
275 return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill(unique_ptr<RadialGradient>((RadialGradient*)(gradient)));
279 /************************************************************************/
281 /************************************************************************/
283 TVG_EXPORT Tvg_Paint* tvg_picture_new()
285 return (Tvg_Paint*) Picture::gen().release();
289 TVG_EXPORT Tvg_Result tvg_picture_load(Tvg_Paint* paint, const char* path)
291 return (Tvg_Result) reinterpret_cast<Picture*>(paint)->load(path);
295 TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(Tvg_Paint* paint, float* x, float* y, float* w, float* h)
297 return (Tvg_Result) reinterpret_cast<Picture*>(paint)->viewbox(x, y, w, h);
301 /************************************************************************/
303 /************************************************************************/
304 TVG_EXPORT Tvg_Gradient* tvg_linear_gradient_new()
306 return (Tvg_Gradient*)LinearGradient::gen().release();
309 TVG_EXPORT Tvg_Gradient* tvg_radial_gradient_new()
311 return (Tvg_Gradient*)RadialGradient::gen().release();
315 TVG_EXPORT Tvg_Result tvg_gradient_del(Tvg_Gradient* grad)
318 return TVG_RESULT_SUCCESS;
321 TVG_EXPORT Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, float y1, float x2, float y2)
323 return (Tvg_Result) reinterpret_cast<LinearGradient*>(grad)->linear(x1, y1, x2, y2);
326 TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, float cy, float radius)
328 return (Tvg_Result) reinterpret_cast<RadialGradient*>(grad)->radial(cx, cy, radius);
331 TVG_EXPORT Tvg_Result tvg_gradient_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt)
333 return (Tvg_Result) reinterpret_cast<Fill*>(grad)->colorStops(reinterpret_cast<const Fill::ColorStop*>(color_stop), cnt);
336 TVG_EXPORT Tvg_Result tvg_gradient_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread)
338 return (Tvg_Result) reinterpret_cast<Fill*>(grad)->spread((FillSpread)spread);