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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shape_to_path(shape: &Shape) -> Path {
|
fn shape_to_path(shape: &Shape) -> Option<Path> {
|
||||||
let mut pb = PathBuilder::new();
|
let mut pb = PathBuilder::new();
|
||||||
match shape {
|
match shape {
|
||||||
Shape::Point(vec) => {
|
Shape::Point(vec) => {
|
||||||
|
@ -111,7 +111,7 @@ impl<'a> Renderer<'a> {
|
||||||
pb.push_circle(position.x, position.y, *radius);
|
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> {
|
fn render_stroke(&mut self, _vm: &Vm, _value: Value, stroke: &Stroke) -> Result<(), Exception> {
|
||||||
|
@ -120,19 +120,19 @@ impl<'a> Renderer<'a> {
|
||||||
..default_paint()
|
..default_paint()
|
||||||
};
|
};
|
||||||
let transform = self.transform();
|
let transform = self.transform();
|
||||||
let path = Self::shape_to_path(&stroke.shape);
|
if let Some(path) = Self::shape_to_path(&stroke.shape) {
|
||||||
|
self.pixmap_mut().stroke_path(
|
||||||
self.pixmap_mut().stroke_path(
|
&path,
|
||||||
&path,
|
&paint,
|
||||||
&paint,
|
&SStroke {
|
||||||
&SStroke {
|
width: stroke.thickness,
|
||||||
width: stroke.thickness,
|
line_cap: LineCap::Round,
|
||||||
line_cap: LineCap::Round,
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
transform,
|
||||||
transform,
|
None,
|
||||||
None,
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -142,11 +142,12 @@ impl<'a> Renderer<'a> {
|
||||||
shader: Shader::SolidColor(tiny_skia_color(fill.color)),
|
shader: Shader::SolidColor(tiny_skia_color(fill.color)),
|
||||||
..default_paint()
|
..default_paint()
|
||||||
};
|
};
|
||||||
let transform = self.transform();
|
|
||||||
let path = Self::shape_to_path(&fill.shape);
|
|
||||||
|
|
||||||
self.pixmap_mut()
|
let transform = self.transform();
|
||||||
.fill_path(&path, &paint, FillRule::EvenOdd, transform, None);
|
if let Some(path) = Self::shape_to_path(&fill.shape) {
|
||||||
|
self.pixmap_mut()
|
||||||
|
.fill_path(&path, &paint, FillRule::EvenOdd, transform, None);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue