pdf-rs / pdf_render

MIT License
112 stars 22 forks source link

Program crashes on Book #8

Closed BioBox closed 2 years ago

BioBox commented 2 years ago

I tried to test this out on a book (first pdf file I tried). The first three pages where fine, but on the fourth page I got this:

    Finished release [optimized] target(s) in 0.16s
     Running `target/release/view /home/daniel/docs/code/go.pdf`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Try { file: "render/src/renderstate.rs", line: 227, column: 29, context: Context([]), source: Other { msg: "expected 3 color arguments, got [Number(0.061)]" } }', /home/daniel/proj/rs-pdf/pdf_render/view/src/lib.rs:47:76
stack backtrace:
   0: rust_begin_unwind
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
   2: core::result::unwrap_failed
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1785:5
   3: <pdf_view::PdfView<B> as pathfinder_view::view::Interactive>::scene
   4: pathfinder_view::show::show::{{closure}}
   5: winit::platform_impl::platform::x11::EventLoop<T>::run_return
   6: pathfinder_view::show::show
   7: view::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
missing fonts:

Here's a full backtrace:

stack backtrace:
   0:     0x558f8e172a3d - std::backtrace_rs::backtrace::libunwind::trace::h22893a5306c091b4
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x558f8e172a3d - std::backtrace_rs::backtrace::trace_unsynchronized::h29c3bc6f9e91819d
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x558f8e172a3d - std::sys_common::backtrace::_print_fmt::he497d8a0ec903793
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x558f8e172a3d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9c2a9d2774d81873
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x558f8e19523c - core::fmt::write::hba4337c43d992f49
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/fmt/mod.rs:1194:17
   5:     0x558f8e16f891 - std::io::Write::write_fmt::heb73de6e02cfabed
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/io/mod.rs:1655:15
   6:     0x558f8e174515 - std::sys_common::backtrace::_print::h63c8b24acdd8e8ce
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x558f8e174515 - std::sys_common::backtrace::print::h426700d6240cdcc2
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x558f8e174515 - std::panicking::default_hook::{{closure}}::hc9a76eed0b18f82b
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:295:22
   9:     0x558f8e1741c9 - std::panicking::default_hook::h2e88d02087fae196
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:314:9
  10:     0x558f8e174a62 - std::panicking::rust_panic_with_hook::habfdcc2e90f9fd4c
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:698:17
  11:     0x558f8e174947 - std::panicking::begin_panic_handler::{{closure}}::he054b2a83a51d2cd
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:588:13
  12:     0x558f8e172ef4 - std::sys_common::backtrace::__rust_end_short_backtrace::ha48b94ab49b30915
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/sys_common/backtrace.rs:138:18
  13:     0x558f8e174679 - rust_begin_unwind
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
  14:     0x558f8dc768f3 - core::panicking::panic_fmt::h366d3a309ae17c94
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
  15:     0x558f8dc769e3 - core::result::unwrap_failed::hddd78f4658ac7d0f
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1785:5
  16:     0x558f8de1e786 - <pdf_view::PdfView<B> as pathfinder_view::view::Interactive>::scene::h8b7dd69dfdb0b391
  17:     0x558f8de23fb8 - pathfinder_view::show::show::{{closure}}::h547afd43c791e3d8
  18:     0x558f8de16ce7 - winit::platform_impl::platform::x11::EventLoop<T>::run_return::h8241d74d0f13d5c5
  19:     0x558f8dc7eef9 - pathfinder_view::show::show::h1903cbab3e784b5a
  20:     0x558f8dd590ce - view::main::h6329ec99029927c8
  21:     0x558f8dd65133 - std::sys_common::backtrace::__rust_begin_short_backtrace::hc0669745f611c36c
  22:     0x558f8dce7b09 - std::rt::lang_start::{{closure}}::h55713de905b4b591
  23:     0x558f8e169cae - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::had4f69b3aefb47a8
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/ops/function.rs:259:13
  24:     0x558f8e169cae - std::panicking::try::do_call::hf2ad5355fcafe775
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:492:40
  25:     0x558f8e169cae - std::panicking::try::h0a63ac363423e61e
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:456:19
  26:     0x558f8e169cae - std::panic::catch_unwind::h18088edcecb8693a
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panic.rs:137:14
  27:     0x558f8e169cae - std::rt::lang_start_internal::{{closure}}::ha7dad166dc711761
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/rt.rs:128:48
  28:     0x558f8e169cae - std::panicking::try::do_call::hda0c61bf3a57d6e6
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:492:40
  29:     0x558f8e169cae - std::panicking::try::hbc940e68560040a9
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:456:19
  30:     0x558f8e169cae - std::panic::catch_unwind::haed0df2aeb3fa368
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panic.rs:137:14
  31:     0x558f8e169cae - std::rt::lang_start_internal::h9c06694362b5b80c
                               at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/rt.rs:128:20
  32:     0x558f8dd59242 - main
  33:     0x7f7aad3d9290 - <unknown>
  34:     0x7f7aad3d934a - __libc_start_main
  35:     0x558f8dc76b95 - _start
                               at /build/glibc/src/glibc/csu/../sysdeps/x86_64/start.S:115
  36:                0x0 - <unknown>

I get the message "missing fonts:", so it looks like the font instructions don't provide all of the fonts necessary to view my desired content. This should be easy to fix with some extra fonts right? I noticed that there's a download_fonts.sh file but it doesn't generate the fonts.json file needed by pathfinder or whatever it's called so I'm not sure what that's for.

Please let me know of a solution because I need to make a pdf viewer and if this doesn't work then I'll have to do it in C++.

s3bk commented 2 years ago

Sorry for missing this issue. I have added instructions for the new font system: https://github.com/pdf-rs/pdf_render#fonts

BioBox commented 2 years ago

Yeah I already did that; my issue was submitted a day after the pdf_fonts repo was posted.

Without settnig the standard fonts it can't even load the first page. When doing STANDARD_FONTS=../pdf_fonts I can load the first three pages before the main thread panicks.

BioBox commented 2 years ago

Oh wait, there's some additional information I forgot to include:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Try { file: "render/src/renderstate.rs", line: 227, column: 29, context: Context([]), source: Other { msg: "expected 3 color arguments, got [Number(0.061)]" } }', /home/daniel/proj/rs-pdf/pdf_render/view/src/lib.rs:47:76
s3bk commented 2 years ago

You can set allow_error_in_option to true in ParseOptions to ignore this.

BioBox commented 2 years ago

Okay I set ParseOptions from strict to tolerant and set the cargo file to use a patched version of the library and it works fine now. Thank you!

s3bk commented 2 years ago

If you want to debug the cause further and think the value is correct, feel free to reopen. I briefly looked at the code and it looks like a bug in the file.