Encode Latin-1 text bytes in the PDF writer
This commit is contained in:
1 parent
c00edaf357
commit
495b615220
1 file changed
+13
@@ -15,6 +15,7 @@ fn escape(text: &str) -> String {
|
|||||||
')' => out.push_str("\\)"),
|
')' => out.push_str("\\)"),
|
||||||
'\\' => out.push_str("\\\\"),
|
'\\' => out.push_str("\\\\"),
|
||||||
c if c.is_ascii() => out.push(c),
|
c if c.is_ascii() => out.push(c),
|
||||||
|
c if (c as u32) <= 0xFF => out.push_str(&format!("\\{:03o}", c as u32)),
|
||||||
_ => out.push('?'),
|
_ => out.push('?'),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,3 +279,15 @@ pub fn display_lists_to_pdf(pages: &[DisplayList], page_height: i64) -> Vec<u8>
|
|||||||
pub fn display_list_to_pdf(list: &DisplayList, page_height: i64) -> Vec<u8> {
|
pub fn display_list_to_pdf(list: &DisplayList, page_height: i64) -> Vec<u8> {
|
||||||
display_lists_to_pdf(std::slice::from_ref(list), page_height)
|
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("中文"), "??");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user