Commit Graph

14128 Commits

Author SHA1 Message Date
Jonas Jenwald
3294d4d5a3 Move the Ascii85Stream from src/core/stream.js and into its own file 2021-04-28 10:16:51 +02:00
Jonas Jenwald
d2227a7d10 Convert src/core/ascii_hex_stream.js to use standard classes 2021-04-28 10:16:50 +02:00
Jonas Jenwald
59591f8788 Enable the no-var rule in the src/core/ascii_hex_stream.js file 2021-04-28 10:16:50 +02:00
Jonas Jenwald
d63df04854 Move the AsciiHexStream from src/core/stream.js and into its own file 2021-04-28 10:16:50 +02:00
Jonas Jenwald
704514c7cd Convert src/core/run_length_stream.js to use standard classes 2021-04-28 10:16:50 +02:00
Jonas Jenwald
66b898eb58 Enable the no-var rule in the src/core/run_length_stream.js file 2021-04-28 10:16:50 +02:00
Jonas Jenwald
342b0c1bbc Move the RunLengthStream from src/core/stream.js and into its own file 2021-04-28 10:16:50 +02:00
Jonas Jenwald
1f0685cee6 Convert src/core/lzw_stream.js to use standard classes 2021-04-28 10:16:50 +02:00
Jonas Jenwald
1f9b134c6a Enable the no-var rule in the src/core/src/core/lzw_stream.js file 2021-04-28 10:16:50 +02:00
Jonas Jenwald
6c1a321500 Move the LZWStream from src/core/stream.js and into its own file 2021-04-28 10:16:50 +02:00
Brendan Dahl
d10da907da
Fix position of highlighted all text. (#13306)
Adds a new integration test to ensure we don't
regress this again.
2021-04-28 10:15:31 +02:00
Tim van der Meij
0acd801b1e
Merge pull request #13305 from timvandermeij/annotation-polygon-polyline-no-appearance-stream
Implement rendering polyline/polygon annotations without appearance stream
2021-04-27 20:03:35 +02:00
Tim van der Meij
fae183b7cc
Merge pull request #13304 from Snuffleupagus/src-core-classes
Convert more code in `src/core/` to use standard classes
2021-04-27 19:37:09 +02:00
Tim van der Meij
60ab15427f
Implement rendering polyline/polygon annotations without appearance stream 2021-04-27 19:02:20 +02:00
Jonas Jenwald
0ecb42f4d7 Convert src/core/jpx_stream.js to use standard classes 2021-04-27 13:29:09 +02:00
Jonas Jenwald
c51ef1f21f Convert src/core/jbig2_stream.js to use standard classes 2021-04-27 13:29:09 +02:00
Jonas Jenwald
d9c1bf96b6 Convert src/core/jpeg_stream.js to use standard classes 2021-04-27 13:29:09 +02:00
Jonas Jenwald
0ca63f94b4 Convert src/core/ccitt_stream.js to use standard classes 2021-04-27 13:29:09 +02:00
Jonas Jenwald
8ff213871b Convert src/core/ccitt.js to use standard classes
Given that we're using modules, meaning that only explicitly `export`ed things are visible to the outside, it's no longer necessary to wrap all of the code in a closure.
2021-04-27 13:29:09 +02:00
Tim van der Meij
ca668587c6
Merge pull request #13300 from Snuffleupagus/canvas-class
Convert the code in `src/display/canvas.js` to use standard classes
2021-04-27 13:19:36 +02:00
Jonas Jenwald
6f4394fcd8
Support InkAnnotations without appearance streams (issue 13298) (#13301)
For now, we keep things purposely simple by using straight lines (rather than curves); please see https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.2096579
2021-04-27 11:49:03 +02:00
Jonas Jenwald
e6601f4582 Convert the code in src/display/canvas.js to use standard classes
This gets rid of *a lot* of boilerplate that stems from our old way of simulating classes, and it actually reduces the filesize noticeably.
For e.g. `gulp mozcentral`, the *built* `pdf.js` files decreases from `318 404` to `314 722` bytes (~1 percent) with this patch.
2021-04-26 22:10:38 +02:00
Tim van der Meij
72be684c10
Merge pull request #13294 from timvandermeij/src-no-var
Enable the `no-var` linting rule in `src/core/{cmap,image,worker}.js`
2021-04-25 17:44:13 +02:00
Tim van der Meij
270e56dae8
Enable the no-var linting rule in src/core/image.js
This is done automatically with `gulp lint --fix` and the following
manual changes:

```diff
diff --git a/src/core/image.js b/src/core/image.js
index 35c06b8ab..e718b9937 100644
--- a/src/core/image.js
+++ b/src/core/image.js
@@ -97,7 +97,7 @@ class PDFImage {
     if (isName(filter)) {
       switch (filter.name) {
         case "JPXDecode":
-          var jpxImage = new JpxImage();
+          const jpxImage = new JpxImage();
           jpxImage.parseImageProperties(image.stream);
           image.stream.reset();
```
2021-04-25 17:40:00 +02:00
Tim van der Meij
16efd09c9f
Enable the no-var linting rule in src/core/worker.js
This is done automatically with `gulp lint --fix` and the following
manual changes:

```diff
diff --git a/src/core/worker.js b/src/core/worker.js
index aec9c1d39..f88691622 100644
--- a/src/core/worker.js
+++ b/src/core/worker.js
@@ -300,7 +300,7 @@ class WorkerMessageHandler {
         cachedChunks = [];
       };
       const readPromise = new Promise(function (resolve, reject) {
-        var readChunk = function ({ value, done }) {
+        const readChunk = function ({ value, done }) {
           try {
             ensureNotTerminated();
             if (done) {
```
2021-04-25 17:40:00 +02:00
Tim van der Meij
85659b4cf0
Enable the no-var linting rule in src/core/cmap.js
This is done automatically with `gulp lint --fix` and the following
manual changes:

```diff
diff --git a/src/core/cmap.js b/src/core/cmap.js
index 850275a19..8794726dd 100644
--- a/src/core/cmap.js
+++ b/src/core/cmap.js
@@ -519,8 +519,8 @@ const BinaryCMapReader = (function BinaryCMapReaderClosure() {

     readHexNumber(num, size) {
       let last;
-      let stack = this.tmpBuf,
-        sp = 0;
+      const stack = this.tmpBuf;
+      let sp = 0;
       do {
         const b = this.readByte();
         if (b < 0) {
@@ -603,7 +603,6 @@ const BinaryCMapReader = (function BinaryCMapReaderClosure() {

         const ucs2DataSize = 1;
         const subitemsCount = stream.readNumber();
-        var i;
         switch (type) {
           case 0: // codespacerange
             stream.readHex(start, dataSize);
@@ -614,7 +613,7 @@ const BinaryCMapReader = (function BinaryCMapReaderClosure() {
               hexToInt(start, dataSize),
               hexToInt(end, dataSize)
             );
-            for (i = 1; i < subitemsCount; i++) {
+            for (let i = 1; i < subitemsCount; i++) {
               incHex(end, dataSize);
               stream.readHexNumber(start, dataSize);
               addHex(start, end, dataSize);
@@ -633,7 +632,7 @@ const BinaryCMapReader = (function BinaryCMapReaderClosure() {
             addHex(end, start, dataSize);
             stream.readNumber(); // code
             // undefined range, skipping
-            for (i = 1; i < subitemsCount; i++) {
+            for (let i = 1; i < subitemsCount; i++) {
               incHex(end, dataSize);
               stream.readHexNumber(start, dataSize);
               addHex(start, end, dataSize);
@@ -647,7 +646,7 @@ const BinaryCMapReader = (function BinaryCMapReaderClosure() {
             stream.readHex(char, dataSize);
             code = stream.readNumber();
             cMap.mapOne(hexToInt(char, dataSize), code);
-            for (i = 1; i < subitemsCount; i++) {
+            for (let i = 1; i < subitemsCount; i++) {
               incHex(char, dataSize);
               if (!sequence) {
                 stream.readHexNumber(tmp, dataSize);
@@ -667,7 +666,7 @@ const BinaryCMapReader = (function BinaryCMapReaderClosure() {
               hexToInt(end, dataSize),
               code
             );
-            for (i = 1; i < subitemsCount; i++) {
+            for (let i = 1; i < subitemsCount; i++) {
               incHex(end, dataSize);
               if (!sequence) {
                 stream.readHexNumber(start, dataSize);
@@ -692,7 +691,7 @@ const BinaryCMapReader = (function BinaryCMapReaderClosure() {
               hexToInt(char, ucs2DataSize),
               hexToStr(charCode, dataSize)
             );
-            for (i = 1; i < subitemsCount; i++) {
+            for (let i = 1; i < subitemsCount; i++) {
               incHex(char, ucs2DataSize);
               if (!sequence) {
                 stream.readHexNumber(tmp, ucs2DataSize);
@@ -717,7 +716,7 @@ const BinaryCMapReader = (function BinaryCMapReaderClosure() {
               hexToInt(end, ucs2DataSize),
               hexToStr(charCode, dataSize)
             );
-            for (i = 1; i < subitemsCount; i++) {
+            for (let i = 1; i < subitemsCount; i++) {
               incHex(end, ucs2DataSize);
               if (!sequence) {
                 stream.readHexNumber(start, ucs2DataSize);
```
2021-04-25 17:40:00 +02:00
Tim van der Meij
2e9c2ab3b8
Merge pull request #13297 from Snuffleupagus/webpack-example-minification-warning
Add a note about minification to the webpack-example README (issue 13290)
2021-04-25 17:38:32 +02:00
Jonas Jenwald
24aae858b9 Add a note about minification to the webpack-example README (issue 13290)
Since we really don't want to let a particular Webpack-mode dictate how we can/can't write code, let's add a note in the webpack-example README about minification instead.
2021-04-25 17:20:57 +02:00
Tim van der Meij
ab2428270f
Merge pull request #13291 from Snuffleupagus/rm-forEach
Replace a bunch of `Array.prototype.forEach()` cases with `for...of` loops instead
2021-04-24 20:08:51 +02:00
Jonas Jenwald
4078dd856c Clear some Arrays, rather than re-initialize them, in src/display/-code
It's generally better to re-use the same Array, by clearing out all of its elements, rather than creating a new Array.
2021-04-24 13:00:53 +02:00
Jonas Jenwald
da22146b95 Replace a bunch of Array.prototype.forEach() cases with for...of loops instead
Using `for...of` is a modern and generally much nicer pattern, since it gets rid of unnecessary callback-functions. (In a couple of spots, a "regular" `for` loop had to be used.)
2021-04-24 13:00:19 +02:00
Tim van der Meij
da0e7ea969
Merge pull request #13272 from calixteman/issue13271
Update all the text widgets having the same name with the same value
2021-04-23 21:08:54 +02:00
Tim van der Meij
a6e3ad4c72
Merge pull request #13283 from Snuffleupagus/NameOrNumberTree-getAll-map
Change `NameOrNumberTree.getAll` to return a `Map` rather than an Object
2021-04-23 20:53:52 +02:00
calixteman
762cfd2d1b
[JS] Use heap allocation when initializing quickjs sandbox (#13286)
- In case of large string the sandbox initialization failed because of an OOM
    * so allocate a new string in the heap
    * and free it after use.
  - it requires a quickjs update since we need to export some symbols (stringToNewUTF8 and free).
2021-04-23 12:04:14 +02:00
Jonas Jenwald
4ec0a4fb43 Re-factor the Catalog._collectJavaScript method slightly
This patch first of all moves all checking/validation into the `appendIfJavaScriptDict` function, to avoid duplicating it in multiple places. Secondly, also removes what's now an outdated/incorrect comment since we have implemented scripting support.
2021-04-23 09:42:32 +02:00
Jonas Jenwald
83f7009e4b Change NameOrNumberTree.getAll to return a Map rather than an Object
Given that we're (almost) always iterating through the result of the `getAll`-calls, using a `Map` seems nicer overall since it's more suited to iteration compared to a regular Object.

Also, add a couple of `Dict`-checks in existing code touched by this patch, since it really cannot hurt to prevent *potential* errors in a corrupt PDF document.
2021-04-22 13:15:50 +02:00
Jonas Jenwald
57a1ea840f
Ensure that saveDocument works if there's no /ID-entry in the PDF document (issue 13279) (#13280)
First of all, while it should be very unlikely that the /ID-entry is an *indirect* object, note how we're using `Dict.get` when parsing it e.g. in `PDFDocument.fingerprint`. Hence we definitely should be consistent here, since if the /ID-entry is an *indirect* object the existing code in `src/core/writer.js` would already fail.
Secondly, to fix the referenced issue, we also need to check that the /ID-entry actually is an Array before attempting to access its contents in `src/core/writer.js`.

*Drive-by change:* In the `xrefInfo` object passed to the `incrementalUpdate` function, re-name the `encrypt` property to `encryptRef` since its data is fetched using `Dict.getRaw` (given the names of the other properties fetched similarly).
2021-04-22 12:08:56 +02:00
Jonas Jenwald
8538cdf845
Update Puppeteer to version 9 (#13282)
* Update Puppeteer to version 9

Hopefully the updated Chromium-version might help reduce the number of intermittent test failures.

Please find additional information at https://github.com/puppeteer/puppeteer/releases/tag/v9.0.0

* Update the `eslint-plugin-sort-exports`/`eslint-plugin-unicorn"` packages to their latest versions

Both of these ESLint plugins have increased their version numbers, however `npm update` doesn't handle this automatically.

https://www.npmjs.com/package/eslint-plugin-sort-exports
https://www.npmjs.com/package/eslint-plugin-unicorn
2021-04-22 11:35:16 +02:00
Tim van der Meij
2d073b91b8
Merge pull request #13263 from Snuffleupagus/font-tests-rm-done
Replace `done` callbacks in the font-tests with async/await instead
2021-04-21 21:07:44 +02:00
Brendan Dahl
066cbcfb27
Merge pull request #13277 from Snuffleupagus/adjustToUnicode-cff
For CFF fonts without proper `ToUnicode`/`Encoding` data, utilize the "charset"/"Encoding"-data from the font file to improve text-selection (issue 13260)
2021-04-21 10:41:36 -07:00
Brendan Dahl
5231d922ec
Add presentation role to text layer spans. (#13278)
Keeps screen readers from pausing on every span so
paragraphs are read more naturally. Note: this only seems
to affect Firefox, Chrome automatically combines the spans.
2021-04-21 10:47:51 +02:00
Jonas Jenwald
7b8d2495ca Convert the font-test ttx helper function to use the Fetch API
By replacing `XMLHttpRequest` with a `fetch` call, the helper function can be modernized to use async/await instead.
Note that the headers doesn't seem necessary to set now, since:
 - The Fetch API provides a method for accessing the response as *text*, which renders the "Content-type" header unnecessary.
 - According to https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name, the "Content-length" header isn't necessary.
2021-04-20 23:44:15 +02:00
Tim van der Meij
b0d58efb6a
Merge pull request #13275 from Snuffleupagus/loadResources-Properties
Ensure that the /Properties, used with optional content, is actually loaded *before* parsing the operatorList/textContent (PR 12095 follow-up)
2021-04-20 21:45:39 +02:00
Jonas Jenwald
7fab73ed23 For CFF fonts without proper ToUnicode/Encoding data, utilize the "charset"/"Encoding"-data from the font file to improve text-selection (issue 13260)
This patch extends the approach, implemented in PR 7550, to also apply to CFF fonts.
2021-04-20 20:48:44 +02:00
Jonas Jenwald
8f6543c218 Ensure that the /Properties, used with optional content, is actually loaded *before* parsing the operatorList/textContent (PR 12095 follow-up)
By not waiting for the /Properties to load, before parsing of the operatorList/textContent starts, there's a very real risk that a `MissingDataException` will be thrown when trying to access the data in the `PartialEvaluator.parseMarkedContentProps` method.
If this ever happens it will thus lead to incomplete and/or outright broken rendering, and with e.g. `disableAutoFetch=true` set the likelihood of this occuring would increase quite a bit.

*Please note:* While I've not yet seen this error in an actual PDF document, it can happen during loading if you're unlucky enough with e.g. the structure of the PDF document and/or the download speed offered by the server.
2021-04-20 20:22:44 +02:00
Calixte Denizet
e868ab0051 Update all the text widgets having the same name with the same value 2021-04-20 20:03:19 +02:00
Jonas Jenwald
3d55b2b10e Replace done callbacks in the font-tests with async/await instead 2021-04-19 13:26:39 +02:00
Tim van der Meij
fd82adccfa
Merge pull request #13256 from timvandermeij/unit-test-async-await-pt4
Convert done callbacks to async/await in the last two unit test files
2021-04-18 14:25:40 +02:00
Tim van der Meij
d42f3d0bfe
Convert done callbacks to async/await in test/unit/evaluator_spec.js 2021-04-18 14:20:54 +02:00
Tim van der Meij
692304247c
Merge pull request #13258 from Snuffleupagus/update-packages
Update packages and translations
2021-04-18 14:19:51 +02:00