diff --git a/crates/haku/src/render.rs b/crates/haku/src/render.rs index ed8aa74..b31fa7d 100644 --- a/crates/haku/src/render.rs +++ b/crates/haku/src/render.rs @@ -89,7 +89,7 @@ impl<'a> Renderer<'a> { Ok(()) } - fn shape_to_path(shape: &Shape) -> Path { + fn shape_to_path(shape: &Shape) -> Option { let mut pb = PathBuilder::new(); match shape { Shape::Point(vec) => { @@ -111,7 +111,7 @@ impl<'a> Renderer<'a> { pb.push_circle(position.x, position.y, *radius); } } - pb.finish().unwrap() + pb.finish() } fn render_stroke(&mut self, _vm: &Vm, _value: Value, stroke: &Stroke) -> Result<(), Exception> { @@ -120,19 +120,19 @@ impl<'a> Renderer<'a> { ..default_paint() }; let transform = self.transform(); - let path = Self::shape_to_path(&stroke.shape); - - self.pixmap_mut().stroke_path( - &path, - &paint, - &SStroke { - width: stroke.thickness, - line_cap: LineCap::Round, - ..Default::default() - }, - transform, - None, - ); + if let Some(path) = Self::shape_to_path(&stroke.shape) { + self.pixmap_mut().stroke_path( + &path, + &paint, + &SStroke { + width: stroke.thickness, + line_cap: LineCap::Round, + ..Default::default() + }, + transform, + None, + ); + } Ok(()) } @@ -142,11 +142,12 @@ impl<'a> Renderer<'a> { shader: Shader::SolidColor(tiny_skia_color(fill.color)), ..default_paint() }; - let transform = self.transform(); - let path = Self::shape_to_path(&fill.shape); - self.pixmap_mut() - .fill_path(&path, &paint, FillRule::EvenOdd, transform, None); + let transform = self.transform(); + if let Some(path) = Self::shape_to_path(&fill.shape) { + self.pixmap_mut() + .fill_path(&path, &paint, FillRule::EvenOdd, transform, None); + } Ok(()) }