summaryrefslogtreecommitdiffstats
path: root/wgpu/src/image/vector.rs
diff options
context:
space:
mode:
Diffstat (limited to 'wgpu/src/image/vector.rs')
-rw-r--r--wgpu/src/image/vector.rs32
1 files changed, 21 insertions, 11 deletions
diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs
index cd511a45..4c830913 100644
--- a/wgpu/src/image/vector.rs
+++ b/wgpu/src/image/vector.rs
@@ -1,7 +1,9 @@
+use crate::image::atlas::{self, Atlas};
+
use iced_native::svg;
-use std::collections::{HashMap, HashSet};
-use crate::image::atlas::{self, Atlas};
+use std::collections::{HashMap, HashSet};
+use std::fs;
pub enum Svg {
Loaded(usvg::Tree),
@@ -46,13 +48,21 @@ impl Cache {
let svg = match handle.data() {
svg::Data::Path(path) => {
- match usvg::Tree::from_file(path, &Default::default()) {
- Ok(tree) => Svg::Loaded(tree),
- Err(_) => Svg::NotFound,
- }
+ let tree = fs::read_to_string(path).ok().and_then(|contents| {
+ usvg::Tree::from_str(
+ &contents,
+ &usvg::Options::default().to_ref(),
+ )
+ .ok()
+ });
+
+ tree.map(Svg::Loaded).unwrap_or(Svg::NotFound)
}
svg::Data::Bytes(bytes) => {
- match usvg::Tree::from_data(&bytes, &Default::default()) {
+ match usvg::Tree::from_data(
+ &bytes,
+ &usvg::Options::default().to_ref(),
+ ) {
Ok(tree) => Svg::Loaded(tree),
Err(_) => Svg::NotFound,
}
@@ -100,17 +110,17 @@ impl Cache {
// We currently rerasterize the SVG when its size changes. This is slow
// as heck. A GPU rasterizer like `pathfinder` may perform better.
// It would be cool to be able to smooth resize the `svg` example.
- let img = resvg::render(
+ let mut img = tiny_skia::Pixmap::new(width, height)?;
+
+ let _ = resvg::render(
tree,
if width > height {
usvg::FitTo::Width(width)
} else {
usvg::FitTo::Height(height)
},
- None,
+ img.as_mut(),
)?;
- let width = img.width();
- let height = img.height();
let mut rgba = img.take();
rgba.chunks_exact_mut(4).for_each(|rgba| rgba.swap(0, 2));