mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-25 07:39:02 +00:00
lottie: allow custom effects to use nm/mn both identifiers
This commit is contained in:
parent
a4ed00b08e
commit
882cb316c4
3 changed files with 27 additions and 16 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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() {}
|
||||
|
|
Loading…
Add table
Reference in a new issue