Update resvg to 0.18 in iced_wgpu
This commit is contained in:
parent
35c4ad6dd9
commit
73f2881568
2 changed files with 29 additions and 15 deletions
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
use iced_native::svg;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use crate::image::atlas::{self, Atlas};
|
||||
|
||||
use iced_native::svg;
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs;
|
||||
|
||||
pub enum Svg {
|
||||
Loaded(usvg::Tree),
|
||||
NotFound,
|
||||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue