Commit Graph

13031 Commits

Author SHA1 Message Date
Tim van der Meij
4b4ac8a13d
Merge pull request #12491 from Snuffleupagus/update-packages
Update packages and translations
2020-10-18 14:27:47 +02:00
Jonas Jenwald
ab31f95cb4 Update l10n files 2020-10-18 11:01:06 +02:00
Jonas Jenwald
641ad1c3a0 Update npm packages 2020-10-18 10:57:52 +02:00
Tim van der Meij
d2874d4ed4
Merge pull request #12489 from calixteman/field_obj_test
Add a test for pdfDocument::fieldObjects
2020-10-17 22:59:27 +02:00
Calixte Denizet
e46e314867 Add a test for pdfDocument::fieldObjects 2020-10-17 19:48:40 +02:00
Tim van der Meij
3fa3cb6d8a
Merge pull request #12485 from calixteman/calculation_order
[api-minor] JS - Add a function in api to get the fields ids in AcroForm::CO
2020-10-17 15:06:22 +02:00
Calixte Denizet
c30a3a94f0 JS - Add a function in api to get the fields ids in AcroForm::CO 2020-10-17 12:56:40 +02:00
Tim van der Meij
ff2631493e
Merge pull request #12481 from calixteman/issue_12475
Get urls if any in AA::D dictionary for pushbuttons
2020-10-16 22:55:43 +02:00
Tim van der Meij
32bceae732
Merge pull request #12483 from Snuffleupagus/formInfo-hasFields
Don't store complex data in `PDFDocument.formInfo`, and replace the `fields` object with a `hasFields` boolean instead
2020-10-16 22:40:40 +02:00
Tim van der Meij
127bb03e03
Merge pull request #12486 from Snuffleupagus/font-Dict-cacheKey
Stop caching the *parsed* Font data on its `Dict` object (PR 7347 follow-up)
2020-10-16 22:30:17 +02:00
Jonas Jenwald
f956d0a96a Stop caching the *parsed* Font data on its Dict object (PR 7347 follow-up)
Given that *all* fonts are, ever since PR 7347, now cached in the "normal" `fontCache` there's actually no reason for the special `font.translated` construction. (Given how Objects in JavaScript are references, rather than raw values, the old code shouldn't have caused any significant memory overhead.)

