From 71a5c3ad0271580812ea50201f2ffd51c1d2c69c Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Fri, 23 Feb 2024 15:24:15 +0900 Subject: [PATCH] binding/capi: support lottie extensions these experimental apis are allowed to use when the lottie loader is enabled. APIs: - Tvg_Animation* tvg_lottie_animation_new() - Tvg_Result tvg_lottie_animation_override(Tvg_Animation* animation, const char* slot) --- src/bindings/capi/thorvg_capi.h | 42 ++++++++++++++++++++++++++++++++- src/bindings/capi/tvgCapi.cpp | 23 ++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/bindings/capi/thorvg_capi.h b/src/bindings/capi/thorvg_capi.h index 347fc248..6de03276 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -2316,7 +2316,47 @@ TVG_API Tvg_Result tvg_animation_get_duration(Tvg_Animation* animation, float* d TVG_API Tvg_Result tvg_animation_del(Tvg_Animation* animation); -/** \} */ // end defgroup ThorVG_CAPI +/** \} */ // end defgroup ThorVGCapi_Animation + + +/** +* \defgroup ThorVGCapi_LottieAnimation LottieAnimation +* \brief A module for manipulation of lottie extension features. +* +* The module enables control of advanced Lottie features. +* \{ +*/ + +/************************************************************************/ +/* LottieAnimation Extension API */ +/************************************************************************/ + +/*! +* \brief Creates a new LottieAnimation object. (Experimental API) +* +* \return Tvg_Animation A new Tvg_LottieAnimation object. +*/ +TVG_API Tvg_Animation* tvg_lottie_animation_new(); + + +/*! +* \brief Override the lottie properties through the slot data. (Experimental API) +* +* \param[in] animation The Tvg_Animation object to override the property with the slot. +* \param[in] slot The lottie slot data in json. +* +* \return Tvg_Animation A new Tvg_LottieAnimation object. +* \retval TVG_RESULT_SUCCESS Succeed. +* \retval TVG_RESULT_INSUFFICIENT_CONDITION When the given @p slot is invalid +* \retval TVG_RESULT_NOT_SUPPORTED The Lottie Animation is not supported. +*/ +TVG_API Tvg_Result tvg_lottie_animation_override(Tvg_Animation* animation, const char* slot); + + +/** \} */ // end addtogroup ThorVGCapi_LottieAnimation + + +/** \} */ // end defgroup ThorVGCapi #ifdef __cplusplus diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index 620adf4b..5f47d7c2 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -773,6 +773,29 @@ TVG_API Tvg_Result tvg_animation_del(Tvg_Animation* animation) return TVG_RESULT_SUCCESS; } + +/************************************************************************/ +/* Lottie Animation API */ +/************************************************************************/ + +TVG_API Tvg_Animation* tvg_lottie_animation_new() +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + return (Tvg_Animation*) LottieAnimation::gen().release(); +#endif + return nullptr; +} + + +TVG_API Tvg_Result tvg_lottie_animation_override(Tvg_Animation* animation, const char* slot) +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + if (!animation) return TVG_RESULT_INVALID_ARGUMENT; + return (Tvg_Result) reinterpret_cast(animation)->override(slot); +#endif + return TVG_RESULT_NOT_SUPPORTED; +} + #ifdef __cplusplus } #endif