From 7e7a561d9f5a6dd9e1dba0e7fed0e54e5b31fc06 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Tue, 20 Jun 2023 17:16:29 +0900 Subject: [PATCH] common loader: enable lottie loader json/lottie extensions are recognized as Lottie file format. --- src/lib/tvgCommon.h | 2 +- src/lib/tvgLoader.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/lib/tvgCommon.h b/src/lib/tvgCommon.h index 3800c055..22683a6a 100644 --- a/src/lib/tvgCommon.h +++ b/src/lib/tvgCommon.h @@ -62,7 +62,7 @@ using namespace tvg; #define TVG_CLASS_ID_LINEAR 4 #define TVG_CLASS_ID_RADIAL 5 -enum class FileType { Tvg = 0, Svg, Raw, Png, Jpg, Webp, Unknown }; +enum class FileType { Tvg = 0, Svg, Lottie, Raw, Png, Jpg, Webp, Unknown }; #ifdef THORVG_LOG_ENABLED constexpr auto ErrorColor = "\033[31m"; //red diff --git a/src/lib/tvgLoader.cpp b/src/lib/tvgLoader.cpp index 4e6f7c3e..16b604c8 100644 --- a/src/lib/tvgLoader.cpp +++ b/src/lib/tvgLoader.cpp @@ -42,6 +42,10 @@ #include "tvgWebpLoader.h" #endif +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + #include "tvgLottieLoader.h" +#endif + #include "tvgRawLoader.h" /************************************************************************/ @@ -60,6 +64,12 @@ static LoadModule* _find(FileType type) case FileType::Svg: { #ifdef THORVG_SVG_LOADER_SUPPORT return new SvgLoader; +#endif + break; + } + case FileType::Lottie: { +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + return new LottieLoader; #endif break; } @@ -101,6 +111,10 @@ static LoadModule* _find(FileType type) format = "SVG"; break; } + case FileType::Lottie: { + format = "lottie(json)"; + break; + } case FileType::Raw: { format = "RAW"; break; @@ -133,6 +147,8 @@ static LoadModule* _findByPath(const string& path) auto ext = path.substr(path.find_last_of(".") + 1); if (!ext.compare("tvg")) return _find(FileType::Tvg); if (!ext.compare("svg")) return _find(FileType::Svg); + if (!ext.compare("json")) return _find(FileType::Lottie); + if (!ext.compare("lottie")) return _find(FileType::Lottie); if (!ext.compare("png")) return _find(FileType::Png); if (!ext.compare("jpg")) return _find(FileType::Jpg); if (!ext.compare("webp")) return _find(FileType::Webp); @@ -148,6 +164,7 @@ static LoadModule* _findByType(const string& mimeType) if (mimeType == "tvg") type = FileType::Tvg; else if (mimeType == "svg" || mimeType == "svg+xml") type = FileType::Svg; + else if (mimeType == "lottie" || mimeType == "json") type = FileType::Lottie; else if (mimeType == "raw") type = FileType::Raw; else if (mimeType == "png") type = FileType::Png; else if (mimeType == "jpg" || mimeType == "jpeg") type = FileType::Jpg;