Commit Graph

14875 Commits

Author SHA1 Message Date
Jonas Jenwald
c6d400ed06 Export the XFA/StructTree-layers in the viewer components
While e.g. the `simpleviewer` and `singlepageviewer` examples work, since they're based on the `BaseViewer`-class, the standalone `pageviewer` example currently doesn't support either XFA- or StructTree-layers. This seems like an obvious oversight, which can be easily addressed simply by exporting the necessary functionality through `pdf_viewer.component.js`, similar to the existing Text/Annotation-layers.

While working on, and testing, these changes I happened to notice a number of smaller things that's also fixed in this patch:

 - Ensure that `XfaLayerBuilder.render` always have a *consistent* return type, to prevent possible run-time failures in `PDFPageView`; PR 13908 follow-up.

 - Change the order of the options in the `XfaLayerBuilder`-constructor to agree with the parameter order in the `DefaultXfaLayerFactory.createXfaLayerBuilder`-method.

 - Add a missing `textHighlighterFactory`-option, in the JSDocs for the `PDFPageView`-class.

 - A couple of small tweaks in the `TextLayerBuilder.render`-method: Re-use an existing Array rather than creating a new one, and replace an `if` with optional chaining instead.

*Please note:* For now XFA-support is currently disabled by default, similar to the regular viewer.
2021-08-28 18:43:08 +02:00
Jonas Jenwald
9ea3fa0747 Ensure that PasswordException is handled correctly in the wrapReason function
While running the unit-tests with some logging statements added to this code, I noticed that `PasswordException` was missing from the list of potential Errors that could be passed to the `wrapReason` function.
2021-08-28 12:24:12 +02:00
Tim van der Meij
153d058b3a
Merge pull request #13933 from brendandahl/xfa-checkbox2
Fix saving of XFA checkboxes. (bug 1726381)
2021-08-27 22:45:44 +02:00
Tim van der Meij
b0929dceba
Merge pull request #13940 from Snuffleupagus/cleanup-supportsFullscreen
Simplify the `PDFViewerApplication.supportsFullscreen` getter
2021-08-27 22:31:31 +02:00
Tim van der Meij
c82381eb06
Merge pull request #13930 from michael-yx-wu/mw/fix-typings
Fix Viewer API definitions and include in CI
2021-08-27 22:15:32 +02:00
Tim van der Meij
46f6351287
Merge pull request #13939 from Snuffleupagus/gulpfile-ci-test
Remove the `npm test`-command
2021-08-27 21:59:49 +02:00
Jonas Jenwald
bc2bb18af7 Simplify the PDFViewerApplication.supportsFullscreen getter
A lot of the code in this getter has existed ever since the initial PresentationMode-implementation was first added all the way back in PR 1938 (which is nine years ago now).
At this point in time however, there's now a simpler way detect if a browser supports the FullScreen API and we should thus be able to simplify this getter; please refer to https://developer.mozilla.org/en-US/docs/Web/API/Document/fullscreenEnabled#browser_compatibility
2021-08-27 17:51:55 +02:00
Jonas Jenwald
8ff0f8e4df Use optional chaining even more in the web/app.js file 2021-08-27 17:29:00 +02:00
Jonas Jenwald
d67d48486c Remove the npm test-command
This command was added all the way back when basic CI-support was first introduced (using Travis at the time), however it's never really intended to be used e.g. for local development.
By having a `npm test`-command listed in the `package.json` file, there's a very real risk that someone unfamiliar with the code-base would only run that one and thus miss all the other (more important) test-suites[1].

Hence this patch which removes the `npm test`-command, and instead simply calls the relevant gulp-task[2] directly in the GitHub Actions configuration.

---
[1] Which consist of the unit-tests (run in browsers), the font-tests (potentially), the reference-tests, and the integration-tests.

