2 * Copyright 2016 Xamarin Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "SkParsePath.h"
14 #include "sk_types_priv.h"
16 void sk_path_rmove_to(sk_path_t* cpath, float dx, float dy) {
17 AsPath(cpath)->rMoveTo(dx, dy);
20 void sk_path_rline_to(sk_path_t* cpath, float dx, float dy) {
21 AsPath(cpath)->rLineTo(dx, dy);
24 void sk_path_rquad_to(sk_path_t* cpath, float dx0, float dy0, float dx1, float dy1) {
25 AsPath(cpath)->rQuadTo(dx0, dy0, dx1, dy1);
28 void sk_path_rconic_to(sk_path_t* cpath, float dx0, float dy0, float dx1, float dy1, float w) {
29 AsPath(cpath)->rConicTo(dx0, dy0, dx1, dy1, w);
32 void sk_path_rcubic_to(sk_path_t* cpath, float dx0, float dy0, float dx1, float dy1, float dx2, float dy2) {
33 AsPath(cpath)->rCubicTo(dx0, dy0, dx1, dy1, dx2, dy2);
36 void sk_path_add_rect_start(sk_path_t* cpath, const sk_rect_t* crect, sk_path_direction_t cdir, uint32_t startIndex) {
37 AsPath(cpath)->addRect(AsRect(*crect), (SkPath::Direction)cdir, startIndex);
40 void sk_path_add_arc(sk_path_t* cpath, const sk_rect_t* crect, float startAngle, float sweepAngle) {
41 AsPath(cpath)->addArc(AsRect(*crect), startAngle, sweepAngle);
44 void sk_path_set_filltype(sk_path_t* cpath, sk_path_filltype_t cfilltype) {
45 AsPath(cpath)->setFillType((SkPath::FillType)cfilltype);
48 sk_path_filltype_t sk_path_get_filltype(sk_path_t *cpath) {
49 return (sk_path_filltype_t)AsPath(cpath)->getFillType();
52 void sk_path_transform(sk_path_t* cpath, const sk_matrix_t* cmatrix)
56 from_c(cmatrix, &matrix);
58 return AsPath(cpath)->transform(matrix);
61 sk_path_t* sk_path_clone(const sk_path_t* cpath)
63 return (sk_path_t*)new SkPath(AsPath(*cpath));
66 void sk_path_rewind (sk_path_t* cpath)
68 AsPath (cpath)->rewind ();
71 void sk_path_reset (sk_path_t* cpath)
73 AsPath (cpath)->reset ();
76 sk_path_iterator_t* sk_path_create_iter (sk_path_t *cpath, int forceClose)
78 SkPath::Iter* iter = new SkPath::Iter(AsPath(*cpath), forceClose);
79 return ToPathIter(iter);
82 sk_path_verb_t sk_path_iter_next (sk_path_iterator_t *iterator, sk_point_t points [4], int doConsumeDegenerates, int exact)
84 SkPath::Iter *iter = AsPathIter(iterator);
85 SkPoint *pts = AsPoint(points);
86 SkPath::Verb verb = iter->next(pts, doConsumeDegenerates, exact);
87 return (sk_path_verb_t)verb;
90 float sk_path_iter_conic_weight (sk_path_iterator_t *iterator)
92 return AsPathIter(iterator)->conicWeight ();
95 int sk_path_iter_is_close_line (sk_path_iterator_t *iterator)
97 return AsPathIter(iterator)->isCloseLine ();
100 int sk_path_iter_is_closed_contour (sk_path_iterator_t *iterator)
102 return AsPathIter(iterator)->isClosedContour ();
105 void sk_path_iter_destroy (sk_path_iterator_t *iterator)
107 delete AsPathIter (iterator);
110 sk_path_rawiterator_t* sk_path_create_rawiter (sk_path_t *cpath)
112 SkPath::RawIter* iter = new SkPath::RawIter(AsPath(*cpath));
113 return ToPathRawIter(iter);
116 sk_path_verb_t sk_path_rawiter_next (sk_path_rawiterator_t *iterator, sk_point_t points [4])
118 SkPath::RawIter *iter = AsPathRawIter(iterator);
119 SkPoint *pts = AsPoint(points);
120 SkPath::Verb verb = iter->next(pts);
121 return (sk_path_verb_t)verb;
124 sk_path_verb_t sk_path_rawiter_peek (sk_path_rawiterator_t *iterator)
126 return (sk_path_verb_t) AsPathRawIter(iterator)->peek ();
129 float sk_path_rawiter_conic_weight (sk_path_rawiterator_t *iterator)
131 return AsPathRawIter(iterator)->conicWeight ();
134 void sk_path_rawiter_destroy (sk_path_rawiterator_t *iterator)
136 delete AsPathRawIter (iterator);
139 void sk_path_add_path_offset (sk_path_t* cpath, sk_path_t* other, float dx, float dy, sk_path_add_mode_t add_mode)
141 AsPath (cpath)->addPath (AsPath (*other), dx, dy, (SkPath::AddPathMode) add_mode);
144 void sk_path_add_path_matrix (sk_path_t* cpath, sk_path_t* other, sk_matrix_t *matrix, sk_path_add_mode_t add_mode)
147 from_c(matrix, &skmatrix);
148 AsPath (cpath)->addPath (AsPath (*other), skmatrix, (SkPath::AddPathMode) add_mode);
151 void sk_path_add_path (sk_path_t* cpath, sk_path_t* other, sk_path_add_mode_t add_mode)
153 AsPath (cpath)->addPath (AsPath (*other), (SkPath::AddPathMode) add_mode);
156 void sk_path_add_path_reverse (sk_path_t* cpath, sk_path_t* other)
158 AsPath (cpath)->reverseAddPath (AsPath (*other));
161 sk_path_t* sk_path_new() { return (sk_path_t*)new SkPath; }
163 void sk_path_delete(sk_path_t* cpath) { delete AsPath(cpath); }
165 void sk_path_move_to(sk_path_t* cpath, float x, float y) {
166 AsPath(cpath)->moveTo(x, y);
169 void sk_path_line_to(sk_path_t* cpath, float x, float y) {
170 AsPath(cpath)->lineTo(x, y);
173 void sk_path_quad_to(sk_path_t* cpath, float x0, float y0, float x1, float y1) {
174 AsPath(cpath)->quadTo(x0, y0, x1, y1);
177 void sk_path_conic_to(sk_path_t* cpath, float x0, float y0, float x1, float y1, float w) {
178 AsPath(cpath)->conicTo(x0, y0, x1, y1, w);
181 void sk_path_cubic_to(sk_path_t* cpath, float x0, float y0, float x1, float y1, float x2, float y2) {
182 AsPath(cpath)->cubicTo(x0, y0, x1, y1, x2, y2);
185 void sk_path_arc_to(sk_path_t* cpath, float rx, float ry, float xAxisRotate, sk_path_arc_size_t largeArc, sk_path_direction_t sweep, float x, float y) {
186 AsPath(cpath)->arcTo(rx, ry, xAxisRotate, (SkPath::ArcSize)largeArc, (SkPath::Direction)sweep, x, y);
189 void sk_path_rarc_to(sk_path_t* cpath, float rx, float ry, float xAxisRotate, sk_path_arc_size_t largeArc, sk_path_direction_t sweep, float x, float y) {
190 AsPath(cpath)->rArcTo(rx, ry, xAxisRotate, (SkPath::ArcSize)largeArc, (SkPath::Direction)sweep, x, y);
193 void sk_path_close(sk_path_t* cpath) {
194 AsPath(cpath)->close();
197 void sk_path_add_rect(sk_path_t* cpath, const sk_rect_t* crect, sk_path_direction_t cdir) {
198 AsPath(cpath)->addRect(AsRect(*crect), (SkPath::Direction)cdir);
201 void sk_path_add_rounded_rect(sk_path_t* cpath, const sk_rect_t* crect, float rx, float ry, sk_path_direction_t cdir) {
202 AsPath(cpath)->addRoundRect(AsRect(*crect), rx, ry, (SkPath::Direction)cdir);
205 void sk_path_add_oval(sk_path_t* cpath, const sk_rect_t* crect, sk_path_direction_t cdir) {
206 AsPath(cpath)->addOval(AsRect(*crect), (SkPath::Direction)cdir);
209 void sk_path_add_circle(sk_path_t* cpath, float x, float y, float radius, sk_path_direction_t dir) {
210 AsPath(cpath)->addCircle(x, y, radius, (SkPath::Direction)dir);
213 bool sk_path_get_bounds(const sk_path_t* cpath, sk_rect_t* crect) {
214 const SkPath& path = AsPath(*cpath);
216 if (path.isEmpty()) {
218 *crect = ToRect(SkRect::MakeEmpty());
224 *crect = ToRect(path.getBounds());
229 int sk_path_count_points(const sk_path_t* cpath) {
230 const SkPath& path = AsPath(*cpath);
231 return path.countPoints();
234 void sk_path_get_point(const sk_path_t* cpath, int index, sk_point_t* cpoint) {
235 const SkPath& path = AsPath(*cpath);
237 SkPoint point = path.getPoint(index);
238 *cpoint = ToPoint(point);
242 int sk_path_get_points(const sk_path_t* cpath, sk_point_t* cpoints, int max) {
243 const SkPath& path = AsPath(*cpath);
244 return path.getPoints(AsPoint(cpoints), max);
247 bool sk_path_contains (const sk_path_t* cpath, float x, float y) {
248 return AsPath(*cpath).contains(x, y);
251 sk_path_convexity_t sk_path_get_convexity (const sk_path_t* cpath) {
252 return (sk_path_convexity_t)AsPath(*cpath).getConvexity();
255 void sk_path_set_convexity (sk_path_t* cpath, sk_path_convexity_t convexity) {
256 AsPath(cpath)->setConvexity((SkPath::Convexity)convexity);
259 SK_API bool sk_path_parse_svg_string (sk_path_t* cpath, const char* str) {
260 return SkParsePath::FromSVGString(str, AsPath(cpath));
263 SK_API void sk_path_to_svg_string (const sk_path_t* cpath, sk_string_t* str) {
264 SkParsePath::ToSVGString(AsPath(*cpath), AsString(str));
267 bool sk_path_get_last_point (const sk_path_t* cpath, sk_point_t* point) {
269 return AsPath(*cpath).getLastPt(AsPoint(point));
275 bool sk_pathop_op(const sk_path_t* one, const sk_path_t* two, sk_pathop_t op, sk_path_t* result) {
276 return Op(AsPath(*one), AsPath(*two), (SkPathOp)op, AsPath(result));
279 bool sk_pathop_simplify(const sk_path_t* path, sk_path_t* result) {
280 return Simplify(AsPath(*path), AsPath(result));
283 bool sk_pathop_tight_bounds(const sk_path_t* path, sk_rect_t* result) {
284 return TightBounds(AsPath(*path), AsRect(result));
287 sk_opbuilder_t* sk_opbuilder_new() {
288 return ToOpBuilder(new SkOpBuilder());
291 void sk_opbuilder_destroy(sk_opbuilder_t* builder) {
292 delete AsOpBuilder(builder);
295 void sk_opbuilder_add(sk_opbuilder_t* builder, const sk_path_t* path, sk_pathop_t op) {
296 AsOpBuilder(builder)->add(AsPath(*path), (SkPathOp)op);
299 bool sk_opbuilder_resolve(sk_opbuilder_t* builder, sk_path_t* result) {
300 return AsOpBuilder(builder)->resolve(AsPath(result));