Update resvg in iced_graphics

This commit is contained in:
Héctor Ramón Jiménez 2023-02-25 15:04:40 +01:00
parent 573d27eb52
commit 1475f5fa58
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
2 changed files with 9 additions and 20 deletions

View file

@ -11,7 +11,7 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"]
categories = ["gui"] categories = ["gui"]
[features] [features]
svg = ["resvg", "usvg", "tiny-skia"] svg = ["resvg"]
image = ["png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp"] image = ["png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp"]
png = ["image_rs/png"] png = ["image_rs/png"]
jpeg = ["image_rs/jpeg"] jpeg = ["image_rs/jpeg"]
@ -71,15 +71,7 @@ default-features = false
optional = true optional = true
[dependencies.resvg] [dependencies.resvg]
version = "0.18" version = "0.29"
optional = true
[dependencies.usvg]
version = "0.18"
optional = true
[dependencies.tiny-skia]
version = "0.6"
optional = true optional = true
[dependencies.kamadak-exif] [dependencies.kamadak-exif]

View file

@ -5,6 +5,8 @@ use crate::Color;
use iced_native::svg; use iced_native::svg;
use iced_native::Size; use iced_native::Size;
use resvg::tiny_skia;
use resvg::usvg;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::fs; use std::fs;
@ -21,7 +23,7 @@ impl Svg {
pub fn viewport_dimensions(&self) -> Size<u32> { pub fn viewport_dimensions(&self) -> Size<u32> {
match self { match self {
Svg::Loaded(tree) => { Svg::Loaded(tree) => {
let size = tree.svg_node().size; let size = tree.size;
Size::new(size.width() as u32, size.height() as u32) Size::new(size.width() as u32, size.height() as u32)
} }
@ -51,20 +53,14 @@ impl<T: Storage> Cache<T> {
let svg = match handle.data() { let svg = match handle.data() {
svg::Data::Path(path) => { svg::Data::Path(path) => {
let tree = fs::read_to_string(path).ok().and_then(|contents| { let tree = fs::read_to_string(path).ok().and_then(|contents| {
usvg::Tree::from_str( usvg::Tree::from_str(&contents, &usvg::Options::default())
&contents, .ok()
&usvg::Options::default().to_ref(),
)
.ok()
}); });
tree.map(Svg::Loaded).unwrap_or(Svg::NotFound) tree.map(Svg::Loaded).unwrap_or(Svg::NotFound)
} }
svg::Data::Bytes(bytes) => { svg::Data::Bytes(bytes) => {
match usvg::Tree::from_data( match usvg::Tree::from_data(bytes, &usvg::Options::default()) {
bytes,
&usvg::Options::default().to_ref(),
) {
Ok(tree) => Svg::Loaded(tree), Ok(tree) => Svg::Loaded(tree),
Err(_) => Svg::NotFound, Err(_) => Svg::NotFound,
} }
@ -125,6 +121,7 @@ impl<T: Storage> Cache<T> {
} else { } else {
usvg::FitTo::Height(height) usvg::FitTo::Height(height)
}, },
tiny_skia::Transform::default(),
img.as_mut(), img.as_mut(),
)?; )?;