mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
capi: dashed stroke setter and getter modyfied
tvg_shape_set_stroke_dash() and tvg_shape_get_stroke_dash() require an extra argument: offset
This commit is contained in:
parent
478e45f9f3
commit
8c0fc2b25a
4 changed files with 16 additions and 19 deletions
|
@ -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);
|
||||
|
||||
|
||||
/*!
|
||||
|
|
|
@ -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<Shape*>(paint)->stroke(dashPattern, cnt);
|
||||
return (Tvg_Result) reinterpret_cast<Shape*>(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<const Shape*>(paint)->strokeDash(dashPattern);
|
||||
if (!paint || !cnt || !dashPattern || !offset) return TVG_RESULT_INVALID_ARGUMENT;
|
||||
*cnt = reinterpret_cast<const Shape*>(paint)->strokeDash(dashPattern, offset);
|
||||
return TVG_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue