diff options
author | 2021-09-27 14:23:22 +0700 | |
---|---|---|
committer | 2021-09-27 14:23:22 +0700 | |
commit | 73f288156899ddd51ae686e95bdf09f9bd129df4 (patch) | |
tree | 5597839448f583299d53fb6c9851fc343eea48c3 /wgpu | |
parent | 35c4ad6dd950fa91d181f4d3253fcb486bcf1b11 (diff) | |
download | iced-73f288156899ddd51ae686e95bdf09f9bd129df4.tar.gz iced-73f288156899ddd51ae686e95bdf09f9bd129df4.tar.bz2 iced-73f288156899ddd51ae686e95bdf09f9bd129df4.zip |
Update `resvg` to `0.18` in `iced_wgpu`
Diffstat (limited to 'wgpu')
-rw-r--r-- | wgpu/Cargo.toml | 10 | ||||
-rw-r--r-- | wgpu/src/image/vector.rs | 32 |
2 files changed, 28 insertions, 14 deletions
diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index a904fe87..4c2a3e42 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT AND OFL-1.1" repository = "https://github.com/hecrj/iced" [features] -svg = ["resvg", "usvg"] +svg = ["resvg", "usvg", "tiny-skia"] image = ["png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp"] png = ["image_rs/png"] jpeg = ["image_rs/jpeg"] @@ -55,11 +55,15 @@ default-features = false optional = true [dependencies.resvg] -version = "0.12" +version = "0.18" optional = true [dependencies.usvg] -version = "0.12" +version = "0.18" +optional = true + +[dependencies.tiny-skia] +version = "0.6" optional = true [package.metadata.docs.rs] 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)); |