Instead we can simply store the `cacheKey`, which is a simple string, on only the Font `Dict`s where it's needed and thus look-up all fonts using the `fontCache` instead.
2020-10-16 17:45:01 +02:00
Jonas Jenwald
29af15f37e Add more validation in the PDFDocument._hasOnlyDocumentSignatures method
If this method is ever passed invalid/unexpected data, or if during the course of parsing (since it's used recursively) such data is found, it will fail in a non-graceful way.
Hence this patch, which ensures that we don't attempt to access non-existent properties and also that errors such as the one fixed in PR 12479 wouldn't have occured.
2020-10-16 13:03:47 +02:00
Jonas Jenwald
3351d3476d Don't store complex data in PDFDocument.formInfo, and replace the fields object with a hasFields boolean instead
*This patch is based on a couple of smaller things that I noticed when working on PR 12479.*

 - Don't store the /Fields on the `formInfo` getter, since that feels like overloading it with unintended (and too complex) data, and utilize a `hasFields` boolean instead.
   This functionality was originally added in PR 12271, to help determine what kind of form data a PDF document contains, and I think that we should ensure that the return value of `formInfo` only consists of "simple" data.
   With these changes the `fieldObjects` getter instead has to look-up the /Fields manually, however that shouldn't be a problem since the access is guarded by a `formInfo.hasFields` check which ensures that the data both exists and is valid. Furthermore, most documents doesn't even have any /AcroForm data anyway.

 - Determine the `hasFields` property *first*, to ensure that it's always correct even if there's errors when checking e.g. the /XFA or /SigFlags entires, since the `fieldObjects` getter depends on it.

 - Simplify a loop in `fieldObjects`, since the object being accessed is a `Map` and those have built-in iteration support.

 - Use a higher logging level for errors in the `formInfo` getter, and include the actual error message, since that'd have helped with fixing PR 12479 a lot quicker.

 - Update the JSDoc comment in `src/display/api.js` to list the return values correctly, and also slightly extend/improve the description.
2020-10-16 12:47:27 +02:00
Tim van der Meij
b710fbcb00
Merge pull request #12478 from Snuffleupagus/async-translateFont
Convert `PartialEvaluator.translateFont` to an `async` method
2020-10-15 22:25:34 +02:00
Tim van der Meij
ee665fc053
Merge pull request #12479 from Snuffleupagus/fix-formInfo-test
Fix the "should get form info when AcroForm is present" unit-test
2020-10-15 22:19:05 +02:00
Calixte Denizet
ce3d3a6ff8 Get urls if any in AA::D dictionary for pushbuttons 2020-10-15 19:42:36 +02:00
Jonas Jenwald
5f8957e8df Fix the "should get form info when AcroForm is present" unit-test
The last unit-test didn't work correctly, since an error was thrown in `PDFDocument._hasOnlyDocumentSignatures` because the mocked `XRef`-instance wasn't actually being set correctly.

Also, updates the `XRefMock` to use `async` methods where appropriate.
2020-10-15 13:26:32 +02:00
Jonas Jenwald
bc6b47a50e Convert PartialEvaluator.translateFont to an async method
This allows us to make a slight simplification in `PartialEvaluator.loadFont`, which thus removes an old TODO-comment from the method.
Furthermore, in `PartialEvaluator.translateFont`, the CMap-handling is now limited to only *composite* fonts to avoid having to wait for a "dummy"-Promise for most fonts.
2020-10-15 09:42:58 +02:00
Tim van der Meij
a373137304
Merge pull request #12429 from calixteman/collect_js
[api-minor] Add the possibility to collect Javascript actions
2020-10-14 23:27:47 +02:00
Calixte Denizet
71ecc3129b Add the possibility to collect Javascript actions 2020-10-14 10:44:16 +02:00
Tim van der Meij
1034769ca1
Merge pull request #12477 from Snuffleupagus/SaveDocument-WorkerTask
Handle `WorkerTask`s, and various PDF document properties, correctly in the "SaveDocument" handler in `src/core/worker.js`
2020-10-13 21:11:54 +02:00
Tim van der Meij
0700a3de36
Merge pull request #12476 from Snuffleupagus/worker-rm-handler-scope
Remove the `scope` parameter from the "GetOperatorList" handler in `src/core/worker.js` (PR 11110 follow-up)
2020-10-13 21:08:48 +02:00
Jonas Jenwald
65132ba5d8 Handle WorkerTasks, and various PDF document properties, correctly in the "SaveDocument" handler in src/core/worker.js
- Actually register/unregister the `WorkerTask`s, used when saving each page, correctly.
   To prevent issues when terminating the Worker, we purposely wait for all running `WorkerTask`s to complete first. Hence we need to actually handle `WorkerTask`s the same way in "SaveDocument" as in the rest of this file, see e.g. "GetOperatorList" and "GetTextContent".

 - Access `PDFDocument` properties in a generally safe/consistent way.
   While the current code works fine, given how the PDF document is being loaded, it still seems like a very good idea to be *consistent* in how we access these kind of properties (since in general you need to avoid `MissingDataException` everywhere in this file).

 - Change a variable name, since there's essentially no precedent in the code-base for *local* variable names to start with an underscore.
2020-10-13 19:30:43 +02:00
Jonas Jenwald
38629c345d Remove the scope parameter from the "GetOperatorList" handler in src/core/worker.js (PR 11110 follow-up)
Support for the `scope` parameter, in `MessageHandler.on`, was removed in PR 11110 however this particular case was unused/unnecessary for years prior to that change. (From a quick look through the history, I'm not even sure if it was actually needed in the first place.)
2020-10-13 15:58:38 +02:00
Tim van der Meij
49791f55b3
Merge pull request #12470 from Snuffleupagus/webpack-5
Upgrade `webpack` to version 5
2020-10-11 14:50:32 +02:00
Jonas Jenwald
e7437a0b67 Use standard import statements when loading PDFViewerApplication/AppOptions in web/viewer
Given that we're no longer using SystemJS to load the `web/` files, see PR 11919, there's nothing that prevents us from using standard `ìmport` statements in this file.
Obviously it's still necessary to load part of the code conditionally on the build type, however this still allows us to clean-up and simplify at least some of this file.
2020-10-11 14:06:47 +02:00
Jonas Jenwald
666dd73ce8 Upgrade webpack to version 5
The only noticeable changes are that the built files are now *slightly* smaller, and that Webpack now supports optional chaining and nullish coalescing without the need for Babel plugins.
2020-10-11 10:23:38 +02:00
Tim van der Meij
e59a90d8e9
Merge pull request #12458 from Snuffleupagus/LocalTilingPatternCache
Add local caching of TilingPatterns in `PartialEvaluator.getOperatorList` (issue 2765 and 8473)
2020-10-08 22:47:13 +02:00
Jonas Jenwald
30e8d5dea1 Add local caching of TilingPatterns in PartialEvaluator.getOperatorList (issue 2765 and 8473)
In practice it's not uncommon for PDF documents to re-use the same TilingPatterns more than once, and parsing them is essentially equal to parsing of a (small) page since a `getOperatorList` call is required.

By caching the internal TilingPattern representation we can thus avoid having to re-parse the same data over and over, and there's also *less* asynchronous parsing required for repeated TilingPatterns.

Initially I had intended to include (standard) benchmark results with this patch, however it's not entirely clear that this is actually necessary here given the preliminary results.
When testing this manually in the development viewer, using `pdfBug=Stats`, the following (approximate) reduction in rendering times were observed when comparing `master` against this patch:
 - http://pubs.usgs.gov/sim/3067/pdf/sim3067sheet-2.pdf (from issue 2765): `6800 ms` -> `4100 ms`.
 - https://github.com/mozilla/pdf.js/files/1046131/stepped.pdf (from issue 8473): `54000 ms` -> `13000 ms`
 - https://github.com/mozilla/pdf.js/files/1046130/proof.pdf (from issue 8473): `5900 ms` -> `2500 ms`

As always, whenever you're dealing with documents which are "slow", there's usually a certain level of subjectivity involved with regards to what's deemed acceptable performance.
Hence it's not clear to me that we want to regard any of the referenced issues as fixed, however the improvements are significant enough to warrant caching of TilingPatterns in my opinion.
2020-10-08 18:43:21 +02:00
Tim van der Meij
99a2302d88
Merge pull request #12454 from Snuffleupagus/terser-5
Upgrade `terser` to version 5
2020-10-07 22:04:31 +02:00
Jonas Jenwald
3461eac7b8 Upgrade terser to version 5
The only significant change is that the `minify` command is now asynchronous, which we can handle easily by simply making the containing functions `async`.
Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function#Browser_compatibility, using `async`/`await` in the gulpfile should no longer be an issue as far as I can tell.
2020-10-07 14:38:17 +02:00
Tim van der Meij
fd1d9cc85f
Merge pull request #12451 from Snuffleupagus/acorn-8
Upgrade `acorn` to version 8
2020-10-06 22:03:03 +02:00
Jonas Jenwald
bc036c05bd Upgrade acorn to version 8
I've run `gulp mozcentral`, `gulp generic`, and `gulp generic-es5` with `master` respectively this patch and then diffed the build output. With the (obvious) exception of increased version/build numbers, there were no actual changes from the updated Acorn version.
2020-10-06 13:53:08 +02:00
Tim van der Meij
7ae3e13f16
Merge pull request #12450 from janpe2/cff-xuid
Fix invalid `XUID` entries in CFF fonts
2020-10-05 22:54:39 +02:00
Tim van der Meij
10e7623123
Merge pull request #12448 from Snuffleupagus/eslint-no-debugger-alert
Enable the ESLint `no-debugger` and `no-alert` rules
2020-10-05 22:47:31 +02:00
Jani Pehkonen
935568c2f1 Fix invalid XUID entries in CFF fonts
In CFF fonts, entry `XUID` should be an array that has no more than
16 elements. In the issue, the length is 20, which causes the fonts to fail.
See Appendix B, "Implementation Limits" in PostScript Language Reference Manual
https://web.archive.org/web/20170218093716/https://www.adobe.com/products/postscript/pdfs/PLRM.pdf
Actually entries `XUID` and `UniqueID` are obsolete altogether.
https://blogs.adobe.com/CCJKType/2016/06/no-more-xuid-arrays.html
2020-10-05 17:38:01 +03:00
Jonas Jenwald
ba079453bf Enable the ESLint no-debugger and no-alert rules
The `debugger`-statement would only, potentially, make sense during development and we thus want to prevent it from being accidentally included when landing code.
The `alert`, `confirm`, and `prompt` functions should generally be avoided, with the few intended cases manually allowed.

Please find additional details about the ESLint rules at:
 - https://eslint.org/docs/rules/no-debugger
 - https://eslint.org/docs/rules/no-alert
2020-10-05 13:41:06 +02:00
Tim van der Meij
b3e32e2001
Merge pull request #12446 from Snuffleupagus/firefox-print-RenderingCancelledException
[Firefox] Stop logging `RenderingCancelledException`s as errors when printing
2020-10-04 23:38:31 +02:00
Tim van der Meij
a1028e2b9b
Merge pull request #12445 from timvandermeij/packages
Upgrade minor/major versions of dependencies that don't require code changes
2020-10-04 23:27:22 +02:00
Tim van der Meij
505f14e816
Upgrade minor/major versions of dependencies that don't require code changes
The changelogs of those dependencies showed no breaking changes for us.
Most of the time the major version bump was done to remove compatibility
with very outdated Node.js versions.

Only for `autoprefixer` and `gulp-postcss` a change was required, which
is including `postcss` in our `package.json` explicitly since it's now
a peer dependency of those packages.

Now only `acorn`,`systemjs`, `terser` and `yargs` are not the latest
versions because they require more work.
2020-10-04 20:26:59 +02:00
Jonas Jenwald
069ddc8686 [Firefox] Stop logging RenderingCancelledExceptions as errors when printing
In the rest of the viewer code-base, we purposely don't treat `RenderingCancelledException`s as actual errors (since they aren't) and consequently we never log them.
Hence it makes sense, as far as I'm concerned, to simply treat `RenderingCancelledException`s the same way when printing in Firefox.

While I don't print a whole lot, I cannot remember seeing these "errors" logged when printing until *very* recently[1]. Given that the browser print functionality and UI, in Firefox, is under active development it's certainly possible that there's some recent changes to the related timings which make `RenderingCancelledException`s more likely now.

---
[1] Interestingly, only some PDF documents seem to be affected as well; I'm able to reproduce this pretty consistently by opening https://www.uni-muenster.de/imperia/md/content/ziv/pdf/printpay_flyer.pdf in Firefox and then repeating the following sequence:
Clicking on the PDF.js print button, and then cancelling printing.
2020-10-04 20:25:31 +02:00
Tim van der Meij
e0c80a3556
Remove the fancy-log dependency
This dependency hasn't been updated in two years and the only place that
uses it is the `externaltest` target in the Gulpfile. We can simply
replace `fancy-log` usage there with `console.log` like we do in all
other places in the Gulpfile because we're not interested in the
timestamps here. Gulp already prints timestamps and these tests finish
within a second anyway.

Note that it remains in `package-lock.json` because other Gulp-related
packages have it as a dependency, but at least we're no longer depending
on it directly anymore now.
2020-10-04 17:30:39 +02:00
Tim van der Meij
910772cfcf
Merge pull request #12444 from Snuffleupagus/update-packages
Update packages and translations
2020-10-04 16:15:44 +02:00
Jonas Jenwald
c5a1a6fdd5 Remove now unnecessary no-unsanitized/method disabling in test/unit/jasmine-boot.js
With the latest release of the `eslint-plugin-no-unsanitized` package, we no longer need to disable this rule; see https://github.com/mozilla/eslint-plugin-no-unsanitized/pull/150
2020-10-04 15:30:24 +02:00
Jonas Jenwald
ffb0bb885c Update l10n files 2020-10-04 15:30:24 +02:00
Jonas Jenwald
082e7b5200 Fix (some) vulnerabilities reported by npm audit
This was done automatically, using the `npm audit fix` command.
2020-10-04 15:30:24 +02:00
Jonas Jenwald
522c93b916 Update npm packages 2020-10-04 15:30:23 +02:00
Tim van der Meij
47131707bc
Merge pull request #12442 from timvandermeij/upgrade-puppeteer
Upgrade Puppeteer to version 5.3.1
2020-10-04 15:01:09 +02:00
Tim van der Meij
c10aac9a1d
Upgrade Puppeteer to version 5.3.1 2020-10-03 23:06:31 +02:00
Tim van der Meij
2823beba69
Merge pull request #12441 from Snuffleupagus/src-eslint-config
Re-factor how the ESLint `no-var` rule is enabled in the `src/` folder
2020-10-03 22:36:13 +02:00