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

[api-minor] Remove the manual passing of an AnnotationStorage-instance when calling various API-method #13207

Merged

Conversation

Snuffleupagus
Copy link
Collaborator

Note how we purposely don't expose the AnnotationStorage-class directly in the official API (see src/pdf.js), since trying to use multiple ones simultaneously doesn't really make sense (e.g. in the viewer).
Instead we lazily initialize, and cache, just one instance via PDFDocumentProxy.annotationStorage which should thus be available internally in the API itself without having to be manually passed to various methods.

To support these changes, the AnnotationStorage-instance initialization is moved into the WorkerTransport-class to allow both PDFDocumentProxy and PDFPageProxy to access it.
This patch implements the following simplifications:

  • Remove the annotationStorage-parameter from PDFDocumentProxy.saveDocument, since it's already available internally.
    Furthermore, while it's currently possible to call that method without an AnnotationStorage-instance, that really does not make any sense at all. In this case you're effectively reducing PDFDocumentProxy.saveDocument to a "regular" PDFDocumentProxy.getData call, but with a lot more overhead, which was obviously not the intention of the PDFDocumentProxy.saveDocument-method.

  • Try to discourage third-party users from calling PDFDocumentProxy.saveDocument unconditionally, as a replacement for PDFDocumentProxy.getData (note the previous point).

  • Replace the annotationStorage-parameter, in PDFPageProxy.render, with a boolean includeAnnotationStorage-parameter which simply indicates if the (internally available) AnnotationStorage-instance should be used during rendering (e.g. for printing).

  • By removing the need to manually provide annotationStorage-parameters to various API-methods, using the API should become simpler (e.g. for third-parties) since you no longer need to worry about manually fetching and passing around this data.

…nce when calling various API-method

Note how we purposely don't expose the `AnnotationStorage`-class directly in the official API (see `src/pdf.js`), since trying to use *multiple* ones simultaneously doesn't really make sense (e.g. in the viewer).
Instead we lazily initialize, and cache, just *one* instance via `PDFDocumentProxy.annotationStorage` which should thus be available internally in the API itself without having to be manually passed to various methods.

To support these changes, the `AnnotationStorage`-instance initialization is moved into the `WorkerTransport`-class to allow both `PDFDocumentProxy` and `PDFPageProxy` to access it.
This patch implements the following simplifications:
 - Remove the `annotationStorage`-parameter from `PDFDocumentProxy.saveDocument`, since it's already available internally.
   Furthermore, while it's currently possible to call that method without an `AnnotationStorage`-instance, that really does *not* make any sense at all. In this case you're effectively reducing `PDFDocumentProxy.saveDocument` to a "regular" `PDFDocumentProxy.getData` call, but with *a lot* more overhead, which was obviously not the intention of the `PDFDocumentProxy.saveDocument`-method.

 - Try to discourage third-party users from calling `PDFDocumentProxy.saveDocument` unconditionally, as a replacement for `PDFDocumentProxy.getData` (note the previous point).

 - Replace the `annotationStorage`-parameter, in `PDFPageProxy.render`, with a boolean `includeAnnotationStorage`-parameter which simply indicates if the (internally available) `AnnotationStorage`-instance should be used during rendering (e.g. for printing).

 - By removing the need to *manually* provide `annotationStorage`-parameters to various API-methods, using the API should become simpler (e.g. for third-parties) since you no longer need to worry about manually fetching and passing around this data.
…parameters

These changes are done separately, to make it easier to remove them in the future.
@Snuffleupagus
Copy link
Collaborator Author

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Apr 9, 2021

From: Bot.io (Linux m4)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/1049e38337a39c4/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Apr 9, 2021

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://3.101.106.178:8877/0f28b2034cc2ed0/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Apr 9, 2021

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/1049e38337a39c4/output.txt

Total script time: 25.00 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED

Image differences available at: http://54.67.70.0:8877/1049e38337a39c4/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

pdfjsbot commented Apr 9, 2021

From: Bot.io (Windows)


Failed

Full output at http://3.101.106.178:8877/0f28b2034cc2ed0/output.txt

Total script time: 28.49 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED

Image differences available at: http://3.101.106.178:8877/0f28b2034cc2ed0/reftest-analyzer.html#web=eq.log

@timvandermeij timvandermeij merged commit b0473eb into mozilla:master Apr 9, 2021
@timvandermeij
Copy link
Contributor

I agree that this is a simpler API overall. Thanks!

@Snuffleupagus Snuffleupagus deleted the api-AnnotationStorage-params branch April 9, 2021 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants