diff options
| author | 2021-09-27 14:23:22 +0700 | |
|---|---|---|
| committer | 2021-09-27 14:23:22 +0700 | |
| commit | 73f288156899ddd51ae686e95bdf09f9bd129df4 (patch) | |
| tree | 5597839448f583299d53fb6c9851fc343eea48c3 /wgpu/src | |
| 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 '')
| -rw-r--r-- | wgpu/src/image/vector.rs | 32 | 
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)); | 
