diff --git a/crates/texrra-tex-core/src/pdf.rs b/crates/texrra-tex-core/src/pdf.rs index 274e2e8..76c9d76 100755 --- a/crates/texrra-tex-core/src/pdf.rs +++ b/crates/texrra-tex-core/src/pdf.rs @@ -15,6 +15,7 @@ fn escape(text: &str) -> String { ')' => out.push_str("\\)"), '\\' => out.push_str("\\\\"), c if c.is_ascii() => out.push(c), + c if (c as u32) <= 0xFF => out.push_str(&format!("\\{:03o}", c as u32)), _ => out.push('?'), } } @@ -278,3 +279,15 @@ pub fn display_lists_to_pdf(pages: &[DisplayList], page_height: i64) -> Vec pub fn display_list_to_pdf(list: &DisplayList, page_height: i64) -> Vec { display_lists_to_pdf(std::slice::from_ref(list), page_height) } + +#[cfg(test)] +mod tests { + use super::escape; + + #[test] + fn latin1_text_is_octal_escaped_in_the_content_stream() { + assert_eq!(escape("café"), "caf\\351"); + assert_eq!(escape("über"), "\\374ber"); + assert_eq!(escape("中文"), "??"); + } +}