fix crash occurring when a path cannot be created
this can occur if tiny_skia decides it doesn't like the path (e.g. circle with negative radius) i don't really care to render these since they're degenerate cases anyways
This commit is contained in:
parent
b059ef4c35
commit
43e6951f7d
|
@ -89,7 +89,7 @@ impl<'a> Renderer<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn shape_to_path(shape: &Shape) -> Path {
|
||||
fn shape_to_path(shape: &Shape) -> Option<Path> {
|
||||
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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue