Commit Graph

14761 Commits

Author SHA1 Message Date
Jonas Jenwald
833f27c677 Disable a LGTM warning, again (PR 13787 follow-up)
Apparently I didn't put one of the disable comments on the *correct* line, since I didn't read the instructions carefully enough, so let's try again.

Note that, most unfortunately, disabling of warnings isn't applied until *after* a patch has been merged.
2021-07-25 10:32:40 +02:00
Jonas Jenwald
aad0316137 Update l10n files 2021-07-25 10:31:40 +02:00
Jonas Jenwald
2a667b92d8 Update npm packages 2021-07-25 10:24:10 +02:00
Jonas Jenwald
bcd6dc416a
Merge pull request #13788 from timvandermeij/eslint-rules
Enable the `no-empty-character-class` and `no-template-curly-in-string` linting rules
2021-07-24 15:51:54 +02:00
Tim van der Meij
41a2b5c809
Merge pull request #13787 from Snuffleupagus/lgtm-fix-warnings
Fix (most) LGTM warnings
2021-07-24 15:20:07 +02:00
Tim van der Meij
fb99b0df0e
Enable the no-empty-character-class and no-template-curly-in-string linting rules
The former prevents unintended errors in regexes. The latter is
something I ran into a couple of times before editors had proper support
for syntax highlighting in template literals, and it's an easy mistake
to make, especially when converting older code to use template literals.
Nowadays most editors display template literals in different colors, but
nevertheless it seems like a good idea to enable this rule.

Fortunately both rules don't require any code changes, so it's more for
prevention.
2021-07-24 15:12:41 +02:00
Tim van der Meij
7b6767d415
Merge pull request #13784 from Snuffleupagus/issue-13783
When parsing corrupt documents, avoid inserting obviously broken data in the XRef-table (issue 13783)
2021-07-24 14:37:39 +02:00
Tim van der Meij
687cfcecd4
Merge pull request #13786 from Snuffleupagus/rm-more-src-core-closures
Remove a couple of small closures in `src/core/` code
2021-07-24 14:26:57 +02:00
Jonas Jenwald
70bac87fed Fix (most) LGTM warnings
Most of the warnings we don't really care about, and those are simply white-listed using inline comments; however two cases prompted actual code changes:

 - In `src/display/pattern_helper.js` the branch in question is indeed unreachable, and should thus be safe to remove. (This code originated in PR 4192, which is now over seven years ago.)

 - In `test/test.js`, the function in question indeed doesn't accept any arguments. (The patch also re-formats a string just above, which didn't seem worthy of a separated patch.)

This now leaves only *one* warning in the LGTM report, however that one is a false positive that we'll need to report upstream.
2021-07-24 14:23:59 +02:00
Tim van der Meij
9854b85dc1
Merge pull request #13775 from Snuffleupagus/Dict-merge-refactor
Remove some duplication in the `Dict.merge` method
2021-07-24 14:21:41 +02:00
Jonas Jenwald
ebbbc973a5 Remove the closure used with the PostScriptToken class
This patch uses the same approach as used in lots of other parts of the code-base, which thus *slightly* reduces the size of this code.
2021-07-24 13:05:46 +02:00
Jonas Jenwald
81009d42cf Remove the closure used with the PostScriptStack class
This patch uses the same approach as used in lots of other parts of the code-base, which thus *slightly* reduces the size of this code.
2021-07-24 12:59:53 +02:00
Jonas Jenwald
834a638aad
Merge pull request #13782 from Snuffleupagus/viewer-reset-xfaLayer
[api-minor] XFA - Remove the `xfaLayer` from the DOM when resetting pages (bug 1721977, PR 13427 follow-up)
2021-07-24 10:39:30 +02:00
Jonas Jenwald
b82c802dff When parsing corrupt documents, avoid inserting obviously broken data in the XRef-table (issue 13783)
In cases where even the very *first* attempt at reading from an object will throw, simply ignoring such objects will help improve rendering of *some* corrupt documents.
Note that this will lead to more parsing in some cases, but considering that this only applies to *corrupt* documents that shouldn't be a big deal.
2021-07-23 18:10:53 +02:00
Jonas Jenwald
f85f579971 Reduce unnecessary duplication when cancelling annotationLayer/xfaLayer rendering
There's no good reason, as far as I can tell, to have `PDFPageView.reset` attempt to cancel `annotationLayer`/`xfaLayer` rendering in one special-case (this is mostly a leftover from older code). Previously cancelling was moved into the separate `PDFPageView.cancelRendering`-method, and by slightly tweaking the conditions there we're able to remove a bit of now unnecessary code from the `PDFPageView.reset`-method.
2021-07-23 14:30:34 +02:00
Jonas Jenwald
d22ffbbc0a [api-minor] XFA - Remove the xfaLayer from the DOM when resetting pages (bug 1721977, PR 13427 follow-up)
Originally the `xfaLayer` wasn't implemented in such a way that it supported being removed from the DOM when pages were evicted from the cache, however this limitation was lifted in PR 13427 and the `xfaLayer` should thus be handled similar to e.g. the `annotationLayer`.