[2] Which is also renamed slightly, to better fit its current usage.
2021-08-27 16:29:55 +02:00
Jonas Jenwald
b34d2cdc42 Ensure that beginMarkedContentProps/endMarkedContent-operators, for /XObjects, are balanced in corrupt documents (PR 13854 follow-up)
Something that I *just* realized is that while PR 13854 fixed an issue as reported, it could still cause bugs in other similarily broken documents since we'll not insert a matching endMarkedContent-operator in the operatorList.
2021-08-26 17:05:30 +02:00
Jonas Jenwald
1a1de9bb3e Add support for specifying non-default Optional Content in the ref-tests 2021-08-26 16:54:16 +02:00
Jonas Jenwald
853b1172a1 Support Optional Content in Image-/XObjects (issue 13931)
Currently, in the `PartialEvaluator`, we only support Optional Content in Form-/XObjects. Hence this patch adds support for Image-/XObjects as well, which looks like a simple oversight in PR 12095 since the canvas-implementation already contains the necessary code to support this.
2021-08-26 16:54:15 +02:00
Michael Wu
c08b4ea30d Fix Viewer API definitions and include in CI
The Viewer API definitions do not compile because of missing imports and
anonymous objects are typed as `Object`. These issues were not caught
during CI because the test project was not compiling anything from the
Viewer API.

As an example of the first problem:

```
/**
 * @implements MyInterface
 */
export class MyClass {
    ...
}
```

will generate a broken definition that doesn’t import MyInterface:

```
/**
 * @implements MyInterface
 */
export class MyClass implements MyInterface {
    ...
}
```

This can be fixed by adding a typedef jsdoc to specify the import:

```
/** @typedef {import("./otherFile").MyInterface} MyInterface */
```

See https://github.com/jsdoc/jsdoc/issues/1537 and
https://github.com/microsoft/TypeScript/issues/22160 for more details.

As an example of the second problem:

```
/**
 * Gets the size of the specified page, converted from PDF units to inches.
 * @param {Object} An Object containing the properties: {Array} `view`,
 *   {number} `userUnit`, and {number} `rotate`.
 */
function getPageSizeInches({ view, userUnit, rotate }) {
    ...
}
```

generates the broken definition:

```
function getPageSizeInches({ view, userUnit, rotate }: Object) {
    ...
}
```

The jsdoc should specify the type of each nested property:

```
/**
 * Gets the size of the specified page, converted from PDF units to inches.
 * @param {Object} options An object containing the properties: {Array} `view`,
 *   {number} `userUnit`, and {number} `rotate`.
 * @param {number[]} options.view
 * @param {number} options.userUnit
 * @param {number} options.rotate
 */
```
2021-08-25 18:45:46 -04:00
Tim van der Meij
ada283cc35
Merge pull request #13935 from Snuffleupagus/TextHighlighter-tweaks
A couple of small `TextHighlighter`/`TextLayerBuilder` tweaks (PR 13908 follow-up)
2021-08-25 23:06:51 +02:00
Tim van der Meij
4346b39cbd
Merge pull request #13934 from Snuffleupagus/rm-IPDFHistory
Remove the `IPDFHistory` interface
2021-08-25 22:57:07 +02:00
Jonas Jenwald
fa4e82c453 A couple of small TextHighlighter/TextLayerBuilder tweaks (PR 13908 follow-up)
- Use `Node.TEXT_NODE` rather than a magical constant, in `TextHighlighter._convertMatches`, to improve readability. According to MDN, this has been supported since "forever": https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType#browser_compatibility

 - Remove the `pageIdx`-property, on `TextLayerBuilder`-instances, since the re-factoring in PR 13908 meant that it's now unused.

 - Remove the `matches`-property, on `TextLayerBuilder`-instances, since the re-factoring in PR 13908 meant that it's now unused.
2021-08-25 14:14:44 +02:00
Jonas Jenwald
ae90d9162b Remove the IPDFHistory interface
Generalizing, and documenting, the `PDFHistory`-implementation as part of the web-interfaces doesn't seem entirely necessary and in hindsight I'm not entirely sure why we need it since:

 - The `PDFHistory` implementation is/was written specifically for the default viewer use-case, which is why e.g. the `simpleviewer` component example isn't using it. (While it *could* be used there, it'd need to be manually created/initialized correctly.)

 - There's only *one* `PDFHistory`-implementation present (and no other viewer-component will fail without it being available), as opposed to the other web-interfaces documented in this file.

 - The `PDFHistory` implementation is not even usable with e.g. the `pageviewer` component example, since it (obviously) requires a complete viewer to work. (This is in contrast to e.g. `IPDFTextLayerFactory` and `IPDFAnnotationLayerFactory`.)
