Commit Graph

14648 Commits

Author SHA1 Message Date
Tim van der Meij
5a08d62e76
Improve the CI workflow YAML file
This makes it consistent with the GitHub Advanced Security file and,
more importantly, ensures that all steps have a proper name for better
visibility.
2021-07-31 13:33:14 +02:00
Mathew Payne
4774858d3c
Introduce the GitHub Advanced Security workflow
This can help to find security problems sooner.
2021-07-31 13:32:22 +02:00
Tim van der Meij
10a1db6980
Merge pull request #13824 from Snuffleupagus/issue-13823
When no "V" entry exists, let the fieldValue fallback to the "DV" entry (issue 13823)
2021-07-30 22:48:38 +02:00
Tim van der Meij
67f4c34f63
Merge pull request #13822 from Snuffleupagus/ReadableStreams-cancel-no-Uncaught_promise
Prevent "Uncaught promise" messages in the console when cancelling (some) `ReadableStream`s
2021-07-30 22:09:29 +02:00
Tim van der Meij
99b14a9da0
Merge pull request #13813 from Snuffleupagus/rm-closure-API
Remove a couple of closures in the `src/display/api.js` file
2021-07-30 21:55:45 +02:00
Tim van der Meij
314a1365bc
Merge pull request #13816 from Snuffleupagus/rm-BaseViewer-enableScripting-option
[api-minor] Remove the separate `enableScripting` option in `BaseViewer`
2021-07-30 21:49:14 +02:00
Jonas Jenwald
ff71be793d When no "V" entry exists, let the fieldValue fallback to the "DV" entry (issue 13823) 2021-07-30 16:17:42 +02:00
calixteman
649d091167
Merge pull request #13819 from calixteman/xfa_exdata
XFA - Avoid an error when an exdata is a string (bug 1723114)
2021-07-30 16:12:32 +02:00
Calixte Denizet
7bb5331087 XFA - Avoid an error when an exdata is a string (bug 1723114) 2021-07-30 14:43:53 +02:00
Jonas Jenwald
1df9da949e Prevent "Uncaught promise" messages in the console when cancelling (some) ReadableStreams
While fixing issue 13794, I noticed that cancelling the `ReadableStream` returned by the `PDFPageProxy.streamTextContent`-method could lead to "Uncaught promise" messages in the console.[1]
Generally speaking, we don't really care about errors when *cancelling* a `ReadableStream` and it thus seems reasonable to simply suppress any output in those cases.

---
[1] Although, after that issue was fixed you'd now need to set the API-option `stopAtErrors = true` to actually trigger this.
2021-07-30 14:27:38 +02:00
Jonas Jenwald
5fac0a4350 Simplify some code related to fallbackWorkerSrc and getMainThreadWorkerMessageHandler 2021-07-30 11:34:47 +02:00
Jonas Jenwald
4c679d80ac Remove the closure used with the InternalRenderTask class
This patch utilizes 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-30 11:34:47 +02:00
Jonas Jenwald
b18620ac0f Remove the closure used with the PDFDocumentLoadingTask class
This patch utilizes the same approach as used in lots of other parts of the code-base, which thus *slightly* reduces the size of this code.

By removing some of the (current) indirection, we can also simplify the JSDocs a little bit. Looking at the `gulp jsdoc` output, this actually seem to *improve* the documentation for this class.
2021-07-30 11:34:47 +02:00
Jonas Jenwald
76c805f83b [api-minor] Remove the separate enableScripting option in BaseViewer
Prior to PR 13042, when scripting wasn't really possible to use outside of the full viewer, the `enableScripting` option made sense.
However, at this point in time having to both pass in a `PDFScriptingManager`-instance *and* set the `enableScripting`-boolean when creating a `BaseViewer`-instance feels redundant and (mostly) annoying. Hence this patch, which removes the *separate* boolean and always enables scripting when `scriptingManager` is provided.

The relevant "viewer component" examples are also updated (with a comment), but in such a way that scripting support won't just break when used with the current PDF.js releases.
2021-07-29 10:06:03 +02:00
Brendan Dahl
4ad5c5d52a
Merge pull request #13808 from brendandahl/pattern-cache-v2
Improve caching of shading patterns. (bug 1721949)
2021-07-28 11:17:16 -07:00
calixteman
edbe9692b4
Merge pull request #13815 from calixteman/xfa_fonts2
XFA - Fix font scale factors (bug 1720888)
2021-07-28 19:45:45 +02:00
Brendan Dahl
c836e1f0fb Improve caching of shading patterns. (bug 1721949)
The PDF in bug 1721949 uses many unique pattern objects
that references the same shading many times. This caused
a new canvas pattern to be created and cached many times
driving up memory use.

To fix, I've changed the cache in the worker to key off the
shading object and instead send the shading and matrix
separately. While that worked well to fix the above bug,
there could be PDFs that use many shading that could
cause memory issues, so I've also added a LRU cache
on the main thread for canvas patterns. This should prevent
memory use from getting too high.
2021-07-28 10:29:20 -07:00
Calixte Denizet
4a4591bd2c XFA - Fix font scale factors (bug 1720888)
- All the scale factors in for the substitution font were wrong because of different glyph positions between Liberation and the other ones:
    - regenerate all the factors
  - Text may have polish chars for example and in this case the glyph widths were wrong:
    - treat substitution font as a composite one
    - add a map glyphIndex to unicode for Liberation in order to generate width array for cid font
2021-07-28 19:10:42 +02:00
calixteman
ac5c4b7fd0
Merge pull request #13806 from calixteman/xfa_fields
XFA - Fix auto-sized fields (bug 1722030)
2021-07-28 17:01:15 +02:00
Calixte Denizet
92f4cc52a6 XFA - Add a transparent blue background on all text fields for consistency 2021-07-28 14:47:29 +02:00
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