summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tiny_skia/Cargo.toml4
-rw-r--r--tiny_skia/src/backend.rs10
-rw-r--r--tiny_skia/src/raster.rs6
-rw-r--r--tiny_skia/src/text.rs34
-rw-r--r--tiny_skia/src/vector.rs48
-rw-r--r--wgpu/Cargo.toml2
-rw-r--r--wgpu/src/image/vector.rs32
7 files changed, 85 insertions, 51 deletions
diff --git a/tiny_skia/Cargo.toml b/tiny_skia/Cargo.toml
index 431f324b..d9276ea5 100644
--- a/tiny_skia/Cargo.toml
+++ b/tiny_skia/Cargo.toml
@@ -11,7 +11,7 @@ geometry = ["iced_graphics/geometry"]
[dependencies]
raw-window-handle = "0.5"
softbuffer = "0.2"
-tiny-skia = "0.9"
+tiny-skia = "0.10"
bytemuck = "1"
rustc-hash = "1.1"
kurbo = "0.9"
@@ -34,5 +34,5 @@ version = "1.6.1"
features = ["std"]
[dependencies.resvg]
-version = "0.32"
+version = "0.35"
optional = true
diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs
index e0134220..a8add70b 100644
--- a/tiny_skia/src/backend.rs
+++ b/tiny_skia/src/backend.rs
@@ -753,7 +753,15 @@ fn adjust_clip_mask(clip_mask: &mut tiny_skia::Mask, bounds: Rectangle) {
let path = {
let mut builder = tiny_skia::PathBuilder::new();
- builder.push_rect(bounds.x, bounds.y, bounds.width, bounds.height);
+ builder.push_rect(
+ tiny_skia::Rect::from_xywh(
+ bounds.x,
+ bounds.y,
+ bounds.width,
+ bounds.height,
+ )
+ .unwrap(),
+ );
builder.finish().unwrap()
};
diff --git a/tiny_skia/src/raster.rs b/tiny_skia/src/raster.rs
index 3887ec8d..dedb127c 100644
--- a/tiny_skia/src/raster.rs
+++ b/tiny_skia/src/raster.rs
@@ -80,9 +80,9 @@ impl Cache {
for (i, pixel) in image.pixels().enumerate() {
let [r, g, b, a] = pixel.0;
- buffer[i] = tiny_skia::ColorU8::from_rgba(b, g, r, a)
- .premultiply()
- .get();
+ buffer[i] = bytemuck::cast(
+ tiny_skia::ColorU8::from_rgba(b, g, r, a).premultiply(),
+ );
}
entry.insert(Some(Entry {
diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs
index 8f494650..15f25740 100644
--- a/tiny_skia/src/text.rs
+++ b/tiny_skia/src/text.rs
@@ -288,14 +288,15 @@ impl GlyphCache {
for _y in 0..image.placement.height {
for _x in 0..image.placement.width {
- buffer[i] = tiny_skia::ColorU8::from_rgba(
- b,
- g,
- r,
- image.data[i],
- )
- .premultiply()
- .get();
+ buffer[i] = bytemuck::cast(
+ tiny_skia::ColorU8::from_rgba(
+ b,
+ g,
+ r,
+ image.data[i],
+ )
+ .premultiply(),
+ );
i += 1;
}
@@ -307,14 +308,15 @@ impl GlyphCache {
for _y in 0..image.placement.height {
for _x in 0..image.placement.width {
// TODO: Blend alpha
- buffer[i >> 2] = tiny_skia::ColorU8::from_rgba(
- image.data[i + 2],
- image.data[i + 1],
- image.data[i],
- image.data[i + 3],
- )
- .premultiply()
- .get();
+ buffer[i >> 2] = bytemuck::cast(
+ tiny_skia::ColorU8::from_rgba(
+ image.data[i + 2],
+ image.data[i + 1],
+ image.data[i],
+ image.data[i + 3],
+ )
+ .premultiply(),
+ );
i += 4;
}
diff --git a/tiny_skia/src/vector.rs b/tiny_skia/src/vector.rs
index a3f3c2e3..433ca0f5 100644
--- a/tiny_skia/src/vector.rs
+++ b/tiny_skia/src/vector.rs
@@ -130,30 +130,42 @@ impl Cache {
let mut image = tiny_skia::Pixmap::new(size.width, size.height)?;
- resvg::render(
- tree,
- if size.width > size.height {
- resvg::FitTo::Width(size.width)
- } else {
- resvg::FitTo::Height(size.height)
- },
- tiny_skia::Transform::default(),
- image.as_mut(),
- )?;
+ let tree_size = tree.size.to_int_size();
+
+ let target_size = if size.width > size.height {
+ tree_size.scale_to_width(size.width)
+ } else {
+ tree_size.scale_to_height(size.height)
+ };
+
+ let transform = if let Some(target_size) = target_size {
+ let tree_size = tree_size.to_size();
+ let target_size = target_size.to_size();
+
+ tiny_skia::Transform::from_scale(
+ target_size.width() / tree_size.width(),
+ target_size.height() / tree_size.height(),
+ )
+ } else {
+ tiny_skia::Transform::default()
+ };
+
+ resvg::Tree::from_usvg(tree).render(transform, &mut image.as_mut());
if let Some([r, g, b, _]) = key.color {
// Apply color filter
for pixel in
bytemuck::cast_slice_mut::<u8, u32>(image.data_mut())
{
- *pixel = tiny_skia::ColorU8::from_rgba(
- b,
- g,
- r,
- (*pixel >> 24) as u8,
- )
- .premultiply()
- .get();
+ *pixel = bytemuck::cast(
+ tiny_skia::ColorU8::from_rgba(
+ b,
+ g,
+ r,
+ (*pixel >> 24) as u8,
+ )
+ .premultiply(),
+ );
}
} else {
// Swap R and B channels for `softbuffer` presentation
diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml
index 15db5b5d..22cfad55 100644
--- a/wgpu/Cargo.toml
+++ b/wgpu/Cargo.toml
@@ -55,7 +55,7 @@ version = "1.0"
optional = true
[dependencies.resvg]
-version = "0.32"
+version = "0.35"
optional = true
[dependencies.tracing]
diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs
index 6b9be651..2c03d36b 100644
--- a/wgpu/src/image/vector.rs
+++ b/wgpu/src/image/vector.rs
@@ -114,16 +114,28 @@ 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 {
+ tree_size.scale_to_width(width)
+ } else {
+ 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();
+
+ tiny_skia::Transform::from_scale(
+ target_size.width() / tree_size.width(),
+ target_size.height() / tree_size.height(),
+ )
+ } else {
+ tiny_skia::Transform::default()
+ };
+
+ resvg::Tree::from_usvg(tree)
+ .render(transform, &mut img.as_mut());
let mut rgba = img.take();