2021-08-25 12:44:55 +02:00
Jonas Jenwald
bb81f4029a
Merge pull request #13923 from Snuffleupagus/AnnotationMode
[api-minor] Introduce a new `annotationMode`-option, in `PDFPageProxy.{render, getOperatorList}`
2021-08-25 11:10:47 +02:00
Brendan Dahl
6d2193a812 Fix saving of XFA checkboxes. (bug 1726381)
Previously were were always setting the storage value to the on value.
2021-08-24 15:53:55 -07:00
Jonas Jenwald
2a0ad8e696 Add deprecation warnings for the renderInteractiveForms and includeAnnotationStorage options, in PDFPageProxy.render
*This is done separately from the previous patch, to make it easier to revert these changes once they've been included in a couple of releases.*

Please note that because these two options are mutually exclusive, which is a large part of the reason for the previous patch, it's not guaranteed that the fallback-values will always be correct in every situation (but it's the best that we can do).
2021-08-24 01:40:12 +02:00
Jonas Jenwald
41efa3c071 [api-minor] Introduce a new annotationMode-option, in PDFPageProxy.{render, getOperatorList}
*This is a follow-up to PRs 13867 and 13899.*

This patch is tagged `api-minor` for the following reasons:
 - It replaces the `renderInteractiveForms`/`includeAnnotationStorage`-options, in the `PDFPageProxy.render`-method, with the single `annotationMode`-option that controls which annotations are being rendered and how. Note that the old options were mutually exclusive, and setting both to `true` would result in undefined behaviour.

 - For improved consistency in the API, the `annotationMode`-option will also work together with the `PDFPageProxy.getOperatorList`-method.

 - It's now also possible to disable *all* annotation rendering in both the API and the Viewer, since the other changes meant that this could now be supported with a single added line on the worker-thread[1]; fixes 7282.

---
[1] Please note that in order to simplify the overall implementation, we'll purposely only support disabling of *all* annotations and that the option is being shared between the API and the Viewer. For any more "specialized" use-cases, where e.g. only some annotation-types are being rendered and/or the API and Viewer render different sets of annotations, that'll have to be handled in third-party implementations/forks of the PDF.js code-base.
2021-08-24 01:13:02 +02:00
Brendan Dahl
56e7bb626c
Merge pull request #13660 from calixteman/no_xfaf
XFA - Disable xfa rendering for XFAF pdfs
2021-08-23 12:30:29 -07:00
Calixte Denizet
04573d2dc8 XFA - Disable xfa rendering for XFAF pdfs
- we'll implement XFAF support later.
2021-08-23 12:18:20 -07:00
Brendan Dahl
bf5a45ce6d
Merge pull request #13908 from brendandahl/xfa-find
[api-minor] XFA - Support text search in XFA documents.
2021-08-23 08:53:02 -07:00
Brendan Dahl
bb47128864 XFA - Support text search in XFA documents.
Moves the logic out of TextLayerBuilder to handle
highlighting matches into a new separate class `TextHighlighter`
that can be used with regular PDFs and XFA PDFs.

To mimic the current find functionality in XFA, two arrays
from the XFA rendering are created to get the text content
and map those to DOM nodes.

Fixes #13878
2021-08-23 08:44:20 -07:00
Tim van der Meij
d022333618
Merge pull request #13922 from Snuffleupagus/eslint-object-shorthand-chromium
Enable the ESLint `object-shorthand` rule in the `extensions/chromium/`-folder
2021-08-22 13:58:02 +02:00
Tim van der Meij
4477cb2804
Merge pull request #13921 from Snuffleupagus/update-packages
Update packages and translations
2021-08-22 13:56:44 +02:00
Jonas Jenwald
66c8a0897a Enable the ESLint object-shorthand rule in the extensions/chromium/-folder
Based on the following compatibility information, there can't be any compelling reason to not enable this ESLint rule now: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#browser_compatibility

