mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-23 14:48:24 +00:00
Merge e7057ef118
into 16604a873a
This commit is contained in:
commit
092bcfc1c3
3 changed files with 42 additions and 32 deletions
|
@ -203,7 +203,7 @@ void LottieSlot::reset()
|
|||
}
|
||||
|
||||
|
||||
void LottieSlot::assign(LottieObject* target, bool byDefault)
|
||||
void LottieSlot::assign(LottieProperty* target, bool byDefault)
|
||||
{
|
||||
auto copy = !overridden && !byDefault;
|
||||
auto shallow = pairs.count == 1 ? true : false;
|
||||
|
@ -214,22 +214,22 @@ void LottieSlot::assign(LottieObject* target, bool byDefault)
|
|||
switch (type) {
|
||||
case LottieProperty::Type::Float: {
|
||||
if (copy) pair->prop = new LottieFloat(static_cast<LottieTransform*>(pair->obj)->rotation);
|
||||
pair->obj->override(&static_cast<LottieTransform*>(target)->rotation, shallow, !copy);
|
||||
pair->obj->override(target, shallow, !copy);
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::Scalar: {
|
||||
if (copy) pair->prop = new LottieScalar(static_cast<LottieTransform*>(pair->obj)->scale);
|
||||
pair->obj->override(&static_cast<LottieTransform*>(target)->scale, shallow, !copy);
|
||||
pair->obj->override(target, shallow, !copy);
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::Vector: {
|
||||
if (copy) pair->prop = new LottieVector(static_cast<LottieTransform*>(pair->obj)->position);
|
||||
pair->obj->override(&static_cast<LottieTransform*>(target)->position, shallow, !copy);
|
||||
pair->obj->override(target, shallow, !copy);
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::Color: {
|
||||
if (copy) pair->prop = new LottieColor(static_cast<LottieSolid*>(pair->obj)->color);
|
||||
pair->obj->override(&static_cast<LottieSolid*>(target)->color, shallow, !copy);
|
||||
pair->obj->override(target, shallow, !copy);
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::Opacity: {
|
||||
|
@ -237,22 +237,22 @@ void LottieSlot::assign(LottieObject* target, bool byDefault)
|
|||
if (pair->obj->type == LottieObject::Type::Transform) pair->prop = new LottieOpacity(static_cast<LottieTransform*>(pair->obj)->opacity);
|
||||
else pair->prop = new LottieOpacity(static_cast<LottieSolid*>(pair->obj)->opacity);
|
||||
}
|
||||
pair->obj->override(&static_cast<LottieSolid*>(target)->opacity, shallow, !copy);
|
||||
pair->obj->override(target, shallow, !copy);
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::ColorStop: {
|
||||
if (copy) pair->prop = new LottieColorStop(static_cast<LottieGradient*>(pair->obj)->colorStops);
|
||||
pair->obj->override(&static_cast<LottieGradient*>(target)->colorStops, shallow, !copy);
|
||||
pair->obj->override(target, shallow, !copy);
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::TextDoc: {
|
||||
if (copy) pair->prop = new LottieTextDoc(static_cast<LottieText*>(pair->obj)->doc);
|
||||
pair->obj->override(&static_cast<LottieText*>(target)->doc, shallow, !copy);
|
||||
pair->obj->override(target, shallow, !copy);
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::Image: {
|
||||
if (copy) pair->prop = new LottieBitmap(static_cast<LottieImage*>(pair->obj)->data);
|
||||
pair->obj->override(&static_cast<LottieImage*>(target)->data, shallow, !copy);
|
||||
pair->obj->override(target, shallow, !copy);
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
|
|
|
@ -1058,7 +1058,7 @@ struct LottieSlot
|
|||
LottieProperty* prop;
|
||||
};
|
||||
|
||||
void assign(LottieObject* target, bool byDefault);
|
||||
void assign(LottieProperty* target, bool byDefault);
|
||||
void reset();
|
||||
|
||||
LottieSlot(LottieLayer* layer, LottieObject* parent, char* sid, LottieObject* obj, LottieProperty::Type type) : context{layer, parent}, sid(sid), type(type)
|
||||
|
|
|
@ -1543,68 +1543,78 @@ bool LottieParser::apply(LottieSlot* slot, bool byDefault)
|
|||
{
|
||||
enterObject();
|
||||
|
||||
//OPTIMIZE: we can create the property directly, without object
|
||||
LottieObject* obj = nullptr; //slot object
|
||||
LottieProperty* prop = nullptr;
|
||||
context = {slot->context.layer, slot->context.parent};
|
||||
|
||||
switch (slot->type) {
|
||||
case LottieProperty::Type::Float: {
|
||||
obj = new LottieTransform;
|
||||
parseSlotProperty(static_cast<LottieTransform*>(obj)->rotation);
|
||||
prop = new LottieFloat;
|
||||
parseSlotProperty(*static_cast<LottieFloat*>(prop));
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::Scalar: {
|
||||
obj = new LottieTransform;
|
||||
parseSlotProperty(static_cast<LottieTransform*>(obj)->scale);
|
||||
prop = new LottieScalar;
|
||||
parseSlotProperty(*static_cast<LottieScalar*>(prop));
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::Vector: {
|
||||
obj = new LottieTransform;
|
||||
parseSlotProperty(static_cast<LottieTransform*>(obj)->position);
|
||||
prop = new LottieVector;
|
||||
parseSlotProperty(*static_cast<LottieVector*>(prop));
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::Opacity: {
|
||||
obj = new LottieSolid;
|
||||
parseSlotProperty(static_cast<LottieSolid*>(obj)->opacity);
|
||||
prop = new LottieOpacity;
|
||||
parseSlotProperty(*static_cast<LottieOpacity*>(prop));
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::Color: {
|
||||
obj = new LottieSolid;
|
||||
parseSlotProperty(static_cast<LottieSolid*>(obj)->color);
|
||||
prop = new LottieColor;
|
||||
parseSlotProperty(*static_cast<LottieColor*>(prop));
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::ColorStop: {
|
||||
obj = new LottieGradient;
|
||||
auto obj = new LottieGradient;
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("p")) parseColorStop(static_cast<LottieGradient*>(obj));
|
||||
if (KEY_AS("p")) parseColorStop(obj);
|
||||
else skip();
|
||||
}
|
||||
if (!obj) {
|
||||
delete(obj);
|
||||
return false;
|
||||
}
|
||||
prop = new LottieColorStop(obj->colorStops);
|
||||
delete(obj);
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::TextDoc: {
|
||||
obj = new LottieText;
|
||||
parseSlotProperty(static_cast<LottieText*>(obj)->doc);
|
||||
prop = new LottieTextDoc;
|
||||
parseSlotProperty(*static_cast<LottieTextDoc*>(prop));
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::Image: {
|
||||
auto obj = new LottieObject;
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("p")) obj = parseAsset();
|
||||
else skip();
|
||||
}
|
||||
if (!obj) {
|
||||
delete(obj);
|
||||
return false;
|
||||
}
|
||||
prop = new LottieBitmap(static_cast<LottieImage*>(obj)->data);
|
||||
delete(obj);
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (!obj || Invalid()) {
|
||||
delete(obj);
|
||||
if (!prop || Invalid()) {
|
||||
delete(prop);
|
||||
return false;
|
||||
}
|
||||
|
||||
slot->assign(obj, byDefault);
|
||||
|
||||
delete(obj);
|
||||
|
||||
slot->assign(prop, byDefault);
|
||||
delete(prop);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue