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 --- tiny_skia/Cargo.toml | 4 ++-- tiny_skia/src/backend.rs | 10 +++++++++- tiny_skia/src/raster.rs | 6 +++--- tiny_skia/src/text.rs | 35 +++++++++++++++++++---------------- tiny_skia/src/vector.rs | 48 ++++++++++++++++++++++++++++++------------------ 5 files changed, 63 insertions(+), 40 deletions(-) (limited to 'tiny_skia') diff --git a/tiny_skia/Cargo.toml b/tiny_skia/Cargo.toml index 431f324b..0de7e4c3 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.34" 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..74b21d4a 100644 --- a/tiny_skia/src/raster.rs +++ b/tiny_skia/src/raster.rs @@ -2,6 +2,7 @@ use crate::core::image as raster; use crate::core::{Rectangle, Size}; use crate::graphics; +use bytemuck::cast; use rustc_hash::{FxHashMap, FxHashSet}; use std::cell::RefCell; use std::collections::hash_map; @@ -80,9 +81,8 @@ 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] = 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..58f7d145 100644 --- a/tiny_skia/src/text.rs +++ b/tiny_skia/src/text.rs @@ -3,6 +3,7 @@ use crate::core::font::{self, Font}; use crate::core::text::{Hit, LineHeight, Shaping}; use crate::core::{Color, Pixels, Point, Rectangle, Size}; +use bytemuck::cast; use rustc_hash::{FxHashMap, FxHashSet}; use std::borrow::Cow; use std::cell::RefCell; @@ -288,14 +289,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] = cast( + tiny_skia::ColorU8::from_rgba( + b, + g, + r, + image.data[i], + ) + .premultiply(), + ); i += 1; } @@ -307,14 +309,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] = 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..194fc52d 100644 --- a/tiny_skia/src/vector.rs +++ b/tiny_skia/src/vector.rs @@ -1,6 +1,7 @@ use crate::core::svg::{Data, Handle}; use crate::core::{Color, Rectangle, Size}; +use bytemuck::cast; use resvg::usvg; use rustc_hash::{FxHashMap, FxHashSet}; @@ -130,30 +131,41 @@ 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 { + target_size = tree_size.scale_to_width(size.width); + } else { + target_size = 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(); + 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 image.as_mut()); if let Some([r, g, b, _]) = key.color { // Apply color filter for pixel in bytemuck::cast_slice_mut::(image.data_mut()) { - *pixel = tiny_skia::ColorU8::from_rgba( - b, - g, - r, - (*pixel >> 24) as u8, - ) - .premultiply() - .get(); + *pixel = cast( + tiny_skia::ColorU8::from_rgba( + b, + g, + r, + (*pixel >> 24) as u8, + ) + .premultiply(), + ); } } else { // Swap R and B channels for `softbuffer` presentation -- cgit From 9f73ee3206c69a2db79cfb5d596b60926a829218 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 12 Jul 2023 09:03:24 +0200 Subject: Fix import consistency for `bytemuck` --- tiny_skia/src/raster.rs | 6 +++--- tiny_skia/src/text.rs | 5 ++--- tiny_skia/src/vector.rs | 3 +-- 3 files changed, 6 insertions(+), 8 deletions(-) (limited to 'tiny_skia') diff --git a/tiny_skia/src/raster.rs b/tiny_skia/src/raster.rs index 74b21d4a..dedb127c 100644 --- a/tiny_skia/src/raster.rs +++ b/tiny_skia/src/raster.rs @@ -2,7 +2,6 @@ use crate::core::image as raster; use crate::core::{Rectangle, Size}; use crate::graphics; -use bytemuck::cast; use rustc_hash::{FxHashMap, FxHashSet}; use std::cell::RefCell; use std::collections::hash_map; @@ -81,8 +80,9 @@ impl Cache { for (i, pixel) in image.pixels().enumerate() { let [r, g, b, a] = pixel.0; - buffer[i] = cast(tiny_skia::ColorU8::from_rgba(b, g, r, a) - .premultiply()); + 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 58f7d145..15f25740 100644 --- a/tiny_skia/src/text.rs +++ b/tiny_skia/src/text.rs @@ -3,7 +3,6 @@ use crate::core::font::{self, Font}; use crate::core::text::{Hit, LineHeight, Shaping}; use crate::core::{Color, Pixels, Point, Rectangle, Size}; -use bytemuck::cast; use rustc_hash::{FxHashMap, FxHashSet}; use std::borrow::Cow; use std::cell::RefCell; @@ -289,7 +288,7 @@ impl GlyphCache { for _y in 0..image.placement.height { for _x in 0..image.placement.width { - buffer[i] = cast( + buffer[i] = bytemuck::cast( tiny_skia::ColorU8::from_rgba( b, g, @@ -309,7 +308,7 @@ impl GlyphCache { for _y in 0..image.placement.height { for _x in 0..image.placement.width { // TODO: Blend alpha - buffer[i >> 2] = cast( + buffer[i >> 2] = bytemuck::cast( tiny_skia::ColorU8::from_rgba( image.data[i + 2], image.data[i + 1], diff --git a/tiny_skia/src/vector.rs b/tiny_skia/src/vector.rs index 194fc52d..9836fb0a 100644 --- a/tiny_skia/src/vector.rs +++ b/tiny_skia/src/vector.rs @@ -1,7 +1,6 @@ use crate::core::svg::{Data, Handle}; use crate::core::{Color, Rectangle, Size}; -use bytemuck::cast; use resvg::usvg; use rustc_hash::{FxHashMap, FxHashSet}; @@ -157,7 +156,7 @@ impl Cache { for pixel in bytemuck::cast_slice_mut::(image.data_mut()) { - *pixel = cast( + *pixel = bytemuck::cast( tiny_skia::ColorU8::from_rgba( b, g, -- cgit From 6502cf1111380c66f96bf5677425a902c4662ef5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 12 Jul 2023 09:07:20 +0200 Subject: Improve code style in `vector` modules --- tiny_skia/src/vector.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'tiny_skia') diff --git a/tiny_skia/src/vector.rs b/tiny_skia/src/vector.rs index 9836fb0a..433ca0f5 100644 --- a/tiny_skia/src/vector.rs +++ b/tiny_skia/src/vector.rs @@ -131,23 +131,24 @@ impl Cache { let mut image = tiny_skia::Pixmap::new(size.width, size.height)?; let tree_size = tree.size.to_int_size(); - let target_size; - if size.width > size.height { - target_size = tree_size.scale_to_width(size.width); + + let target_size = if size.width > size.height { + tree_size.scale_to_width(size.width) } else { - target_size = tree_size.scale_to_height(size.height); - } - let transform; - if let Some(target_size) = target_size { + 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(); - transform = tiny_skia::Transform::from_scale( + + tiny_skia::Transform::from_scale( target_size.width() / tree_size.width(), target_size.height() / tree_size.height(), - ); + ) } else { - transform = tiny_skia::Transform::default(); - } + tiny_skia::Transform::default() + }; resvg::Tree::from_usvg(tree).render(transform, &mut image.as_mut()); -- cgit From 5dd923402e07578a0002884ac14044fe8762f8b0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 12 Jul 2023 09:10:58 +0200 Subject: Update `resvg` dependency to `0.35` --- tiny_skia/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tiny_skia') diff --git a/tiny_skia/Cargo.toml b/tiny_skia/Cargo.toml index 0de7e4c3..d9276ea5 100644 --- a/tiny_skia/Cargo.toml +++ b/tiny_skia/Cargo.toml @@ -34,5 +34,5 @@ version = "1.6.1" features = ["std"] [dependencies.resvg] -version = "0.34" +version = "0.35" optional = true -- cgit