See also https://eslint.org/docs/rules/object-shorthand
2021-08-22 12:33:02 +02:00
Jonas Jenwald
ab06773758 Update l10n files 2021-08-22 10:43:02 +02:00
Jonas Jenwald
a24702b942 Update npm packages 2021-08-22 10:38:52 +02:00
Tim van der Meij
83e1064360
Merge pull request #13920 from Snuffleupagus/issue-13916
Extend the glyph maps for standard respectively Calibri fonts (issue 13916)
2021-08-21 15:05:08 +02:00
Tim van der Meij
db11ba024d
Merge pull request #13899 from Snuffleupagus/includeAnnotationStorage-fix-caching
[Regression] Re-factor the *internal* `includeAnnotationStorage` handling, since it's currently subtly wrong
2021-08-21 15:04:28 +02:00
Tim van der Meij
1b3382f921
Merge pull request #13904 from Snuffleupagus/fix-LocalTilingPatternCache
Re-factor the LocalTilingPatternCache to cache by Ref rather than Name (PR 12458 follow-up, issue 13780)
2021-08-21 14:46:34 +02:00
Tim van der Meij
50dffdaf55
Merge pull request #13905 from Snuffleupagus/refactor-loadAndEnablePDFBug
Re-factor `loadAndEnablePDFBug` and `PDFBug.init`
2021-08-21 14:39:57 +02:00
Jonas Jenwald
ac27f96987 Extend the glyph maps for standard respectively Calibri fonts (issue 13916) 2021-08-21 00:48:38 +02:00
Jonas Jenwald
6b2c913413
Merge pull request #13913 from michael-yx-wu/mw/fix-typings
Fix pdf_viewer definitions
2021-08-20 22:10:30 +02:00
Michael Wu
acfb54a836 Fix pdf_viewer definitions
Current pdf_viewer definitions result in errors like the following when
trying to use them in a ts project:

[error] TypeScript error
node_modules/.pnpm/pdfjs-dist@2.10.377/node_modules/pdfjs-dist/web/pdf_viewer.d.ts:1:15
- error TS2691: An import path cannot end with a '.d.ts' extension.
Consider importing 'pdfjs-dist/types/web/pdf_viewer.component.js'
instead.

1 export * from "pdfjs-dist/types/web/pdf_viewer.component.d.ts";

Import/export statements in typescript should not include file extensions.
2021-08-20 12:23:43 -04:00
Brendan Dahl
3c8ee25e05
Merge pull request #13911 from Snuffleupagus/gulpfile-fix-TESTING-define
Ensure that the `TESTING` define can always be overridden in `gulpfile.js`
2021-08-19 13:15:47 -07:00
Jonas Jenwald
88d39e51c3 When running tests, enable XFA by default in the viewer (PR 13745 follow-up) 2021-08-19 20:13:19 +02:00
Jonas Jenwald
1f468e523f Ensure that the TESTING define can always be overridden in gulpfile.js
Currently a `TESTING = true` environment variable will *always* take precedence in the various build-tasks, and there's no way to explicitly disable it for a particular build. That's clearly an oversight on my part, however it's easy enough to fix this; sorry about breaking this!
2021-08-19 19:54:36 +02:00
Jonas Jenwald
bc8787b049 Re-factor loadAndEnablePDFBug and PDFBug.init
The `loadAndEnablePDFBug` helper function, in `web/app.js`, can be simplified a little bit by making it `async`. Furthermore, given how `PDFBug` is being used, we can also (slightly) re-factor `PDFBug.init` such that the `PDFBug.enable`-call is done internally rather than having to handle that manually at the call-site.

(Finally, utilize `await` more in the `loadFakeWorker` helper function.)
2021-08-19 12:06:23 +02:00
Jonas Jenwald
5f25fea0fe Re-factor the LocalTilingPatternCache to cache by Ref rather than Name (PR 12458 follow-up, issue 13780)
This way there cannot be any *incorrect* cache hits, since Refs are guaranteed to be unique.
Please note that the reason for caching by Ref rather than doing something along the lines of the `localShadingPatternCache` (which uses a `Map` directly), is that TilingPatterns are streams and those cannot be cached on the `XRef`-instance (this way we avoid unnecessary parsing).
2021-08-18 12:49:01 +02:00
Jonas Jenwald
8ee5acd85d Tweak handling of the onlyRefs-option in the BaseLocalCache class 2021-08-18 12:24:51 +02:00
Jonas Jenwald
a7f0301f21 [Regression] Re-factor the *internal* includeAnnotationStorage handling, since it's currently subtly wrong
*This patch is very similar to the recently fixed `renderInteractiveForms`-options, see PR 13867.*
As far as I can tell, this *subtle* bug has existed ever since `AnnotationStorage`-support was first added in PR 12106 (a little over a year ago).

The value of the `includeAnnotationStorage`-option, as passed to the `PDFPageProxy.render` method, will (potentially) affect the size/content of the operatorList that's returned from the worker (for documents with forms).
Given that operatorLists will generally, unless they contain huge images, be cached in the API, repeated `PDFPageProxy.render` calls where the form-data has been changed by the user in between, can thus *wrongly* return a cached operatorList.

