lottie: enhance parsing of position's SeparateCoords

The "s" key does not have to appear at the beginning
of the position block. Previously, such cases would
result in a parsing error — now they are handled correctly.
This commit is contained in:
Mira Grudzinska 2025-05-06 22:15:35 +02:00 committed by Hermet Park
parent 0b77659136
commit 2e03fbd630
2 changed files with 15 additions and 5 deletions

View file

@ -639,6 +639,12 @@ struct LottieTransform : LottieObject
LottieFloat y = 0.0f;
};
SeparateCoord* separateCoord()
{
if (!coords) coords = new SeparateCoord;
return coords;
}
struct RotationEx
{
LottieFloat x = 0.0f;

View file

@ -566,11 +566,15 @@ LottieTransform* LottieParser::parseTransform(bool ddd)
enterObject();
while (auto key = nextObjectKey()) {
if (KEY_AS("k")) parsePropertyInternal(transform->position);
else if (KEY_AS("s") && getBool()) transform->coords = new LottieTransform::SeparateCoord;
//check separateCoord to figure out whether "x(expression)" / "x(coord)"
else if (transform->coords && KEY_AS("x")) parseProperty(transform->coords->x);
else if (transform->coords && KEY_AS("y")) parseProperty(transform->coords->y);
else if (KEY_AS("x") && expressions) transform->position.exp = getExpression(getStringCopy(), comp, context.layer, context.parent, &transform->position);
else if (KEY_AS("x"))
{
//check separateCoord to figure out whether "x(expression)" / "x(coord)"
if (peekType() == kStringType) {
if (expressions) transform->position.exp = getExpression(getStringCopy(), comp, context.layer, context.parent, &transform->position);
else skip();
} else parseProperty(transform->separateCoord()->x);
}
else if (KEY_AS("y")) parseProperty(transform->separateCoord()->y);
else if (KEY_AS("sid")) registerSlot(transform, getString(), LottieProperty::Type::Vector);
else if (KEY_AS("ix")) transform->position.ix = getInt();
else skip();