From 882cb316c4f3498665fbae627cc9d6f47fe44734 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Wed, 9 Apr 2025 22:33:52 +0900 Subject: [PATCH] lottie: allow custom effects to use nm/mn both identifiers --- src/loaders/lottie/tvgLottieModel.h | 24 +++++++++++++++++------- src/loaders/lottie/tvgLottieParser.cpp | 17 +++++++++-------- src/loaders/lottie/tvgLottieProperty.h | 2 +- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/loaders/lottie/tvgLottieModel.h b/src/loaders/lottie/tvgLottieModel.h index 4d926810..0df20b9f 100644 --- a/src/loaders/lottie/tvgLottieModel.h +++ b/src/loaders/lottie/tvgLottieModel.h @@ -96,8 +96,15 @@ struct LottieEffect struct LottieFxCustom : LottieEffect { + struct Property + { + LottieProperty* property; + unsigned long nm = 0; //encoded by djb2 + unsigned long mn = 0; //encoded by djb2 + }; + char* name = nullptr; - Array props; + Array props; LottieFxCustom() { @@ -106,10 +113,10 @@ struct LottieFxCustom : LottieEffect ~LottieFxCustom() { - ARRAY_FOREACH(p, props) delete(*p); + ARRAY_FOREACH(p, props) delete(p->property); } - LottieProperty* property(int type) + Property* property(int type) { LottieProperty* prop = nullptr; @@ -126,15 +133,18 @@ struct LottieFxCustom : LottieEffect TVGLOG("LOTTIE", "missing custom property = %d\n", type); return nullptr; } - if (prop) props.push(prop); - return prop; + if (prop) { + props.push({prop, }); + return &props.last(); + } + return nullptr; } LottieProperty* property(const char* name) { - auto ix = static_cast(djb2Encode(name)); + auto id = djb2Encode(name); ARRAY_FOREACH(p, props) { - if ((*p)->ix == ix) return *p; + if (p->mn == id || p->nm == id) return p->property; } return nullptr; } diff --git a/src/loaders/lottie/tvgLottieParser.cpp b/src/loaders/lottie/tvgLottieParser.cpp index 277e0211..2cc8b7b6 100644 --- a/src/loaders/lottie/tvgLottieParser.cpp +++ b/src/loaders/lottie/tvgLottieParser.cpp @@ -1260,16 +1260,16 @@ bool LottieParser::parseEffect(LottieEffect* effect, void(LottieParser::*func)(L { //custom effect expects dynamic property allocations auto custom = (effect->type == LottieEffect::Custom) ? true : false; - LottieProperty* property = nullptr; + LottieFxCustom::Property* property = nullptr; enterArray(); int idx = 0; while (nextArrayValue()) { enterObject(); while (auto key = nextObjectKey()) { - if (custom && KEY_AS("ty")) { - property = static_cast(effect)->property(getInt()); - } else if (KEY_AS("v")) { + if (custom && KEY_AS("ty")) property = static_cast(effect)->property(getInt()); + else if (KEY_AS("v")) + { if (peekType() == kObjectType) { enterObject(); while (auto key = nextObjectKey()) { @@ -1277,9 +1277,10 @@ bool LottieParser::parseEffect(LottieEffect* effect, void(LottieParser::*func)(L else skip(); } } else skip(); - } else if (property && KEY_AS("nm")) { - property->ix = djb2Encode(getString()); - } else skip(); + } + else if (property && KEY_AS("nm")) property->nm = djb2Encode(getString()); + else if (property && KEY_AS("mn")) property->mn = djb2Encode(getString()); + else skip(); } } return true; @@ -1293,7 +1294,7 @@ void LottieParser::parseCustom(LottieEffect* effect, int idx) return; } - auto prop = static_cast(effect)->props[idx]; + auto prop = static_cast(effect)->props[idx].property; switch (prop->type) { case LottieProperty::Type::Integer: { diff --git a/src/loaders/lottie/tvgLottieProperty.h b/src/loaders/lottie/tvgLottieProperty.h index 8d542fb6..5ad224ea 100644 --- a/src/loaders/lottie/tvgLottieProperty.h +++ b/src/loaders/lottie/tvgLottieProperty.h @@ -189,8 +189,8 @@ struct LottieProperty enum class Type : uint8_t {Invalid = 0, Integer, Float, Scalar, Vector, PathSet, Color, Opacity, ColorStop, TextDoc, Image}; LottieExpression* exp = nullptr; - uint32_t ix; //property index (used as a name id for indexing by custom layer effect as well) Type type; + uint8_t ix; //property index LottieProperty(Type type = Type::Invalid) : type(type) {} virtual ~LottieProperty() {}