diff --git a/include/c/sk_matrix.h b/include/c/sk_matrix.h index c97783826c64..6913fc1b65a7 100644 --- a/include/c/sk_matrix.h +++ b/include/c/sk_matrix.h @@ -25,6 +25,41 @@ SK_C_API void sk_matrix_map_vectors (sk_matrix_t *matrix, sk_point_t *dst, sk_po SK_C_API void sk_matrix_map_xy (sk_matrix_t *matrix, float x, float y, sk_point_t* result); SK_C_API void sk_matrix_map_vector (sk_matrix_t *matrix, float x, float y, sk_point_t* result); SK_C_API float sk_matrix_map_radius (sk_matrix_t *matrix, float radius); +// additional +SK_C_API sk_matrix_t sk_matrix_scale(float sx, float sy); +SK_C_API sk_matrix_t sk_matrix_translate(float dx, float dy); +SK_C_API sk_matrix_t sk_matrix_translate_point(sk_point_t t); +SK_C_API sk_matrix_t sk_matrix_translate_ipoint(sk_ipoint_t t); +SK_C_API sk_matrix_t sk_matrix_rotate_deg(float deg); +SK_C_API sk_matrix_t sk_matrix_rotate_deg_point(float deg, sk_point_t t); +SK_C_API sk_matrix_t sk_matrix_rotate_rad(float rad); +SK_C_API sk_matrix_type_mask_t sk_matrix_get_type(sk_matrix_t* matrix); +SK_C_API bool sk_matrix_is_identity(sk_matrix_t* matrix); +SK_C_API bool sk_matrix_is_scale_translate(sk_matrix_t* matrix); +SK_C_API bool sk_matrix_is_translate(sk_matrix_t* matrix); +SK_C_API bool sk_matrix_rect_stays_rect(sk_matrix_t* matrix); +SK_C_API bool sk_matrix_preserves_axis_alignment(sk_matrix_t* matrix); +SK_C_API bool sk_matrix_has_perspective(sk_matrix_t* matrix); +SK_C_API bool sk_matrix_is_similarity(sk_matrix_t* matrix, float tol); +SK_C_API bool sk_matrix_preserves_right_angles(sk_matrix_t* matrix, float tol); +SK_C_API float sk_matrix_get(sk_matrix_t* matrix, sk_matrix_row_major_mask_t mask); +SK_C_API float sk_matrix_rc(sk_matrix_t* matrix, int r, int c); +SK_C_API void sk_matrix_get9(sk_matrix_t* matrix, float* buffer); +SK_C_API void sk_matrix_set9(sk_matrix_t* matrix, float* buffer, sk_matrix_t* result); +SK_C_API void sk_matrix_reset(sk_matrix_t* matrix, sk_matrix_t* result); +SK_C_API void sk_matrix_set_identity(sk_matrix_t* matrix, sk_matrix_t* result); +SK_C_API void sk_matrix_normalize_perspective(sk_matrix_t* matrix, sk_matrix_t* result); +SK_C_API void sk_matrix_map_homogeneous_points3(sk_matrix_t* matrix, sk_point3_t* dst, sk_point3_t* src, int count); +SK_C_API void sk_matrix_map_homogeneous_points(sk_matrix_t* matrix, sk_point3_t* dst, sk_point_t* src, int count); +SK_C_API bool sk_matrix_is_finite(sk_matrix_t* matrix); +SK_C_API void sk_matrix_pre_scale(sk_matrix_t* result, sk_matrix_t* matrix, float sx, float sy); +SK_C_API void sk_matrix_pre_scale_with_pivot(sk_matrix_t* result, sk_matrix_t* matrix, float sx, float sy, float px, float py); +SK_C_API void sk_matrix_post_scale(sk_matrix_t* result, sk_matrix_t* matrix, float sx, float sy); +SK_C_API void sk_matrix_post_scale_with_pivot(sk_matrix_t* result, sk_matrix_t* matrix, float sx, float sy, float px, float py); +SK_C_API void sk_matrix_pre_translate(sk_matrix_t* result, sk_matrix_t* matrix, float dx, float dy); +SK_C_API void sk_matrix_post_translate(sk_matrix_t* result, sk_matrix_t* matrix, float dx, float dy); +SK_C_API bool sk_matrix_set_rect_to_rect(sk_matrix_t* matrix, sk_matrix_t* result, sk_rect_t* dest, sk_rect_t* source, sk_matrix_scale_to_fit_t stf); + SK_C_API sk_3dview_t* sk_3dview_new (void); diff --git a/include/c/sk_types.h b/include/c/sk_types.h index 289ecaee92ee..71e0677cd45b 100644 --- a/include/c/sk_types.h +++ b/include/c/sk_types.h @@ -178,6 +178,42 @@ typedef enum { PERSPECTIVE_SK_MATRIX44_TYPE_MASK = 0x08 } sk_matrix44_type_mask_t; +typedef enum { + IDENTITY_SK_MATRIX_TYPE_MASK = 0, + TRANSLATE_SK_MATRIX_TYPE_MASK = 0x01, + SCALE_SK_MATRIX_TYPE_MASK = 0x02, + AFFINE_SK_MATRIX_TYPE_MASK = 0x04, + PERSPECTIVE_SK_MATRIX_TYPE_MASK = 0x08 +} sk_matrix_type_mask_t; + +typedef enum { + ScaleX = 0, //!< horizontal scale factor + SkewX = 1, //!< horizontal skew factor + TransX = 2, //!< horizontal translation + SkewY = 3, //!< vertical skew factor + ScaleY = 4, //!< vertical scale factor + TransY = 5, //!< vertical translation + Persp0 = 6, //!< input x perspective factor + Persp1 = 7, //!< input y perspective factor + Persp2 = 8 //!< perspective bias +} sk_matrix_row_major_mask_t; + +typedef enum { + AScaleX = 0, //!< horizontal scale factor + ASkewY = 1, //!< vertical skew factor + ASkewX = 2, //!< horizontal skew factor + AScaleY = 3, //!< vertical scale factor + ATransX = 4, //!< horizontal translation + ATransY = 5, //!< vertical translation +} sk_matrix_affine_colomn_major_mask_t; + +typedef enum { + Fill, //!< scales in x and y to fill destination SkRect + Start, //!< scales and aligns to left and top + Center, //!< scales and aligns to center + End, //!< scales and aligns to right and bottom +} sk_matrix_scale_to_fit_t; + /** A sk_canvas_t encapsulates all of the state about drawing into a destination This includes a reference to the destination itself, diff --git a/src/c/sk_matrix.cpp b/src/c/sk_matrix.cpp index aa28b845675c..4f2795943b94 100644 --- a/src/c/sk_matrix.cpp +++ b/src/c/sk_matrix.cpp @@ -72,6 +72,132 @@ float sk_matrix_map_radius(sk_matrix_t *matrix, float radius) { return AsMatrix(matrix).mapRadius(radius); } +// additional +sk_matrix_t sk_matrix_scale(float sx, float sy) { + return ToMatrix(SkMatrix::Scale(sx, sy)); +} +sk_matrix_t sk_matrix_translate(float dx, float dy) { + return ToMatrix(SkMatrix::Translate(dx, dy)); +} +sk_matrix_t sk_matrix_translate_point(sk_point_t t) { + return ToMatrix(SkMatrix::Translate(AsPoint(t))); +} +sk_matrix_t sk_matrix_translate_ipoint(sk_ipoint_t t) { + return ToMatrix(SkMatrix::Translate(AsIPoint(t))); +} +sk_matrix_t sk_matrix_rotate_deg(float deg) { + return ToMatrix(SkMatrix::RotateDeg(deg)); +} +sk_matrix_t sk_matrix_rotate_deg_point(float deg, sk_point_t t) { + return ToMatrix(SkMatrix::RotateDeg(deg, AsPoint(t))); +} +sk_matrix_t sk_matrix_rotate_rad(float rad) { + return ToMatrix(SkMatrix::RotateRad(rad)); +} +sk_matrix_type_mask_t sk_matrix_get_type(sk_matrix_t* matrix) { + return (sk_matrix_type_mask_t)AsMatrix(matrix).getType(); // calls ComputeTypeMask +} +bool sk_matrix_is_identity(sk_matrix_t* matrix) { + return AsMatrix(matrix).isIdentity(); // calls getType() +} +bool sk_matrix_is_scale_translate(sk_matrix_t* matrix) { + return AsMatrix(matrix).isScaleTranslate(); // calls getType() +} +bool sk_matrix_is_translate(sk_matrix_t* matrix) { + return AsMatrix(matrix).isTranslate(); // calls getType() +} +bool sk_matrix_rect_stays_rect(sk_matrix_t* matrix) { + return AsMatrix(matrix).rectStaysRect(); // calls getType() +} +bool sk_matrix_preserves_axis_alignment(sk_matrix_t* matrix) { + return AsMatrix(matrix).preservesAxisAlignment(); +} +bool sk_matrix_has_perspective(sk_matrix_t* matrix) { + return AsMatrix(matrix).hasPerspective(); // calls getType() +} +bool sk_matrix_is_similarity(sk_matrix_t* matrix, float tol) { + return AsMatrix(matrix).isSimilarity(tol); +} +bool sk_matrix_preserves_right_angles(sk_matrix_t* matrix, float tol) { + return AsMatrix(matrix).preservesRightAngles(tol); +} +float sk_matrix_get(sk_matrix_t* matrix, sk_matrix_row_major_mask_t mask) { + return AsMatrix(matrix).get(mask); +} +float sk_matrix_rc(sk_matrix_t* matrix, int r, int c) { + return AsMatrix(matrix).rc(r, c); +} +void sk_matrix_get9(sk_matrix_t* matrix, float* buffer) { + return AsMatrix(matrix).get9(buffer); +} +void sk_matrix_set9(sk_matrix_t* matrix, float* buffer, sk_matrix_t* result) { + SkMatrix m = AsMatrix(matrix); + m.set9(buffer); + *result = ToMatrix(&m); +} +void sk_matrix_reset(sk_matrix_t* matrix, sk_matrix_t* result) { + SkMatrix m = AsMatrix(matrix); + m.reset(); + *result = ToMatrix(&m); +} +void sk_matrix_set_identity(sk_matrix_t* matrix, sk_matrix_t* result) { + SkMatrix m = AsMatrix(matrix); + m.setIdentity(); + *result = ToMatrix(&m); +} +void sk_matrix_normalize_perspective(sk_matrix_t* matrix, sk_matrix_t* result) { + SkMatrix m = AsMatrix(matrix); + m.normalizePerspective(); + *result = ToMatrix(&m); +} +void sk_matrix_map_homogeneous_points3(sk_matrix_t* matrix, sk_point3_t* dst, sk_point3_t* src, int count) { + AsMatrix(matrix).mapHomogeneousPoints(AsPoint3(dst), AsPoint3(src), count); +} +void sk_matrix_map_homogeneous_points(sk_matrix_t* matrix, sk_point3_t* dst, sk_point_t* src, int count) { + AsMatrix(matrix).mapHomogeneousPoints(AsPoint3(dst), AsPoint(src), count); +} +bool sk_matrix_is_finite(sk_matrix_t* matrix) { + return AsMatrix(matrix).isFinite(); +} +void sk_matrix_pre_scale(sk_matrix_t* result, sk_matrix_t* matrix, float sx, float sy) { + SkMatrix m = AsMatrix(matrix); + m.preScale(sx, sy); + *result = ToMatrix(&m); +} +void sk_matrix_pre_scale_with_pivot(sk_matrix_t* result, sk_matrix_t* matrix, float sx, float sy, float px, float py) { + SkMatrix m = AsMatrix(matrix); + m.preScale(sx, sy, px, py); + *result = ToMatrix(&m); +} +void sk_matrix_post_scale(sk_matrix_t* result, sk_matrix_t* matrix, float sx, float sy) { + SkMatrix m = AsMatrix(matrix); + m.postScale(sx, sy); + *result = ToMatrix(&m); +} +void sk_matrix_post_scale_with_pivot(sk_matrix_t* result, sk_matrix_t* matrix, float sx, float sy, float px, float py) { + SkMatrix m = AsMatrix(matrix); + m.postScale(sx, sy, px, py); + *result = ToMatrix(&m); +} +void sk_matrix_pre_translate(sk_matrix_t* result, sk_matrix_t* matrix, float dx, float dy) { + SkMatrix m = AsMatrix(matrix); + m.preTranslate(dx, dy); + *result = ToMatrix(&m); +} +void sk_matrix_post_translate(sk_matrix_t* result, sk_matrix_t* matrix, float dx, float dy) { + SkMatrix m = AsMatrix(matrix); + m.postTranslate(dx, dy); + *result = ToMatrix(&m); +} +bool sk_matrix_set_rect_to_rect(sk_matrix_t* matrix, sk_matrix_t* result, sk_rect_t* dest, sk_rect_t* source, sk_matrix_scale_to_fit_t stf) { + SkMatrix m = AsMatrix(matrix); + bool r = m.setRectToRect(*AsRect(source), *AsRect(dest), (SkMatrix::ScaleToFit)stf); + *result = ToMatrix(&m); + return r; +} + + + // 3d view sk_3dview_t* sk_3dview_new(void) {