From c0c59e0ffcade41b8f9f55b31b4df54b9ae22d64 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 16 Oct 2024 09:50:19 -0400 Subject: [PATCH] svg scaling fixes --- examples/svg/Cargo.toml | 2 +- tiny_skia/src/engine.rs | 42 ++++++++++++++++++++--------------------- tiny_skia/src/vector.rs | 2 +- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/examples/svg/Cargo.toml b/examples/svg/Cargo.toml index d5b95d0178..4be61237af 100644 --- a/examples/svg/Cargo.toml +++ b/examples/svg/Cargo.toml @@ -7,4 +7,4 @@ publish = false [dependencies] iced.workspace = true -iced.features = ["svg", "winit"] +iced.features = ["svg", "winit", "tokio"] diff --git a/tiny_skia/src/engine.rs b/tiny_skia/src/engine.rs index 350436414f..7e5b517a6c 100644 --- a/tiny_skia/src/engine.rs +++ b/tiny_skia/src/engine.rs @@ -1,3 +1,5 @@ +use tiny_skia::Transform; + use crate::core::renderer::Quad; use crate::core::{ Background, Color, Gradient, Rectangle, Size, Transformation, Vector, @@ -271,22 +273,22 @@ impl Engine { // Draw corners that have too small border radii as having no border radius, // but mask them with the rounded rectangle with the correct border radius. let mut temp_pixmap = tiny_skia::Pixmap::new( - physical_bounds.width as u32, - physical_bounds.height as u32, + path_bounds.width as u32, + path_bounds.height as u32, ) .unwrap(); let mut quad_mask = tiny_skia::Mask::new( - physical_bounds.width as u32, - physical_bounds.height as u32, + path_bounds.width as u32, + path_bounds.height as u32, ) .unwrap(); let zero_bounds = Rectangle { x: 0.0, y: 0.0, - width: physical_bounds.width, - height: physical_bounds.height, + width: path_bounds.width, + height: path_bounds.height, }; let path = rounded_rectangle(zero_bounds, fill_border_radius); @@ -297,16 +299,12 @@ impl Engine { transform, ); let path_bounds = Rectangle { - x: (border_width / 2.0) * transformation.scale_factor(), - y: (border_width / 2.0) * transformation.scale_factor(), - width: physical_bounds.width - - border_width * transformation.scale_factor(), - height: physical_bounds.height - - border_width * transformation.scale_factor(), + x: (border_width / 2.0), + y: (border_width / 2.0), + width: path_bounds.width - border_width, + height: path_bounds.height - border_width, }; - for r in &mut border_radius { - *r /= transformation.scale_factor(); - } + let border_radius_path = rounded_rectangle(path_bounds, border_radius); @@ -320,7 +318,7 @@ impl Engine { ..tiny_skia::Paint::default() }, &tiny_skia::Stroke { - width: border_width * transformation.scale_factor(), + width: border_width, ..tiny_skia::Stroke::default() }, transform, @@ -328,8 +326,8 @@ impl Engine { ); pixels.draw_pixmap( - (quad.bounds.x / transformation.scale_factor()) as i32, - (quad.bounds.y / transformation.scale_factor()) as i32, + (quad.bounds.x) as i32, + (quad.bounds.y) as i32, temp_pixmap.as_ref(), &tiny_skia::PixmapPaint::default(), transform, @@ -579,7 +577,7 @@ impl Engine { let center = physical_bounds.center(); let radians = f32::from(handle.rotation); - let transform = into_transform(_transformation).post_rotate_at( + let transform = Transform::default().post_rotate_at( radians.to_degrees(), center.x, center.y, @@ -588,7 +586,7 @@ impl Engine { self.raster_pipeline.draw( &handle.handle, handle.filter_method, - *bounds, + physical_bounds, handle.opacity, _pixels, transform, @@ -610,7 +608,7 @@ impl Engine { let center = physical_bounds.center(); let radians = f32::from(handle.rotation); - let transform = into_transform(_transformation).post_rotate_at( + let transform = Transform::default().post_rotate_at( radians.to_degrees(), center.x, center.y, @@ -619,7 +617,7 @@ impl Engine { self.vector_pipeline.draw( &handle.handle, handle.color, - *bounds, + physical_bounds, handle.opacity, _pixels, transform, diff --git a/tiny_skia/src/vector.rs b/tiny_skia/src/vector.rs index b19fad78fc..4eb9add55a 100644 --- a/tiny_skia/src/vector.rs +++ b/tiny_skia/src/vector.rs @@ -50,7 +50,7 @@ impl Pipeline { image, &tiny_skia::PixmapPaint { opacity, - quality: tiny_skia::FilterQuality::Bilinear, + quality: tiny_skia::FilterQuality::Bicubic, ..tiny_skia::PixmapPaint::default() }, transform,