Skip to content

Commit

Permalink
Update resvg dependency
Browse files Browse the repository at this point in the history
Don't import all the dependent crate, use the re-export

And use a workspace dependency
  • Loading branch information
ogoffart committed Mar 28, 2023
1 parent b2a149e commit 977b1cc
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions internal/compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/embedded_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions internal/compiler/passes/embed_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ fn embed_image(
}

#[cfg(feature = "software-renderer")]

trait Pixel {
//fn alpha(&self) -> f32;
//fn rgb(&self) -> (u8, u8, u8);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
)
Expand Down
6 changes: 2 additions & 4 deletions internal/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down Expand Up @@ -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" ] }
Expand Down
7 changes: 4 additions & 3 deletions internal/core/graphics/image/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -45,7 +46,7 @@ impl ParsedSVG {
size: euclid::Size2D<u32, PhysicalPx>,
) -> Result<SharedImageBuffer, usvg::Error> {
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 =
Expand Down

0 comments on commit 977b1cc

Please sign in to comment.