mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-13 11:36:25 +00:00
lottie: text range selector++
Change in the algorithm for selecting characters included in the range selector. This is the first step towards adding support for maxAmount, smoothness, and easing. @Issue: https://github.com/thorvg/thorvg/issues/2178
This commit is contained in:
parent
1528ae3729
commit
4ee73be95b
3 changed files with 26 additions and 17 deletions
|
@ -1095,15 +1095,13 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo)
|
||||||
|
|
||||||
//text range process
|
//text range process
|
||||||
for (auto s = text->ranges.begin(); s < text->ranges.end(); ++s) {
|
for (auto s = text->ranges.begin(); s < text->ranges.end(); ++s) {
|
||||||
float start, end;
|
|
||||||
(*s)->range(frameNo, float(totalChars), start, end);
|
|
||||||
|
|
||||||
auto basedIdx = idx;
|
auto basedIdx = idx;
|
||||||
if ((*s)->based == LottieTextRange::Based::CharsExcludingSpaces) basedIdx = idx - space;
|
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::Words) basedIdx = line + space;
|
||||||
else if ((*s)->based == LottieTextRange::Based::Lines) basedIdx = line;
|
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;
|
needGroup = true;
|
||||||
|
|
||||||
translation = translation + (*s)->style.position(frameNo);
|
translation = translation + (*s)->style.position(frameNo);
|
||||||
|
@ -1145,13 +1143,13 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo)
|
||||||
//center pivoting
|
//center pivoting
|
||||||
textGroupMatrix.e13 += (pivotX * textGroupMatrix.e11 + pivotX * textGroupMatrix.e12);
|
textGroupMatrix.e13 += (pivotX * textGroupMatrix.e11 + pivotX * textGroupMatrix.e12);
|
||||||
textGroupMatrix.e23 += (pivotY * textGroupMatrix.e21 + pivotY * textGroupMatrix.e22);
|
textGroupMatrix.e23 += (pivotY * textGroupMatrix.e21 + pivotY * textGroupMatrix.e22);
|
||||||
|
|
||||||
textGroup->transform(textGroupMatrix);
|
textGroup->transform(textGroupMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& matrix = shape->transform();
|
auto& matrix = shape->transform();
|
||||||
identity(&matrix);
|
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);
|
tvg::scale(&matrix, scaling.x, scaling.y);
|
||||||
shape->transform(matrix);
|
shape->transform(matrix);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<float>(random % int(len - range));
|
||||||
|
end = start + range;
|
||||||
|
}
|
||||||
|
|
||||||
auto divisor = (rangeUnit == Unit::Percent) ? (100.0f / totalLen) : 1.0f;
|
auto divisor = (rangeUnit == Unit::Percent) ? (100.0f / totalLen) : 1.0f;
|
||||||
auto offset = this->offset(frameNo) / divisor;
|
start /= divisor;
|
||||||
start = nearbyintf(this->start(frameNo) / divisor) + offset;
|
end /= divisor;
|
||||||
end = nearbyintf(this->end(frameNo) / divisor) + offset;
|
|
||||||
|
|
||||||
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;
|
return f;
|
||||||
auto len = (rangeUnit == Unit::Percent) ? 100.0f : totalLen;
|
|
||||||
start = static_cast<float>(random % int(len - range));
|
|
||||||
end = start + range;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -228,7 +228,7 @@ struct LottieTextRange
|
||||||
uint8_t random = 0;
|
uint8_t random = 0;
|
||||||
bool expressible = false;
|
bool expressible = false;
|
||||||
|
|
||||||
void range(float frameNo, float totalLen, float& start, float& end);
|
float factor(float frameNo, float totalLen, float idx);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue