Commit Graph

14735 Commits

Author SHA1 Message Date
Brendan Dahl
a7f807b059 Only use base encoding if it's populated. (bug 1727053)
The font dict in this file has an encoding entry, but only specifies a
differences map. The base encoding is empty in this case and shouldn't
be used.
2021-08-30 12:51:59 -07:00
Brendan Dahl
306119b12a
Merge pull request #13932 from Snuffleupagus/oc-images
Support Optional Content in Image-/XObjects (issue 13931)
2021-08-30 10:10:14 -07:00
Jonas Jenwald
cf0ccc4bab
Merge pull request #13937 from overleaf/jpa-fix-error-handling
Fix handling of fetch errors
2021-08-30 15:50:03 +02:00
Jakob Ackermann
291ffd3059
Fix handling of fetch errors
Testing:
- delete the pdf file while the initial request is inflight
- delete the pdf file after the initial request has finished

Repeat for a small file and large file, exercising both one-off and
 chunked transports.
2021-08-30 12:43:28 +01:00
Tim van der Meij
e18d577ace
Merge pull request #13944 from Snuffleupagus/setPDFNetworkStreamFactory-unit
Re-factor the `setPDFNetworkStreamFactory` usage for the unit-tests (PR 13549 follow-up)
2021-08-29 18:51:21 +02:00
Jonas Jenwald
e69afc6f3d Re-factor the setPDFNetworkStreamFactory usage for the unit-tests (PR 13549 follow-up)
This should have been part of PR 13549, since we no longer support browsers without native Fetch API and ReadableStream implementations.
2021-08-29 18:27:53 +02:00
Tim van der Meij
954e1a1694
Merge pull request #13943 from Snuffleupagus/api-more-async
Use `async` a bit more in the API
2021-08-29 14:34:14 +02:00
Tim van der Meij
a270baeb67
Merge pull request #13942 from Snuffleupagus/viewer-components-export-layers
Export the XFA/StructTree-layers in the viewer components
2021-08-29 14:30:28 +02:00
Tim van der Meij
13bc661681
Merge pull request #13941 from Snuffleupagus/MessageHandler-PasswordException
Ensure that `PasswordException` is handled correctly in the `wrapReason` function
2021-08-29 14:23:46 +02:00
Jonas Jenwald
ce3f5ea2bf Use async a bit more in the API
This patch changes the `PDFDocumentLoadingTask.destroy`-method and the `_fetchDocument`-function to be `async`, which slightly simplifies the relevant code.

Furthermore, remove the catch-handler from the `WorkerTransport.getPageIndex`-method since it's no longer needed. Given that the `MessageHandler` is nowadays wrapping every possible Exception, it's no longer necessary to try and re-wrap the reason here.
2021-08-29 12:31:28 +02:00
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