Embed image XObjects in route-D PDF output

This commit is contained in:
gloamxun committed 2026-10-20 18:13:33 +08:00
1 parent 7dd3961e21
commit 431bbd14d4
3 files changed
+169 -34

No files matched your search

+28
View File
@@ -1333,6 +1333,34 @@ mod tests {
assert!(text.contains("/Count 2"));
assert_eq!(text.matches("/Type /Page ").count(), 2);
}
#[test]
fn image_xobject_is_embedded_and_painted() {
use crate::render::{DisplayItem, DisplayList, PdfImage};
let mut list = DisplayList {
width: 612 * 65_536,
height: 792 * 65_536,
items: Vec::new(),
images: Vec::new(),
};
let index = list.add_image(PdfImage {
width: 1,
height: 1,
rgb: vec![255, 0, 0],
});
list.push(DisplayItem::Image {
x: 0,
y: 0,
width: 10 * 65_536,
height: 10 * 65_536,
index,
});
let pdf = crate::pdf::display_list_to_pdf(&list, 792 * 65_536);
let text = String::from_utf8_lossy(&pdf);
assert!(text.contains("/Subtype /Image"));
assert!(text.contains("/XObject << /Im0"));
assert!(text.contains("/Im0 Do"));
}
#[test]
fn display_list_writes_a_minimal_pdf() {
let document = Document::new(400, vec![Unit::paragraph(1, "hello")]);