summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-25 11:08:56 -0300
committerGabriel Schneider <[email protected]>2026-10-25 11:08:56 -0300
commitc8ad18df1d46265c30721861760a744227e57b31 (patch)
tree05fd97d7fac1ab696a4ed53c6d23f28884758460 /test
parent53539a43789d402a9f774d8cf30c0a102331b5b3 (diff)
downloadpardes-c8ad18df1d46265c30721861760a744227e57b31.tar.gz
pardes-c8ad18df1d46265c30721861760a744227e57b31.zip
pdfrender 3: a PDF's place on the jumplist is its page and how far down it (a fraction, which a zoom or a resize keeps), its file's hash, so Back and Forward land on the exact offset through the motion system (a far one as one body's slide), places on one page more than a body apart are two entries, JumpScope file keeps to the PDF, and a closed PDF reopens at its place; the Jumplist pane prints a PDF's place as path:page
Diffstat (limited to 'test')
-rw-r--r--test/pdf.zig110
1 files changed, 110 insertions, 0 deletions
diff --git a/test/pdf.zig b/test/pdf.zig
index 5f7ebc52..bbb0da66 100644
--- a/test/pdf.zig
+++ b/test/pdf.zig
@@ -2448,3 +2448,113 @@ test "a PDF's fit and tint, and Collapse, read in its ctl and come back from a D
try std.testing.expectEqualStrings("height", @tagName(pv.fit));
try std.testing.expectEqualStrings("full", @tagName(pv.tint));
}
+
+/// The jumplist's PDF (pdfrender): the Intel SDM (5363 pages, the author's
+/// stress file) when this machine has it, else the docs' PDF; the same
+/// checks either way.
+fn jumpPdf() []const u8 {
+ const sdm = "/home/goblin/00-projects/kvmctf/harnesses/contained-official/visor-uefi/intel-ia32-manual.pdf";
+ std.Io.Dir.accessAbsolute(std.testing.io, sdm, .{}) catch return "docs/design.pdf";
+ return sdm;
+}
+
+/// Lays the PDF pane out (a frame drawn) and syncs, so the jumplist sees it.
+fn jumpFrame(p: *Pardes) !void {
+ var frame: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer frame.deinit();
+ _ = try p.render(frame.allocator());
+ p.sync();
+}
+
+fn stripAtPlace(p: *Pardes, pane: *pardes.Pane, page: usize, fraction: f64) !f64 {
+ const pv = &pane.pdf.?;
+ pv.document_scroll_y = @as(f64, @floatFromInt(pv.page_starts[page])) + fraction * @as(f64, @floatFromInt(pv.page_heights[page]));
+ try jumpFrame(p);
+ return pv.document_scroll_y;
+}
+
+test "a PDF's jumps: Back after a far jump returns to the exact offset, two places on one page are two entries" {
+ if (!pdf_enabled or platform == .web) return error.SkipZigTest;
+ const p = try Pardes.init(std.testing.allocator, .{ .file = jumpPdf(), .cols = 80, .rows = 28 });
+ defer p.deinit();
+ p.native_images = true;
+ p.presentation.enabled = false;
+ const id = p.active;
+ const pane = p.panes[id].?;
+ const pv = &pane.pdf.?;
+ try jumpFrame(p);
+ try std.testing.expect(pv.page_count > 3);
+ // Two places on page 1, more than a body apart: two entries.
+ const before = p.njumps;
+ _ = try stripAtPlace(p, pane, 1, 0.05);
+ const near = try stripAtPlace(p, pane, 1, 0.8);
+ try std.testing.expectEqual(before + 2, p.njumps);
+ try std.testing.expect(p.jumps[p.njumps - 1].pdf);
+ // A far jump (a Look at a page), then Back: the exact offset, not the
+ // page's top, and its page.
+ look.lookAt(p, id, if (pv.page_count > 3000) ":3000" else ":4");
+ try jumpFrame(p);
+ try std.testing.expect(pv.page >= 3);
+ p.jumpBy(-1);
+ try jumpFrame(p);
+ try std.testing.expectEqual(@as(usize, 1), pv.page);
+ try std.testing.expectApproxEqAbs(near, pv.document_scroll_y, 0.5);
+ // A wheel's small steps are the same visit: the entry follows them.
+ const n = p.njumps;
+ for (0..4) |_| {
+ _ = panes.Pdf.scrollPane(p, pane, 30, true);
+ try jumpFrame(p);
+ }
+ try std.testing.expectEqual(n, p.njumps);
+}
+
+test "a PDF's jumps: JumpScope file keeps to the PDF, and a closed PDF reopens at its place" {
+ if (!pdf_enabled or platform == .web) return error.SkipZigTest;
+ // Recent keeps a file by the path it was opened as: a real one here,
+ // as a Look opens one.
+ var cwd_buf: [4096]u8 = undefined;
+ const cwd = cwd_buf[0..try std.Io.Dir.cwd().realPath(std.testing.io, &cwd_buf)];
+ var path_buf: [4200]u8 = undefined;
+ const path = try std.fmt.bufPrint(&path_buf, "{s}/docs/design.pdf", .{cwd});
+ const p = try Pardes.init(std.testing.allocator, .{ .file = path, .cols = 80, .rows = 28 });
+ defer p.deinit();
+ p.native_images = true;
+ p.presentation.enabled = false;
+ try std.testing.expectEqual(config.Runtime.JumpScope.file, p.settings.jump_scope);
+ const doc = p.active;
+ const pane = p.panes[doc].?;
+ try jumpFrame(p);
+ const first = try stripAtPlace(p, pane, 1, 0.3);
+ // A text between, then a far place in the PDF.
+ look.lookAt(p, doc, "../build.zig:10");
+ try jumpFrame(p);
+ try std.testing.expect(p.active != doc);
+ p.active = doc;
+ _ = try stripAtPlace(p, pane, 3, 0.5);
+ // Back from the PDF keeps to it: its own earlier place, not the text.
+ p.jumpBy(-1);
+ try jumpFrame(p);
+ try std.testing.expectEqual(doc, p.active);
+ try std.testing.expectApproxEqAbs(first, pane.pdf.?.document_scroll_y, 0.5);
+ // Closed, its entries stay; Back from the text reopens it at the place.
+ p.jumpBy(1);
+ try jumpFrame(p);
+ try p.removePane(doc, null);
+ try jumpFrame(p);
+ var closed = false;
+ for (p.jumps[0..p.njumps]) |j| closed = closed or (j.serial == 0 and j.pdf);
+ try std.testing.expect(closed);
+ var tries: usize = 0;
+ while (tries < 4) : (tries += 1) {
+ p.jumpBy(-1);
+ try jumpFrame(p);
+ if (p.panes[p.active].?.pdf != null) break;
+ }
+ const reopened = p.panes[p.active].?;
+ try std.testing.expect(reopened.pdf != null);
+ const pv = &reopened.pdf.?;
+ // The newest PDF place before the text: page 4, half way down.
+ try std.testing.expectEqual(@as(usize, 3), pv.page);
+ const want = @as(f64, @floatFromInt(pv.page_starts[3])) + 0.5 * @as(f64, @floatFromInt(pv.page_heights[3]));
+ try std.testing.expectApproxEqAbs(want, pv.document_scroll_y, 0.5);
+}