Embed only the font faces used by a route-D PDF

This commit is contained in:
gloamxun committed 2026-10-20 22:15:53 +08:00
1 parent 472f778e75
commit 295093ae5a
3 files changed
+29 -5

No files matched your search

+12
View File
@@ -1957,6 +1957,18 @@ mod tests {
assert!(text.trim_end().ends_with("%%EOF"));
}
#[test]
fn pdf_embeds_only_the_used_faces() {
let document = Document::new(400, vec![Unit::paragraph(1, "roman only")]);
let engine = Engine::layout(&document);
let list = engine.pages()[0].display_list();
let pdf = crate::pdf::display_list_to_pdf(&list, 400 * 65_536);
let text = String::from_utf8_lossy(&pdf);
assert_eq!(text.matches("/Subtype /Type0").count(), 1);
assert!(!text.contains("/BaseFont /LiberationSerif-Bold"));
assert!(!text.contains("/BaseFont /LiberationMono"));
}
#[test]
fn sans_paragraph_paints_with_the_sans_face() {
let unit = Unit::paragraph_with_face(1, "sans face", ParagraphFont::Sans);