diff --git a/example/lottieview.cpp b/example/lottieview.cpp index 7671735e62..383aa6dd98 100644 --- a/example/lottieview.cpp +++ b/example/lottieview.cpp @@ -369,9 +369,9 @@ void LottieView::setFilePath(const char *filePath) } } -void LottieView::loadFromData(const std::string &jsonData, const std::string &key) +void LottieView::loadFromData(const std::string &jsonData, const std::string &key, const std::string &resourcePath) { - if (mPlayer = Animation::loadFromData(jsonData, key)) { + if (mPlayer = Animation::loadFromData(jsonData, key, resourcePath)) { mFrameRate = mPlayer->frameRate(); mTotalFrame = mPlayer->totalFrame(); } else { diff --git a/example/lottieview.h b/example/lottieview.h index 1ff8266c5c..f979c56a9c 100644 --- a/example/lottieview.h +++ b/example/lottieview.h @@ -49,7 +49,7 @@ public: void setSize(int w, int h); void setPos(int x, int y); void setFilePath(const char *filePath); - void loadFromData(const std::string &jsonData, const std::string &key); + void loadFromData(const std::string &jsonData, const std::string &key, const std::string &resourcePath=""); void show(); void hide(); void loop(bool loop); diff --git a/inc/rlottie.h b/inc/rlottie.h index 7821641188..135ab53d90 100644 --- a/inc/rlottie.h +++ b/inc/rlottie.h @@ -143,7 +143,7 @@ public: * @internal */ static std::unique_ptr - loadFromData(std::string jsonData, const std::string &key); + loadFromData(std::string jsonData, const std::string &key, const std::string &resourcePath=""); /** * @brief Returns default framerate of the Lottie resource. diff --git a/inc/rlottie_capi.h b/inc/rlottie_capi.h index 8cc84c57d9..2c8a199fc7 100644 --- a/inc/rlottie_capi.h +++ b/inc/rlottie_capi.h @@ -49,6 +49,7 @@ LOT_EXPORT Lottie_Animation *lottie_animation_from_file(const char *path); * * @param[in] data The JSON string data. * @param[in] key the string that will be used to cache the JSON string data. + * @param[in] resource_path the path that will be used to load external resource needed by the JSON data. * * @return Animation object that can build the contents of the * Lottie resource represented by JSON string data. @@ -56,7 +57,7 @@ LOT_EXPORT Lottie_Animation *lottie_animation_from_file(const char *path); * @ingroup Lottie_Animation * @internal */ -LOT_EXPORT Lottie_Animation *lottie_animation_from_data(const char *data, const char *key); +LOT_EXPORT Lottie_Animation *lottie_animation_from_data(const char *data, const char *key, const char *resource_path); /** * @brief Free given Animation object resource. diff --git a/src/binding/c/lottieanimation_capi.cpp b/src/binding/c/lottieanimation_capi.cpp index dd7f5e13fe..cd85bd3789 100644 --- a/src/binding/c/lottieanimation_capi.cpp +++ b/src/binding/c/lottieanimation_capi.cpp @@ -41,9 +41,9 @@ LOT_EXPORT Lottie_Animation_S *lottie_animation_from_file(const char *path) } } -LOT_EXPORT Lottie_Animation_S *lottie_animation_from_data(const char *data, const char *key) +LOT_EXPORT Lottie_Animation_S *lottie_animation_from_data(const char *data, const char *key, const char *resourcePath) { - if (auto animation = Animation::loadFromData(data, key) ) { + if (auto animation = Animation::loadFromData(data, key, resourcePath) ) { Lottie_Animation_S *handle = new Lottie_Animation_S(); handle->mAnimation = std::move(animation); return handle; diff --git a/src/lottie/lottieanimation.cpp b/src/lottie/lottieanimation.cpp index 2fcfceb547..bc86d4be57 100644 --- a/src/lottie/lottieanimation.cpp +++ b/src/lottie/lottieanimation.cpp @@ -198,7 +198,7 @@ std::future AnimationImpl::renderAsync(size_t frameNo, Surface &&surfac * @param path add the details */ std::unique_ptr -Animation::loadFromData(std::string jsonData, const std::string &key) +Animation::loadFromData(std::string jsonData, const std::string &key, const std::string &resourcePath) { if (jsonData.empty()) { vWarning << "jason data is empty"; @@ -206,7 +206,8 @@ Animation::loadFromData(std::string jsonData, const std::string &key) } LottieLoader loader; - if (loader.loadFromData(std::move(jsonData), key)) { + if (loader.loadFromData(std::move(jsonData), key, + (resourcePath.empty() ? " " : resourcePath))) { auto animation = std::unique_ptr(new Animation); animation->d->init(loader.model()); return animation; diff --git a/src/lottie/lottieloader.cpp b/src/lottie/lottieloader.cpp index 6b540f8102..7aab52585f 100644 --- a/src/lottie/lottieloader.cpp +++ b/src/lottie/lottieloader.cpp @@ -90,14 +90,14 @@ bool LottieLoader::load(const std::string &path) return true; } -bool LottieLoader::loadFromData(std::string &&jsonData, const std::string &key) +bool LottieLoader::loadFromData(std::string &&jsonData, const std::string &key, const std::string &resourcePath) { LottieFileCache &fileCache = LottieFileCache::get(); mModel = fileCache.find(key); if (mModel) return true; - LottieParser parser(const_cast(jsonData.c_str())); + LottieParser parser(const_cast(jsonData.c_str()), resourcePath.c_str()); mModel = parser.model(); fileCache.add(key, mModel); diff --git a/src/lottie/lottieloader.h b/src/lottie/lottieloader.h index 1f6f3d5258..d7228bbce1 100644 --- a/src/lottie/lottieloader.h +++ b/src/lottie/lottieloader.h @@ -27,7 +27,7 @@ class LottieLoader { public: bool load(const std::string &filePath); - bool loadFromData(std::string &&jsonData, const std::string &key); + bool loadFromData(std::string &&jsonData, const std::string &key, const std::string &resourcePath); std::shared_ptr model(); private: std::shared_ptr mModel; diff --git a/src/lottie/lottieparser.h b/src/lottie/lottieparser.h index d892c24507..21e5ae8a43 100644 --- a/src/lottie/lottieparser.h +++ b/src/lottie/lottieparser.h @@ -25,7 +25,7 @@ class LottieParserImpl; class LottieParser { public: ~LottieParser(); - LottieParser(char* str, const char *dir_path=""); + LottieParser(char* str, const char *dir_path); std::shared_ptr model(); private: LottieParserImpl *d;