A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
SVG files get thumbnails of their own (1001)
gelenmedya2239da5d290f
diff --git a/crates/rf-win/src/look/decode.rs b/crates/rf-win/src/look/decode.rsindex fa81a366..8526f8c1 100644--- a/crates/rf-win/src/look/decode.rs+++ b/crates/rf-win/src/look/decode.rs@@ -170,6 +170,19 @@ fn with_image_crate_oriented(Ok(Decoded { source: DecodedSource::Image, frames: vec![(to_bgra(resize(img.into_rgba8(), max_side)), 0)], orientation, exif, width, height })}+/// An SVG file's picture for a thumbnail, at most `size` on its long side (resvg, the reader the preview uses). `None` for a file+/// that is too big or does not read. Issue 1001: Windows has no thumbnail provider for SVG of its own, so the list showed a+/// generic icon for every SVG, while the preview drew it.+pub fn svg_thumbnail(path: &Path, size: u32) -> Option<Bgra> {+ // (a drawing of several megabytes is a map or a plot: left to the shell's icon rather than parsed for a thumbnail)+ if std::fs::metadata(path).ok()?.len() > 8 << 20 {+ return None;+ }+ let bytes = std::fs::read(path).ok()?;+ let decoded = std::panic::catch_unwind(|| svg(&bytes, size.max(16))).ok()?.ok()?;+ decoded.frames.into_iter().next().map(|(frame, _)| frame)+}+fn svg(bytes: &[u8], max_side: u32) -> anyhow::Result<Decoded> {use resvg::{tiny_skia, usvg};let mut opt = usvg::Options::default();@@ -579,6 +592,15 @@ mod tests {std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/data").join(name)}+ /// Issue 1001: an SVG gets a thumbnail of its own, fitted into the size asked for.+ #[test]+ fn an_svg_gets_a_thumbnail_of_its_size() {+ let b = svg_thumbnail(&data("look/a.svg"), 96).expect("a thumbnail");+ assert!(b.width.max(b.height) <= 96 && b.width.max(b.height) >= 48, "{}x{}", b.width, b.height);+ assert!(b.data.chunks_exact(4).any(|p| p[3] > 0), "something is drawn");+ assert!(svg_thumbnail(&data("look/a.png"), 96).is_none(), "a picture that is no SVG gives none");+ }+#[test]fn decodes_common_formats() {for f in ["look/a.png", "look/a.jpg", "look/a.webp", "look/a.gif", "look/a.svg"] {diff --git a/crates/rf-win/src/thumbs.rs b/crates/rf-win/src/thumbs.rsindex 5db211c8..c0fc9bda 100644--- a/crates/rf-win/src/thumbs.rs+++ b/crates/rf-win/src/thumbs.rs@@ -152,6 +152,12 @@ pub fn get_image(path: &Path, size: u32, kind: Kind) -> anyhow::Result<Bgra> {{return Ok(b);}+ // SVG drawings from the file itself (issue 1001): Windows has no thumbnail provider for them either+ if path.extension().is_some_and(|e| e.eq_ignore_ascii_case("svg"))+ && let Some(b) = crate::look::decode::svg_thumbnail(path, size)+ {+ return Ok(b);+ }// Photoshop files from the file itself: Windows has no thumbnail provider for themif crate::psd_thumb::handles(path)&& let Some(b) = crate::psd_thumb::thumbnail(path, size)