diff --git a/examples/Capi.cpp b/examples/Capi.cpp index b2936de6..0ca4afdc 100644 --- a/examples/Capi.cpp +++ b/examples/Capi.cpp @@ -149,7 +149,7 @@ void contents() tvg_shape_set_stroke_width(scene_shape1, 10.0f); tvg_shape_set_stroke_cap(scene_shape1, Tvg_Stroke_Cap::TVG_STROKE_CAP_ROUND); tvg_shape_set_stroke_join(scene_shape1, Tvg_Stroke_Join::TVG_STROKE_JOIN_ROUND); - tvg_shape_set_stroke_trim(scene_shape1, 0.25f, 0.75f, true); + tvg_shape_set_trimpath(scene_shape1, 0.25f, 0.75f, true); //Set circles with a dashed stroke Tvg_Paint* scene_shape2 = tvg_paint_duplicate(scene_shape1); diff --git a/examples/StrokeTrim.cpp b/examples/StrokeTrim.cpp index 956d48ec..11328006 100644 --- a/examples/StrokeTrim.cpp +++ b/examples/StrokeTrim.cpp @@ -43,7 +43,7 @@ struct UserExample : tvgexam::Example shape1->strokeJoin(tvg::StrokeJoin::Round); shape1->strokeCap(tvg::StrokeCap::Round); shape1->strokeWidth(12); - shape1->strokeTrim(0.25f, 0.75f, false); + shape1->trimpath(0.25f, 0.75f, false); auto shape2 = static_cast(shape1->duplicate()); shape2->translate(300, 300); @@ -52,7 +52,7 @@ struct UserExample : tvgexam::Example float dashPatterns[] = {10, 20}; shape2->strokeDash(dashPatterns, 2, 10); - shape2->strokeTrim(0.25f, 0.75f, true); + shape2->trimpath(0.25f, 0.75f, true); canvas->push(shape1); canvas->push(shape2); diff --git a/inc/thorvg.h b/inc/thorvg.h index 60879b66..a1618b81 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -1097,7 +1097,7 @@ public: Result strokeMiterlimit(float miterlimit) noexcept; /** - * @brief Sets the trim of the stroke along the defined path segment, allowing control over which part of the stroke is visible. + * @brief Sets the trim of the shape along the defined path segment, allowing control over which part of the shape is visible. * * If the values of the arguments @p begin and @p end exceed the 0-1 range, they are wrapped around in a manner similar to angle wrapping, effectively treating the range as circular. * @@ -1108,7 +1108,7 @@ public: * * @note Experimental API */ - Result strokeTrim(float begin, float end, bool simultaneous = true) noexcept; + Result trimpath(float begin, float end, bool simultaneous = true) noexcept; /** * @brief Sets the solid color for all of the figures from the path. diff --git a/src/bindings/capi/thorvg_capi.h b/src/bindings/capi/thorvg_capi.h index 5414aed4..17633b67 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -1413,7 +1413,7 @@ TVG_API Tvg_Result tvg_shape_get_stroke_miterlimit(const Tvg_Paint* paint, float /*! -* @brief Sets the trim of the stroke along the defined path segment, allowing control over which part of the stroke is visible. +* @brief Sets the trim of the shape along the defined path segment, allowing control over which part of the shape is visible. * * If the values of the arguments @p begin and @p end exceed the 0-1 range, they are wrapped around in a manner similar to angle wrapping, effectively treating the range as circular. * @@ -1428,7 +1428,7 @@ TVG_API Tvg_Result tvg_shape_get_stroke_miterlimit(const Tvg_Paint* paint, float * * @note Experimental API */ -TVG_API Tvg_Result tvg_shape_set_stroke_trim(Tvg_Paint* paint, float begin, float end, bool simultaneous); +TVG_API Tvg_Result tvg_shape_set_trimpath(Tvg_Paint* paint, float begin, float end, bool simultaneous); /*! diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index 986a472a..358bc4f3 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -478,10 +478,10 @@ TVG_API Tvg_Result tvg_shape_get_stroke_miterlimit(const Tvg_Paint* paint, float } -TVG_API Tvg_Result tvg_shape_set_stroke_trim(Tvg_Paint* paint, float begin, float end, bool simultaneous) +TVG_API Tvg_Result tvg_shape_set_trimpath(Tvg_Paint* paint, float begin, float end, bool simultaneous) { if (!paint) return TVG_RESULT_INVALID_ARGUMENT; - return (Tvg_Result) reinterpret_cast(paint)->strokeTrim(begin, end, simultaneous); + return (Tvg_Result) reinterpret_cast(paint)->trimpath(begin, end, simultaneous); } diff --git a/src/loaders/lottie/tvgLottieBuilder.cpp b/src/loaders/lottie/tvgLottieBuilder.cpp index 4fc81527..6416c307 100644 --- a/src/loaders/lottie/tvgLottieBuilder.cpp +++ b/src/loaders/lottie/tvgLottieBuilder.cpp @@ -764,7 +764,7 @@ void LottieBuilder::updateTrimpath(TVG_UNUSED LottieGroup* parent, LottieObject* end = (length * end) + pbegin; } - ctx->propagator->strokeTrim(begin, end, trimpath->type == LottieTrimpath::Type::Simultaneous); + ctx->propagator->trimpath(begin, end, trimpath->type == LottieTrimpath::Type::Simultaneous); ctx->merging = nullptr; } @@ -1257,7 +1257,7 @@ void LottieBuilder::updateStrokeEffect(LottieLayer* layer, LottieFxStroke* effec } shape->transform(layer->cache.matrix); - shape->strokeTrim(effect->begin(frameNo) * 0.01f, effect->end(frameNo) * 0.01f); + shape->trimpath(effect->begin(frameNo) * 0.01f, effect->end(frameNo) * 0.01f); shape->strokeFill(255, 255, 255, (int)(effect->opacity(frameNo) * 255.0f)); shape->strokeJoin(StrokeJoin::Round); shape->strokeCap(StrokeCap::Round); diff --git a/src/renderer/gl_engine/tvgGlTessellator.cpp b/src/renderer/gl_engine/tvgGlTessellator.cpp index 1f624d47..48527aaf 100644 --- a/src/renderer/gl_engine/tvgGlTessellator.cpp +++ b/src/renderer/gl_engine/tvgGlTessellator.cpp @@ -1544,7 +1544,7 @@ void Stroker::stroke(const RenderShape *rshape) Point *pts, *trimmedPts = nullptr; uint32_t cmdCnt = 0, ptsCnt = 0; - if (rshape->strokeTrim()) { + if (rshape->trimpath()) { RenderPath trimmedPath; if (!rshape->stroke->trim.trim(rshape->path, trimmedPath)) return; diff --git a/src/renderer/sw_engine/tvgSwRenderer.cpp b/src/renderer/sw_engine/tvgSwRenderer.cpp index b1a8cac8..0e915114 100644 --- a/src/renderer/sw_engine/tvgSwRenderer.cpp +++ b/src/renderer/sw_engine/tvgSwRenderer.cpp @@ -85,7 +85,7 @@ struct SwShapeTask : SwTask Additionally, the stroke style should not be dashed. */ bool antialiasing(float strokeWidth) { - return strokeWidth < 2.0f || rshape->stroke->dashCnt > 0 || rshape->stroke->strokeFirst || rshape->strokeTrim() || rshape->stroke->color.a < 255; + return strokeWidth < 2.0f || rshape->stroke->dashCnt > 0 || rshape->stroke->strokeFirst || rshape->trimpath() || rshape->stroke->color.a < 255; } float validStrokeWidth(bool clipper) diff --git a/src/renderer/sw_engine/tvgSwShape.cpp b/src/renderer/sw_engine/tvgSwShape.cpp index e57e75ec..b3f4edc9 100644 --- a/src/renderer/sw_engine/tvgSwShape.cpp +++ b/src/renderer/sw_engine/tvgSwShape.cpp @@ -510,7 +510,7 @@ bool shapeGenStrokeRle(SwShape* shape, const RenderShape* rshape, const Matrix& auto ret = true; //Dash style with/without trimming - auto trimmed = rshape->strokeTrim(); + auto trimmed = rshape->trimpath(); if (rshape->stroke->dashCnt > 0) { shapeOutline = _genDashOutline(rshape, transform, mpool, tid, trimmed); if (!shapeOutline) return false; diff --git a/src/renderer/tvgRender.h b/src/renderer/tvgRender.h index c826b3c9..9c15b253 100644 --- a/src/renderer/tvgRender.h +++ b/src/renderer/tvgRender.h @@ -175,18 +175,18 @@ struct RenderShape if (a) *a = color.a; } + bool trimpath() const + { + if (!stroke) return false; + return stroke->trim.valid(); + } + float strokeWidth() const { if (!stroke) return 0; return stroke->width; } - bool strokeTrim() const - { - if (!stroke) return false; - return stroke->trim.valid(); - } - bool strokeFill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const { if (!stroke) return false; diff --git a/src/renderer/tvgShape.cpp b/src/renderer/tvgShape.cpp index de0a3dc9..e82cd80d 100644 --- a/src/renderer/tvgShape.cpp +++ b/src/renderer/tvgShape.cpp @@ -231,9 +231,9 @@ float Shape::strokeMiterlimit() const noexcept } -Result Shape::strokeTrim(float begin, float end, bool simultaneous) noexcept +Result Shape::trimpath(float begin, float end, bool simultaneous) noexcept { - SHAPE(this)->strokeTrim(begin, end, simultaneous); + SHAPE(this)->trimpath({begin, end, simultaneous}); return Result::Success; } diff --git a/src/renderer/tvgShape.h b/src/renderer/tvgShape.h index b581f82b..40511eee 100644 --- a/src/renderer/tvgShape.h +++ b/src/renderer/tvgShape.h @@ -209,25 +209,20 @@ struct Shape::Impl : Paint::Impl renderFlag |= RenderUpdateFlag::Stroke; } - void strokeTrim(float begin, float end, bool simultaneous) + void trimpath(const TrimPath& trim) { - //Even if there is no trimming effect, begin can still affect dashing starting point - if (fabsf(end - begin) >= 1.0f) end = begin + 1.0f; - if (!rs.stroke) { - if (begin == 0.0f && end == 1.0f) return; + if (trim.begin == 0.0f && trim.end == 1.0f) return; rs.stroke = new RenderStroke(); } - if (tvg::equal(rs.stroke->trim.begin, begin) && tvg::equal(rs.stroke->trim.end, end) && rs.stroke->trim.simultaneous == simultaneous) return; + if (tvg::equal(rs.stroke->trim.begin, trim.begin) && tvg::equal(rs.stroke->trim.end, trim.end) && rs.stroke->trim.simultaneous == trim.simultaneous) return; - rs.stroke->trim.begin = begin; - rs.stroke->trim.end = end; - rs.stroke->trim.simultaneous = simultaneous; - renderFlag |= RenderUpdateFlag::Stroke; + rs.stroke->trim = trim; + renderFlag |= RenderUpdateFlag::Path; } - bool strokeTrim(float* begin, float* end) + bool trimpath(float* begin, float* end) { if (rs.stroke) { if (begin) *begin = rs.stroke->trim.begin; diff --git a/src/renderer/wg_engine/tvgWgRenderData.cpp b/src/renderer/wg_engine/tvgWgRenderData.cpp index 7fbb054a..9cbdcaa1 100755 --- a/src/renderer/wg_engine/tvgWgRenderData.cpp +++ b/src/renderer/wg_engine/tvgWgRenderData.cpp @@ -374,7 +374,7 @@ void WgRenderDataShape::updateMeshes(WgContext& context, const RenderShape &rsha // path decoded vertex buffer auto pbuff = pool->reqVertexBuffer(scale); - if (rshape.strokeTrim()) { + if (rshape.trimpath()) { auto trimbuff = pool->reqVertexBuffer(scale); pbuff->decodePath(rshape, true, [&](const WgVertexBuffer& path_buff) { appendShape(context, path_buff); diff --git a/test/testShape.cpp b/test/testShape.cpp index 7d67f642..6361a1f7 100644 --- a/test/testShape.cpp +++ b/test/testShape.cpp @@ -196,7 +196,7 @@ TEST_CASE("Stroking", "[tvgShape]") REQUIRE(shape->strokeMiterlimit() == 1000.0f); REQUIRE(shape->strokeMiterlimit(-0.001f) == Result::InvalidArguments); - REQUIRE(shape->strokeTrim(0.3f, 0.88f, false) == Result::Success); + REQUIRE(shape->trimpath(0.3f, 0.88f, false) == Result::Success); //Stroke Order After Stroke Setting REQUIRE(shape->order(true) == Result::Success);