summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2023-05-23 10:07:23 +0200
committerCanop <cano.petrole@gmail.com>2023-05-23 10:07:23 +0200
commit9d696cf749be9955f4160a44e47f8c352752fd5c (patch)
treebf3ad1c194ebe6bbf69fd0c9fc59d42ee85cc965
parent8adaebdd44d84c15dbd1447e56d98166db683a8a (diff)
update resvg dependency
-rw-r--r--Cargo.lock156
-rw-r--r--Cargo.toml5
-rw-r--r--src/errors.rs2
-rw-r--r--src/image/svg.rs48
4 files changed, 121 insertions, 90 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 00c859f..148aa7a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -163,7 +163,7 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
[[package]]
name = "broot"
-version = "1.22.0"
+version = "1.22.1-dev"
dependencies = [
"ahash 0.7.6",
"ansi_colours",
@@ -191,7 +191,7 @@ dependencies = [
"lazy-regex",
"lfs-core",
"libc",
- "memmap2 0.6.1",
+ "memmap2",
"once_cell",
"opener",
"pathdiff",
@@ -209,13 +209,10 @@ dependencies = [
"termimad 0.22.0",
"terminal-clipboard",
"terminal-light",
- "tiny-skia",
"toml",
"umask",
"unicode-width",
"users",
- "usvg",
- "usvg-text-layout",
"which",
"xterm-query 0.1.0",
]
@@ -751,19 +748,21 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ab2e12762761366dcb876ab8b6e0cfa4797ddcd890575919f008b5ba655672a"
dependencies = [
- "roxmltree 0.18.0",
+ "roxmltree",
]
[[package]]
name = "fontdb"
-version = "0.10.0"
+version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8131752b3f3b876a20f42b3d08233ad177d6e7ec6d18aaa6954489a201071be5"
+checksum = "af8d8cbea8f21307d7e84bca254772981296f058a1d36b461bf4d83a7499fc9e"
dependencies = [
"fontconfig-parser",
"log",
- "memmap2 0.5.10",
- "ttf-parser",
+ "memmap2",
+ "slotmap",
+ "tinyvec",
+ "ttf-parser 0.19.0",
]
[[package]]
@@ -802,16 +801,6 @@ dependencies = [
[[package]]
name = "gif"
-version = "0.11.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3edd93c6756b4dfaf2709eafcc345ba2636565295c198a9cfbf75fa5e3e00b06"
-dependencies = [
- "color_quant",
- "weezl",
-]
-
-[[package]]
-name = "gif"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80792593675e051cf94a4b111980da2ba60d4a83e43e0048c5693baab3977045"
@@ -971,7 +960,7 @@ dependencies = [
"byteorder",
"color_quant",
"exr",
- "gif 0.12.0",
+ "gif",
"jpeg-decoder",
"num-rational",
"num-traits",
@@ -982,9 +971,9 @@ dependencies = [
[[package]]
name = "imagesize"
-version = "0.10.1"
+version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "df19da1e92fbfec043ca97d622955381b1f3ee72a180ec999912df31b1ccd951"
+checksum = "029d73f573d8e8d63e6d5020011d3255b28c3ba85d6cf870a07184ed23de9284"
[[package]]
name = "include_dir"
@@ -1079,9 +1068,9 @@ dependencies = [
[[package]]
name = "kurbo"
-version = "0.8.3"
+version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7a53776d271cfb873b17c618af0298445c88afc52837f3e948fa3fafd131f449"
+checksum = "bd85a5776cd9500c2e2059c8c76c3b01528566b7fcbaf8098b55a33fc298849b"
dependencies = [
"arrayvec",
]
@@ -1230,15 +1219,6 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "memmap2"
-version = "0.5.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327"
-dependencies = [
- "libc",
-]
-
-[[package]]
-name = "memmap2"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0aa1b505aeecb0adb017db2b6a79a17a38e64f882a201f05e9de8a982cd6096"
@@ -1811,11 +1791,11 @@ checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c"
[[package]]
name = "resvg"
-version = "0.28.0"
+version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c115863f2d3621999cf187e318bc92b16402dfeff6a48c74df700d77381394c1"
+checksum = "1df5f3de3bb51d8a4766a1ef5d85851f2737716dea899516248d25e313a51b0d"
dependencies = [
- "gif 0.11.4",
+ "gif",
"jpeg-decoder",
"log",
"pico-args",
@@ -1825,7 +1805,6 @@ dependencies = [
"svgtypes",
"tiny-skia",
"usvg",
- "usvg-text-layout",
]
[[package]]
@@ -1838,12 +1817,16 @@ dependencies = [
]
[[package]]
-name = "roxmltree"
-version = "0.15.1"
+name = "rosvgtree"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6b9de9831a129b122e7e61f242db509fa9d0838008bf0b29bb0624669edfe48a"
+checksum = "ad747e7384940e7bf33b15ba433b7bad9f44c0c6d5287a67c2cb22cd1743d497"
dependencies = [
- "xmlparser",
+ "log",
+ "roxmltree",
+ "simplecss",
+ "siphasher",
+ "svgtypes",
]
[[package]]
@@ -1886,14 +1869,14 @@ dependencies = [
[[package]]
name = "rustybuzz"
-version = "0.6.0"
+version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ab9e34ecf6900625412355a61bda0bd68099fe674de707c67e5e4aed2c05e489"
+checksum = "162bdf42e261bee271b3957691018634488084ef577dddeb6420a9684cab2a6a"
dependencies = [
"bitflags",
"bytemuck",
"smallvec",
- "ttf-parser",
+ "ttf-parser 0.18.1",
"unicode-bidi-mirroring",
"unicode-ccc",
"unicode-general-category",
@@ -2019,6 +2002,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
[[package]]
+name = "slotmap"
+version = "1.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342"
+dependencies = [
+ "version_check",
+]
+
+[[package]]
name = "smallvec"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2106,10 +2098,11 @@ dependencies = [
[[package]]
name = "svgtypes"
-version = "0.8.2"
+version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "22975e8a2bac6a76bb54f898a6b18764633b00e780330f0b689f65afb3975564"
+checksum = "ed4b0611e7f3277f68c0fa18e385d9e2d26923691379690039548f867cef02a7"
dependencies = [
+ "kurbo",
"siphasher",
]
@@ -2315,23 +2308,24 @@ dependencies = [
[[package]]
name = "tiny-skia"
-version = "0.8.4"
+version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "df8493a203431061e901613751931f047d1971337153f96d0e5e363d6dbf6a67"
+checksum = "ce2986c82f77818c7b9144c70818fdde98db15308e329ae2f7204d767808fd3c"
dependencies = [
"arrayref",
"arrayvec",
"bytemuck",
"cfg-if",
+ "log",
"png",
"tiny-skia-path",
]
[[package]]
name = "tiny-skia-path"
-version = "0.8.4"
+version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "adbfb5d3f3dd57a0e11d12f4f13d4ebbbc1b5c15b7ab0a156d030b21da5f677c"
+checksum = "f7acb0ccda1ac91084353a56d0b69b0e29c311fd809d2088b1ed2f9ae1841c47"
dependencies = [
"arrayref",
"bytemuck",
@@ -2364,9 +2358,15 @@ dependencies = [
[[package]]
name = "ttf-parser"
-version = "0.17.1"
+version = "0.18.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0609f771ad9c6155384897e1df4d948e692667cc0588548b68eb44d052b27633"
+
+[[package]]
+name = "ttf-parser"
+version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff"
+checksum = "44dcf002ae3b32cd25400d6df128c5babec3927cd1eb7ce813cfff20eb6c3746"
[[package]]
name = "umask"
@@ -2457,29 +2457,41 @@ dependencies = [
[[package]]
name = "usvg"
-version = "0.28.0"
+version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8b5b7c2b30845b3348c067ca3d09e20cc6e327c288f0ca4c48698712abf432e9"
+checksum = "ae32eb823aab35fc343b19c4d354f70e713b442ce34cdfa8497bf6c39af8a342"
+dependencies = [
+ "base64 0.21.0",
+ "log",
+ "pico-args",
+ "usvg-parser",
+ "usvg-text-layout",
+ "usvg-tree",
+ "xmlwriter",
+]
+
+[[package]]
+name = "usvg-parser"
+version = "0.33.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c7529174e721c8078d62b08399258469b1d68b4e5f2983b347d6a9d39779366c"
dependencies = [
- "base64 0.13.1",
"data-url",
"flate2",
"imagesize",
"kurbo",
"log",
- "rctree",
- "roxmltree 0.15.1",
- "simplecss",
- "siphasher",
+ "rosvgtree",
"strict-num",
"svgtypes",
+ "usvg-tree",
]
[[package]]
name = "usvg-text-layout"
-version = "0.28.0"
+version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c9550670848028641bf976b06f5c520ffdcd6f00ee7ee7eb0853f78e2c249d7"
+checksum = "6e672fbc19261c6553113cc04ff2ff38ae52fadbd90f2d814040857795fb5c50"
dependencies = [
"fontdb",
"kurbo",
@@ -2488,7 +2500,19 @@ dependencies = [
"unicode-bidi",
"unicode-script",
"unicode-vo",
- "usvg",
+ "usvg-tree",
+]
+
+[[package]]
+name = "usvg-tree"
+version = "0.33.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a56e9cd3be5eb6d6744477e95b82d52d393fc1dba4b5b090912c33af337c20b"
+dependencies = [
+ "kurbo",
+ "rctree",
+ "strict-num",
+ "svgtypes",
]
[[package]]
@@ -2795,6 +2819,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d25c75bf9ea12c4040a97f829154768bbbce366287e2dc044af160cd79a13fd"
[[package]]
+name = "xmlwriter"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9"
+
+[[package]]
name = "xterm-query"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 194cf12..7262b99 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -50,7 +50,7 @@ pathdiff = "0.2"
phf = { version = "0.10", features = ["macros"] }
rayon = "1.5"
regex = "1.5"
-resvg = "0.28"
+resvg = "0.33"
secular = { version = "1.0", features = ["normalization"] }
serde = { version = "1.0", features = ["derive"] }
smallvec = "1.9"
@@ -61,12 +61,9 @@ tempfile = "3.2"
termimad = "0.22.0"
terminal-clipboard = { version = "0.4.0", optional = true }
terminal-light = "1.1.1"
-tiny-skia = "0.8.2"
toml = "0.5"
umask = "2.1.0"
unicode-width = "0.1.8"
-usvg = "0.28.0"
-usvg-text-layout = { version = "0.28.0", default-features = false }
which = "4.4.0"
xterm-query = { version = "0.1", optional = true }
diff --git a/src/errors.rs b/src/errors.rs
index a373137..15141b8 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -114,5 +114,5 @@ custom_error! {pub NetError
custom_error! {pub SvgError
Io {source: io::Error} = "IO Error : {source}",
Internal { message: &'static str } = "Internal error : {message}",
- Svg {source: usvg::Error} = "SVG Error: {source}",
+ Svg {source: resvg::usvg::Error} = "SVG Error: {source}",
}
diff --git a/src/image/svg.rs b/src/image/svg.rs
index 4176983..84eec80 100644
--- a/src/image/svg.rs
+++ b/src/image/svg.rs
@@ -7,13 +7,18 @@ use {
RgbaImage,
},
std::path::PathBuf,
- usvg::ScreenSize,
- usvg_text_layout::{fontdb, TreeTextToPath},
+ resvg::{
+ usvg::{
+ self,
+ fontdb,
+ TreeParsing,
+ TreeTextToPath,
+ },
+ tiny_skia,
+ },
};
-fn compute_zoom(width:u32, height:u32, max_width:u32, max_height:u32) -> Result<f32, SvgError> {
- let w: f32 = width as f32;
- let h: f32 = height as f32;
+fn compute_zoom(w:f32, h:f32, max_width:u32, max_height:u32) -> Result<f32, SvgError> {
let mw: f32 = max_width.max(2) as f32;
let mh: f32 = max_height.max(2) as f32;
let zoom = 1.0f32
@@ -42,28 +47,27 @@ pub fn render<P: Into<PathBuf>>(
fontdb.load_system_fonts();
let svg_data = std::fs::read(path)?;
let mut tree = usvg::Tree::from_data(&svg_data, &opt)?;
- debug!("SVG natural size: {} x {}", tree.size.width(), tree.size.height());
- let px_size = tree.size.to_screen_size();
- let zoom = compute_zoom(px_size.width(), px_size.height(), max_width, max_height)?;
+ tree.convert_text(&fontdb);
+ let t_width = tree.size.width() as f32;
+ let t_height = tree.size.height() as f32;
+ debug!("SVG natural size: {t_width} x {t_height}");
+ let zoom = compute_zoom(t_width, t_height, max_width, max_height)?;
debug!("svg rendering zoom: {zoom}");
- let Some(px_size) = ScreenSize::new(
- (px_size.width() as f32 * zoom) as u32,
- (px_size.height() as f32 * zoom) as u32,
- ) else {
+ let px_width = (t_width * zoom) as u32;
+ let px_height = (t_height * zoom) as u32;
+ if px_width == 0 || px_height == 0 {
return Err(SvgError::Internal { message: "invalid SVG dimensions" });
};
- debug!("px_size: {px_size:?}");
- tree.convert_text(&fontdb, opt.keep_named_groups);
+ debug!("px_size: ({px_width}, {px_height})");
let mut pixmap = tiny_skia::Pixmap::new(
- px_size.width(),
- px_size.height(),
+ px_width,
+ px_height,
).ok_or(SvgError::Internal { message: "unable to create pixmap buffer" })?;
- resvg::render(
- &tree,
- usvg::FitTo::Zoom(zoom),
- tiny_skia::Transform::default(),
- pixmap.as_mut(),
- ).ok_or(SvgError::Internal { message: "resvg doesn't look happy (not sure)" })?;
+ let tree = resvg::Tree::from_usvg(&tree);
+ tree.render(
+ tiny_skia::Transform::from_scale(zoom, zoom),
+ &mut pixmap.as_mut(),
+ );
let image_buffer = RgbaImage::from_vec(
pixmap.width(),
pixmap.height(),