In the viewer we're only using the `includeAnnotationStorage`-option when printing, which is probably why this has gone unnoticed for so long. Note that we, for performance reasons, don't cache printing-operatorLists in the API.
However, there's nothing stopping an API-user from using the `includeAnnotationStorage`-option during "normal" rendering, which could thus result in *subtle* (and difficult to understand) rendering bugs.

In order to handle this, we need to know if the `AnnotationStorage`-instance has been updated since the last `PDFPageProxy.render` call. The most "correct" solution would obviously be to create a hash of the `AnnotationStorage` contents, however that would require adding a bunch of code, complexity, and runtime overhead.
Given that operatorList caching in the API doesn't have to be perfect[1], but only have to avoid *false* cache-hits, we can simplify things significantly be only keeping track of the last time that the `AnnotationStorage`-data was modified.

*Please note:* While working on this patch, I also noticed that the `renderInteractiveForms`- and `includeAnnotationStorage`-options in the `PDFPageProxy.render` method are mutually exclusive.[2]
Given that the various Annotation-related options in `PDFPageProxy.render` have been added at different times, this has unfortunately led to the current "messy" situation.[3]

---
[1] Note how we're already not caching operatorLists for pages with *huge* images, in order to save memory, hence there's no guarantee that operatorLists will always be cached.

[2] Setting both to `true` will result in undefined behaviour, since trying to insert `AnnotationStorage`-values into fields that are being excluded from the operatorList-building will obviously not work, which isn't at all clear from the documentation.

[3] My intention is to try and fix this in a follow-up PR, and I've got a WIP patch locally, however it will result in a number of API-observable changes.
2021-08-18 10:09:03 +02:00
Jonas Jenwald
1465b1670f [src/display/api.js] Move the getRenderingIntent helper function into WorkerTransport
By doing this re-factoring *separately*, since it's mostly a mechanical change, the size/scope of the next patch will be reduced somewhat.
2021-08-18 09:58:26 +02:00
Tim van der Meij
a936509b77
Merge pull request #13900 from Snuffleupagus/rm-babel-logical-assignment
[api-minor] Stop translating logical assignment in non-`legacy` builds (PR 12887 follow-up)
2021-08-17 22:01:27 +02:00
Jonas Jenwald
b9a6258ad2 [api-minor] Stop translating logical assignment in non-legacy builds (PR 12887 follow-up)
When we started using logical assignment operators in the PDF.js project, the feature was new enough that browser support was somewhat limited. That should no longer be the case, since logical assignment has now been available for approximately one year.
Hence this patch, which (basically) reverts PR 12887, since using the Babel plugin unconditionally was never intended to be a permanent thing. For browsers/environments without native logical assignment support, users will now have to use a `legacy` build instead.

Please refer to the browser compatibility information on MDN:
 - https://wiki.mozilla.org/RapidRelease/Calendar
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment#browser_compatibility
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_nullish_assignment#browser_compatibility

Note also the release information for the major browsers:
 - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_nullish_assignment#browser_compatibility
 - https://en.wikipedia.org/wiki/Google_Chrome_version_history
 - https://en.wikipedia.org/wiki/Safari_version_history#Safari_14
2021-08-17 12:21:10 +02:00
Tim van der Meij
e9146b19e6
Merge pull request #13892 from Snuffleupagus/Dict-merge-refactor-2
Move some validation, in `Dict.merge`, used during merging of sub-dictionaries (PR 13775 follow-up)
2021-08-14 12:26:19 +02:00
Tim van der Meij
0e7df95e90
Merge pull request #13896 from Snuffleupagus/cleanup-ReadableStream-polyfill
Simplify the `ReadableStream` polyfill
2021-08-14 12:21:55 +02:00
Jonas Jenwald
e2aa067603 Simplify the ReadableStream polyfill
At this point in time, all of the supported browsers (in the PDF.js project) have native `ReadableStream` implementations; see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#browser_compatibility

Hence the polyfill is *only* necessary in Node.js environments now, and we shouldn't need to do any detailed feature detection either (since that was only done for the non-Chromium versions of the MS Edge browser).
Finally, we can slightly reduce the size of the Chromium-extension since the polyfill shouldn't be needed there either.
2021-08-13 12:28:55 +02:00