Commit Graph

12774 Commits

Author SHA1 Message Date
Tim van der Meij
3116216e1d
Improve the API documentation for PDFDocumentLoadingTask
This commit:
- formats the documentation block according to the standards;
- replaces the callback definitions with the `function` type (we have
  that for other definitions already and the callback type was not
  rendered correctly by JSDoc);
- synchronizes the type documentation and the class documentation;
- fixes the documentation by making it easier to read and making sure
  that all optional properties are indicated as such;
- uses the `@link` tag to indicate links to other code.

The `typestest` still passes and JSDoc now renders this class correctly.
2020-08-04 23:17:24 +02:00
Tim van der Meij
7e759c6e2b
Improve the typestest target in the Gulpfile
This commit:
- moves the preparation work to a new `typestest-pre` target similar to
  how the other targets work;
- moves the `TYPESTEST_DIR` definition to the top of the file like we
  did for all other directory variables;
- renames the `TYPES_BUILD_DIR` variable to `TYPES_DIR` since it's
  shorter and the naming scheme then corresponds to the other directory
  variables;
- switches to `const`/template strings in the types targets where needed;
- converts the `if (err !== null)` check to `if (err)` similar to other
  targets.
2020-08-04 23:17:20 +02:00
Jonas Jenwald
13e44c0776 Attempt to reduce intermittent failures in the "multiple render() on the same canvas" unit-test
This patch should *hopefully* remove the intermittent unit-test failure, by using the *same* `optionalContentConfigPromise` for both `renderTask`s and thus get more predictable timing behaviour.
2020-08-04 22:31:24 +02:00
Brendan Dahl
9989879458
Merge pull request #12095 from brendandahl/oc
Add support for optional marked content.
2020-08-04 12:00:20 -07:00
Brendan Dahl
ac494a2278 Add support for optional marked content.
Add a new method to the API to get the optional content configuration. Add
a new render task param that accepts the above configuration.
For now, the optional content is not controllable by the user in
the viewer, but renders with the default configuration in the PDF.

All of the test files added exhibit different uses of optional content.

Fixes #269.

Fix test to work with optional content.

- Change the stopAtErrors test to ensure the operator list has something,
  instead of asserting the exact number of operators.
2020-08-04 09:26:55 -07:00
Tim van der Meij
e68ac05f18
Merge pull request #12160 from tamuratak/worker_options
Use typedef to define the type of GlobalWorkerOptions (PR 12102 follow-up)
2020-08-03 22:55:49 +02:00
Tim van der Meij
0b75701012
Merge pull request #12157 from tamuratak/fix_svggraphics
Fix the type of SVGGraphics (PR 12102 follow-up)
2020-08-03 22:52:10 +02:00
Tim van der Meij
adc7645a44
Merge pull request #12161 from tamuratak/exported_func
Add types to functions exported as API in src/pdf.js (PR 12102 follow-up)
2020-08-03 22:43:50 +02:00
Tim van der Meij
82fece76df
Merge pull request #12162 from tamuratak/viewbox
Tweak for the type of PageViewportParameters.viewBox (PR 12102 follow-up)
2020-08-03 22:35:28 +02:00
Jonas Jenwald
0b65d4cacd Re-factor the dispatching of "attachmentsloaded" events, when the PDF document contains no "regular" attachments
Since the attachment fetching/parsing is already asynchronous, possibly delaying the dispatching of an "attachmentsloaded" event should thus not be a problem in general.
Note that in some cases, i.e. PDF documents with no "regular" attachments and only FileAttachment annotations, we'll thus no longer dispatch an "attachmentsloaded" event when `attachmentsCount === 0` and instead wait for the FileAttachment parsing to finish. (The use of a timeout still guarantees that an "attachmentsloaded" event is *eventually* dispatched though.)

This patch *considerably* simplifies the "attachmentsloaded" event handler, in `PDFSidebar`, since the details are now abstracted away from the consumer.

Finally, add a check in `_appendAttachment` to ensure (indirectly) that the FileAttachment annotation is actually relevant for the active document.
2020-08-03 14:23:44 +02:00
Takashi Tamura
923ba27f1f Tweak for the type of PageViewportParameters.viewBox 2020-08-03 20:42:42 +09:00
Takashi Tamura
bc4648c0a6 Add types to functions exported as API in src/pdf.js. 2020-08-03 19:19:48 +09:00
Jonas Jenwald
24d8933023 Use a DocumentFragment when building the attachmentsView in PDFAttachmentViewer.render
This approach is already used in other parts of the code-base, see e.g. `PDFOutlineViewer`, and has the advantage of only invalidating the DOM once rather than for every attachment item.
2020-08-03 12:11:46 +02:00
Takashi Tamura
f6fd8e9e7f Use typedef to define the type of GlobalWorkerOptions. 2020-08-03 19:06:28 +09:00
Takashi Tamura
d72bbecee2 Fix the type of SVGGraphics. 2020-08-03 09:58:19 +09:00
Tim van der Meij
00a8b42e67
Merge pull request #12102 from ineiti/add_types_annotations
Add types annotations
2020-08-02 16:45:37 +02:00
Tim van der Meij
5a66c56eca
Merge pull request #12108 from calixteman/radio
Add support for radios printing
2020-08-02 14:47:46 +02:00
Tim van der Meij
277a92d278
Merge pull request #12153 from timvandermeij/jasmine
Unit test improvements
2020-08-01 21:59:28 +02:00
Tim van der Meij
c53e403049
Update Jasmine to version 3.6.1
This is possible now that most intermittent unit test failures have been
resolved by other patches. There is only one remaining, but it's very
rare and doesn't have to block this update anymore.
2020-08-01 21:12:26 +02:00
Tim van der Meij
b789a0e216
Log the total number of tests and the random seed in the test runner
This might make debugging intermittent failures a bit easier in the
future because it allows us to spot unexpected differences in the number
of tests being run and allows us to run the tests locally in the same
order in case of intermittent failures.
2020-08-01 21:09:01 +02:00
Tim van der Meij
662ac5548f
Log suite start failures in the test runner 2020-08-01 21:02:20 +02:00
Tim van der Meij
c19d76f9b8
Use a for...of loop in the specDone handler in the test reporter
Moreover, remove a left-over reference to `test.py` since that was
ported to JavaScript a long time ago.
2020-08-01 20:50:30 +02:00
Tim van der Meij
252f2ba529
Merge pull request #12151 from Snuffleupagus/revert-12131-issue-8271
Revert "[api-minor] Allow loading pdf fonts into another document."
2020-08-01 15:06:40 +02:00
Jonas Jenwald
05baa4c89f
Revert "[api-minor] Allow loading pdf fonts into another document." 2020-08-01 12:52:39 +02:00
Tim van der Meij
173b92a873
Merge pull request #12131 from jsg2021/issue-8271
[api-minor] Allow loading pdf fonts into another document.
2020-08-01 01:13:41 +02:00
Tim van der Meij
0c2cef8024
Merge pull request #12148 from timvandermeij/revert
Revert "Populate the find field with the search query when URL has #search hash"
2020-08-01 00:53:51 +02:00
Tim van der Meij
81ae565d8a
Revert "Populate the find field with the search query when URL has #search hash"
This reverts commit 50f73092e1. This
causes an inconsistency with the integrated find bar that should be
discussed more before moving on with this (refer to PR #12141).
2020-08-01 00:41:56 +02:00
Tim van der Meij
0d20a2b7b4
Merge pull request #12144 from Snuffleupagus/uncaught-promise-AbortException
Prevent `Uncaught (in promise) AbortException` when running the unit-tests
2020-08-01 00:22:10 +02:00
Tim van der Meij
b037e59abf
Merge pull request #12147 from Snuffleupagus/fix-AnnotationStorage-usage
[api-minor] Fix the `AnnotationStorage` usage properly in the viewer/tests (PR 12107 and 12143 follow-up)
2020-07-31 23:41:18 +02:00
Jonas Jenwald
6d192f987e Prevent Uncaught (in promise) AbortException when running the unit-tests
These errors can/will occur if data is still loading when the document is destroyed, which is the case in the API unit-tests that load the `tracemonkey.pdf` file.
While this patch prevents these kind of problems, and thus allows us to update Jasmine again, I cannot help but thinking that it's slightly "hacky". Basically, we'll simply catch and ignore (some) rejected promises once the document is destroyed and/or its data loading is aborted. However, I don't *think* that these changes should cause issues in general, since we don't really care about errors once document destruction has started (note e.g. the fair number of `catch` handlers ignoring `AbortException`s already).
2020-07-31 23:29:05 +02:00
Jonathan Grimes
9b16b8ef71
Allow loading pdf fonts into another document. 2020-07-31 11:41:48 -05:00
Jonas Jenwald
95bfc43a3b Avoid doing unnecessary work in AnnotationLayerBuilder.render, such as cloning a PageViewport, when no annotations exist for a page 2020-07-31 16:42:49 +02:00
Jonas Jenwald
346afd1e1c [api-minor] Fix the AnnotationStorage usage properly in the viewer/tests (PR 12107 and 12143 follow-up)
*The [api-minor] label probably ought to have been added to the original PR, given the changes to the `createAnnotationLayerBuilder` signature (if nothing else).*

This patch fixes the following things:
 - Let the `AnnotationLayer.render` method create an `AnnotationStorage`-instance if none was provided, thus making the parameter *properly* optional. This not only fixes the reference tests, it also prevents issues when the viewer components are used.
 - Stop exporting `AnnotationStorage` in the official API, i.e. the `src/pdf.js` file, since it's no longer necessary given the change above. Generally speaking, unless absolutely necessary we probably shouldn't export unused things in the API.
 - Fix a number of JSDocs `typedef`s, in `src/display/` and `web/` code, to actually account for the new `annotationStorage` parameter.
 - Update `web/interfaces.js` to account for the changes in `createAnnotationLayerBuilder`.
 - Initialize the storage, in `AnnotationStorage`, using `Object.create(null)` rather than `{}` (which is the PDF.js default).
2020-07-31 16:32:46 +02:00
Calixte Denizet
f22e702ecc Amend test for checkboxes printing to test the unchecked appearance 2020-07-31 14:39:11 +02:00
Calixte Denizet
538017f7a7 Add support for radios printing 2020-07-31 14:31:49 +02:00
Tim van der Meij
c5663f2f6b
Merge pull request #12141 from phillipj/populate-findbar-on-search-hash
Populate the find field with the search query when URL has #search hash
2020-07-31 00:07:18 +02:00
Tim van der Meij
f676a00762
Merge pull request #12143 from escapewindow/fix-12107
fix reftests after #12107
2020-07-30 23:56:54 +02:00
Aki Sasaki
7bb65bab7f fix reftests after #12107
The f1040-annotations reftest started hanging after #12107. We traced
this to `TypeError: can't access property "getOrCreateValue", storage is
undefined`.

We essentially need to add `annotationStorage` to the parameters in
test/driver.js.
2020-07-30 12:25:27 -07:00
Linus Gasser
f1bbfdc16d Add typescript definitions
This PR adds typescript definitions from the JSDoc already present.
It adds a new gulp-target 'types' that calls 'tsc', the typescript
compiler, to create the definitions.

To use the definitions, users can simply do the following:

```
import {getDocument, GlobalWorkerOptions} from "pdfjs-dist";
import pdfjsWorker from "pdfjs-dist/build/pdf.worker.entry";
GlobalWorkerOptions.workerSrc = pdfjsWorker;

const pdf = await getDocument("file:///some.pdf").promise;
```

Co-authored-by: @oBusk
Co-authored-by: @tamuratak
2020-07-30 11:10:37 +02:00
Phillip Johnsen
50f73092e1 Populate the find field with the search query when URL has #search hash
These changes improves the existing search functionality triggered when
the URL contains a `#search` hash.

In addition to performing the actual search immediately like before,
this will ensure the search text field inside the find bar gets
populated with the text currently being searched for.
2020-07-30 10:11:30 +02:00
Tim van der Meij
eb4d6a0652
Merge pull request #12107 from calixteman/checkbox
Add support for checkboxes printing
2020-07-30 00:11:41 +02:00
Calixte Denizet
cb60523a15 Add support for checkboxes printing 2020-07-29 16:42:57 +02:00
Tim van der Meij
6537e64cb8
Merge pull request #12136 from Snuffleupagus/PDFFetchStreamRangeReader-AbortError
Ignore `fetch()` errors, in `PDFFetchStreamRangeReader`, once the request has been aborted
2020-07-29 00:09:51 +02:00
Tim van der Meij
bcbbd03f7b
Merge pull request #12135 from Snuffleupagus/pdfManagerReady-loadDocument-promise
[src/core/worker.js] Remove a useless Promise handler from the `pdfManagerReady` function
2020-07-29 00:07:25 +02:00
Jonas Jenwald
1b720a4b23 Ignore fetch() errors, in PDFFetchStreamRangeReader, once the request has been aborted
Besides making general sense, as far as I can tell, this patch should also prevent *one* source of `Uncaught (in promise) ...` exceptions.
Unfortunately `reason instanceof AbortError` doesn't work here, since `AbortError` isn't actually defined in browsers; note how even the DOM specification contains an example using the `name` property: https://dom.spec.whatwg.org/#aborting-ongoing-activities

This patch prevents the following errors from being logged in the console, when the unit-tests are running:
 - Firefox: `Uncaught (in promise) DOMException: The operation was aborted.`
 - Chrome: `Uncaught (in promise) DOMException: The user aborted a request.`
2020-07-28 17:18:49 +02:00
Jonas Jenwald
fbe90b63ec [src/core/worker.js] Remove a useless Promise handler from the pdfManagerReady function
Looking carefully at this code, you'll notice that the `loadDocument` function has no less than *three* Promise handling functions. This obviously makes no sense, since a Promise can only have one resolve and one reject handler.

Hence the final `onFailure`-case is unreachable, which only serves to add confusion when reading the code. Note that this code has been re-factored more than once over the years, but it seems as if this may even have been incorrect already in PR 3310 (and no-one have noticed for seven years :-).
2020-07-28 14:51:50 +02:00
Tim van der Meij
403816040e
Merge pull request #12127 from Snuffleupagus/type3Dependencies
Improve how Type3-fonts with dependencies are handled
2020-07-27 23:44:51 +02:00
Jonas Jenwald
835b5ffddd Only check isType3Font the first time that TranslatedFont.loadType3Data is called
If the `TranslatedFont.type3Loaded` property exists, then you already know that the font must be a Type3 one.
2020-07-27 13:20:15 +02:00
Jonas Jenwald
f3ff526019 Send/receive Type3 images the same way as other globally-cached images
There's quite frankly no particular reason to special-case Type3-fonts with image resources, which are very rare anyway, now that we have a general mechanism for sending/receiving images globally.
2020-07-27 13:20:15 +02:00
Jonas Jenwald
7c9d0d5939 Improve how Type3-fonts with dependencies are handled
While the `CharProcs` streams of Type3-fonts *usually* don't rely on dependencies, such as e.g. images, it does happen in some cases.

Currently any dependencies are simply appended to the parent operatorList, which in practice means *only* the operatorList of the *first* page where the Type3-font is being used.
However, there's one thing that's slightly unfortunate with that approach: Since fonts are global to the PDF document, we really ought to ensure that any Type3 dependencies are appended to the operatorList of *all* pages where the Type3-font is being used. Otherwise there's a theoretical risk that, if one page has its rendering paused, another page may try to use a Type3-font whose dependencies are not yet fully resolved. In that case there would be errors, since Type3 operatorLists are executed synchronously.

Hence this patch, which ensures that all relevant pages will have Type3 dependencies appended to the main operatorList. (Note here that the `OperatorList.addDependencies` method, via `OperatorList.addDependency`, ensures that a dependency is only added *once* to any operatorList.)

Finally, these changes also remove the need for the "waiting for the main-thread"-hack that was added to `PartialEvaluator.buildPaintImageXObject` as part of fixing issue 10717.
2020-07-27 13:20:13 +02:00