lottie/expressions: minor updates

- added toComp() initial ver.
- added mn property for effects

issue: https://github.com/thorvg/thorvg/issues/2233
This commit is contained in:
Hermet Park 2025-04-14 16:03:00 +09:00
parent d0f33a1bc5
commit 5c27fefef8
3 changed files with 7 additions and 7 deletions

View file

@ -175,9 +175,8 @@ static unsigned long _idByName(jerry_value_t args)
static jerry_value_t _toComp(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) static jerry_value_t _toComp(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt)
{ {
TVGLOG("LOTTIE", "toComp is not supported in expressions!"); auto layer = static_cast<LottieLayer*>(jerry_object_get_native_ptr(info->function, nullptr));
return _point2d(_point2d(args[0]) * layer->cache.matrix);
return jerry_undefined();
} }
@ -469,8 +468,6 @@ static jerry_value_t _addsub(const jerry_value_t args[], float addsub)
} }
static jerry_value_t _muldiv(const jerry_value_t arg1, float arg2) static jerry_value_t _muldiv(const jerry_value_t arg1, float arg2)
{ {
//1d //1d
@ -637,7 +634,7 @@ static jerry_value_t _content(const jerry_call_info_t* info, const jerry_value_t
switch (target->type) { switch (target->type) {
case LottieObject::Group: return _buildGroup(static_cast<LottieGroup*>(target), data->frameNo); case LottieObject::Group: return _buildGroup(static_cast<LottieGroup*>(target), data->frameNo);
case LottieObject::Path: { case LottieObject::Path: {
jerry_value_t obj = jerry_object(); auto obj = jerry_object();
jerry_object_set_native_ptr(obj, nullptr, &static_cast<LottiePath*>(target)->pathset); jerry_object_set_native_ptr(obj, nullptr, &static_cast<LottiePath*>(target)->pathset);
jerry_object_set_sz(obj, "path", obj); jerry_object_set_sz(obj, "path", obj);
return obj; return obj;
@ -690,6 +687,7 @@ static jerry_value_t _nearestKey(const jerry_call_info_t* info, const jerry_valu
return obj; return obj;
} }
static jerry_value_t _property(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt) static jerry_value_t _property(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt)
{ {
auto data = static_cast<ExpContent*>(jerry_object_get_native_ptr(info->function, &freeCb)); auto data = static_cast<ExpContent*>(jerry_object_get_native_ptr(info->function, &freeCb));

View file

@ -88,6 +88,7 @@ struct LottieEffect
virtual ~LottieEffect() {} virtual ~LottieEffect() {}
unsigned long nm; //encoded by djb2 unsigned long nm; //encoded by djb2
unsigned long mn; //encoded by djb2
int16_t ix; int16_t ix;
Type type; Type type;
bool enable = false; bool enable = false;
@ -1007,7 +1008,7 @@ struct LottieLayer : LottieGroup
LottieEffect* effectById(unsigned long id) LottieEffect* effectById(unsigned long id)
{ {
ARRAY_FOREACH(p, effects) { ARRAY_FOREACH(p, effects) {
if (id == (*p)->nm) return *p; if (id == (*p)->nm || id == (*p)->mn) return *p;
} }
return nullptr; return nullptr;
} }

View file

@ -1416,6 +1416,7 @@ void LottieParser::parseEffects(LottieLayer* layer)
else invalid = false; else invalid = false;
} }
else if (effect && KEY_AS("nm")) effect->nm = djb2Encode(getString()); else if (effect && KEY_AS("nm")) effect->nm = djb2Encode(getString());
else if (effect && KEY_AS("mn")) effect->mn = djb2Encode(getString());
else if (effect && KEY_AS("ix")) effect->ix = getInt(); else if (effect && KEY_AS("ix")) effect->ix = getInt();
else if (effect && KEY_AS("en")) effect->enable = getInt(); else if (effect && KEY_AS("en")) effect->enable = getInt();
else if (effect && KEY_AS("ef")) parseEffect(effect); else if (effect && KEY_AS("ef")) parseEffect(effect);