From 060f85856807ecee0955d426cff010485fcf5cad Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Tue, 16 Apr 2024 18:32:17 +0900 Subject: [PATCH] lottie: specify the explicit parsing type. these explicit type values are expected to be referenced by the expressions. --- src/loaders/lottie/tvgLottieParser.cpp | 93 +++++++++++++------------- src/loaders/lottie/tvgLottieParser.h | 2 +- 2 files changed, 46 insertions(+), 49 deletions(-) diff --git a/src/loaders/lottie/tvgLottieParser.cpp b/src/loaders/lottie/tvgLottieParser.cpp index 25b0fc9b..d65ce4e9 100644 --- a/src/loaders/lottie/tvgLottieParser.cpp +++ b/src/loaders/lottie/tvgLottieParser.cpp @@ -339,11 +339,11 @@ void LottieParser::getInperpolatorPoint(Point& pt) } -template +template void LottieParser::parseSlotProperty(T& prop) { while (auto key = nextObjectKey()) { - if (KEY_AS("p")) parseProperty(prop); + if (KEY_AS("p")) parseProperty(prop); else skip(key); } } @@ -499,9 +499,9 @@ LottieRect* LottieParser::parseRect() context.parent = rect; while (auto key = nextObjectKey()) { - if (KEY_AS("s")) parseProperty(rect->size); - else if (KEY_AS("p")) parseProperty(rect->position); - else if (KEY_AS("r")) parseProperty(rect->radius); + if (KEY_AS("s")) parseProperty(rect->size); + else if (KEY_AS("p"))parseProperty(rect->position); + else if (KEY_AS("r")) parseProperty(rect->radius); else if (KEY_AS("nm")) rect->name = getStringCopy(); else if (KEY_AS("hd")) rect->hidden = getBool(); else skip(key); @@ -520,8 +520,8 @@ LottieEllipse* LottieParser::parseEllipse() while (auto key = nextObjectKey()) { if (KEY_AS("nm")) ellipse->name = getStringCopy(); - else if (KEY_AS("p")) parseProperty(ellipse->position); - else if (KEY_AS("s")) parseProperty(ellipse->size); + else if (KEY_AS("p")) parseProperty(ellipse->position); + else if (KEY_AS("s")) parseProperty(ellipse->size); else if (KEY_AS("hd")) ellipse->hidden = getBool(); else skip(key); } @@ -548,23 +548,20 @@ LottieTransform* LottieParser::parseTransform(bool ddd) enterObject(); while (auto key = nextObjectKey()) { if (KEY_AS("k")) parsePropertyInternal(transform->position); - else if (KEY_AS("s")) { - if (getBool()) transform->coords = new LottieTransform::SeparateCoord; + 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 skip(key); + else if (transform->coords && KEY_AS("x")) parseProperty(transform->coords->x); + else if (transform->coords && KEY_AS("y")) parseProperty(transform->coords->y); + else skip(key); } } - else if (KEY_AS("a")) parseProperty(transform->anchor); - else if (KEY_AS("s")) parseProperty(transform->scale); - else if (KEY_AS("r")) parseProperty(transform->rotation); - else if (KEY_AS("o")) parseProperty(transform->opacity); - else if (transform->rotationEx && KEY_AS("rx")) parseProperty(transform->rotationEx->x); - else if (transform->rotationEx && KEY_AS("ry")) parseProperty(transform->rotationEx->y); - else if (transform->rotationEx && KEY_AS("rz")) parseProperty(transform->rotation); + else if (KEY_AS("a")) parseProperty(transform->anchor); + else if (KEY_AS("s")) parseProperty(transform->scale); + else if (KEY_AS("r")) parseProperty(transform->rotation); + else if (KEY_AS("o")) parseProperty(transform->opacity); + else if (transform->rotationEx && KEY_AS("rx")) parseProperty(transform->rotationEx->x); + else if (transform->rotationEx && KEY_AS("ry")) parseProperty(transform->rotationEx->y); + else if (transform->rotationEx && KEY_AS("rz")) parseProperty(transform->rotation); else if (KEY_AS("nm")) transform->name = getStringCopy(); //else if (KEY_AS("sk")) //TODO: skew //else if (KEY_AS("sa")) //TODO: skew axis @@ -609,7 +606,7 @@ void LottieParser::parseStrokeDash(LottieStroke* stroke) else if (!strcmp("d", style)) idx = 1; //dash else if (!strcmp("g", style)) idx = 2; //gap } else if (KEY_AS("v")) { - parseProperty(stroke->dash(idx)); + parseProperty(stroke->dash(idx)); } else skip(key); } } @@ -682,13 +679,13 @@ LottiePolyStar* LottieParser::parsePolyStar() while (auto key = nextObjectKey()) { if (KEY_AS("nm")) star->name = getStringCopy(); - else if (KEY_AS("p")) parseProperty(star->position); - else if (KEY_AS("pt")) parseProperty(star->ptsCnt); - else if (KEY_AS("ir")) parseProperty(star->innerRadius); - else if (KEY_AS("is")) parseProperty(star->innerRoundness); - else if (KEY_AS("or")) parseProperty(star->outerRadius); - else if (KEY_AS("os")) parseProperty(star->outerRoundness); - else if (KEY_AS("r")) parseProperty(star->rotation); + else if (KEY_AS("p")) parseProperty(star->position); + else if (KEY_AS("pt")) parseProperty(star->ptsCnt); + else if (KEY_AS("ir")) parseProperty(star->innerRadius); + else if (KEY_AS("is")) parseProperty(star->innerRoundness); + else if (KEY_AS("or")) parseProperty(star->outerRadius); + else if (KEY_AS("os")) parseProperty(star->outerRoundness); + else if (KEY_AS("r")) parseProperty(star->rotation); else if (KEY_AS("sy")) star->type = (LottiePolyStar::Type) getInt(); else if (KEY_AS("hd")) star->hidden = getBool(); else skip(key); @@ -707,7 +704,7 @@ LottieRoundedCorner* LottieParser::parseRoundedCorner() while (auto key = nextObjectKey()) { if (KEY_AS("nm")) corner->name = getStringCopy(); - else if (KEY_AS("r")) parseProperty(corner->radius); + else if (KEY_AS("r")) parseProperty(corner->radius); else if (KEY_AS("hd")) corner->hidden = getBool(); else skip(key); } @@ -770,7 +767,7 @@ LottieGradientStroke* LottieParser::parseGradientStroke() else if (KEY_AS("lj")) stroke->join = getStrokeJoin(); else if (KEY_AS("ml")) stroke->miterLimit = getFloat(); else if (KEY_AS("hd")) stroke->hidden = getBool(); - else if (KEY_AS("w")) parseProperty(stroke->width); + else if (KEY_AS("w")) parseProperty(stroke->width); else if (KEY_AS("d")) parseStrokeDash(stroke); else parseGradient(stroke, key); } @@ -789,9 +786,9 @@ LottieTrimpath* LottieParser::parseTrimpath() while (auto key = nextObjectKey()) { if (KEY_AS("nm")) trim->name = getStringCopy(); - else if (KEY_AS("s")) parseProperty(trim->start); - else if (KEY_AS("e")) parseProperty(trim->end); - else if (KEY_AS("o")) parseProperty(trim->offset); + else if (KEY_AS("s")) parseProperty(trim->start); + else if (KEY_AS("e")) parseProperty(trim->end); + else if (KEY_AS("o")) parseProperty(trim->offset); else if (KEY_AS("m")) trim->type = static_cast(getInt()); else if (KEY_AS("hd")) trim->hidden = getBool(); else skip(key); @@ -811,19 +808,19 @@ LottieRepeater* LottieParser::parseRepeater() while (auto key = nextObjectKey()) { if (KEY_AS("nm")) repeater->name = getStringCopy(); - else if (KEY_AS("c")) parseProperty(repeater->copies); - else if (KEY_AS("o")) parseProperty(repeater->offset); + else if (KEY_AS("c")) parseProperty(repeater->copies); + else if (KEY_AS("o")) parseProperty(repeater->offset); else if (KEY_AS("m")) repeater->inorder = getInt(); else if (KEY_AS("tr")) { enterObject(); while (auto key = nextObjectKey()) { - if (KEY_AS("a")) parseProperty(repeater->anchor); - else if (KEY_AS("p")) parseProperty(repeater->position); - else if (KEY_AS("r")) parseProperty(repeater->rotation); - else if (KEY_AS("s")) parseProperty(repeater->scale); - else if (KEY_AS("so")) parseProperty(repeater->startOpacity); - else if (KEY_AS("eo")) parseProperty(repeater->endOpacity); + if (KEY_AS("a")) parseProperty(repeater->anchor); + else if (KEY_AS("p")) parseProperty(repeater->position); + else if (KEY_AS("r")) parseProperty(repeater->rotation); + else if (KEY_AS("s")) parseProperty(repeater->scale); + else if (KEY_AS("so")) parseProperty(repeater->startOpacity); + else if (KEY_AS("eo")) parseProperty(repeater->endOpacity); else skip(key); } } @@ -1057,7 +1054,7 @@ LottieObject* LottieParser::parseGroup() void LottieParser::parseTimeRemap(LottieLayer* layer) { - parseProperty(layer->timeRemap); + parseProperty(layer->timeRemap); } @@ -1105,7 +1102,7 @@ void LottieParser::parseTextRange(LottieText* text) if (KEY_AS("a")) { //text style enterObject(); while (auto key = nextObjectKey()) { - if (KEY_AS("t")) parseProperty(text->spacing); + if (KEY_AS("t")) parseProperty(text->spacing); else skip(key); } } else skip(key); @@ -1155,7 +1152,7 @@ LottieMask* LottieParser::parseMask() if (KEY_AS("inv")) mask->inverse = getBool(); else if (KEY_AS("mode")) mask->method = getMaskMethod(mask->inverse); else if (KEY_AS("pt")) getPathSet(mask->pathset); - else if (KEY_AS("o")) parseProperty(mask->opacity); + else if (KEY_AS("o")) parseProperty(mask->opacity); else skip(key); } @@ -1307,19 +1304,19 @@ bool LottieParser::apply(LottieSlot* slot) case LottieProperty::Type::ColorStop: { obj = new LottieGradient; context.parent = obj; - parseSlotProperty(static_cast(obj)->colorStops); + parseSlotProperty(static_cast(obj)->colorStops); break; } case LottieProperty::Type::Color: { obj = new LottieSolid; context.parent = obj; - parseSlotProperty(static_cast(obj)->color); + parseSlotProperty(static_cast(obj)->color); break; } case LottieProperty::Type::TextDoc: { obj = new LottieText; context.parent = obj; - parseSlotProperty(static_cast(obj)->doc); + parseSlotProperty(static_cast(obj)->doc); break; } default: break; diff --git a/src/loaders/lottie/tvgLottieParser.h b/src/loaders/lottie/tvgLottieParser.h index 70a9c7d1..a05e9e1b 100644 --- a/src/loaders/lottie/tvgLottieParser.h +++ b/src/loaders/lottie/tvgLottieParser.h @@ -70,7 +70,7 @@ private: template void parseKeyFrame(T& prop); template void parsePropertyInternal(T& prop); template void parseProperty(T& prop, LottieObject* obj = nullptr); - template void parseSlotProperty(T& prop); + template void parseSlotProperty(T& prop); LottieObject* parseObject(); LottieObject* parseAsset();