From fc9ecb40e72bb3d539ae16d158b84ebed4c65024 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 01:22:58 -0500 Subject: [PATCH] Extend shared file-format registry --- Cargo.lock | 1 + crates/file-formats/Cargo.toml | 1 + crates/file-formats/src/lib.rs | 39 +++++++++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5e004a7ce..87ef135e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1459,6 +1459,7 @@ name = "craft-file-formats" version = "0.1.0" dependencies = [ "craft-eps", + "craft-svg", ] [[package]] diff --git a/crates/file-formats/Cargo.toml b/crates/file-formats/Cargo.toml index 0a5be5e76..00d3b388a 100644 --- a/crates/file-formats/Cargo.toml +++ b/crates/file-formats/Cargo.toml @@ -9,6 +9,7 @@ rust-version.workspace = true [dependencies] craft-eps = { workspace = true } +craft-svg = { workspace = true } [lints] workspace = true diff --git a/crates/file-formats/src/lib.rs b/crates/file-formats/src/lib.rs index 9d3a3c438..9df7fe16a 100644 --- a/crates/file-formats/src/lib.rs +++ b/crates/file-formats/src/lib.rs @@ -14,6 +14,8 @@ pub enum Format { Illustrator, Dxf, Svg, + /// Gzip-compressed SVG. Kept distinct so writers do not place plain SVG under `.svgz`. + Svgz, Png, Jpeg, Bmp, @@ -29,6 +31,13 @@ pub enum Format { Pdn, Raw, Pcraft, + Idml, + DesignCraft, + Docx, + Rtf, + Xlsx, + TaggedText, + Pptx, Gcode, Studio, StencilCraft, @@ -63,16 +72,29 @@ pub fn detect(name: &str, bytes: &[u8]) -> Option { if bytes.starts_with(b"silhouette04;") || bytes.starts_with(b"silhouette05;") { return Some(Format::Studio); } + let tagged = bytes.strip_prefix(b"\xef\xbb\xbf").unwrap_or(bytes).trim_ascii_start(); + if tagged.starts_with(b" Option { "ps" => Some(Format::PostScript), "ai" => Some(Format::Illustrator), "dxf" => Some(Format::Dxf), - "svg" | "svgz" => Some(Format::Svg), + "svg" => Some(Format::Svg), + "svgz" => Some(Format::Svgz), "png" => Some(Format::Png), "jpg" | "jpeg" => Some(Format::Jpeg), "bmp" => Some(Format::Bmp), @@ -105,6 +128,12 @@ pub fn from_extension(ext: &str) -> Option { | "kdc" | "mdc" | "mef" | "mos" | "mrw" | "nef" | "nrw" | "obm" | "orf" | "pef" | "ptx" | "pxn" | "r3d" | "raf" | "raw" | "rwl" | "rw2" | "rwz" | "sr2" | "srf" | "sti" | "x3f" => Some(Format::Raw), "pcraft" => Some(Format::Pcraft), + "idml" => Some(Format::Idml), + "designcraft" | "dcdoc" => Some(Format::DesignCraft), + "docx" => Some(Format::Docx), + "rtf" => Some(Format::Rtf), + "xlsx" => Some(Format::Xlsx), + "pptx" => Some(Format::Pptx), "studio" | "studio3" => Some(Format::Studio), "stencilcraft" => Some(Format::StencilCraft), "gcode" | "nc" => Some(Format::Gcode),