From 0f9e10299e20dbcc718008578dcf9040ca947dbb Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Thu, 12 Jun 2025 00:47:21 +0200 Subject: [PATCH] lottie: enhance rounded corners modifier Added support for LineTo path commands in the rounding corners modifier algorithm. This is necessary to allow other modifiers to be applied before rounding, as previously only CubicTo segments from the original lottie data were handled. --- src/loaders/lottie/tvgLottieModifier.cpp | 33 +++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/loaders/lottie/tvgLottieModifier.cpp b/src/loaders/lottie/tvgLottieModifier.cpp index ecbfa67a..e9a54682 100644 --- a/src/loaders/lottie/tvgLottieModifier.cpp +++ b/src/loaders/lottie/tvgLottieModifier.cpp @@ -205,7 +205,13 @@ bool LottieRoundnessModifier::modifyPath(PathCommand* inCmds, uint32_t inCmdsCnt _roundCorner(path.cmds, path.pts, prev, curr, inPts[iPts + 5], r); iPts += 3; break; - } else if (inCmds[iCmds + 1] == PathCommand::Close) { + } + if (inCmds[iCmds + 1] == PathCommand::LineTo) { + _roundCorner(path.cmds, path.pts, prev, curr, inPts[iPts + 3], r); + iPts += 3; + break; + } + if (inCmds[iCmds + 1] == PathCommand::Close) { _roundCorner(path.cmds, path.pts, prev, curr, inPts[2], r); path.pts[startIndex] = path.pts.last(); iPts += 3; @@ -218,6 +224,31 @@ bool LottieRoundnessModifier::modifyPath(PathCommand* inCmds, uint32_t inCmdsCnt path.pts.push(inPts[iPts++]); break; } + case PathCommand::LineTo: { + if (iCmds < inCmdsCnt - 1) { + auto& prev = inPts[iPts - 1]; + auto& curr = inPts[iPts]; + if (inCmds[iCmds + 1] == PathCommand::CubicTo && _colinear(inPts + iPts)) { + _roundCorner(path.cmds, path.pts, prev, curr, inPts[iPts + 3], r); + ++iPts; + break; + } + if (inCmds[iCmds + 1] == PathCommand::LineTo) { + _roundCorner(path.cmds, path.pts, prev, curr, inPts[iPts + 1], r); + ++iPts; + break; + } + if (inCmds[iCmds + 1] == PathCommand::Close) { + _roundCorner(path.cmds, path.pts, prev, curr, inPts[1], r); + path.pts[startIndex] = path.pts.last(); + ++iPts; + break; + } + } + path.cmds.push(PathCommand::LineTo); + path.pts.push(inPts[iPts++]); + break; + } case PathCommand::Close: { path.cmds.push(PathCommand::Close); break;