mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-25 23:59:12 +00:00
lottie: fix transformations in text range selector
Since the translate API was used while text updating, the subsequent range selector transformations gets overwritten when updating the shape (scale and rotate, adding another translation will persist). This caused unexpected results. Fixed by using the transform API when additional transformations are needed - also fixes applying more than one range selector.
This commit is contained in:
parent
1d78835609
commit
d9be58d4b7
2 changed files with 34 additions and 27 deletions
|
@ -1060,6 +1060,11 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo)
|
|||
shape->strokeFill(doc.stroke.color.rgb[0], doc.stroke.color.rgb[1], doc.stroke.color.rgb[2]);
|
||||
}
|
||||
|
||||
if (!text->ranges.empty()) {
|
||||
Point scaling = {1.0f, 1.0f};
|
||||
auto rotation = 0.0f;
|
||||
auto translation = cursor;
|
||||
|
||||
//text range process
|
||||
for (auto s = text->ranges.begin(); s < text->ranges.end(); ++s) {
|
||||
float start, end;
|
||||
|
@ -1071,21 +1076,16 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo)
|
|||
else if ((*s)->based == LottieTextRange::Based::Lines) basedIdx = line;
|
||||
|
||||
if (basedIdx < start || basedIdx >= end) continue;
|
||||
auto& matrix = shape->transform();
|
||||
|
||||
translation = translation + (*s)->style.position(frameNo);
|
||||
scaling = scaling * (*s)->style.scale(frameNo) * 0.01f;
|
||||
rotation += (*s)->style.rotation(frameNo);
|
||||
|
||||
shape->opacity((*s)->style.opacity(frameNo));
|
||||
|
||||
auto color = (*s)->style.fillColor(frameNo);
|
||||
shape->fill(color.rgb[0], color.rgb[1], color.rgb[2], (*s)->style.fillOpacity(frameNo));
|
||||
|
||||
rotate(&matrix, (*s)->style.rotation(frameNo));
|
||||
|
||||
auto glyphScale = (*s)->style.scale(frameNo) * 0.01f;
|
||||
tvg::scale(&matrix, glyphScale.x, glyphScale.y);
|
||||
|
||||
auto position = (*s)->style.position(frameNo);
|
||||
translate(&matrix, position.x, position.y);
|
||||
|
||||
if (doc.stroke.render) {
|
||||
auto strokeColor = (*s)->style.strokeColor(frameNo);
|
||||
shape->strokeWidth((*s)->style.strokeWidth(frameNo) / scale);
|
||||
|
@ -1096,6 +1096,13 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo)
|
|||
auto spacing = (*s)->style.lineSpacing(frameNo);
|
||||
if (spacing > lineSpacing) lineSpacing = spacing;
|
||||
}
|
||||
auto& matrix = shape->transform();
|
||||
identity(&matrix);
|
||||
translate(&matrix, translation.x, translation.y);
|
||||
tvg::scale(&matrix, scaling.x, scaling.y);
|
||||
rotate(&matrix, rotation);
|
||||
shape->transform(matrix);
|
||||
}
|
||||
|
||||
scene->push(cast(shape));
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace tvg
|
|||
|
||||
bool transform(const Matrix& m)
|
||||
{
|
||||
tr.m = m;
|
||||
if (&tr.m != &m) tr.m = m;
|
||||
tr.overriding = true;
|
||||
renderFlag |= RenderUpdateFlag::Transform;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue