git.lucas.co / cce-files
file manager
git clone https://git.lucas.co/cce-files.git

commitc9bcb2b095e7757a7cf8ea92794125953438685a
parent6f62c60e4c
authorLucas Galante <[email protected]>
date2026-08-04 20:47
feat: SVG previews — rasterize vectors at the 512px pane budget

svg/svgz selections render through cce-ui's shared rasterize_svg on the
FsService thread, flowing into the same straight-RGBA ImagePreviewData
as raster files. Parse failures fall through to the text preview (SVG
source).

Co-Authored-By: Claude Fable 5 <[email protected]>

 src/services/fs.rs | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/services/fs.rs b/src/services/fs.rs
index efded5b..09a2bcb 100644
--- a/src/services/fs.rs
+++ b/src/services/fs.rs
@@ -193,6 +193,15 @@ fn load_image_preview(path: &Path) -> Option<ImagePreviewData> {
     })
 }
 
+/// Vector previews rasterize at the same 512px pane budget via cce-ui's shared
+/// resvg path (fontdb-backed, thread-safe — this runs on the FsService thread)
+/// and hand back the same straight-RGBA ImagePreviewData as raster files.
+fn load_svg_preview(path: &Path) -> Option<ImagePreviewData> {
+    let data = fs::read(path).ok()?;
+    let (pixels, width, height) = cce_ui::rasterize_svg(&data, 512)?;
+    Some(ImagePreviewData { width, height, pixels })
+}
+
 /// Path-traced thumbnail for a cce-designer project directory, cached as a
 /// PNG under `~/.cache/cce/thumbnails/` keyed on the project path and its
 /// `state.json` mtime — the GPU renders only on cache misses. Rendering is
@@ -319,8 +328,12 @@ fn load_preview_data_internal(path: &Path) -> PreviewData {
         
         if is_img_ext {
             image_preview = load_image_preview(path);
+        } else if matches!(ext.as_str(), "svg" | "svgz") {
+            // On parse failure this stays None and the text fallback below
+            // shows the SVG source.
+            image_preview = load_svg_preview(path);
         }
-        
+
         if image_preview.is_none() {
             if let Ok(mut file) = fs::File::open(path) {
                 use std::io::Read;