summaryrefslogtreecommitdiff
path: root/src/pdf_view.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdf_view.zig')
-rw-r--r--src/pdf_view.zig13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/pdf_view.zig b/src/pdf_view.zig
index 5646a92f..6c137202 100644
--- a/src/pdf_view.zig
+++ b/src/pdf_view.zig
@@ -1877,6 +1877,9 @@ pub fn openPane(
id: usize,
path: []const u8,
page_one_based: usize,
+ /// A page past the last: the last page (a restore, a start-up), or
+ /// refused with error.NoSuchPage (a look, which names a place).
+ past_end: enum { last, refuse },
) !*pardes.Pane {
if (comptime !enabled) return error.PdfDisabled;
// The slot stays ours across the read: another request may make a
@@ -1891,6 +1894,7 @@ pub fn openPane(
break :virtual try State.openBytes(core.pdf_gpa, path, bytes, page_one_based);
};
errdefer state.deinit(core.pdf_gpa);
+ if (past_end == .refuse and page_one_based > state.page_count) return error.NoSuchPage;
const pane = try core.newDocPane(id);
pane.pdf = state;
pane.body.cur_pinned = true;
@@ -2004,11 +2008,16 @@ pub fn openSections(core: *pardes.Pardes, id: usize) void {
const pane = core.panes[id] orelse return;
const state = &(pane.pdf orelse return);
if (rearmCleanSections(core, id, pane, state)) return;
- const content = state.renderSections(core.pdf_gpa, core.gpa) catch return;
+ const content = state.renderSections(core.pdf_gpa, core.gpa) catch |err| return core.reportError(id, "PdfSections", err);
+ // No outline: said, not an empty pane to puzzle over.
+ if (content.len == 0) {
+ core.gpa.free(content);
+ return core.reportFailure(id, "PdfSections: this PDF has no outline");
+ }
const free = core.freeSlot() orelse {
core.gpa.free(content);
- return;
+ return core.reportError(id, "PdfSections", error.NoPaneSlots);
};
const dir = std.fs.path.dirname(state.path) orelse "/";
const result = Output.open(