In addition to removing the `xfaLayer` from the DOM, this patch *also* implements proper rendering/hiding-handling for it (mirroring the `annotationLayer`-code).

*Please note:* This patch is tagged API-minor just in case[1], since it changes the signatures of a couple of `PDFPageView`-methods to improve readability of the code.

---
[1] Although users are *hopefully* not directly accessing any of the affected methods, and are rather using e.g. `PDFViewer` in which case none of these changes will matter.
2021-07-23 13:44:13 +02:00
Jonas Jenwald
51f0a81085
Merge pull request #13770 from brendandahl/cache-pattern
Improve performance of reused patterns.
2021-07-23 10:43:23 +02:00
Brendan Dahl
da1af02ac8 Improve performance of reused patterns.
Bug 1721218 has a shading pattern that was used thousands of times.
To improve performance of this PDF:
 - add a cache for patterns in the evaluator and only send the IR form once
   to the main thread (this also makes caching in canvas easier)
 - cache the created canvas radial/axial patterns
 - for shading fill radial/axial use the pattern directly instead of creating temporary
   canvas
2021-07-22 16:47:40 -07:00
calixteman
ead394debd
Merge pull request #13778 from calixteman/default_ui
XFA - A field without an ui must provide a default one (bug 1718245)
2021-07-22 21:14:01 +02:00
Calixte Denizet
a51c4a3a0f XFA - A field without an ui must provide a default one (bug 1718245) 2021-07-22 20:31:25 +02:00
calixteman
4860ea4711
Merge pull request #13777 from calixteman/xfa_rect
XFA - SVG elements mustn't get any pointer events (bug 1721589)
2021-07-22 19:45:29 +02:00
Calixte Denizet
b68d2100b4 XFA - SVG elements mustn't get any pointer events (bug 1721589)
- a rectangle can be defined after a field and so from a z-index pov, it's on top of the field, which means that the rectangle avoid to have some mouse events in the fields;
  - so this patch just disable pointer events for all elements under svg (included).
2021-07-22 18:47:29 +02:00
Jonas Jenwald
181580062c
Merge pull request #13776 from Snuffleupagus/lgtm-more-test
Include most of the `test`-folder in the LGTM report (PR 13772 follow-up)
2021-07-22 15:16:07 +02:00
Jonas Jenwald
10c29ed473 Include most of the test-folder in the LGTM report (PR 13772 follow-up)
Given that PR 13772 seem to have worked as intended, it probably cannot hurt to enable the LGTM report for *most* of the remaining code in the `test`-folder. (The one remaining exception is code which originated *outside* of the PDF.js project.)

