[C API] Add sk_path's iterators, and add the missing sk_matrix methods that I lost
authorMiguel de Icaza <miguel@gnome.org>
Sun, 3 Jul 2016 04:10:18 +0000 (00:10 -0400)
committerMiguel de Icaza <miguel@gnome.org>
Sun, 3 Jul 2016 04:10:18 +0000 (00:10 -0400)
include/c/xamarin/sk_x_matrix.h [new file with mode: 0644]
include/c/xamarin/sk_x_path.h
include/c/xamarin/sk_x_types.h
src/c/xamarin/sk_x_matrix.cpp [new file with mode: 0644]
src/c/xamarin/sk_x_path.cpp
src/c/xamarin/sk_x_types_priv.h

diff --git a/include/c/xamarin/sk_x_matrix.h b/include/c/xamarin/sk_x_matrix.h
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
index 5ffc788e3ae3859998bf91ebc41b485d3bc50286..d8363ade3b7ed5f97983e66ec152e080dc97c470 100644 (file)
@@ -75,6 +75,17 @@ SK_API void sk_path_transform(sk_path_t* cpath, const sk_matrix_t* cmatrix);
     Creates a copy of the path
 */
 SK_API sk_path_t* sk_path_clone(const sk_path_t* cpath);
+
+SK_API sk_path_iterator_t* sk_path_create_iter (sk_path_t *cpath, int forceClose);
+
+SK_API sk_path_verb_t sk_path_iter_next (sk_path_iterator_t *iterator, sk_point_t points [4], int doConsumeDegenerates, int exact);
+
+SK_API float sk_path_iter_conic_weight (sk_path_iterator_t *iterator);
+
+SK_API int sk_path_iter_is_close_line (sk_path_iterator_t *iterator);
+
+SK_API int sk_path_iter_is_closed_contour (sk_path_iterator_t *iterator);
+       
 SK_C_PLUS_PLUS_END_GUARD
 
 #endif
index 8d4e7f0f0b951786b68d84be8b4aaf6231755f51..e3a9c69ff58f5c675e89c76023fb4c089c75a1a2 100644 (file)
@@ -222,6 +222,19 @@ typedef enum {
     REPLACE_SK_REGION_OP,             //!< replace the dst region with the op region
 } sk_region_op_t;
 
+// The verbs that can be foudn on a path
+typedef enum {
+       MOVE_PATH_VERB,
+       LINE_PATH_VERB,
+       QUAD_PATH_VERB,
+       CONIC_PATH_VERB,
+       CUBIC_PATH_VERB,
+       CLOSE_PATH_VERB,
+       DONE_PATH_VERB
+} sk_path_verb_t;
+
+typedef struct sk_path_iterator_t sk_path_iterator_t;
+
 SK_C_PLUS_PLUS_END_GUARD
 
 #endif
diff --git a/src/c/xamarin/sk_x_matrix.cpp b/src/c/xamarin/sk_x_matrix.cpp
new file mode 100644 (file)
index 0000000..85c05f5
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2016 Xamarin Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkStream.h"
+
+#include "xamarin/sk_x_matrix.h"
+
+#include "../sk_types_priv.h"
+#include "sk_x_types_priv.h"
+
+int sk_matrix_try_invert (sk_matrix_t *matrix, sk_matrix_t *result)
+{
+       SkMatrix copy, inverse;
+       from_c (matrix, &copy);
+       if (copy.invert (&inverse)){
+               from_sk (&inverse, result);
+               return 1;
+       }
+       return 0;
+}
+
+void sk_matrix_concat (sk_matrix_t *matrix, sk_matrix_t *first, sk_matrix_t *second)
+{
+       SkMatrix target, skfirst, sksecond;
+
+       from_c (matrix, &target);
+       from_c (first, &skfirst);
+       from_c (second, &sksecond);
+       target.setConcat (skfirst, sksecond);
+       from_sk (&target, matrix);
+}
+
+void sk_matrix_pre_concat (sk_matrix_t *target, sk_matrix_t *matrix)
+{
+       SkMatrix sktarget, skmatrix;
+       from_c (target, &sktarget);
+       from_c (matrix, &skmatrix);
+       sktarget.preConcat (skmatrix);
+       from_sk (&sktarget, target);
+}
+
+void sk_matrix_post_concat (sk_matrix_t *target, sk_matrix_t *matrix)
+{
+       SkMatrix sktarget, skmatrix;
+       from_c (target, &sktarget);
+       from_c (matrix, &skmatrix);
+       sktarget.postConcat (skmatrix);
+       from_sk (&sktarget, target);
+}
+
+void sk_matrix_map_rect (sk_matrix_t *matrix, sk_rect_t *dest, sk_rect_t *source)
+{
+       SkMatrix skmatrix;
+       from_c (matrix, &skmatrix);
+       skmatrix.mapRect (AsRect (dest), *AsRect(source));
+}
+
+void sk_matrix_map_points (sk_matrix_t *matrix, sk_point_t *dst, sk_point_t *src, int count)
+{
+       SkMatrix skmatrix;
+       from_c (matrix, &skmatrix);
+       skmatrix.mapPoints (AsPoint (dst), AsPoint (src), count);
+}
+
+void sk_matrix_map_vectors (sk_matrix_t *matrix, sk_point_t *dst, sk_point_t *src, int count)
+{
+       SkMatrix skmatrix;
+       from_c (matrix, &skmatrix);
+       skmatrix.mapVectors (AsPoint (dst), AsPoint (src), count);
+}
+
+sk_point_t sk_matrix_map_xy (sk_matrix_t *matrix, float x, float y)
+{
+       SkMatrix skmatrix;
+       SkPoint result;
+       from_c (matrix, &skmatrix);
+       skmatrix.mapXY (x, y, &result);
+       return *ToPoint(&result);
+}
+
+sk_point_t sk_matrix_map_vector (sk_matrix_t *matrix, float x, float y)
+{
+       SkMatrix skmatrix;
+       SkPoint result;
+       from_c (matrix, &skmatrix);
+       skmatrix.mapVector (x, y, &result);
+       return *ToPoint(&result);
+}
+
+float sk_matrix_map_radius (sk_matrix_t *matrix, float radius)
+{
+       SkMatrix skmatrix;
+       from_c (matrix, &skmatrix);
+       return skmatrix.mapRadius (radius);
+}
+
index 93f6066ca2ded9ee2d34fabceebe159bab5bd4c9..c36d2d153108b96ff61b84109a6b604427f4d14d 100644 (file)
@@ -83,3 +83,42 @@ void sk_path_reset (sk_path_t* cpath)
 {
     as_path (cpath)->reset ();
 }
