Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rlottie: now loadFromData() api takes resourcePath for loading external resource #3

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/lottieview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion example/lottieview.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class LottieView
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);
Expand Down
2 changes: 1 addition & 1 deletion inc/rlottie.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class LOT_EXPORT Animation {
* @internal
*/
static std::unique_ptr<Animation>
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.
Expand Down
3 changes: 2 additions & 1 deletion inc/rlottie_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ 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.
*
* @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.
Expand Down
4 changes: 2 additions & 2 deletions src/binding/c/lottieanimation_capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/lottie/lottieanimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,16 @@ std::future<Surface> AnimationImpl::renderAsync(size_t frameNo, Surface &&surfac
* @param path add the details
*/
std::unique_ptr<Animation>
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";
return nullptr;
}

LottieLoader loader;
if (loader.loadFromData(std::move(jsonData), key)) {
if (loader.loadFromData(std::move(jsonData), key,
(resourcePath.empty() ? " " : resourcePath))) {
auto animation = std::unique_ptr<Animation>(new Animation);
animation->d->init(loader.model());
return animation;
Expand Down
4 changes: 2 additions & 2 deletions src/lottie/lottieloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char *>(jsonData.c_str()));
LottieParser parser(const_cast<char *>(jsonData.c_str()), resourcePath.c_str());
mModel = parser.model();
fileCache.add(key, mModel);

Expand Down
2 changes: 1 addition & 1 deletion src/lottie/lottieloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<LOTModel> model();
private:
std::shared_ptr<LOTModel> mModel;
Expand Down
2 changes: 1 addition & 1 deletion src/lottie/lottieparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<LOTModel> model();
private:
LottieParserImpl *d;
Expand Down