Commit Graph

13060 Commits

Author SHA1 Message Date
Jonas Jenwald
f2fa053c51 Ensure that MurmurHash3_64.update handles ArrayBuffer input correctly, to avoid hash-collisions (issue 12533)
Different fonts incorrectly end up with *identical* hashes, despite having different /ToUnicode data.
The issue, and it's very interesting that we've apparently not seen it before, appears to be caused by the fact that different /ToUnicode entries share the *same* underlying `ArrayBuffer`, which thus becomes problematic at the `const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);` line. The simplest solution thus seem to be to just *copy* the input, when it's an `ArrayBuffer`, rather than using it as-is. (Note that if we'd stringified the input, when calling `MurmurHash3_64.update`, the issue would also have been fixed. In this case, we're already creating an unique TypedArray.)
2020-10-26 16:27:33 +01:00
Tim van der Meij
b2a4dacd31
Merge pull request #12529 from Snuffleupagus/scripting-build-tweaks
Tweak the `pdf.scripting.js` bundling, to improve overall consistency
2020-10-25 18:41:20 +01:00
Tim van der Meij
2251677e5a
Merge pull request #12528 from timvandermeij/test-unit-no-var
Convert `var` to `const`/`let` in the `test/unit` folder
2020-10-25 18:34:13 +01:00
Jonas Jenwald
61ffa9caa9 Tweak the pdf.scripting.js bundling, to improve overall consistency
This brings the new `pdf.scripting.js` bundling more in-line with the pre-existing handling for the  `pdf.js`/`pdf.worker.js` files:
 - Add a new `src/pdf.scripting.js` file as the entry-point for the build scripts.

 - Add the version/build numbers at the top of the *built* `pdf.scripting.js` files, since all other built files include that information given that it's often helpful to be able to easily determine the *exact* version.

 - Tweak the `createScriptingBundle` in the gulp-file, since it looks like a little bit too much copy-and-paste in the variable names.
2020-10-25 16:36:56 +01:00
Tim van der Meij
fe08ef4e39
Fix var conversions that ESLint could not do automatically
This mainly involves the `crypto_spec.js` file which declared most
variables before their usage, which is not really consistent with the
rest of the codebase. This also required reformatting some long arrays
in that file because otherwise we would exceed the 80 character line
limit. Overall, this makes the code more readable.
2020-10-25 16:17:12 +01:00
Tim van der Meij
3e2bfb5819
Convert var to const/let in the test/unit folder
This has been done automatically using ESLint's `--fix` argument.
2020-10-25 15:40:51 +01:00
Tim van der Meij
314ac21842
Disable var usage for the test/unit folder
This allows us to enforce that `var` is not used anymore in the unit
tests to modernize the code and prevent subtle bugs.
2020-10-25 15:38:52 +01:00
Tim van der Meij
b4ca3d55b8
Merge pull request #12508 from calixteman/button_fallback_font
Fallback font for buttons must be ZapfDingbats.
2020-10-24 18:56:12 +02:00
Tim van der Meij
0d1a874358
Merge pull request #12464 from baloone/Fix_getVisibleElements_in_rtl_direction
Fix getVisibleElements helper in RTL-locales
2020-10-24 17:03:57 +02:00
Tim van der Meij
e8e029dfb5
Merge pull request #12522 from Snuffleupagus/_initializeJavaScript-fixes
Fix a couple of edge-cases in `PDFViewerApplication._initializeJavaScript` (PR 12432 follow-up)
2020-10-24 16:11:06 +02:00
Tim van der Meij
da73537fdb
Merge pull request #12524 from Snuffleupagus/pr-12333-followup
A couple of small (viewer) tweaks of tooltip-only Annotations (PR 12333 follow-up)
2020-10-24 16:06:01 +02:00
Tim van der Meij
180f35ee91
Merge pull request #12526 from Snuffleupagus/TilingPattern-args
Improve argument/name handling when parsing TilingPatterns (PR 12458 follow-up)
2020-10-24 15:47:57 +02:00
Tim van der Meij
c493dc96fa
Merge pull request #12516 from Snuffleupagus/fieldObjects-annotation-undefined
Prevent issues, in `PDFDocument.fieldObjects`, for invalid Annotations
2020-10-24 15:42:33 +02:00
Jonas Jenwald
b478d3e7b9 Improve argument/name handling when parsing TilingPatterns (PR 12458 follow-up)
- Handle the arguments correctly in `PartialEvaluator.handleColorN`.
   For TilingPatterns with a base-ColorSpace, we're currently using the `args` when computing the color. However, as can be seen we're passing the Array as-is to the `ColorSpace.getRgb` method, which means that the `Name` is included as well.[1]
   Thankfully this hasn't, as far as I know, caused any actual bugs, but that may be more luck than anything else given how the `ColorSpace` code is implemented. This can be easily fixed though, simply by popping the `Name`-object off of the `args` Array.

 - Cache TilingPatterns using the `Name`-string, rather than the object directly.
   This is not only consistent with other caches in `PartialEvaluator`, but importantly it also ensures that the cache lookup always works correctly. Note that since `Name`-objects, similar to other primitives, uses a cache themselves a *manually* triggered `cleanup`-call could thus (theoretically) cause the `LocalTilingPatternCache` to not find an existing entry. While the likelihood of this happening is *extremely* small, it's still something that we should fix.

