From a114a79a694eb65d9cc7bb2dcd317a1e1baa0c1e Mon Sep 17 00:00:00 2001 From: divyanshu2074 <43274510+divyanshu2074@users.noreply.github.com> Date: Sun, 18 Oct 2026 21:09:37 +0530 Subject: [PATCH] fix(doc, formats): support OEM character set 255 in charset_code_page (#2195) Co-authored-by: Brandon Thomas --- crates/doc/src/encoding.rs | 5 +++-- crates/formats/src/rtf.rs | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/doc/src/encoding.rs b/crates/doc/src/encoding.rs index a1a1e1892..ee70d4151 100644 --- a/crates/doc/src/encoding.rs +++ b/crates/doc/src/encoding.rs @@ -287,12 +287,12 @@ pub fn code_page_byte(code_page: u16, b: u8) -> char { } /// The code page of an RTF or Word font charset (`\fcharset`): 204 Russian → 1251, 238 Eastern -/// European → 1250, 77 Mac → 10000, 254 PC → 437… `None` for the ANSI and default charsets (the +/// European → 1250, 77 Mac → 10000, 254 PC / 255 OEM → 437… `None` for the ANSI and default charsets (the /// document's code page applies), symbol fonts and the double-byte East Asian charsets. pub fn charset_code_page(charset: i32) -> Option { Some(match charset { 77 => MAC_ROMAN_CODE_PAGE, - 254 => 437, + 254 | 255 => 437, 161 => 1253, 162 => 1254, 163 => 1258, @@ -323,6 +323,7 @@ mod tests { assert_eq!(decode(10000, &[0x80, 0x8E, 0xDB, 0xF1, 0xF2, 0xF3, 0xD2, 0xD3, 0x41]), "Äé€ÒÚÛ“”A"); assert_eq!(charset_code_page(77), Some(10000)); assert_eq!(charset_code_page(254), Some(437)); + assert_eq!(charset_code_page(255), Some(437)); assert_eq!(charset_code_page(204), Some(1251)); assert_eq!(charset_code_page(0), None); for cp in SINGLE_BYTE_CODE_PAGES { diff --git a/crates/formats/src/rtf.rs b/crates/formats/src/rtf.rs index bdfbeca73..80314f550 100644 --- a/crates/formats/src/rtf.rs +++ b/crates/formats/src/rtf.rs @@ -2839,6 +2839,9 @@ mod tests { assert_eq!(texts(&f), ["Normal:ÒÚÛ"]); let f = parse(br"{\rtf1\ansi\deff0{\fonttbl{\f0 Arial;}{\f1\fcharset77 Geneva;}}caf\'e9 {\f1 caf\'8e \'d2ok\'d3}\par}").unwrap(); assert_eq!(texts(&f), ["Normal:café café “ok”"]); + // \fcharset255 is the standard OEM character set (CP437). + let f = parse(br"{\rtf1\ansi\deff0{\fonttbl{\f0 Arial;}{\f1\fcharset255 Terminal;}}caf\'e9 {\f1 caf\'82}\par}").unwrap(); + assert_eq!(texts(&f), ["Normal:café café"]); // DOS documents: `\pc` is code page 437, `\pca` 850; a font can name one with `\cpg`. let f = parse(br"{\rtf1\pc\deff0{\fonttbl{\f0 Courier;}}caf\'82 \'a0 la carte\par}").unwrap(); assert_eq!(texts(&f), ["Normal:café á la carte"]);