diff --git a/Cargo.toml b/Cargo.toml index eeab433ca15..cbf74b586af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,6 +86,9 @@ resolver="2" [workspace.package] rust-version = "1.66" +[workspace.dependencies] +resvg = { version= "0.30.0", default-features = false } + [profile.release] lto = true panic = "abort" diff --git a/internal/compiler/Cargo.toml b/internal/compiler/Cargo.toml index ec3206a70eb..498199471c1 100644 --- a/internal/compiler/Cargo.toml +++ b/internal/compiler/Cargo.toml @@ -28,7 +28,7 @@ proc_macro_span = ["quote", "proc-macro2"] display-diagnostics = ["codemap", "codemap-diagnostic"] # Enabled the support to render images and font in the binary -software-renderer = ["image", "tiny-skia", "resvg", "usvg", "fontdb", "fontdue", "libc", "yeslogic-fontconfig-sys"] +software-renderer = ["image", "dep:resvg", "fontdb", "fontdue", "libc", "yeslogic-fontconfig-sys"] [dependencies] @@ -56,9 +56,7 @@ linked_hash_set = "0.1.4" # for processing and embedding the rendered image (texture) image = { version = "0.24", optional = true } -tiny-skia = { version = "0.8.2", optional = true } -resvg = { version = "0.29.0", optional = true } -usvg = { version = "0.29.0", optional = true } +resvg = { workspace = true, optional = true } # font embedding fontdb = { version = "0.12", features = ["fontconfig"], optional = true } fontdue = { version = "0.7.1", optional = true } diff --git a/internal/compiler/embedded_resources.rs b/internal/compiler/embedded_resources.rs index 6be0d766b12..9e493341445 100644 --- a/internal/compiler/embedded_resources.rs +++ b/internal/compiler/embedded_resources.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial #[cfg(feature = "software-renderer")] -pub use tiny_skia::IntRect as Rect; +pub use resvg::tiny_skia::IntRect as Rect; #[derive(Debug, Clone, Copy, Default)] pub struct Size { diff --git a/internal/compiler/passes/embed_images.rs b/internal/compiler/passes/embed_images.rs index 5373031aa0d..66d443d7d95 100644 --- a/internal/compiler/passes/embed_images.rs +++ b/internal/compiler/passes/embed_images.rs @@ -130,7 +130,6 @@ fn embed_image( } #[cfg(feature = "software-renderer")] - trait Pixel { //fn alpha(&self) -> f32; //fn rgb(&self) -> (u8, u8, u8); @@ -272,6 +271,8 @@ fn load_image( file: crate::fileaccess::VirtualFile, scale_factor: f64, ) -> image::ImageResult<(image::RgbaImage, Size)> { + use resvg::{tiny_skia, usvg}; + use usvg::TreeParsing; if file.path.ends_with(".svg") || file.path.ends_with(".svgz") { let options = usvg::Options::default(); let tree = match file.builtin_contents { @@ -303,7 +304,7 @@ fn load_image( .ok_or_else(size_error)?; resvg::render( &tree, - usvg::FitTo::Original, + resvg::FitTo::Original, tiny_skia::Transform::from_scale(scale_factor as _, scale_factor as _), skia_buffer, ) diff --git a/internal/core/Cargo.toml b/internal/core/Cargo.toml index 95e9eeda67c..820c90a5432 100644 --- a/internal/core/Cargo.toml +++ b/internal/core/Cargo.toml @@ -34,7 +34,7 @@ unicode = ["unicode-script", "unicode-linebreak"] software-renderer-systemfonts = ["fontdb", "rustybuzz", "fontdue"] image-decoders = ["image", "clru"] -svg = ["resvg", "usvg", "tiny-skia"] +svg = ["dep:resvg"] box-shadow-cache = [] @@ -77,9 +77,7 @@ integer-sqrt = { version = "0.1.5" } image = { version = "0.24.0", optional = true, default-features = false, features = [ "png", "jpeg" ] } clru = { version = "0.6.0", optional = true } -resvg = { version= "0.29.0", optional = true, default-features = false } -usvg = { version= "0.29.0", optional = true, default-features = false } -tiny-skia = { version= "0.8.2", optional = true, default-features = false } +resvg = { workspace = true, optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] instant = { version = "0.1", features = [ "wasm-bindgen", "now" ] } diff --git a/internal/core/graphics/image/svg.rs b/internal/core/graphics/image/svg.rs index 05bffa479b4..eba9680623d 100644 --- a/internal/core/graphics/image/svg.rs +++ b/internal/core/graphics/image/svg.rs @@ -3,11 +3,12 @@ #![cfg(feature = "svg")] +use super::{ImageCacheKey, SharedImageBuffer, SharedPixelBuffer}; use crate::lengths::PhysicalPx; #[cfg(not(target_arch = "wasm32"))] use crate::SharedString; - -use super::{ImageCacheKey, SharedImageBuffer, SharedPixelBuffer}; +use resvg::{tiny_skia, usvg}; +use usvg::TreeParsing; pub struct ParsedSVG { svg_tree: usvg::Tree, @@ -45,7 +46,7 @@ impl ParsedSVG { size: euclid::Size2D, ) -> Result { let tree = &self.svg_tree; - let fit = usvg::FitTo::Size(size.width, size.height); + let fit = resvg::FitTo::Size(size.width, size.height); let size = fit.fit_to(tree.size.to_screen_size()).ok_or(usvg::Error::InvalidSize)?; let mut buffer = SharedPixelBuffer::new(size.width(), size.height()); let skia_buffer =