Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions graphics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"]
categories = ["gui"]

[features]
svg = ["resvg", "usvg", "tiny-skia"]
svg = ["resvg"]
image = ["png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp"]
png = ["image_rs/png"]
jpeg = ["image_rs/jpeg"]
Expand Down Expand Up @@ -71,15 +71,7 @@ default-features = false
optional = true

[dependencies.resvg]
version = "0.18"
optional = true

[dependencies.usvg]
version = "0.18"
optional = true

[dependencies.tiny-skia]
version = "0.6"
version = "0.29"
optional = true

[dependencies.kamadak-exif]
Expand Down
17 changes: 7 additions & 10 deletions graphics/src/image/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::Color;
use iced_native::svg;
use iced_native::Size;

use resvg::tiny_skia;
use resvg::usvg;
use std::collections::{HashMap, HashSet};
use std::fs;

Expand All @@ -21,7 +23,7 @@ impl Svg {
pub fn viewport_dimensions(&self) -> Size<u32> {
match self {
Svg::Loaded(tree) => {
let size = tree.svg_node().size;
let size = tree.size;

Size::new(size.width() as u32, size.height() as u32)
}
Expand Down Expand Up @@ -51,20 +53,14 @@ impl<T: Storage> Cache<T> {
let svg = match handle.data() {
svg::Data::Path(path) => {
let tree = fs::read_to_string(path).ok().and_then(|contents| {
usvg::Tree::from_str(
&contents,
&usvg::Options::default().to_ref(),
)
.ok()
usvg::Tree::from_str(&contents, &usvg::Options::default())
.ok()
});

tree.map(Svg::Loaded).unwrap_or(Svg::NotFound)
}
svg::Data::Bytes(bytes) => {
match usvg::Tree::from_data(
bytes,
&usvg::Options::default().to_ref(),
) {
match usvg::Tree::from_data(bytes, &usvg::Options::default()) {
Ok(tree) => Svg::Loaded(tree),
Err(_) => Svg::NotFound,
}
Expand Down Expand Up @@ -125,6 +121,7 @@ impl<T: Storage> Cache<T> {
} else {
usvg::FitTo::Height(height)
},
tiny_skia::Transform::default(),
img.as_mut(),
)?;

Expand Down