mirror of
https://github.com/penpot/penpot.git
synced 2025-05-22 22:46:10 +02:00
♻️ Refactor gradient parsing from bytes
This commit is contained in:
parent
1f58f96e88
commit
64a2a08d24
3 changed files with 45 additions and 190 deletions
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue