lottie: allow custom effects to use nm/mn both identifiers

This commit is contained in:
Hermet Park 2025-04-09 22:33:52 +09:00 committed by Hermet Park
parent a4ed00b08e
commit 882cb316c4
3 changed files with 27 additions and 16 deletions

View file

@ -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<LottieProperty*> props;
Array<Property> 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<uint32_t>(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;
}

View file

@ -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<LottieFxCustom*>(effect)->property(getInt());
} else if (KEY_AS("v")) {
if (custom && KEY_AS("ty")) property = static_cast<LottieFxCustom*>(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<LottieFxCustom*>(effect)->props[idx];
auto prop = static_cast<LottieFxCustom*>(effect)->props[idx].property;
switch (prop->type) {
case LottieProperty::Type::Integer: {

View file

@ -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() {}