Commit Graph

14759 Commits

Author SHA1 Message Date
Tim van der Meij
273cea8675
Merge pull request #13837 from timvandermeij/unit-test-query-string
Implement unit tests for the `parseQueryString` utility function
2021-08-01 14:26:33 +02:00
Tim van der Meij
d1c0f8f91c
Implement unit tests for the parseQueryString utility function
Now that these unit tests are in place, we also take the opportunity to
slightly modernize the code itself by using a `for ... of` loop.
2021-08-01 14:14:33 +02:00
Tim van der Meij
449f941b7b
Merge pull request #13831 from Snuffleupagus/parseQueryString-Map
Change the `parseQueryString` function to return a `Map` rather than an Object (issue 13829)
2021-08-01 12:21:43 +02:00
Jonas Jenwald
1ea8cfa2f2
Merge pull request #13836 from timvandermeij/cmaps
Fix inefficient regular expressions in `external/cmapscompress/parse.js`
2021-08-01 12:20:51 +02:00
Tim van der Meij
0d84f57cfa
Fix inefficient regular expressions in external/cmapscompress/parse.js
The only purpose, according to the README and existing files, is to
parse an integer from those lines, so (\d+) is sufficient for that. This
avoids potential exponential backtracking as flagged by CodeQL. I have
compared the output of the script with and without these changes and the
resulting files are the same.
2021-08-01 12:12:42 +02:00
Jonas Jenwald
4483cba724
Merge pull request #13833 from tamuratak/add_peer_dep_meta_for_worker_loader
Make worker-loader optional as peerDependencies. Close #13825.
2021-08-01 11:28:59 +02:00
Takashi Tamura
9eca5e5c86 Make worker-loader optional as peerDependencies. Close #13825.
- https://docs.npmjs.com/cli/v7/configuring-npm/package-json#peerdependencies
- https://github.blog/2020-10-13-presenting-v7-0-0-of-the-npm-cli/
- https://docs.npmjs.com/cli/v7/configuring-npm/package-json#peerdependenciesmeta

Update worker-loader to v3.0.8.
2021-08-01 17:44:31 +09:00
Jonas Jenwald
4ab4efd42f Change the parseQueryString function to return a Map rather than an Object (issue 13829)
Even though the code as-is *should* be safe, given that we're using an Object with a `null` prototype, it cannot hurt to change this to a Map to prevent any issues (since we're parsing unknown and potentially unsafe data).

Overall I also think that these changes improve the `parseQueryString` call-sites, since we now have a proper way of checking for the existence of a particular key (and don't have to use `in` which stringifies the keys in the Object).

This patch also changes the default, when no `value` exists, from `null` to an empty string since the use of `decodeURIComponent` currently can modify the value in a somewhat surprising way (at least to me).
Note how `decodeURIComponent(null) === "null"` which is unlikely to be what you actually want, whereas `decodeURIComponent("") === ""` which seems much more helpful.
2021-07-31 23:24:49 +02:00
Jonas Jenwald
222c9e7e84
Merge pull request #13830 from timvandermeij/codeql
Improve the code analysis workflow with quality checks
2021-07-31 16:25:24 +02:00
Tim van der Meij
574fed2bdf
Improve the code analysis workflow with quality checks
This allows us to get the quality checks that LGTM does into GitHub
Advanced Security. Since it not only runs security checks anymore, the
workflow is also renamed to CodeQL to make this more explicit (and this
matches the documentation better).
2021-07-31 15:33:07 +02:00
Tim van der Meij
3ec1bac901
Merge pull request #13828 from timvandermeij/github-advanced-security
Introduce the GitHub Advanced Security workflow
2021-07-31 13:44:24 +02:00
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