mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
lottie: code refactoring++
Unified the property expression and default version. This also helps to reduce the binarys size (O3=4k, S=360kb)
This commit is contained in:
parent
2b97cf7a0d
commit
f8da536d1a
2 changed files with 22 additions and 25 deletions
|
@ -980,7 +980,7 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo)
|
||||||
{
|
{
|
||||||
auto text = static_cast<LottieText*>(layer->children.first());
|
auto text = static_cast<LottieText*>(layer->children.first());
|
||||||
auto textGrouping = text->alignOption.grouping;
|
auto textGrouping = text->alignOption.grouping;
|
||||||
auto& doc = text->doc(frameNo);
|
auto& doc = text->doc(frameNo, exps);
|
||||||
auto p = doc.text;
|
auto p = doc.text;
|
||||||
|
|
||||||
if (!p || !text->font) return;
|
if (!p || !text->font) return;
|
||||||
|
|
|
@ -325,8 +325,15 @@ struct LottieGenericProperty : LottieProperty
|
||||||
return (*frames)[frames->count];
|
return (*frames)[frames->count];
|
||||||
}
|
}
|
||||||
|
|
||||||
Value operator()(float frameNo)
|
Value operator()(float frameNo, LottieExpressions* exps = nullptr)
|
||||||
{
|
{
|
||||||
|
//overriding with expressions
|
||||||
|
if (exps && exp) {
|
||||||
|
Value out{};
|
||||||
|
frameNo = _loop(frames, frameNo, exp);
|
||||||
|
if (exps->result<LottieGenericProperty<Frame, Value>>(frameNo, out, exp)) return out;
|
||||||
|
}
|
||||||
|
|
||||||
if (!frames) return value;
|
if (!frames) return value;
|
||||||
if (frames->count == 1 || frameNo <= frames->first().no) return frames->first().value;
|
if (frames->count == 1 || frameNo <= frames->first().no) return frames->first().value;
|
||||||
if (frameNo >= frames->last().no) return frames->last().value;
|
if (frameNo >= frames->last().no) return frames->last().value;
|
||||||
|
@ -336,16 +343,6 @@ struct LottieGenericProperty : LottieProperty
|
||||||
return frame->interpolate(frame + 1, frameNo);
|
return frame->interpolate(frame + 1, frameNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value operator()(float frameNo, LottieExpressions* exps)
|
|
||||||
{
|
|
||||||
if (exps && exp) {
|
|
||||||
Value out{};
|
|
||||||
frameNo = _loop(frames, frameNo, exp);
|
|
||||||
if (exps->result<LottieGenericProperty<Frame, Value>>(frameNo, out, exp)) return out;
|
|
||||||
}
|
|
||||||
return operator()(frameNo);
|
|
||||||
}
|
|
||||||
|
|
||||||
void copy(const LottieGenericProperty<Frame, Value, Scalar>& rhs, bool shallow = true)
|
void copy(const LottieGenericProperty<Frame, Value, Scalar>& rhs, bool shallow = true)
|
||||||
{
|
{
|
||||||
if (rhs.frames) {
|
if (rhs.frames) {
|
||||||
|
@ -448,8 +445,14 @@ struct LottiePathSet : LottieProperty
|
||||||
return (*frames)[frames->count];
|
return (*frames)[frames->count];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator()(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offset)
|
bool operator()(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offset, LottieExpressions* exps = nullptr)
|
||||||
{
|
{
|
||||||
|
//overriding with expressions
|
||||||
|
if (exps && exp) {
|
||||||
|
frameNo = _loop(frames, frameNo, exp);
|
||||||
|
if (exps->result<LottiePathSet>(frameNo, cmds, pts, transform, roundness, offset, exp)) return true;
|
||||||
|
}
|
||||||
|
|
||||||
PathSet* path = nullptr;
|
PathSet* path = nullptr;
|
||||||
LottieScalarFrame<PathSet>* frame = nullptr;
|
LottieScalarFrame<PathSet>* frame = nullptr;
|
||||||
float t;
|
float t;
|
||||||
|
@ -523,16 +526,6 @@ struct LottiePathSet : LottieProperty
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool operator()(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offset, LottieExpressions* exps)
|
|
||||||
{
|
|
||||||
if (exps && exp) {
|
|
||||||
frameNo = _loop(frames, frameNo, exp);
|
|
||||||
if (exps->result<LottiePathSet>(frameNo, cmds, pts, transform, roundness, offset, exp)) return true;
|
|
||||||
}
|
|
||||||
return operator()(frameNo, cmds, pts, transform, roundness, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
void prepare() {}
|
void prepare() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -613,8 +606,9 @@ struct LottieColorStop : LottieProperty
|
||||||
return (*frames)[frames->count];
|
return (*frames)[frames->count];
|
||||||
}
|
}
|
||||||
|
|
||||||
Result operator()(float frameNo, Fill* fill, LottieExpressions* exps)
|
Result operator()(float frameNo, Fill* fill, LottieExpressions* exps = nullptr)
|
||||||
{
|
{
|
||||||
|
//overriding with expressions
|
||||||
if (exps && exp) {
|
if (exps && exp) {
|
||||||
frameNo = _loop(frames, frameNo, exp);
|
frameNo = _loop(frames, frameNo, exp);
|
||||||
if (exps->result<LottieColorStop>(frameNo, fill, exp)) return Result::Success;
|
if (exps->result<LottieColorStop>(frameNo, fill, exp)) return Result::Success;
|
||||||
|
@ -754,8 +748,11 @@ struct LottieTextDoc : LottieProperty
|
||||||
return (*frames)[frames->count];
|
return (*frames)[frames->count];
|
||||||
}
|
}
|
||||||
|
|
||||||
TextDocument& operator()(float frameNo)
|
TextDocument& operator()(float frameNo, LottieExpressions* exps = nullptr)
|
||||||
{
|
{
|
||||||
|
//overriding with expressions
|
||||||
|
if (exps && exp) TVGERR("LOTTIE", "Not support TextDocument expressions?");
|
||||||
|
|
||||||
if (!frames) return value;
|
if (!frames) return value;
|
||||||
if (frames->count == 1 || frameNo <= frames->first().no) return frames->first().value;
|
if (frames->count == 1 || frameNo <= frames->first().no) return frames->first().value;
|
||||||
if (frameNo >= frames->last().no) return frames->last().value;
|
if (frameNo >= frames->last().no) return frames->last().value;
|
||||||
|
|
Loading…
Add table
Reference in a new issue