diff --git a/inc/thorvg.h b/inc/thorvg.h index f84ce3e5..1538ba8d 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -2143,6 +2143,22 @@ public: */ Result set(const Picture* picture, std::function func, void* data) noexcept; + /** + * @brief Generate a unique ID (hash key) from a given name. + * + * This function computes a unique identifier value based on the provided string. + * You can use this to assign a unique ID to the Paint object. + * + * @param[in] name The input string to generate the unique identifier from. + * + * @return The generated unique identifier value. + * + * @see Paint::id + * + * @note Experimental API + */ + static uint32_t id(const char* name) noexcept; + /** * @brief Creates a new Accessor object. * diff --git a/src/bindings/capi/thorvg_capi.h b/src/bindings/capi/thorvg_capi.h index 2313366c..35f49ba9 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -2569,6 +2569,36 @@ TVG_API Tvg_Result tvg_animation_del(Tvg_Animation* animation); /** \} */ // end defgroup ThorVGCapi_Animation +/** +* \defgroup ThorVGCapi_Accesssor Accessor +* \brief A module for manipulation of the scene tree +* +* This module helps to control the scene tree. +* \{ +*/ + +/************************************************************************/ +/* Accessor API */ +/************************************************************************/ + +/*! +* \brief Generate a unique ID (hash key) from a given name. +* +* This function computes a unique identifier value based on the provided string. +* You can use this to assign a unique ID to the Paint object. +* +* \param[in] name The input string to generate the unique identifier from. +* +* \return The generated unique identifier value. +* +* \note Experimental API +*/ +TVG_API uint32_t tvg_accessor_generate_id(const char* name); + + +/** \} */ // end defgroup ThorVGCapi_Accessor + + /** * \defgroup ThorVGCapi_LottieAnimation LottieAnimation * \brief A module for manipulation of lottie extension features. diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index 6a6c8339..bc384889 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -894,6 +894,16 @@ TVG_API Tvg_Result tvg_animation_del(Tvg_Animation* animation) } +/************************************************************************/ +/* Accessor API */ +/************************************************************************/ + +TVG_API uint32_t tvg_accessor_generate_id(const char* name) +{ + return Accessor::id(name); +} + + /************************************************************************/ /* Lottie Animation API */ /************************************************************************/ diff --git a/src/common/tvgCompressor.cpp b/src/common/tvgCompressor.cpp index e7560e79..ffc563f7 100644 --- a/src/common/tvgCompressor.cpp +++ b/src/common/tvgCompressor.cpp @@ -478,6 +478,8 @@ size_t b64Decode(const char* encoded, const size_t len, char** decoded) unsigned long djb2Encode(const char* str) { + if (!str) return 0; + unsigned long hash = 5381; int c; diff --git a/src/renderer/tvgAccessor.cpp b/src/renderer/tvgAccessor.cpp index 213cf433..a1447268 100644 --- a/src/renderer/tvgAccessor.cpp +++ b/src/renderer/tvgAccessor.cpp @@ -21,6 +21,7 @@ */ #include "tvgIteratorAccessor.h" +#include "tvgCompressor.h" /************************************************************************/ /* Internal Class Implementation */ @@ -81,6 +82,12 @@ Result Accessor::set(const Picture* picture, function