Embed Computer Modern Type1 outlines in route-D PDFs

This commit is contained in:
gloamxun committed 2026-10-24 03:28:10 +08:00
1 parent 6eef2f7a54
commit 5f5fc393a4
6 files changed
+295 -10

No files matched your search

+50 -1
View File
@@ -4,7 +4,10 @@
use texrra_tex_core::{
Document, Engine, ParagraphFont, ParagraphStyle, Unit, VerticalItem,
cmr10::Cmr10Metrics,
pdf::{PageOrigin, display_lists_to_pdf, display_lists_to_pdf_with_origin},
pdf::{
PageOrigin, display_lists_to_pdf, display_lists_to_pdf_with_cm_type1,
display_lists_to_pdf_with_origin,
},
};
/// Paragraph style in TeX scaled points, driven by the CMR10 font metrics.
@@ -530,6 +533,52 @@ fn accented_text_round_trips_through_pdf_extraction() {
);
}
#[test]
fn computer_modern_outlines_keep_extracted_text() {
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 body = "The quick brown fox jumps over the lazy dog";
let document = Document::new(62, vec![Unit::paragraph_with_style(1, body, body_style())]);
let engine = Engine::layout(&document);
let lists: Vec<_> = engine
.pages()
.iter()
.map(|page| page.display_list())
.collect();
let pdf = display_lists_to_pdf_with_cm_type1(
&lists,
612 * 65_536,
792 * 65_536,
PageOrigin::default(),
);
let path = std::env::temp_dir().join(format!("texrra-cm-type1-{}.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)
.split_whitespace()
.collect::<Vec<_>>()
.join(" ");
assert!(
text.contains("The quick brown fox jumps over the lazy dog"),
"got {text:?}"
);
}
#[test]
fn route_d_text_matches_pdftex_extraction() {
use std::process::Command;