♻️ Refactor gradient parsing from bytes

This commit is contained in:
Belén Albeza 2025-04-15 12:33:53 +02:00
parent 1f58f96e88
commit 64a2a08d24
3 changed files with 45 additions and 190 deletions

View file

@ -456,21 +456,6 @@ impl Shape {
self.fills.clear();
}
pub fn add_fill_gradient_stops(&mut self, buffer: Vec<RawStopData>) -> Result<(), String> {
let fill = self.fills.last_mut().ok_or("Shape has no fills")?;
let gradient = match fill {
Fill::LinearGradient(g) => Ok(g),
Fill::RadialGradient(g) => Ok(g),
_ => Err("Active fill is not a gradient"),
}?;
for stop in buffer.into_iter() {
gradient.add_stop(stop.color(), stop.offset());
}
Ok(())
}
pub fn strokes(&self) -> std::slice::Iter<Stroke> {
self.strokes.iter()
}
@ -485,22 +470,6 @@ impl Shape {
Ok(())
}
pub fn add_stroke_gradient_stops(&mut self, buffer: Vec<RawStopData>) -> Result<(), String> {
let stroke = self.strokes.last_mut().ok_or("Shape has no strokes")?;
let fill = &mut stroke.fill;
let gradient = match fill {
Fill::LinearGradient(g) => Ok(g),
Fill::RadialGradient(g) => Ok(g),
_ => Err("Active stroke is not a gradient"),
}?;
for stop in buffer.into_iter() {
gradient.add_stop(stop.color(), stop.offset());
}
Ok(())
}
pub fn clear_strokes(&mut self) {
self.strokes.clear();
}