diff --git a/src/common/tvgStr.cpp b/src/common/tvgStr.cpp index 769c30ff..584ef633 100644 --- a/src/common/tvgStr.cpp +++ b/src/common/tvgStr.cpp @@ -265,4 +265,14 @@ const char* fileext(const char* path) return ext; } + +char* concat(const char* a, const char* b) +{ + auto len = strlen(a) + strlen(b) + 1; + auto ret = tvg::malloc(len * sizeof(char)); + strcpy(ret, a); + strcat(ret, b); + return ret; +} + } diff --git a/src/common/tvgStr.h b/src/common/tvgStr.h index 6e9f188c..60f35102 100644 --- a/src/common/tvgStr.h +++ b/src/common/tvgStr.h @@ -33,6 +33,7 @@ static inline bool equal(const char* a, const char* b) return !strcmp(a, b) && strlen(a) == strlen(b); } +char* concat(const char* a, const char* b); float toFloat(const char *str, char **end); //convert to float char* duplicate(const char *str, size_t n = SIZE_MAX); //copy the string char* append(char* lhs, const char* rhs, size_t n); //append the rhs to the lhs diff --git a/src/loaders/lottie/jerryscript/jerry-core/api/jerryscript.cpp b/src/loaders/lottie/jerryscript/jerry-core/api/jerryscript.cpp index b3529f63..6127ae60 100644 --- a/src/loaders/lottie/jerryscript/jerry-core/api/jerryscript.cpp +++ b/src/loaders/lottie/jerryscript/jerry-core/api/jerryscript.cpp @@ -216,6 +216,18 @@ jerry_value_is_object (const jerry_value_t value) /**< api value */ return ecma_is_value_object (value); } /* jerry_value_is_object */ +/** + * Check if the specified value is string. + * + * @return true - if the specified value is string, + * false - otherwise + */ +bool +jerry_value_is_string (const jerry_value_t value) /**< api value */ +{ + return ecma_is_value_string (value); +} /* jerry_value_is_string */ + /** * Check if the specified value is undefined. * diff --git a/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-core.h b/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-core.h index 781bb964..e10e6e35 100644 --- a/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-core.h +++ b/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-core.h @@ -29,6 +29,7 @@ jerry_value_t jerry_run (const jerry_value_t script); bool jerry_value_is_undefined (const jerry_value_t value); bool jerry_value_is_number (const jerry_value_t value); bool jerry_value_is_object (const jerry_value_t value); +bool jerry_value_is_string (const jerry_value_t value); bool jerry_value_is_exception (const jerry_value_t value); jerry_value_t jerry_value_to_object (const jerry_value_t value); jerry_value_t jerry_value_to_string (const jerry_value_t value); diff --git a/src/loaders/lottie/tvgLottieExpressions.cpp b/src/loaders/lottie/tvgLottieExpressions.cpp index 84dfcc7a..df6583c4 100644 --- a/src/loaders/lottie/tvgLottieExpressions.cpp +++ b/src/loaders/lottie/tvgLottieExpressions.cpp @@ -336,6 +336,19 @@ static void _buildLayer(jerry_value_t context, float frameNo, LottieLayer* layer static jerry_value_t _addsub(const jerry_value_t args[], float addsub) { + //string + string + if (jerry_value_is_string(args[0]) || jerry_value_is_string(args[1])) { + auto a = _name(args[0]); + auto b = _name(args[1]); + auto ret = tvg::concat(a, b); + auto val = jerry_string_sz(ret); + tvg::free(ret); + tvg::free(a); + tvg::free(b); + return val; + } + + //number + number auto n1 = jerry_value_is_number(args[0]); auto n2 = jerry_value_is_number(args[1]); diff --git a/src/loaders/lottie/tvgLottieExpressions.h b/src/loaders/lottie/tvgLottieExpressions.h index c7e759ef..6fd1bdda 100644 --- a/src/loaders/lottie/tvgLottieExpressions.h +++ b/src/loaders/lottie/tvgLottieExpressions.h @@ -123,6 +123,21 @@ public: return true; } + bool result(float frameNo, TextDocument& doc, LottieExpression* exp) + { + auto bm_rt = evaluate(frameNo, exp); + if (jerry_value_is_undefined(bm_rt)) return false; + + if (jerry_value_is_string(bm_rt)) { + auto len = jerry_string_length(bm_rt); + doc.text = tvg::realloc(doc.text, (len + 1) * sizeof(jerry_char_t)); + jerry_string_to_buffer(bm_rt, JERRY_ENCODING_UTF8, (jerry_char_t*)doc.text, len); + doc.text[len] = '\0'; + } + jerry_value_free(bm_rt); + return true; + } + void update(float curTime); //singleton (no thread safety) @@ -158,6 +173,7 @@ struct LottieExpressions template bool result(TVG_UNUSED float, TVG_UNUSED RGB24&, TVG_UNUSED LottieExpression*) { return false; } template bool result(TVG_UNUSED float, TVG_UNUSED Fill*, TVG_UNUSED LottieExpression*) { return false; } template bool result(TVG_UNUSED float, TVG_UNUSED RenderPath&, TVG_UNUSED Matrix*, TVG_UNUSED LottieModifier*, TVG_UNUSED LottieExpression*) { return false; } + bool result(TVG_UNUSED float, TVG_UNUSED TextDocument& doc, TVG_UNUSED LottieExpression*) { return false; } void update(TVG_UNUSED float) {} static LottieExpressions* instance() { return nullptr; } static void retrieve(TVG_UNUSED LottieExpressions* instance) {} diff --git a/src/loaders/lottie/tvgLottieProperty.h b/src/loaders/lottie/tvgLottieProperty.h index 01e8df1f..4cafccfc 100644 --- a/src/loaders/lottie/tvgLottieProperty.h +++ b/src/loaders/lottie/tvgLottieProperty.h @@ -890,11 +890,8 @@ struct LottieTextDoc : LottieProperty return (*frames)[frames->count]; } - TextDocument& operator()(float frameNo, LottieExpressions* exps = nullptr) + TextDocument& operator()(float frameNo) { - //overriding with expressions - if (exps && exp) TVGERR("LOTTIE", "Not support TextDocument expressions?"); - if (!frames) return value; if (frames->count == 1 || frameNo <= frames->first().no) return frames->first().value; if (frameNo >= frames->last().no) return frames->last().value; @@ -903,6 +900,19 @@ struct LottieTextDoc : LottieProperty return frame->value; } + TextDocument& operator()(float frameNo, LottieExpressions* exps) + { + auto& out = operator()(frameNo); + + //overriding with expressions + if (exps && exp) { + frameNo = _loop(frames, frameNo, exp); + exps->result(frameNo, out, exp); + } + + return out; + } + void copy(LottieTextDoc& rhs, bool shallow = true) { if (LottieProperty::copy(&rhs, shallow)) return;