mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-07 21:23:32 +00:00
lottie: follow path stabilization++
* lottie: fixes in follow path Each time the 'updateText' was called, the mask path (if the follow path existed) was appended to the previous one, causing it to grow infinitely. A 'clear' call on the existing path was missing. The positions on the follow path for distances larger than 2 x mask path length were not correctly calculated. * lottie: fix crash on follow path It could happen that the searched text position (distance from the start pointt) on the follow path was exactly equal to the path length. In such a case, the cmds pointer pointed to the last element, and in the next iteration, this caused a crash.
This commit is contained in:
parent
eb67549295
commit
f8c5f3a69c
1 changed files with 4 additions and 3 deletions
|
@ -65,6 +65,7 @@ float LottieTextFollowPath::prepare(LottieMask* mask, float frameNo, float scale
|
||||||
{
|
{
|
||||||
this->mask = mask;
|
this->mask = mask;
|
||||||
Matrix m{1.0f / scale, 0.0f, 0.0f, 0.0f, 1.0f / scale, 0.0f, 0.0f, 0.0f, 1.0f};
|
Matrix m{1.0f / scale, 0.0f, 0.0f, 0.0f, 1.0f / scale, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
|
path.clear();
|
||||||
mask->pathset(frameNo, path, &m, tween, exps);
|
mask->pathset(frameNo, path, &m, tween, exps);
|
||||||
|
|
||||||
pts = path.pts.data;
|
pts = path.pts.data;
|
||||||
|
@ -109,10 +110,10 @@ Point LottieTextFollowPath::position(float lenSearched, float& angle)
|
||||||
};
|
};
|
||||||
|
|
||||||
//beyond the curve
|
//beyond the curve
|
||||||
if (lenSearched > totalLen) {
|
if (lenSearched >= totalLen) {
|
||||||
//shape is closed -> wrapping
|
//shape is closed -> wrapping
|
||||||
if (path.cmds.last() == PathCommand::Close) {
|
if (path.cmds.last() == PathCommand::Close) {
|
||||||
lenSearched -= totalLen;
|
while (lenSearched > totalLen) lenSearched -= totalLen;
|
||||||
pts = path.pts.data;
|
pts = path.pts.data;
|
||||||
cmds = path.cmds.data;
|
cmds = path.cmds.data;
|
||||||
cmdsCnt = path.cmds.count;
|
cmdsCnt = path.cmds.count;
|
||||||
|
@ -147,7 +148,7 @@ Point LottieTextFollowPath::position(float lenSearched, float& angle)
|
||||||
|
|
||||||
while (cmdsCnt > 0) {
|
while (cmdsCnt > 0) {
|
||||||
auto dLen = length();
|
auto dLen = length();
|
||||||
if (currentLen + dLen <= lenSearched) {
|
if (currentLen + dLen < lenSearched) {
|
||||||
shift();
|
shift();
|
||||||
currentLen += dLen;
|
currentLen += dLen;
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Reference in a new issue