*Please note:* We'll need to land this patch to actually see any difference in the LGTM results.
2021-07-22 14:37:17 +02:00
Jonas Jenwald
e1ee3835cd Remove some duplication in the Dict.merge method
Currently the `!mergeSubDicts` code-path is essentially just duplicated code, which we can easily avoid by simply moving that check. (This may lead to ever so slightly more parsing for this case, but the difference ought to be negligible in practice.)
2021-07-22 14:01:43 +02:00
Jonas Jenwald
ab7b577d85
Merge pull request #13772 from Snuffleupagus/lgtm-exclude-tests
Include the `font`/`integration`/`unit`-test folders in the LGTM report
2021-07-22 09:35:00 +02:00
Jonas Jenwald
bdde1336f1 Include the font/integration/unit-test folders in the LGTM report
By default all files/folders classified as test-code are excluded in the LGTM report, however I do believe that it makes sense to include at least the `font`/`integration`/`unit`-test folders.
It seems pretty obvious that you want to avoid *accidentally* introducing any simple logical errors in the tests (and not only in the main code), to ensure that e.g. the unit-tests actually test the desired thing.

Hopefully I've interpreted the information at https://lgtm.com/help/lgtm/customizing-file-classification correctly, however note that we may need to land this patch to actually see any difference in the results.
2021-07-22 00:26:21 +02:00
Jonas Jenwald
2cf90cd9ad
Merge pull request #13766 from Snuffleupagus/issue-13751
XFA - Handle `startIndex` correctly in the `Template.$toHTML` method (issue 13751)
2021-07-21 18:58:29 +02:00
calixteman
3fa319ab0e
Merge pull request #13768 from calixteman/ns_agnostic
XFA - Remove namespace from nodes under xfa:data node
2021-07-21 18:25:30 +02:00
Calixte Denizet
5555114bb3 XFA - Remove namespace from nodes under xfa:data node
- in real life some xfa contains xml like <xfa:data><xfa:Foo><xfa:Bar>...</xfa:data>
    since there are no Foo or Bar in the xfa namespace the JS representation are empty
    and that leads to errors.
  - so the idea is to make all nodes under xfa:data namespace agnostic which means
    that ns are removed from nodes in the parser but only xfa:data descendants.
2021-07-21 17:11:31 +02:00
Jonas Jenwald
7d1c19f8bd XFA - Handle startIndex correctly in the Template.$toHTML method (issue 13751)
*Please note:* The PDF document in issue 13751 is *dynamically* created (in e.g. Adobe Reader), with pages added when certain buttons are clicked, hence this patch simply fixes the breaking error and nothing more.

It looks like the current code contains a little bit too much copy-and-paste from the *similar* `index` branch above, since we cannot set the `startIndex` to a negative value. Note how it's being used to initialize the loop-variable, which is then used to lookup values in an Array and accessing the `-1`th element of an Array obviously makes no sense.
2021-07-21 16:17:13 +02:00
Jonas Jenwald
6c9b6bc599
Merge pull request #13764 from Snuffleupagus/issue-13748
XFA - Add a missing method to `XFAAttribute`, to prevent breaking errors (issue 13748)
2021-07-20 18:55:23 +02:00
calixteman
bdeb41a294
Merge pull request #13763 from calixteman/bug_1720907
XFA - Must use bindItems element even if there is no direct binding (bug 1720907)
2021-07-20 18:19:56 +02:00
Jonas Jenwald
c2fe493abe XFA - Add a missing method to XFAAttribute, to prevent breaking errors (issue 13748)
*This is yet another case where I've got no idea if the patch is correct, but it does at least fix a breaking error :-)*

Note how in the [`Binder._bindValue` method](683ce66a48/src/core/xfa/bind.js (L92-L93)), we're assuming that if a `data`-value exists then it'll also be possible to actually access it. For the `XFAAttribute`-implementation however, the second method is missing and that's what causes the breaking errors in issue 13748.

Please note that another possible way of "fixing" the error wouldn't been to simply change the exists-check to return `false`, and I could see that being a preferred solution.
However, the reason for submitting the current patch is that we get *fewer* warnings about Nodes with mis-matched types this way.
2021-07-20 17:41:05 +02:00
Calixte Denizet
1d07ef597e XFA - Must use bindItems element even if there is no direct binding (bug 1720907) 2021-07-20 17:07:32 +02:00
Jonas Jenwald
683ce66a48
Merge pull request #13761 from Snuffleupagus/issue-13756
XFA - Prevent breaking errors in `Binder`, when `searchNode` doesn't return data (issue 13756)
2021-07-19 19:38:30 +02:00
Jonas Jenwald
cf7978d507 XFA - Prevent breaking errors in Binder, when searchNode doesn't return data (issue 13756)
As can be seen in the code (see below), the `searchNode` helper function will return `null` in some cases and all of its call-sites should protect against that before attempting to access the returned data.
While only one of these changes were necessary to fix the breaking errors in issue 13756, in order to prevent future bugs I've added similar defensive code throughout this file.

 - 07955fa1d3/src/core/xfa/som.js (L169)
 - 07955fa1d3/src/core/xfa/som.js (L239)
 - 07955fa1d3/src/core/xfa/som.js (L254)
2021-07-19 18:07:07 +02:00
Tim van der Meij
07955fa1d3
Merge pull request #13735 from Snuffleupagus/bug-1720411
Ensure that the field value, for checkboxes, refers to an existing appearance state (bug 1720411)
2021-07-18 13:48:34 +02:00
Tim van der Meij
668c58d68d
Merge pull request #13746 from Snuffleupagus/getOperatorList-intent
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
2021-07-18 13:28:08 +02:00
Tim van der Meij
e04386c675
Merge pull request #13754 from Snuffleupagus/refactor-PDFFunction
Remove the IR (internal representation) part of the `PDFFunction` parsing
2021-07-18 13:11:26 +02:00
Tim van der Meij
2d1f60f655
Merge pull request #13745 from Snuffleupagus/dev-enableXfa
Enable XFA by default in the development viewer
2021-07-18 13:03:31 +02:00
Jonas Jenwald
481af097b4 Convert PDFFunction to a standard class with static methods
For e.g. `gulp mozcentral`, the *built* `pdf.worker.js` file decreases from `1 837 608` to `1 834 907` bytes with this patch-series.
The improvement comes first of all from less overall indentation in `PDFFunction`, and secondly from the removal of (now) unnecessary indirection in the code.
2021-07-17 16:46:57 +02:00
Jonas Jenwald
d35fe3e796 Remove the IR (internal representation) part of the PDFFunction parsing
*This follows the exact same princial as PR 12083, but for the `PDFFunction` parsing instead.*

Given that the IR format is completely unused now, all that the current code does is add a bunch of unnecessary indirection/overhead to the handling of PDF-functions.
2021-07-17 16:44:58 +02:00
Jonas Jenwald
03cf28bf17 [api-minor] Add intent support to the PDFPageProxy.getOperatorList method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.

Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.

Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).

*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-16 17:16:30 +02:00
Jonas Jenwald
e5845739fd Enable XFA by default in the development viewer
Given that https://bugzilla.mozilla.org/show_bug.cgi?id=1720402 has just landed, enabling XFA in the development viewer probably cannot hurt now.
2021-07-16 14:16:33 +02:00
Jonas Jenwald
da808aeab3 Ensure that the field value, for checkboxes, refers to an existing appearance state (bug 1720411)
Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1720411
2021-07-16 13:11:48 +02:00
calixteman
f1ae7d7b0e
Merge pull request #13743 from calixteman/print_radio
XFA - Checkboxes must be printed (bug 1720182)
2021-07-16 12:57:04 +02:00
Calixte Denizet
3fb30ddde5 XFA - Checkboxes must be printed (bug 1720182)
- to avoid future regressions, annotationStorage is passed to the xfa render in reftests.
2021-07-16 11:32:03 +02:00
calixteman
4b2e0d0d01
Merge pull request #13732 from calixteman/rect
XFA - A rectangle must have the width of its parent but without inner margins
2021-07-15 22:30:25 +02:00
Tim van der Meij
ad34f16861
Merge pull request #13730 from Snuffleupagus/botbrowsertest
Add a new "botbrowsertest" gulp-task, to allow running only the browser tests on the bots
2021-07-15 22:14:17 +02:00