+
+sk_path_iterator_t* sk_path_create_iter (sk_path_t *cpath, int forceClose)
+{
+    SkPath::Iter* iter = new SkPath::Iter(AsPath(*cpath), forceClose);
+    return ToPathIter(iter);
+}
+
+#if __cplusplus >= 199711L
+static_assert (SkPath::kMove_Verb == MOVE_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t");
+static_assert (SkPath::kLine_Verb == LINE_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t");
+static_assert (SkPath::kQuad_Verb == QUAD_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t");
+static_assert (SkPath::kConic_Verb == CONIC_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t");
+static_assert (SkPath::kCubic_Verb == CUBIC_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t");
+static_assert (SkPath::kClose_Verb == CLOSE_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t");
+static_assert (SkPath::kDone_Verb == DONE_PATH_VERB, "ABI changed, you must write a enumeration mapper for SkPath::Verb to sk_path_verb_t");
+#endif
+
+sk_path_verb_t sk_path_iter_next (sk_path_iterator_t *iterator, sk_point_t points [4], int doConsumeDegenerates, int exact)
+{
+    SkPath::Iter *iter = AsPathIter(iterator);
+    SkPoint *pts = AsPoint(points);
+    SkPath::Verb verb = iter->next(pts, doConsumeDegenerates, exact);
+    return (sk_path_verb_t)verb;
+}
+
+float sk_path_iter_conic_weight (sk_path_iterator_t *iterator)
+{
+    return AsPathIter(iterator)->conicWeight ();
+}
+
+int sk_path_iter_is_close_line (sk_path_iterator_t *iterator)
+{
+    return AsPathIter(iterator)->isCloseLine ();
+}
+
+int sk_path_iter_is_closed_contour (sk_path_iterator_t *iterator)
+{
+    return AsPathIter(iterator)->isClosedContour ();
+}
index 8a2e0334e07921edb9a1d8a8e7f598441a8c1f74..f0ef81183d5a49331933879e0e1b744ec6d29a1c 100644 (file)
@@ -650,6 +650,14 @@ static inline const SkPoint* AsPoint(const sk_point_t* p) {
     return reinterpret_cast<const SkPoint*>(p);
 }
 
+static inline SkPoint* AsPoint(sk_point_t* p) {
+    return reinterpret_cast<SkPoint*>(p);
+}
+
+static inline sk_point_t* ToPoint(SkPoint *p) {
+    return reinterpret_cast<sk_point_t*>(p);
+}
+
 static inline const SkIPoint& AsIPoint(const sk_ipoint_t& p) {
     return reinterpret_cast<const SkIPoint&>(p);
 }
@@ -714,5 +722,11 @@ static inline sk_document_t* ToDocument(SkDocument* document) {
     return reinterpret_cast<sk_document_t*>(document);
 }
 
+static inline SkPath::Iter* AsPathIter(sk_path_iterator_t* iter) {
+    return reinterpret_cast<SkPath::Iter*>(iter);
+}
 
+static inline sk_path_iterator_t* ToPathIter(SkPath::Iter* iter) {
+    return reinterpret_cast<sk_path_iterator_t*>(iter);
+}
 #endif