M2: a page inherits a grandparent's /MediaBox, origin kept, tested (view.render-pages)

Tests only: a /MediaBox two /Pages levels up, with its origin away from 0 0, gives the page its
crop, size and view matrix, and the renderer sizes such a page at that box.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyCHD1R3rywQBPCHXZA
This commit is contained in:
mtlcl410andClaude Opus 5.5 committed 2026-11-08 12:37:57 +08:00
1 parent ee1b5454ee
commit 5204abbb08
2 files changed
+37

No files matched your search

+17
View File
@@ -286,6 +286,23 @@ mod tests {
assert_eq!(p.display_size(&d), (300.0, 400.0));
}
/// The box can come from further up: a grandparent `/Pages` node's `/MediaBox`, through a
/// `/Pages` node without one, with its origin away from 0 0 kept in the crop and view matrix.
#[test]
fn a_page_inherits_a_grandparents_media_box_with_its_origin() {
let d = doc_from(&[
"<< /Type /Catalog /Pages 2 0 R >>".to_string(),
"<< /Type /Pages /Kids [3 0 R] /Count 1 /MediaBox [100 200 400 600] >>".to_string(),
"<< /Type /Pages /Parent 2 0 R /Kids [4 0 R] /Count 1 >>".to_string(),
"<< /Type /Page /Parent 3 0 R >>".to_string(),
]);
let p = &pages(&d)[0];
assert_eq!(p.crop(&d), [100.0, 200.0, 400.0, 600.0]);
assert_eq!(p.display_size(&d), (300.0, 400.0));
assert_eq!(p.view_matrix(&d), view_matrix_for(0, [100.0, 200.0, 400.0, 600.0]));
assert_ne!(p.view_matrix(&d), view_matrix_for(0, [0.0, 0.0, 300.0, 400.0]), "the origin is kept");
}
/// A `/MediaBox` without area (`[0 0 0 0]`) is US Letter too, as the renderer draws it.
#[test]
fn a_page_whose_media_box_has_no_area_is_letter() {
+20
View File
@@ -5559,6 +5559,26 @@ trailer << /Root 1 0 R >>
assert_eq!((info.pages[0].width, info.pages[0].height), (300.0, 400.0), "inspected size");
}
/// The same through a `/Pages` node without a box: the page takes its grandparent's `/MediaBox`.
#[test]
fn a_page_inherits_its_grandparents_media_box() {
let pdf = b"%PDF-1.4
1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj
2 0 obj << /Type /Pages /Kids [5 0 R] /Count 1 /MediaBox [0 0 300 400] >> endobj
5 0 obj << /Type /Pages /Parent 2 0 R /Kids [3 0 R] /Count 1 >> endobj
3 0 obj << /Type /Page /Parent 5 0 R /Contents 4 0 R >> endobj
4 0 obj << /Length 25 >> stream
0 0 1 rg 10 10 50 50 re f
endstream endobj
trailer << /Root 1 0 R >>
%%EOF"
.to_vec();
let page = render_first_page(pdf.clone());
assert_eq!((page.width, page.height), (300, 400), "rendered size");
let info = crate::inspect(Arc::new(pdf), None).expect("inspect");
assert_eq!((info.pages[0].width, info.pages[0].height), (300.0, 400.0), "inspected size");
}
/// A page whose content expands far beyond its compressed stream stops at the expansion budget,
/// which is 64 times the compressed size and at least `MAX_DECODED_STREAM`, and the page says so.
#[test]