mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-26 16:16:46 +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 LottieFxCustom : LottieEffect
|
||||||
{
|
{
|
||||||
|
struct Property
|
||||||
|
{
|
||||||
|
LottieProperty* property;
|
||||||
|
unsigned long nm = 0; //encoded by djb2
|
||||||
|
unsigned long mn = 0; //encoded by djb2
|
||||||
|
};
|
||||||
|
|
||||||
char* name = nullptr;
|
char* name = nullptr;
|
||||||
Array<LottieProperty*> props;
|
Array<Property> props;
|
||||||
|
|
||||||
LottieFxCustom()
|
LottieFxCustom()
|
||||||
{
|
{
|
||||||
|
@ -106,10 +113,10 @@ struct LottieFxCustom : LottieEffect
|
||||||
|
|
||||||
~LottieFxCustom()
|
~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;
|
LottieProperty* prop = nullptr;
|
||||||
|
|
||||||
|
@ -126,15 +133,18 @@ struct LottieFxCustom : LottieEffect
|
||||||
TVGLOG("LOTTIE", "missing custom property = %d\n", type);
|
TVGLOG("LOTTIE", "missing custom property = %d\n", type);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (prop) props.push(prop);
|
if (prop) {
|
||||||
return prop;
|
props.push({prop, });
|
||||||
|
return &props.last();
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LottieProperty* property(const char* name)
|
LottieProperty* property(const char* name)
|
||||||
{
|
{
|
||||||
auto ix = static_cast<uint32_t>(djb2Encode(name));
|
auto id = djb2Encode(name);
|
||||||
ARRAY_FOREACH(p, props) {
|
ARRAY_FOREACH(p, props) {
|
||||||
if ((*p)->ix == ix) return *p;
|
if (p->mn == id || p->nm == id) return p->property;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1260,16 +1260,16 @@ bool LottieParser::parseEffect(LottieEffect* effect, void(LottieParser::*func)(L
|
||||||
{
|
{
|
||||||
//custom effect expects dynamic property allocations
|
//custom effect expects dynamic property allocations
|
||||||
auto custom = (effect->type == LottieEffect::Custom) ? true : false;
|
auto custom = (effect->type == LottieEffect::Custom) ? true : false;
|
||||||
LottieProperty* property = nullptr;
|
LottieFxCustom::Property* property = nullptr;
|
||||||
|
|
||||||
enterArray();
|
enterArray();
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
while (nextArrayValue()) {
|
while (nextArrayValue()) {
|
||||||
enterObject();
|
enterObject();
|
||||||
while (auto key = nextObjectKey()) {
|
while (auto key = nextObjectKey()) {
|
||||||
if (custom && KEY_AS("ty")) {
|
if (custom && KEY_AS("ty")) property = static_cast<LottieFxCustom*>(effect)->property(getInt());
|
||||||
property = static_cast<LottieFxCustom*>(effect)->property(getInt());
|
else if (KEY_AS("v"))
|
||||||
} else if (KEY_AS("v")) {
|
{
|
||||||
if (peekType() == kObjectType) {
|
if (peekType() == kObjectType) {
|
||||||
enterObject();
|
enterObject();
|
||||||
while (auto key = nextObjectKey()) {
|
while (auto key = nextObjectKey()) {
|
||||||
|
@ -1277,9 +1277,10 @@ bool LottieParser::parseEffect(LottieEffect* effect, void(LottieParser::*func)(L
|
||||||
else skip();
|
else skip();
|
||||||
}
|
}
|
||||||
} else skip();
|
} else skip();
|
||||||
} else if (property && KEY_AS("nm")) {
|
}
|
||||||
property->ix = djb2Encode(getString());
|
else if (property && KEY_AS("nm")) property->nm = djb2Encode(getString());
|
||||||
} else skip();
|
else if (property && KEY_AS("mn")) property->mn = djb2Encode(getString());
|
||||||
|
else skip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -1293,7 +1294,7 @@ void LottieParser::parseCustom(LottieEffect* effect, int idx)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto prop = static_cast<LottieFxCustom*>(effect)->props[idx];
|
auto prop = static_cast<LottieFxCustom*>(effect)->props[idx].property;
|
||||||
|
|
||||||
switch (prop->type) {
|
switch (prop->type) {
|
||||||
case LottieProperty::Type::Integer: {
|
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};
|
enum class Type : uint8_t {Invalid = 0, Integer, Float, Scalar, Vector, PathSet, Color, Opacity, ColorStop, TextDoc, Image};
|
||||||
|
|
||||||
LottieExpression* exp = nullptr;
|
LottieExpression* exp = nullptr;
|
||||||
uint32_t ix; //property index (used as a name id for indexing by custom layer effect as well)
|
|
||||||
Type type;
|
Type type;
|
||||||
|
uint8_t ix; //property index
|
||||||
|
|
||||||
LottieProperty(Type type = Type::Invalid) : type(type) {}
|
LottieProperty(Type type = Type::Invalid) : type(type) {}
|
||||||
virtual ~LottieProperty() {}
|
virtual ~LottieProperty() {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue