Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print explicit information on MuPDF Fitz count_pages error #377

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/core/src/document/pdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,16 @@ impl Document for PdfDocument {
}

fn pages_count(&self) -> usize {
unsafe { mp_count_pages(self.ctx.0, self.doc) as usize }
unsafe {
let page_count: i32 = mp_count_pages(self.ctx.0, self.doc);

if page_count <= 0 {
eprintln!("Error: MuPDF Fitz count_pages function returned {}.", page_count);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MuPDF prints errors on stderr, so this shouldn't be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly, Plato does not go that far in the process for MuPDF to throw an error and write it to stdout/stderr or to any .log file.

fz_count_pages and its subroutines look like they're fairly simple and don't throw errors, just return 0.

return 0;
}

return page_count as usize;
}
}

fn resolve_location(&mut self, loc: Location) -> Option<usize> {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/view/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ impl Reader {
doc.set_ignore_document_css(true);
}

println!("{}", info.file.path.display());

let first_location = doc.resolve_location(Location::Exact(0))?;

let mut view_port = ViewPort::default();
Expand Down Expand Up @@ -358,8 +360,6 @@ impl Reader {
let synthetic = doc.has_synthetic_page_numbers();
let reflowable = doc.is_reflowable();

println!("{}", info.file.path.display());

hub.send(Event::Update(UpdateMode::Partial)).ok();

Some(Reader {
Expand Down