summaryrefslogtreecommitdiffstats
path: root/tiny_skia
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-04-04 01:47:18 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-04-04 01:56:50 +0200
commit04c0ba04bf8574acdcbd5ad9fa20ac9c863f6087 (patch)
treefe13145749b0d1822c92b3c8499f91973ba15261 /tiny_skia
parent0b459c8e240abf83bb62902a504c018194acdbb6 (diff)
downloadiced-04c0ba04bf8574acdcbd5ad9fa20ac9c863f6087.tar.gz
iced-04c0ba04bf8574acdcbd5ad9fa20ac9c863f6087.tar.bz2
iced-04c0ba04bf8574acdcbd5ad9fa20ac9c863f6087.zip
Warn about invalid paths in `iced_tiny_skia` instead of panicking
Diffstat (limited to 'tiny_skia')
-rw-r--r--tiny_skia/Cargo.toml1
-rw-r--r--tiny_skia/src/geometry.rs20
2 files changed, 14 insertions, 7 deletions
diff --git a/tiny_skia/Cargo.toml b/tiny_skia/Cargo.toml
index 31f5cb6b..349f6903 100644
--- a/tiny_skia/Cargo.toml
+++ b/tiny_skia/Cargo.toml
@@ -15,6 +15,7 @@ tiny-skia = "0.8"
bytemuck = "1"
rustc-hash = "1.1"
kurbo = "0.9"
+log = "0.4"
[dependencies.iced_graphics]
version = "0.7"
diff --git a/tiny_skia/src/geometry.rs b/tiny_skia/src/geometry.rs
index c66621dd..4e3941f3 100644
--- a/tiny_skia/src/geometry.rs
+++ b/tiny_skia/src/geometry.rs
@@ -39,7 +39,7 @@ impl Frame {
}
pub fn fill(&mut self, path: &Path, fill: impl Into<Fill>) {
- let path = convert_path(path);
+ let Some(path) = convert_path(path) else { return };
let fill = fill.into();
self.primitives.push(Primitive::Fill {
@@ -56,7 +56,7 @@ impl Frame {
size: Size,
fill: impl Into<Fill>,
) {
- let path = convert_path(&Path::rectangle(top_left, size));
+ let Some(path) = convert_path(&Path::rectangle(top_left, size)) else { return };
let fill = fill.into();
self.primitives.push(Primitive::Fill {
@@ -71,7 +71,8 @@ impl Frame {
}
pub fn stroke<'a>(&mut self, path: &Path, stroke: impl Into<Stroke<'a>>) {
- let path = convert_path(path);
+ let Some(path) = convert_path(path) else { return };
+
let stroke = stroke.into();
let skia_stroke = into_stroke(&stroke);
@@ -151,7 +152,7 @@ impl Frame {
}
}
-fn convert_path(path: &Path) -> tiny_skia::Path {
+fn convert_path(path: &Path) -> Option<tiny_skia::Path> {
use iced_graphics::geometry::path::lyon_path;
let mut builder = tiny_skia::PathBuilder::new();
@@ -205,9 +206,14 @@ fn convert_path(path: &Path) -> tiny_skia::Path {
}
}
- builder
- .finish()
- .expect("Convert lyon path to tiny_skia path")
+ let result = builder.finish();
+
+ #[cfg(debug_assertions)]
+ if result.is_none() {
+ log::warn!("Invalid path: {:?}", path.raw());
+ }
+
+ result
}
pub fn into_paint(style: Style) -> tiny_skia::Paint<'static> {