From 8c0fc2b25a1d804d8c2ea32fc8046eeafc0f7dcd Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Fri, 18 Aug 2023 23:43:15 +0200 Subject: [PATCH] capi: dashed stroke setter and getter modyfied tvg_shape_set_stroke_dash() and tvg_shape_get_stroke_dash() require an extra argument: offset --- src/bindings/capi/thorvg_capi.h | 17 ++++++----------- src/bindings/capi/tvgCapi.cpp | 10 +++++----- src/examples/Capi.cpp | 2 +- test/capi/capiShape.cpp | 6 ++++-- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/bindings/capi/thorvg_capi.h b/src/bindings/capi/thorvg_capi.h index cf648ede..acd84ccb 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -1316,18 +1316,12 @@ TVG_API Tvg_Result tvg_shape_get_stroke_gradient(const Tvg_Paint* paint, Tvg_Gra /*! -* \brief Sets the shape's stroke dash pattern. -* -* \code -* //dash pattern examples -* float dashPattern[2] = {20, 10}; // -- -- -- -* float dashPattern[2] = {40, 20}; // ---- ---- ---- -* float dashPattern[4] = {10, 20, 30, 40} // - --- - --- -* \endcode +* \brief Sets the shape's stroke dash pattern. (BETA_API) * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] dashPattern The array of consecutive pair values of the dash length and the gap length. * \param[in] cnt The size of the @p dashPattern array. +* \param[in] offset The shift of the starting point within the repeating dash pattern from which the path's dashing begins. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. @@ -1336,23 +1330,24 @@ TVG_API Tvg_Result tvg_shape_get_stroke_gradient(const Tvg_Paint* paint, Tvg_Gra * * \note To reset the stroke dash pattern, pass @c nullptr to @p dashPattern and zero to @p cnt. */ -TVG_API Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt); +TVG_API Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt, float offset); /*! -* \brief Gets the dash pattern of the stroke. +* \brief Gets the dash pattern of the stroke. (BETA_API) * * The function does not allocate any memory. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[out] dashPattern The array of consecutive pair values of the dash length and the gap length. * \param[out] cnt The size of the @p dashPattern array. +* \param[out] offset The shift of the starting point within the repeating dash pattern. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. */ -TVG_API Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt); +TVG_API Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt, float* offset); /*! diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index 9d821bf9..3db0e1ef 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -367,17 +367,17 @@ TVG_API Tvg_Result tvg_shape_get_stroke_gradient(const Tvg_Paint* paint, Tvg_Gra } -TVG_API Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt) +TVG_API Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt, float offset) { if (!paint) return TVG_RESULT_INVALID_ARGUMENT; - return (Tvg_Result) reinterpret_cast(paint)->stroke(dashPattern, cnt); + return (Tvg_Result) reinterpret_cast(paint)->stroke(dashPattern, cnt, offset); } -TVG_API Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt) +TVG_API Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt, float* offset) { - if (!paint || !cnt || !dashPattern) return TVG_RESULT_INVALID_ARGUMENT; - *cnt = reinterpret_cast(paint)->strokeDash(dashPattern); + if (!paint || !cnt || !dashPattern || !offset) return TVG_RESULT_INVALID_ARGUMENT; + *cnt = reinterpret_cast(paint)->strokeDash(dashPattern, offset); return TVG_RESULT_SUCCESS; } diff --git a/src/examples/Capi.cpp b/src/examples/Capi.cpp index 1a0167f9..cbddabf5 100644 --- a/src/examples/Capi.cpp +++ b/src/examples/Capi.cpp @@ -159,7 +159,7 @@ void testCapi() //Prapare a dash for the stroke float dashPattern[4] = {15.0f, 30.0f, 2.0f, 30.0f}; - tvg_shape_set_stroke_dash(scene_shape2, dashPattern, 4); + tvg_shape_set_stroke_dash(scene_shape2, dashPattern, 4, 0.0f); tvg_shape_set_stroke_cap(scene_shape2, TVG_STROKE_CAP_ROUND); tvg_shape_set_stroke_color(scene_shape2, 0, 0, 255, 255); tvg_shape_set_stroke_width(scene_shape2, 15.0f); diff --git a/test/capi/capiShape.cpp b/test/capi/capiShape.cpp index a9c2c1c6..cf64997c 100644 --- a/test/capi/capiShape.cpp +++ b/test/capi/capiShape.cpp @@ -189,13 +189,15 @@ TEST_CASE("Stroke dash", "[capiStrokeDash]") float dash[2] = {20, 10}; float* dash_get; uint32_t cnt; + float offset; - REQUIRE(tvg_shape_set_stroke_dash(paint, dash, 2) == TVG_RESULT_SUCCESS); - REQUIRE(tvg_shape_get_stroke_dash(paint, (const float**) &dash_get, &cnt) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_set_stroke_dash(paint, dash, 2, 4.5f) == TVG_RESULT_SUCCESS); + REQUIRE(tvg_shape_get_stroke_dash(paint, (const float**) &dash_get, &cnt, &offset) == TVG_RESULT_SUCCESS); REQUIRE(cnt == 2); for (uint32_t i = 0; i < cnt; i++) { REQUIRE(dash_get[i] == dash[i]); } + REQUIRE(offset == 4.5f); REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS); }