diff --git a/src/loaders/lottie/tvgLottieParser.cpp b/src/loaders/lottie/tvgLottieParser.cpp index a464dc6e..25b0fc9b 100644 --- a/src/loaders/lottie/tvgLottieParser.cpp +++ b/src/loaders/lottie/tvgLottieParser.cpp @@ -256,7 +256,7 @@ void LottieParser::getValue(ColorStop& color) { if (peekType() == kArrayType) enterArray(); - color.input = new Array(context.gradient->colorStops.count); + color.input = new Array(static_cast(context.parent)->colorStops.count); while (nextArrayValue()) color.input->push(getFloat()); } @@ -496,6 +496,8 @@ LottieRect* LottieParser::parseRect() auto rect = new LottieRect; if (!rect) return nullptr; + context.parent = rect; + while (auto key = nextObjectKey()) { if (KEY_AS("s")) parseProperty(rect->size); else if (KEY_AS("p")) parseProperty(rect->position); @@ -514,6 +516,8 @@ LottieEllipse* LottieParser::parseEllipse() auto ellipse = new LottieEllipse; if (!ellipse) return nullptr; + context.parent = ellipse; + while (auto key = nextObjectKey()) { if (KEY_AS("nm")) ellipse->name = getStringCopy(); else if (KEY_AS("p")) parseProperty(ellipse->position); @@ -531,6 +535,8 @@ LottieTransform* LottieParser::parseTransform(bool ddd) auto transform = new LottieTransform; if (!transform) return nullptr; + context.parent = transform; + if (ddd) { transform->rotationEx = new LottieTransform::RotationEx; TVGLOG("LOTTIE", "3D transform(ddd) is not totally compatible."); @@ -574,6 +580,8 @@ LottieSolidFill* LottieParser::parseSolidFill() auto fill = new LottieSolidFill; if (!fill) return nullptr; + context.parent = fill; + while (auto key = nextObjectKey()) { if (KEY_AS("nm")) fill->name = getStringCopy(); else if (KEY_AS("c")) parseProperty(fill->color, fill); @@ -613,6 +621,8 @@ LottieSolidStroke* LottieParser::parseSolidStroke() auto stroke = new LottieSolidStroke; if (!stroke) return nullptr; + context.parent = stroke; + while (auto key = nextObjectKey()) { if (KEY_AS("c")) parseProperty(stroke->color, stroke); else if (KEY_AS("o")) parseProperty(stroke->opacity, stroke); @@ -668,6 +678,8 @@ LottiePolyStar* LottieParser::parsePolyStar() auto star = new LottiePolyStar; if (!star) return nullptr; + context.parent = star; + while (auto key = nextObjectKey()) { if (KEY_AS("nm")) star->name = getStringCopy(); else if (KEY_AS("p")) parseProperty(star->position); @@ -691,6 +703,8 @@ LottieRoundedCorner* LottieParser::parseRoundedCorner() auto corner = new LottieRoundedCorner; if (!corner) return nullptr; + context.parent = corner; + while (auto key = nextObjectKey()) { if (KEY_AS("nm")) corner->name = getStringCopy(); else if (KEY_AS("r")) parseProperty(corner->radius); @@ -704,8 +718,6 @@ LottieRoundedCorner* LottieParser::parseRoundedCorner() void LottieParser::parseGradient(LottieGradient* gradient, const char* key) { - context.gradient = gradient; - if (KEY_AS("t")) gradient->id = getInt(); else if (KEY_AS("o")) parseProperty(gradient->opacity, gradient); else if (KEY_AS("g")) @@ -730,6 +742,8 @@ LottieGradientFill* LottieParser::parseGradientFill() auto fill = new LottieGradientFill; if (!fill) return nullptr; + context.parent = fill; + while (auto key = nextObjectKey()) { if (KEY_AS("nm")) fill->name = getStringCopy(); else if (KEY_AS("r")) fill->rule = getFillRule(); @@ -748,6 +762,8 @@ LottieGradientStroke* LottieParser::parseGradientStroke() auto stroke = new LottieGradientStroke; if (!stroke) return nullptr; + context.parent = stroke; + while (auto key = nextObjectKey()) { if (KEY_AS("nm")) stroke->name = getStringCopy(); else if (KEY_AS("lc")) stroke->cap = getStrokeCap(); @@ -769,6 +785,8 @@ LottieTrimpath* LottieParser::parseTrimpath() auto trim = new LottieTrimpath; if (!trim) return nullptr; + context.parent = trim; + while (auto key = nextObjectKey()) { if (KEY_AS("nm")) trim->name = getStringCopy(); else if (KEY_AS("s")) parseProperty(trim->start); @@ -789,6 +807,8 @@ LottieRepeater* LottieParser::parseRepeater() auto repeater = new LottieRepeater; if (!repeater) return nullptr; + context.parent = repeater; + while (auto key = nextObjectKey()) { if (KEY_AS("nm")) repeater->name = getStringCopy(); else if (KEY_AS("c")) parseProperty(repeater->copies); @@ -1286,17 +1306,19 @@ bool LottieParser::apply(LottieSlot* slot) switch (slot->type) { case LottieProperty::Type::ColorStop: { obj = new LottieGradient; - context.gradient = static_cast(obj); + context.parent = obj; parseSlotProperty(static_cast(obj)->colorStops); break; } case LottieProperty::Type::Color: { obj = new LottieSolid; + context.parent = obj; parseSlotProperty(static_cast(obj)->color); break; } case LottieProperty::Type::TextDoc: { obj = new LottieText; + context.parent = obj; parseSlotProperty(static_cast(obj)->doc); break; } diff --git a/src/loaders/lottie/tvgLottieParser.h b/src/loaders/lottie/tvgLottieParser.h index 326fe51a..70a9c7d1 100644 --- a/src/loaders/lottie/tvgLottieParser.h +++ b/src/loaders/lottie/tvgLottieParser.h @@ -111,7 +111,7 @@ private: //Current parsing context struct Context { LottieLayer* layer = nullptr; - LottieGradient* gradient = nullptr; + LottieObject* parent = nullptr; } context; };