diff --git a/rlottie/Cargo.toml b/rlottie/Cargo.toml index 4c787ea8..b7324d21 100644 --- a/rlottie/Cargo.toml +++ b/rlottie/Cargo.toml @@ -16,6 +16,7 @@ rust-version = "1.60" [features] serde = ["dep:serde", "rgb/serde"] +telegrand = [] [dependencies] rgb = { version = "0.8.32", default-features = false } diff --git a/rlottie/src/lib.rs b/rlottie/src/lib.rs index ccb681e8..57ed20b3 100644 --- a/rlottie/src/lib.rs +++ b/rlottie/src/lib.rs @@ -247,6 +247,46 @@ impl Animation { Self::from_ptr(ptr) } + /// Constructs an animation object from JSON string data. External resources are + /// resolved relative to `resource_path`. + /// + /// + /// + /// Note that the `cache_key` might be used by the rlottie library to cache the + /// json data and/or its resources. + /// + /// This method will panic if json_data or cache_key contain nul bytes. or fitzpatrick_type not in range 0..=6 + #[cfg(feature = "telegrand")] + pub fn from_data_recolored( + json_data: D, + cache_key: K, + resource_path: P, + fitzpatrick_type: i32 + ) -> Option + where + D: Into>, + K: Into>, + P: AsRef + { + assert!( + (0 ..= 6).contains(&fitzpatrick_type), + "fitzpatrick_type must be in range 0..=6" + ); + let json_data = + CString::new(json_data).expect("json_data must not contain nul"); + let cache_key = CString::new(cache_key).expect("key must not contain nul"); + let resource_path = path_to_cstr(resource_path); + let ptr = unsafe { + lottie_animation_from_data_recolored( + json_data.as_ptr(), + cache_key.as_ptr(), + resource_path.as_ptr(), + fitzpatrick_type + ) + }; + Self::from_ptr(ptr) + } + /// Return the default viewport size of this animation. pub fn size(&self) -> Size { let mut size = Size {