From af386fd0a3de432337ee9cdaa4d3661e98bd4105 Mon Sep 17 00:00:00 2001 From: Alec Deason Date: Sat, 10 Jun 2023 13:18:42 -0700 Subject: Upgrade resvg to 0.34 and tiny_skia to 0.10 --- wgpu/src/image/vector.rs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'wgpu/src/image') diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs index 6b9be651..5bfc1836 100644 --- a/wgpu/src/image/vector.rs +++ b/wgpu/src/image/vector.rs @@ -114,16 +114,27 @@ impl Cache { // It would be cool to be able to smooth resize the `svg` example. let mut img = tiny_skia::Pixmap::new(width, height)?; - resvg::render( - tree, - if width > height { - resvg::FitTo::Width(width) - } else { - resvg::FitTo::Height(height) - }, - tiny_skia::Transform::default(), - img.as_mut(), - )?; + let tree_size = tree.size.to_int_size(); + let target_size; + if width > height { + target_size = tree_size.scale_to_width(width); + } else { + target_size = tree_size.scale_to_height(height); + } + let transform; + if let Some(target_size) = target_size { + let tree_size = tree_size.to_size(); + let target_size = target_size.to_size(); + transform = tiny_skia::Transform::from_scale( + target_size.width() / tree_size.width(), + target_size.height() / tree_size.height(), + ); + } else { + transform = tiny_skia::Transform::default(); + } + + resvg::Tree::from_usvg(tree) + .render(transform, &mut img.as_mut()); let mut rgba = img.take(); -- cgit