🐛 Fix problem with gradient in strokes

This commit is contained in:
alonso.torres 2025-02-25 11:29:57 +01:00
parent 052282cff9
commit c48d862d0f
2 changed files with 14 additions and 12 deletions

View file

@ -347,7 +347,7 @@
offset (:offset stop)] offset (:offset stop)]
[r g b a (* 100 offset)])) [r g b a (* 100 offset)]))
stops))))) stops)))))
(h/call internal-module "_add_shape_stroke_stops" stops-ptr n-stops)) (h/call internal-module "_add_shape_stroke_stops"))
(some? image) (some? image)
(let [id (dm/get-prop image :id) (let [id (dm/get-prop image :id)

View file

@ -546,21 +546,23 @@ pub extern "C" fn add_shape_stroke_radial_fill(
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn add_shape_stroke_stops(ptr: *mut shapes::RawStopData, n_stops: u32) { pub extern "C" fn add_shape_stroke_stops() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); let bytes = mem::bytes();
let entries: Vec<_> = bytes
.chunks(size_of::<shapes::RawStopData>())
.map(|data| shapes::RawStopData::from_bytes(data.try_into().unwrap()))
.collect();
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() { if let Some(shape) = state.current_shape() {
let len = n_stops as usize;
unsafe {
let buffer = Vec::<shapes::RawStopData>::from_raw_parts(ptr, len, len);
shape shape
.add_stroke_gradient_stops(buffer) .add_stroke_gradient_stops(entries)
.expect("could not add gradient stops"); .expect("could not add gradient stops");
}
mem::free_bytes(); mem::free_bytes();
} }
}
}
// Extracts a string from the bytes slice until the next null byte (0) and returns the result as a `String`. // Extracts a string from the bytes slice until the next null byte (0) and returns the result as a `String`.
// Updates the `start` index to the end of the extracted string. // Updates the `start` index to the end of the extracted string.