diff --git a/src/loaders/lottie/tvgLottieBuilder.cpp b/src/loaders/lottie/tvgLottieBuilder.cpp index 8797641b..0b3a4c32 100644 --- a/src/loaders/lottie/tvgLottieBuilder.cpp +++ b/src/loaders/lottie/tvgLottieBuilder.cpp @@ -1095,15 +1095,13 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo) //text range process for (auto s = text->ranges.begin(); s < text->ranges.end(); ++s) { - float start, end; - (*s)->range(frameNo, float(totalChars), start, end); - auto basedIdx = idx; if ((*s)->based == LottieTextRange::Based::CharsExcludingSpaces) basedIdx = idx - space; else if ((*s)->based == LottieTextRange::Based::Words) basedIdx = line + space; else if ((*s)->based == LottieTextRange::Based::Lines) basedIdx = line; - if (basedIdx < start || basedIdx >= end) continue; + auto f = (*s)->factor(frameNo, float(totalChars), (float)basedIdx); + if (tvg::zero(f)) continue; needGroup = true; translation = translation + (*s)->style.position(frameNo); @@ -1145,13 +1143,13 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo) //center pivoting textGroupMatrix.e13 += (pivotX * textGroupMatrix.e11 + pivotX * textGroupMatrix.e12); textGroupMatrix.e23 += (pivotY * textGroupMatrix.e21 + pivotY * textGroupMatrix.e22); - + textGroup->transform(textGroupMatrix); } auto& matrix = shape->transform(); identity(&matrix); - translate(&matrix, (translation.x / scale + cursor.x) - textGroupMatrix.e13, (translation.y / scale + cursor.y) - textGroupMatrix.e23); + translate(&matrix, translation.x / scale + cursor.x - textGroupMatrix.e13, translation.y / scale + cursor.y - textGroupMatrix.e23); tvg::scale(&matrix, scaling.x, scaling.y); shape->transform(matrix); } diff --git a/src/loaders/lottie/tvgLottieModel.cpp b/src/loaders/lottie/tvgLottieModel.cpp index a53de378..ea073ee3 100644 --- a/src/loaders/lottie/tvgLottieModel.cpp +++ b/src/loaders/lottie/tvgLottieModel.cpp @@ -115,21 +115,32 @@ void LottieSlot::assign(LottieObject* target) } -void LottieTextRange::range(float frameNo, float totalLen, float& start, float& end) +float LottieTextRange::factor(float frameNo, float totalLen, float idx) { + auto offset = this->offset(frameNo); + auto start = this->start(frameNo) + offset; + auto end = this->end(frameNo) + offset; + + if (random > 0) { + auto range = end - start; + auto len = (rangeUnit == Unit::Percent) ? 100.0f : totalLen; + start = static_cast(random % int(len - range)); + end = start + range; + } + auto divisor = (rangeUnit == Unit::Percent) ? (100.0f / totalLen) : 1.0f; - auto offset = this->offset(frameNo) / divisor; - start = nearbyintf(this->start(frameNo) / divisor) + offset; - end = nearbyintf(this->end(frameNo) / divisor) + offset; + start /= divisor; + end /= divisor; - if (start > end) std::swap(start, end); + auto f = 0.0f; - if (random == 0) return; + if (idx >= std::floor(start)) { + auto diff = idx - start; + f = diff < 0.0f ? std::min(end, 1.0f) + diff : end - idx; + clamp(f, 0.0f, 1.0f); + } - auto range = end - start; - auto len = (rangeUnit == Unit::Percent) ? 100.0f : totalLen; - start = static_cast(random % int(len - range)); - end = start + range; + return f; } diff --git a/src/loaders/lottie/tvgLottieModel.h b/src/loaders/lottie/tvgLottieModel.h index a22cf196..7f9e53c1 100644 --- a/src/loaders/lottie/tvgLottieModel.h +++ b/src/loaders/lottie/tvgLottieModel.h @@ -228,7 +228,7 @@ struct LottieTextRange uint8_t random = 0; bool expressible = false; - void range(float frameNo, float totalLen, float& start, float& end); + float factor(float frameNo, float totalLen, float idx); };