From c8ad18df1d46265c30721861760a744227e57b31 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 25 Oct 2026 11:08:56 -0300 Subject: 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 --- src/pdf_view.zig | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/pdf_view.zig') diff --git a/src/pdf_view.zig b/src/pdf_view.zig index bcca11b4..f6d26eac 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -3070,6 +3070,56 @@ pub fn revealOutlineDestination( _ = ensurePaneLayout(core, pane); } +/// A PDF's place, as the jumplist keeps it: the page at the strip's top and +/// how far down that page it stands, a fraction in 2^-32 of the page. A +/// fraction, not pixels: a zoom, a fit change or a resize scales every page, +/// and a fraction of one lands on the same line of print after it. +pub const Place = struct { page: usize, at: u32 }; +const place_scale: f64 = std.math.maxInt(u32); + +pub fn place(pane: *const pardes.Pane) ?Place { + if (comptime !enabled) return null; + const state = if (pane.pdf) |*pv| pv else return null; + if (!state.layout_valid or state.document_height == 0) return .{ .page = state.page, .at = 0 }; + const page = pageAtOffset(state, state.document_scroll_y); + const start: f64 = @floatFromInt(state.page_starts[page]); + const height: f64 = @floatFromInt(@max(1, state.page_heights[page])); + const fraction = std.math.clamp((state.document_scroll_y - start) / height, 0, 1); + return .{ .page = page, .at = @intFromFloat(@round(fraction * place_scale)) }; +} + +/// Where `at` stands on the strip as laid out now, in document pixels. +pub fn placeY(pane: *const pardes.Pane, at: Place) ?f64 { + if (comptime !enabled) return null; + const state = if (pane.pdf) |*pv| pv else return null; + if (!state.layout_valid) return null; + const page = @min(at.page, state.page_count -| 1); + return @as(f64, @floatFromInt(state.page_starts[page])) + + @as(f64, @floatFromInt(at.at)) / place_scale * @as(f64, @floatFromInt(state.page_heights[page])); +} + +/// A jump to `at` (Back, Forward): the core is there at once and the strip +/// follows through the motion system, a far one as one body's slide, the +/// page rendered where it comes to rest. Not laid out yet (a pane just +/// reopened), it is anchored there for the first layout. +pub fn landAt(core: *pardes.Pardes, pane: *pardes.Pane, at: Place) void { + if (comptime !enabled) return; + const state = &(pane.pdf orelse return); + const page = @min(at.page, state.page_count -| 1); + activatePage(core, pane, page, false); + state.scroll_to_page_pending = false; + if (placeY(pane, .{ .page = page, .at = at.at })) |y| { + state.layout_anchor_pending = false; + // Where it stands already (half a pixel is the place's rounding): + // not moved, not kicked. + if (@abs(y - state.document_scroll_y) >= 0.5) state.document_scroll_y = y; + } else { + state.layout_anchor_pending = true; + state.layout_anchor_page = page; + state.layout_anchor_fraction = @as(f64, @floatFromInt(at.at)) / place_scale; + } +} + pub fn setPage(core: *pardes.Pardes, pane: *pardes.Pane, page: usize) void { activatePage(core, pane, page, true); } -- cgit v1.3