diff options
Diffstat (limited to 'addons/pdf')
| -rw-r--r-- | addons/pdf/pdf.out | 33 | ||||
| -rw-r--r-- | addons/pdf/pdf.script | 8 | ||||
| -rw-r--r-- | addons/pdf/pdf.zig | 9 | ||||
| -rw-r--r-- | addons/pdf/pdf_bridge.c | 2 | ||||
| -rw-r--r-- | addons/pdf/pdf_bridge.h | 7 |
5 files changed, 58 insertions, 1 deletions
diff --git a/addons/pdf/pdf.out b/addons/pdf/pdf.out index 49ba2a88..2d4566b1 100644 --- a/addons/pdf/pdf.out +++ b/addons/pdf/pdf.out @@ -201,3 +201,36 @@ tag [3/16] petscii:on palette:commodore ascii:on docs/design.pdf |the native macOS host watches with debounced DispatchSourc |instead, then restats the exact path under a pane-generati |guard. All three macOS watchers mark the same two things f +> open test/pdf-fixtures/huge-pages.pdf +window 58x1 +tag [1/4] petscii:on palette:commodore ascii:on test/pdf-fixtures/huge-pages.pdf +| a page past 16777216 pt on a side: laid out at that size +| +> graphics on +tag [1/4] petscii:off palette:commodore ascii:on test/pdf-fixtures/huge-pages.pdf +| a page past 16777216 pt on a side: laid out at that size +| +placement 1x1 src 0,0 1x1 over 0,1 58x1 key fb85a0e4117bdb75 at 0,0 464x1 +placement 1200x1200 src 0,0 1200x19 over 0,1 58x1 key a44f40e9b170318e at 0,9 464x7 +> size 60 20 +window 58x1 +tag [1/4] petscii:off palette:commodore ascii:on test/pdf-fixtures/huge-pages.pdf +| a page past 16777216 pt on a side: laid out at that size +| +placement 1x1 src 0,0 1x1 over 0,1 58x1 key fb85a0e4117bdb75 at 0,0 464x1 +placement 1200x1200 src 0,0 1200x19 over 0,1 58x1 key a44f40e9b170318e at 0,9 464x7 +> key j +tag [2/4] petscii:off palette:commodore ascii:on test/pdf-fixtures/huge-pages.pdf +| a page past 16777216 pt on a side: laid out at that size +| +placement 1200x1200 src 0,18 1200x42 over 0,1 58x1 key a44f40e9b170318e at 0,0 464x16 +> key 2j +tag [2/4] petscii:off palette:commodore ascii:on test/pdf-fixtures/huge-pages.pdf +| a page past 16777216 pt on a side: laid out at that size +| +placement 1200x1200 src 0,100 1200x43 over 0,1 58x1 key a44f40e9b170318e at 0,0 464x16 +> key G +tag [4/4] petscii:off palette:commodore ascii:on test/pdf-fixtures/huge-pages.pdf +| a page past 16777216 pt on a side: laid out at that size +| +placement 816x64 src 0,0 816x29 over 0,1 58x1 key aa6de78f475e58f7 at 0,0 464x16 diff --git a/addons/pdf/pdf.script b/addons/pdf/pdf.script index 60e4bfca..62629ded 100644 --- a/addons/pdf/pdf.script +++ b/addons/pdf/pdf.script @@ -23,3 +23,11 @@ key 3gj key gk key 999gj key gj +# pages past any size (a side of 1e9 pt, one past a float, a UserUnit +# past a float): laid out and drawn at the bridge's bound, never a panic +open test/pdf-fixtures/huge-pages.pdf +graphics on +size 60 20 +key j +key 2j +key G diff --git a/addons/pdf/pdf.zig b/addons/pdf/pdf.zig index 79d79219..5694e8c8 100644 --- a/addons/pdf/pdf.zig +++ b/addons/pdf/pdf.zig @@ -270,6 +270,7 @@ pub const Pdf = extern struct { return addon.say("not a PDF pardes can read", .err); } o.d = d; + sayHuge(o.size[0..1]); st.pages = @intCast(pages); // every page the first's size until a lane measures them o.measured = st.pages == 1; @@ -812,6 +813,7 @@ pub const Pdf = extern struct { if (res.n != st.pages or sizes.len != st.pages) return; for (o.size, sizes) |*to, from| to.* = from; o.measured = true; + sayHuge(o.size); // laid again where a page is not the first's size for (o.size) |s| if (!std.meta.eql(s, o.size[0])) { for (&st.views) |*l| l.laid = false; @@ -958,6 +960,13 @@ fn ownOf(st: *const Pdf) *Own { } /// Page `p`'s size as the strip is laid with it. +/// A page the bridge held to its bound (a crafted MediaBox) is said. +fn sayHuge(sizes: []const m.pardes_pdf_page_size) void { + const most: f32 = m.PARDES_PDF_MAX_PAGE_POINTS; + for (sizes) |s| if (s.width >= most or s.height >= most) + return addon.say(std.fmt.comptimePrint("a page past {d} pt on a side: laid out at that size", .{m.PARDES_PDF_MAX_PAGE_POINTS}), .note); +} + fn sizeOf(st: *const Pdf, o: *Own, p: usize) m.pardes_pdf_page_size { if (st.sizes != .measured) return o.size[0]; // A client joined after the lane measured them: measured here. diff --git a/addons/pdf/pdf_bridge.c b/addons/pdf/pdf_bridge.c index 3b326655..e1279f51 100644 --- a/addons/pdf/pdf_bridge.c +++ b/addons/pdf/pdf_bridge.c @@ -591,6 +591,8 @@ pardes_pdf_get_page_size( out->height = bounds.y1 - bounds.y0; if (!(out->width > 0.0f) || !(out->height > 0.0f)) fz_throw(ctx, FZ_ERROR_FORMAT, "PDF page has empty bounds"); + out->width = fminf(out->width, PARDES_PDF_MAX_PAGE_POINTS); + out->height = fminf(out->height, PARDES_PDF_MAX_PAGE_POINTS); } fz_catch(ctx) { diff --git a/addons/pdf/pdf_bridge.h b/addons/pdf/pdf_bridge.h index fd5d05d0..0e52c505 100644 --- a/addons/pdf/pdf_bridge.h +++ b/addons/pdf/pdf_bridge.h @@ -203,7 +203,12 @@ enum { PARDES_PDF_MAX_LINK_URI_BYTES = 64 * 1024, /* No page raster is taller than this, whatever it is shown at. */ - PARDES_PDF_MAX_RASTER_ROWS = 1 << 20 + PARDES_PDF_MAX_RASTER_ROWS = 1 << 20, + + /* No page is laid out wider or taller than this, in points (5.9 km): a + * crafted MediaBox or UserUnit has any size, a float's infinity too, and + * MuPDF bounds neither; pdf.zig counts a page's pixels in u32s. */ + PARDES_PDF_MAX_PAGE_POINTS = 1 << 24 }; pardes_pdf_document *pardes_pdf_open_memory(const unsigned char *bytes, size_t length, int *page_count); |