---
[1] The `args` Array can e.g. look like this: `[0.043, 0.09, 0.188, 0.004, /P1]`, which means that we're passing in the `Name`-object to the `ColorSpace` method.
2020-10-24 13:49:46 +02:00
Calixte Denizet
37c86b2daa Fallback font for buttons must be ZapfDingbats.
Fix bug https://bugzilla.mozilla.org/show_bug.cgi?id=1669099.
2020-10-24 12:00:03 +02:00
Jonas Jenwald
9f8d9802f9 A couple of small (viewer) tweaks of tooltip-only Annotations (PR 12333 follow-up)
Ensure that these tooltip-only Annotations are handled as "internalLink"s, to ensure that they behave as expected in PresentationMode (e.g. they should still use a `pointer`-cursor).

Ensure that `PDFLinkService.getDestinationHash` won't create links with empty hashes, since those don't really make a lot of sense in general (this improves things for tooltip-only Annotations).

This PDF file can be used for testing: http://mirrors.ctan.org/macros/latex/contrib/pdfcomment/doc/pdfcomment.pdf#page=14
2020-10-23 14:31:45 +02:00
Jonas Jenwald
7bf9a872ed Fix a couple of edge-cases in PDFViewerApplication._initializeJavaScript (PR 12432 follow-up)
- Return early in `PDFViewerApplication._initializeJavaScript` for PDF documents without any `fieldObjects`, which is the vast majority of all documents, to prevent errors when trying to parse a non-existent object.

 - Similar to the other `PDFViewerApplication._initialize*` methods, ignore the `fieldObjects` if the document was closed before the data resolved.

 - Fix the JSDoc comment for the `generateRandomStringForSandbox` helper function, since there's currently a bit too much copy-and-paste going on :-)

 - Change `FirefoxScripting` to a class with static methods, which is consistent with the surrounding code in `web/firefoxcom.js`.
2020-10-23 12:28:44 +02:00
Brendan Dahl
1eaf9c961b
Merge pull request #12432 from calixteman/scripting_api
JS - Add the basic architecture to be able to execute embedded js
2020-10-22 19:57:58 -07:00
Tim van der Meij
8cf27494b3
Merge pull request #12503 from calixteman/no_quad
Invalidate an annotation with no quadPoints (when it's required)
2020-10-23 00:25:52 +02:00
Tim van der Meij
4258586c38
Merge pull request #12515 from Snuffleupagus/eslint-no-abusive-eslint-disable
Enable the `unicorn/no-abusive-eslint-disable` ESLint plugin rule
2020-10-22 22:00:05 +02:00
Jonas Jenwald
b44a975d7c Prevent issues, in PDFDocument.fieldObjects, for invalid Annotations
For an invalid Annotation, there's one code-path where `undefined` is returned from `AnnotationFactory._create`. That'd currently, incorrectly, trigger an error during the `PDFDocument._collectFieldObjects` parsing which thus seem good to avoid.
Along these lines, the filtering in `PDFDocument.fieldObjects` is also updated to handle both `null` and `undefined` the same way.
2020-10-22 13:24:43 +02:00
Jonas Jenwald
60d2ff5408 Enable the unicorn/no-abusive-eslint-disable ESLint plugin rule
This rule prevents *accidental* disabling of ESLint completely, be ensuring that inline ESLint disable comments always list the affected rules explicitly.

Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/no-abusive-eslint-disable.md for additional information.
2020-10-22 12:47:53 +02:00
Calixte Denizet
e76a96892a JS - Add the basic architecture to be able to execute embedded js 2020-10-21 19:00:56 +02:00
Calixte Denizet
d2ef878702 Invalidate an annotation with no quadPoints (when it's required)
Some pdf softwares don't remove highlight annotations but make the QuadPoints array empty.
And the Rect for the annotation can be [-32768, -32768, 32768, 32768] so it leads to have a giant div which catches all the mouse events and make the pdf unusable when there are some forms elements.
2020-10-21 13:53:19 +02:00
Mohamed
b7b048e36c Fix getVisibleElements helper in RTL-locales 2020-10-20 23:34:09 +02:00
Tim van der Meij
e389ed6201
Merge pull request #12493 from Snuffleupagus/PDFHistory.pushPage
Support adding pages, in addition to regular destinations, to the browser history and use it with thumbnails (issue 12440)
2020-10-20 22:20:11 +02:00
Jonas Jenwald
b302fd3a6e Move updating of this._maxUid into PDFHistory._updateInternalState
There's no compelling reason to update this property *manually* in multiple places, since that's error-prone with any future code changes, given that `_updateInternalState` is always called just before anyway.
2020-10-18 16:29:15 +02:00
Jonas Jenwald
295716f496 Support adding pages, in addition to regular destinations, to the browser history and use it with thumbnails (issue 12440)
While the referenced issue could very well be seen as an edge-case, this patch adds support for updating of the browser history when interacting with the thumbnails in the sidebar (assuming we want to do this).

The main reason for adding the history implementation in the first place, was to simplify navigating back to a previous position in the document when named/explicit destinations are used (e.g. when clicking on "links" or when using the outline in the sidebar).
As such, it never really crossed by mind to update the browser history when the thumbnails are used. However, a user clicking on thumbnails could be regarded as a pretty strong indication of user-intent w.r.t. navigation in the document, hence I suppose that updating the browser history in this particular case probably won't hurt.
2020-10-18 16:04:00 +02:00
Jonas Jenwald
8431cfe482 Re-name and re-factor the PDFLinkService.navigateTo method
This modernizes and improves the code, by using `async`/`await` and by extracting the helper function to its own method.
To hopefully avoid confusion, given the next patch, the method is also re-named to `goToDestination` to make is slightly clearer what it actually does.
2020-10-18 14:29:59 +02:00
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