From 10425aba8cce90e6a5581816e73e2532d578c2b9 Mon Sep 17 00:00:00 2001 From: MechaCat02 Date: Sat, 11 Jul 2026 15:24:26 +0200 Subject: [PATCH] feat(formats): name font/image inner formats instead of hex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit inner_format_label mapped only IDXD/xml/printable-tag magics; fonts and images fell through to a bare hex label (00010000, 89504E47, …). Recognize the known binary signatures and return friendly short tags so the pak browser's format column reads them: sfnt/true/typ1 → "ttf", OTTO → "otf", ttcf → "ttc", PNG → "png", plus RIFF/DDS. Still-unidentified magics keep the hex fallback. Shared by the CLI `pak list` and the GUI browser. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/sylpheed-formats/src/pak.rs | 31 ++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/crates/sylpheed-formats/src/pak.rs b/crates/sylpheed-formats/src/pak.rs index 6548389..439b4df 100644 --- a/crates/sylpheed-formats/src/pak.rs +++ b/crates/sylpheed-formats/src/pak.rs @@ -263,19 +263,34 @@ fn be32(b: &[u8], o: usize) -> u32 { } /// Best-effort human label for a decompressed entry's inner format, from its -/// first bytes: `IDXD`, `xml`, a printable 4-char tag (RATC, IXUD, LSTA, …), or -/// a hex fallback. Shared by the CLI `pak list` and the GUI pack browser. +/// first bytes: a known signature (`IDXD`, fonts, `png`, …), a printable 4-char +/// tag (RATC, IXUD, LSTA, …), or a hex fallback for still-unidentified magics. +/// Shared by the CLI `pak list` and the GUI pack browser. pub fn inner_format_label(payload: &[u8]) -> String { if payload.len() < 4 { return "empty".into(); } let m = &payload[0..4]; - if m == b"IDXD" { - "IDXD".into() - } else if payload.starts_with(b" Some("IDXD"), + b"\x89PNG" => Some("png"), + b"\x00\x01\x00\x00" | b"true" | b"typ1" => Some("ttf"), // sfnt TrueType + b"OTTO" => Some("otf"), // OpenType (CFF) + b"ttcf" => Some("ttc"), // TrueType Collection + b"RIFF" => Some("riff"), + b"DDS " => Some("dds"), + _ if payload.starts_with(b" Some("xml"), + _ => None, + }; + if let Some(tag) = known { + return tag.into(); + } + + if m.iter().all(|&b| b.is_ascii_graphic()) { + // Many inner formats are 4-char tags (RATC, T8aD, IXUD, LSTA, …). String::from_utf8_lossy(m).into_owned() } else { format!("{:02X}{:02X}{:02X}{:02X}", m[0], m[1], m[2], m[3])