Commit Graph

14528 Commits

Author SHA1 Message Date
Calixte Denizet
76d882b560 XFA - Fix auto-sized fields (bug 1722030)
- In order to better compute text fields size, use line height with no gaps (and consequently guessed height for text are slightly better in general).
  - Fix default background color in fields.
2021-07-28 09:43:15 +02:00
Tim van der Meij
336a74a0e5
Merge pull request #13796 from Snuffleupagus/issue-13794
Allow `StreamsSequenceStream.readBlock` to skip sub-streams with errors (issue 13794)
2021-07-27 22:25:58 +02:00
calixteman
45f3804737
Merge pull request #13807 from calixteman/fulltext
XFA - Get the full value when binding and not only the 1st line (bug 1718725)
2021-07-27 22:22:37 +02:00
Tim van der Meij
d3dffa7fa3
Merge pull request #13804 from Snuffleupagus/move-viewer-compatibilityParams
Move the `compatibilityParams` into the `web/app_options.js` file
2021-07-27 22:13:40 +02:00
Tim van der Meij
e51cbe63bf
Merge pull request #13801 from Snuffleupagus/AnnotationLayer-check-navigator
Access `navigator` safely in the `src/display/annotation_layer.js` file
2021-07-27 22:10:27 +02:00
Calixte Denizet
bd6f55186d XFA - Get the full value when binding and not only the 1st line (bug 1718725) 2021-07-27 20:25:33 +02:00
Jonas Jenwald
6c95d0cb2c Move the compatibilityParams into the web/app_options.js file
Given that we've over time been reducing the number of `compatibilityParams` in use, there's now few enough left that I think it makes sense to simply inline them directly in the `web/app_options.js` file.
Note that we recently inlined/removed the separate `src/display/api_compatibility.js` file, see PR 13525, and that it (in my opinion) thus makes sense to do the same in the `web/`-folder. This patch will also slightly reduce the size of *built* `web/viewer.js` file, which cannot hurt.
2021-07-27 16:44:49 +02:00
Jonas Jenwald
4b3ab1472c Access navigator safely in the src/display/annotation_layer.js file
For code that's part of the core library, rather than e.g. the `web/`-folder, we should always be careful about *directly* accessing any DOM methods.
The `navigator` is one such structure, which shouldn't be assumed to always be available and we should thus check that it's actually present.[1]

Hence this patch re-factors the `navigator.platform` access, in the `AnnotationLayer`-code, to ensure that it's generally safe. Furthermore, to reduce unnecessary repeated string-matching to determine the current platform, we're now using a shadowed getter which is evaluated only once instead (at first access).

---
[1] Note e.g. the `isSyncFontLoadingSupported` getter, in the `src/display/font_loader.js` file.
2021-07-27 09:40:42 +02:00
calixteman
7305b7464f
Merge pull request #13795 from calixteman/image_gd
XFA - Elements created outside of XML must have all their properties (bug 1722029)
2021-07-27 09:36:55 +02:00
Calixte Denizet
959120e6c9 XFA - Elements created outside of XML must have all their properties (bug 1722029)
- an Image element was created, attached to its parent but the $globalData property was not set and that led to an error.
  - the pdf in bug 1722029 has 27 rendered rows (checked in Acrobat) when only one was displayed: this patch some binding issues around the occur element.
2021-07-26 19:38:52 +02:00
Jonas Jenwald
885e7a8aa4 Allow StreamsSequenceStream.readBlock to skip sub-streams with errors (issue 13794)
This patch makes use of the existing `ignoreErrors` option, thus allowing a page to continue parsing/rendering even if (some of) its sub-streams are corrupt. Obviously this may cause *part* of a page to be broken/missing, however it should be better than (potentially) rendering nothing.
Also, to the best of my knowledge, this is the first bug of its kind that we've encountered.

To avoid having to pass in a bunch of, for a `BaseStream`-instance, mostly unrelated parameters when initializing a `StreamsSequenceStream`-instance, I settled on utilizing a callback function instead to allow conditional Error-suppression.
Note that the `StreamsSequenceStream`-class is a *special* stream-implementation that we only use when the `/Contents`-entry, in the `/Page`-dictionary, consists of an Array with streams.
2021-07-26 16:42:50 +02:00
Tim van der Meij
777d890268
Merge pull request #13792 from Snuffleupagus/rm-canvas-closure
Remove the remaining closure in the `src/display/canvas.js` file
2021-07-25 14:42:44 +02:00
Tim van der Meij
c2e0a36c51
Merge pull request #13793 from timvandermeij/bump
Bump versions in `pdfjs.config`
2021-07-25 13:44:02 +02:00
Tim van der Meij
08f25c05f5
Bump versions in pdfjs.config 2021-07-25 13:39:57 +02:00
Jonas Jenwald
e1fa845293 Only define *existing* methods, when converting the OPS format to method-names on the CanvasGraphics.prototype
There's no good reason, as far as I can tell, to explicitly define a bunch of methods to be `undefined`, which the current unconditional "copying" of methods will do.
Note that of the `OPS` ~23 percent don't, for various reasons, have an associated method on the `CanvasGraphics.prototype`.
2021-07-25 13:28:28 +02:00
Jonas Jenwald
fbaafdc4e8 Remove the remaining closure in the src/display/canvas.js file
For e.g. the `gulp mozcentral` command, the *built* `pdf.js` file decreases from `304 607` to `301 295` bytes with this patch. The improvement comes mostly from having less overall indentation in the code.
2021-07-25 13:14:58 +02:00
Tim van der Meij
156762c482
Merge pull request #13790 from Snuffleupagus/update-packages
Update packages and translations
2021-07-25 12:21:23 +02:00
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