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

Error testing a specific pdf document #244

Open
manfredlotz opened this issue Jan 3, 2025 · 8 comments
Open

Error testing a specific pdf document #244

manfredlotz opened this issue Jan 3, 2025 · 8 comments

Comments

@manfredlotz
Copy link

manfredlotz commented Jan 3, 2025

When I put https://www.ctan.org/tex-archive/fonts/clara/doc/clara-sample.pdf into the files/ directory and run cargo test I get

 == Now testing `/data/vc/github/pdf/files/clara-sample.pdf` ==
thread 'read_pages' panicked at pdf/tests/integration.rs:51:20:
Try at pdf/src/file.rs:614:23:, caused by
  Can't parse field root of struct RcRef < Catalog >, caused by
  Shared, caused by
  Can't parse field pages of struct PagesRc, caused by
  Try at pdf/src/object/types.rs:110:20:, caused by
  Shared, caused by
  Try at pdf/src/object/types.rs:26:43:, caused by
  Can't parse field resources of struct Option < MaybeRef < Resources > >, caused by
  Can't parse field fonts of struct HashMap < Name, MaybeRef < Font > >, caused by
  Shared, caused by
  Can't parse field font_descriptor of struct Option < FontDescriptor >, caused by
  Can't parse field stem_v of struct FontDescriptor, caused by
  Expected primitive Number, found primitive Array instead.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

If I run pdfinfo files/clara-sample.pdf I get

Title:           Font Display for Clara
Author:          Séamas Ãfi Brógáin,,,
Creator:         FontForge
Producer:        FontForge
CreationDate:    Sun Jan 22 14:48:03 2017 CET
Custom Metadata: no
Metadata Stream: no
Tagged:          no
UserProperties:  no
Suspects:        no
Form:            none
JavaScript:      no
Pages:           4
Encrypted:       no
Page size:       595 x 842 pts (A4)
Page rot:        0
File size:       355224 bytes
Optimized:       no
PDF version:     1.4
@s3bk
Copy link
Contributor

s3bk commented Jan 4, 2025

Well, it violates the specification.

I could make a breaking change and lazy load fonts, which would allow you to read the rest of the pdf, but not the font.

@manfredlotz
Copy link
Author

Thanks for your quick reply.

Interestingly pdffonts files/clara-sample.pdf gives

name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
Times-Bold                           Type 1            Standard         no  no  no      36  0
Clara                                Type 1            Custom           yes no  no       5  0
Clara                                Type 1            Custom           yes no  no       8  0
Clara                                Type 1            Custom           yes no  no      11  0
Clara                                Type 1            Custom           yes no  no      14  0
Clara                                Type 1            Custom           yes no  no      17  0
Clara                                Type 1            Custom           yes no  no      20  0

@s3bk
Copy link
Contributor

s3bk commented Jan 4, 2025

https://github.com/pdf-rs/pdf/blob/master/pdf/src/object/types.rs#L387
you can try changing this to

    pub fonts: HashMap<Name, Lazy<Font>>

@manfredlotz
Copy link
Author

If I make that change I get

386 | #[derive(Object, ObjectWrite, Debug, DataSize, Default, DeepClone, Clone)]
    |                                                                    ----- in this derive macro expansion
...
402 |     pub fonts: HashMap<Name, Lazy<Font>>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `Font`, which is required by `HashMap<primitive::Name, object::Lazy<Font>>: Clone`
    |

@s3bk
Copy link
Contributor

s3bk commented Jan 4, 2025

should be fixed now

@manfredlotz
Copy link
Author

Get new errors:

error[E0599]: the method `deep_clone` exists for struct `HashMap<Name, Lazy<Font>>`, but its trait bounds were not satisfied
   --> pdf/src/object/types.rs:371:57
    |
371 | #[derive(Object, ObjectWrite, Debug, DataSize, Default, DeepClone, Clone)]

and

139 |         self.dict.remove(key)
    |                   ^^^^^^
    |
    = note: `#[warn(deprecated)]` on by default

error[E0599]: no method named `deep_clone` found for reference `&object::Lazy<Font>` in the current scope
    --> pdf/src/content.rs:1116:60
     |
1116 |                     resources.fonts.insert(name.clone(), f.deep_clone(cloner)?);
     |                                                            ^^^^^^^^^^

@s3bk
Copy link
Contributor

s3bk commented Jan 4, 2025

okay, I fixed it myself now. Probably breaking pdf-render. I will check now.

@manfredlotz
Copy link
Author

Your fix is working ok for my test now. Thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants