mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
api: change api name strokeTrim() -> trimpath()
No changes in behaviour so far.
This commit is contained in:
parent
02678b67f4
commit
b939a60bfa
14 changed files with 30 additions and 35 deletions
|
@ -149,7 +149,7 @@ void contents()
|
||||||
tvg_shape_set_stroke_width(scene_shape1, 10.0f);
|
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_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_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
|
//Set circles with a dashed stroke
|
||||||
Tvg_Paint* scene_shape2 = tvg_paint_duplicate(scene_shape1);
|
Tvg_Paint* scene_shape2 = tvg_paint_duplicate(scene_shape1);
|
||||||
|
|
|
@ -43,7 +43,7 @@ struct UserExample : tvgexam::Example
|
||||||
shape1->strokeJoin(tvg::StrokeJoin::Round);
|
shape1->strokeJoin(tvg::StrokeJoin::Round);
|
||||||
shape1->strokeCap(tvg::StrokeCap::Round);
|
shape1->strokeCap(tvg::StrokeCap::Round);
|
||||||
shape1->strokeWidth(12);
|
shape1->strokeWidth(12);
|
||||||
shape1->strokeTrim(0.25f, 0.75f, false);
|
shape1->trimpath(0.25f, 0.75f, false);
|
||||||
|
|
||||||
auto shape2 = static_cast<tvg::Shape*>(shape1->duplicate());
|
auto shape2 = static_cast<tvg::Shape*>(shape1->duplicate());
|
||||||
shape2->translate(300, 300);
|
shape2->translate(300, 300);
|
||||||
|
@ -52,7 +52,7 @@ struct UserExample : tvgexam::Example
|
||||||
|
|
||||||
float dashPatterns[] = {10, 20};
|
float dashPatterns[] = {10, 20};
|
||||||
shape2->strokeDash(dashPatterns, 2, 10);
|
shape2->strokeDash(dashPatterns, 2, 10);
|
||||||
shape2->strokeTrim(0.25f, 0.75f, true);
|
shape2->trimpath(0.25f, 0.75f, true);
|
||||||
|
|
||||||
canvas->push(shape1);
|
canvas->push(shape1);
|
||||||
canvas->push(shape2);
|
canvas->push(shape2);
|
||||||
|
|
|
@ -1097,7 +1097,7 @@ public:
|
||||||
Result strokeMiterlimit(float miterlimit) noexcept;
|
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.
|
* 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
|
* @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.
|
* @brief Sets the solid color for all of the figures from the path.
|
||||||
|
|
|
@ -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.
|
* 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
|
* @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);
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -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;
|
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
|
||||||
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->strokeTrim(begin, end, simultaneous);
|
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->trimpath(begin, end, simultaneous);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -764,7 +764,7 @@ void LottieBuilder::updateTrimpath(TVG_UNUSED LottieGroup* parent, LottieObject*
|
||||||
end = (length * end) + pbegin;
|
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;
|
ctx->merging = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1257,7 +1257,7 @@ void LottieBuilder::updateStrokeEffect(LottieLayer* layer, LottieFxStroke* effec
|
||||||
}
|
}
|
||||||
|
|
||||||
shape->transform(layer->cache.matrix);
|
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->strokeFill(255, 255, 255, (int)(effect->opacity(frameNo) * 255.0f));
|
||||||
shape->strokeJoin(StrokeJoin::Round);
|
shape->strokeJoin(StrokeJoin::Round);
|
||||||
shape->strokeCap(StrokeCap::Round);
|
shape->strokeCap(StrokeCap::Round);
|
||||||
|
|
|
@ -1544,7 +1544,7 @@ void Stroker::stroke(const RenderShape *rshape)
|
||||||
Point *pts, *trimmedPts = nullptr;
|
Point *pts, *trimmedPts = nullptr;
|
||||||
uint32_t cmdCnt = 0, ptsCnt = 0;
|
uint32_t cmdCnt = 0, ptsCnt = 0;
|
||||||
|
|
||||||
if (rshape->strokeTrim()) {
|
if (rshape->trimpath()) {
|
||||||
RenderPath trimmedPath;
|
RenderPath trimmedPath;
|
||||||
if (!rshape->stroke->trim.trim(rshape->path, trimmedPath)) return;
|
if (!rshape->stroke->trim.trim(rshape->path, trimmedPath)) return;
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ struct SwShapeTask : SwTask
|
||||||
Additionally, the stroke style should not be dashed. */
|
Additionally, the stroke style should not be dashed. */
|
||||||
bool antialiasing(float strokeWidth)
|
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)
|
float validStrokeWidth(bool clipper)
|
||||||
|
|
|
@ -510,7 +510,7 @@ bool shapeGenStrokeRle(SwShape* shape, const RenderShape* rshape, const Matrix&
|
||||||
auto ret = true;
|
auto ret = true;
|
||||||
|
|
||||||
//Dash style with/without trimming
|
//Dash style with/without trimming
|
||||||
auto trimmed = rshape->strokeTrim();
|
auto trimmed = rshape->trimpath();
|
||||||
if (rshape->stroke->dashCnt > 0) {
|
if (rshape->stroke->dashCnt > 0) {
|
||||||
shapeOutline = _genDashOutline(rshape, transform, mpool, tid, trimmed);
|
shapeOutline = _genDashOutline(rshape, transform, mpool, tid, trimmed);
|
||||||
if (!shapeOutline) return false;
|
if (!shapeOutline) return false;
|
||||||
|
|
|
@ -175,18 +175,18 @@ struct RenderShape
|
||||||
if (a) *a = color.a;
|
if (a) *a = color.a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool trimpath() const
|
||||||
|
{
|
||||||
|
if (!stroke) return false;
|
||||||
|
return stroke->trim.valid();
|
||||||
|
}
|
||||||
|
|
||||||
float strokeWidth() const
|
float strokeWidth() const
|
||||||
{
|
{
|
||||||
if (!stroke) return 0;
|
if (!stroke) return 0;
|
||||||
return stroke->width;
|
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
|
bool strokeFill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const
|
||||||
{
|
{
|
||||||
if (!stroke) return false;
|
if (!stroke) return false;
|
||||||
|
|
|
@ -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;
|
return Result::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,25 +209,20 @@ struct Shape::Impl : Paint::Impl
|
||||||
renderFlag |= RenderUpdateFlag::Stroke;
|
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 (!rs.stroke) {
|
||||||
if (begin == 0.0f && end == 1.0f) return;
|
if (trim.begin == 0.0f && trim.end == 1.0f) return;
|
||||||
rs.stroke = new RenderStroke();
|
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 = trim;
|
||||||
rs.stroke->trim.end = end;
|
renderFlag |= RenderUpdateFlag::Path;
|
||||||
rs.stroke->trim.simultaneous = simultaneous;
|
|
||||||
renderFlag |= RenderUpdateFlag::Stroke;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool strokeTrim(float* begin, float* end)
|
bool trimpath(float* begin, float* end)
|
||||||
{
|
{
|
||||||
if (rs.stroke) {
|
if (rs.stroke) {
|
||||||
if (begin) *begin = rs.stroke->trim.begin;
|
if (begin) *begin = rs.stroke->trim.begin;
|
||||||
|
|
|
@ -374,7 +374,7 @@ void WgRenderDataShape::updateMeshes(WgContext& context, const RenderShape &rsha
|
||||||
// path decoded vertex buffer
|
// path decoded vertex buffer
|
||||||
auto pbuff = pool->reqVertexBuffer(scale);
|
auto pbuff = pool->reqVertexBuffer(scale);
|
||||||
|
|
||||||
if (rshape.strokeTrim()) {
|
if (rshape.trimpath()) {
|
||||||
auto trimbuff = pool->reqVertexBuffer(scale);
|
auto trimbuff = pool->reqVertexBuffer(scale);
|
||||||
pbuff->decodePath(rshape, true, [&](const WgVertexBuffer& path_buff) {
|
pbuff->decodePath(rshape, true, [&](const WgVertexBuffer& path_buff) {
|
||||||
appendShape(context, path_buff);
|
appendShape(context, path_buff);
|
||||||
|
|
|
@ -196,7 +196,7 @@ TEST_CASE("Stroking", "[tvgShape]")
|
||||||
REQUIRE(shape->strokeMiterlimit() == 1000.0f);
|
REQUIRE(shape->strokeMiterlimit() == 1000.0f);
|
||||||
REQUIRE(shape->strokeMiterlimit(-0.001f) == Result::InvalidArguments);
|
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
|
//Stroke Order After Stroke Setting
|
||||||
REQUIRE(shape->order(true) == Result::Success);
|
REQUIRE(shape->order(true) == Result::Success);
|
||||||
|
|
Loading…
Add table
Reference in a new issue