Repository: Canop/broot (language: rust)

Issue:
Update resvg to v0.44
Hi @Canop.

resvg v0.44 will soon be in Debian, so I wrote a patch to update broot's dependency to that version. Judging from [Cargo.toml#L53](https://github.com/Canop/broot/blob/3611b0a68de9c56ef85e53420b009bad97d21bd4/Cargo.toml#L53) I think you may be interested in this. Would you like me to open a PR?

Cheers!


Discussion / hints:

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index f2611fb0..edf1e743 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -50,7 +50,7 @@ opener = "0.6"
 pathdiff = "0.2"
 phf = { version = "0.11", features = ["macros"] }
 rayon = "1.9"
-resvg = "0.36" # several options behind, as it's always a PITA to upgrade
+resvg = "0.44"
 rustc-hash = "2" 
 secular = { version = "1.0", features = ["normalization", "bmp"] }
 serde = { version = "1.0", features = ["derive"] }
diff --git a/src/image/source_image.rs b/src/image/source_image.rs
index 1c62647f..3d91b669 100644
--- a/src/image/source_image.rs
+++ b/src/image/source_image.rs
@@ -27,7 +27,7 @@ pub const MAX_SVG_BITMAP_HEIGHT: u32 = 1000;
 
 pub enum SourceImage {
     Bitmap(DynamicImage),
-    Svg(resvg::Tree),
+    Svg(resvg::usvg::Tree),
 }
 
 impl SourceImage {
@@ -44,8 +44,8 @@ impl SourceImage {
         match self {
             Self::Bitmap(img) => img.dimensions(),
             Self::Svg(tree) => (
-                f32_to_u32(tree.size.width()),
-                f32_to_u32(tree.size.height())
+                f32_to_u32(tree.size().width()),
+                f32_to_u32(tree.size().height())
             )
         }
     }
diff --git a/src/image/svg.rs b/src/image/svg.rs
index f3771c93..828edb4e 100644
--- a/src/image/svg.rs
+++ b/src/image/svg.rs
@@ -6,26 +6,14 @@ use {
         DynamicImage,
         RgbaImage,
     },
-    once_cell::sync::Lazy,
     std::path::PathBuf,
     resvg::{
-        usvg::{
-            self,
-            fontdb,
-            TreeParsing,
-            TreeTextToPath,
-        },
+        usvg,
         tiny_skia,
     },
     termimad::coolor,
 };
 
-static FONT_DB: Lazy<fontdb::Database> = Lazy::new(||{
-    let mut fontdb = fontdb::Database::new();
-    fontdb.load_system_fonts();
-    fontdb
-});
-
 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;
@@ -41,26 +29,25 @@ fn compute_zoom(w:f32, h:f32, max_width:u32, max_height:u32) -> Result<f32, SvgE
 
 pub fn load<P: Into<PathBuf>>(
     path: P,
-) -> Result<resvg::Tree, SvgError> {
+) -> Result<usvg::Tree, SvgError> {
     let path: PathBuf = path.into();
-    let opt = usvg::Options {
+    let mut opt = usvg::Options {
         resources_dir: Some(path.clone()),
         ..Default::default()
     };
+    opt.fontdb_mut().load_system_fonts();
     let svg_data = std::fs::read(path)?;
-    let mut tree = usvg::Tree::from_data(&svg_data, &opt)?;
-    tree.convert_text(&FONT_DB);
-    let tree = resvg::Tree::from_usvg(&tree);
+    let tree = usvg::Tree::from_data(&svg_data, &opt)?;
     Ok(tree)
 }
 pub fn render_tree(
-    tree: &resvg::Tree,
+    tree: &usvg::Tree,
     max_width: u32,
     max_height: u32,
     bg_color: Option<coolor::Color>,
 ) -> Result<DynamicImage, SvgError> {
-    let t_width = tree.size.width();
-    let t_height = tree.size.height();
+    let t_width = tree.size().width();
+    let t_height = tree.size().height();
     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}");
@@ -79,7 +66,8 @@ pub fn render_tree(
         let bg_color = tiny_skia::Color::from_rgba8(rgb.r, rgb.g, rgb.b, 255);
         pixmap.fill(bg_color);
     }
-    tree.render(
+    resvg::render(
+        tree,
         tiny_skia::Transform::from_scale(zoom, zoom),
         &mut pixmap.as_mut(),
     );


Test patch: