Skip to content

Commit

Permalink
svg scaling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Oct 16, 2024
1 parent da4871d commit c0c59e0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/svg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ publish = false

[dependencies]
iced.workspace = true
iced.features = ["svg", "winit"]
iced.features = ["svg", "winit", "tokio"]
42 changes: 20 additions & 22 deletions tiny_skia/src/engine.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use tiny_skia::Transform;

use crate::core::renderer::Quad;
use crate::core::{
Background, Color, Gradient, Rectangle, Size, Transformation, Vector,
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -320,16 +318,16 @@ impl Engine {
..tiny_skia::Paint::default()
},
&tiny_skia::Stroke {
width: border_width * transformation.scale_factor(),
width: border_width,
..tiny_skia::Stroke::default()
},
transform,
Some(&quad_mask),
);

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,
Expand Down Expand Up @@ -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,
Expand All @@ -588,7 +586,7 @@ impl Engine {
self.raster_pipeline.draw(
&handle.handle,
handle.filter_method,
*bounds,
physical_bounds,
handle.opacity,
_pixels,
transform,
Expand All @@ -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,
Expand All @@ -619,7 +617,7 @@ impl Engine {
self.vector_pipeline.draw(
&handle.handle,
handle.color,
*bounds,
physical_bounds,
handle.opacity,
_pixels,
transform,
Expand Down
2 changes: 1 addition & 1 deletion tiny_skia/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c0c59e0

Please sign in to comment.