Report matching PDF widths for accented glyphs

This commit is contained in:
gloamxun committed 2026-10-21 09:25:46 +08:00
1 parent 3d94e28dff
commit c6a58dd646
3 files changed
+68 -21

No files matched your search

+44
View File
@@ -366,3 +366,47 @@ Second page text\par
}
let _ = std::fs::remove_dir_all(&root);
}
#[test]
fn accented_text_round_trips_through_pdf_extraction() {
use std::process::Command;
if Command::new("pdftotext")
.arg("-v")
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.status()
.is_err()
{
return;
}
let document = Document::new(
60,
vec![Unit::paragraph_with_style(
1,
"caf\u{e9} na\u{ef}ve r\u{e9}sum\u{e9}",
ParagraphStyle::default(),
)],
);
let engine = Engine::layout(&document);
let lists: Vec<_> = engine
.pages()
.iter()
.map(|page| page.display_list())
.collect();
let pdf = display_lists_to_pdf(&lists, 792);
let path = std::env::temp_dir().join(format!("texrra-accents-{}.pdf", std::process::id()));
std::fs::write(&path, &pdf).expect("write PDF");
let output = Command::new("pdftotext")
.arg(&path)
.arg("-")
.output()
.expect("pdftotext");
let _ = std::fs::remove_file(&path);
let text = String::from_utf8_lossy(&output.stdout);
assert!(
text.contains("caf\u{e9} na\u{ef}ve r\u{e9}sum\u{e9}"),
"got {text:?}"
);
}