Commit Graph

14223 Commits

Author SHA1 Message Date
Jonas Jenwald
30b2739adf Ensure that composite/non-composite fonts won't get the same hash in PartialEvaluator.preEvaluateFont
To hopefully help prevent any future bugs, make sure that composite/non-composite fonts cannot accidentally get matching `hash`es. Given the differences between those font types, that's very unlikely to be useful or even correct in general.
2021-05-07 21:22:37 +02:00
Jonas Jenwald
fc59a5f709 Take the W array into account when computing the hash, in PartialEvaluator.preEvaluateFont, for composite fonts (issue 13343)
Without this some *composite* fonts may incorrectly end up with matching `hash`es, thus breaking rendering since we'll not actually try to load/parse some of the fonts.

*Please note:* Given that the document, in the referenced issue, doesn't embed *any* of its fonts there's no guarantee that it renders correctly in all configurations even with this patch.
2021-05-07 21:22:36 +02:00
Tim van der Meij
a2652bafd9
Merge pull request #13350 from calixteman/xfa_options
Add option enableXfa to the viewer
2021-05-07 21:16:24 +02:00
Tim van der Meij
a3632c0f38
Merge pull request #13344 from Snuffleupagus/evaluator-no-var
Enable the `no-var` rule in the `src/core/evaluator.js` file
2021-05-07 21:02:46 +02:00
Tim van der Meij
5248d0a77d
Merge pull request #13338 from Snuffleupagus/images-class
Convert the `src/core/{jbig2, jpg, jpx}.js` files to use standard classes
2021-05-07 20:59:58 +02:00
Tim van der Meij
07395f8dc0
Merge pull request #13352 from mozilla/dependabot/npm_and_yarn/hosted-git-info-2.8.9
Bump hosted-git-info from 2.6.0 to 2.8.9
2021-05-07 20:46:53 +02:00
Tim van der Meij
f66829e5ea
Merge pull request #13341 from Snuffleupagus/FontRendererFactory-rm-closure
Remove unnecessary closure in the `src/core/font_renderer.js` file
2021-05-07 20:46:08 +02:00
dependabot[bot]
83aa847e21
Bump hosted-git-info from 2.6.0 to 2.8.9
Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.6.0 to 2.8.9.
- [Release notes](https://github.com/npm/hosted-git-info/releases)
- [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md)
- [Commits](https://github.com/npm/hosted-git-info/compare/v2.6.0...v2.8.9)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-07 18:43:06 +00:00
Tim van der Meij
2ce25bb788
Merge pull request #13349 from mozilla/dependabot/npm_and_yarn/lodash-4.17.21
Bump lodash from 4.17.19 to 4.17.21
2021-05-07 20:41:41 +02:00
Calixte Denizet
a0a4cd3f8a Add option enableXfa to the viewer 2021-05-07 14:52:51 +02:00
dependabot[bot]
e361341449
Bump lodash from 4.17.19 to 4.17.21
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.19 to 4.17.21.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.19...4.17.21)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-07 10:54:18 +00:00
Calixte Denizet
af125cd299 JS - Add support for display property
- in annotation_layer, move common properties treatment in a common method instead having duplicated code in each widget.
2021-05-06 11:15:38 +02:00
Jonas Jenwald
0ef9b5aafc Fix the remaining no-var failures, which couldn't be handled automatically, in the src/core/evaluator.js file
The only *slight* complication here were some of the `switch`-cases, in `getOperatorList`/`getTextContent`, where the parsing is done asynchronously.
However, those cases are easy to deal with by wrapping the code within its own block; please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch#block-scope_variables_within_switch_statements
2021-05-06 10:21:05 +02:00
Jonas Jenwald
f93c3b9aa7 Enable the no-var rule in the src/core/evaluator.js file
These changes were made automatically, using `gulp lint --fix`.
2021-05-06 09:39:21 +02:00
Jonas Jenwald
0a32ad3e42 Remove unnecessary closure in the src/core/font_renderer.js file
With modern JavaScript modules, where you explicitly list the properties that should be exported, it's no longer necessary to wrap *all* of the code within one file into a top-level closure.[1]

This patch reduces the size, of even the *built* `pdf.worker.js` file, since there's now a lot less unnecessary whitespace.

---
[1] For files which contain *different* functionality, some closures may however still make sense in order to separate the code.
It might be possible to remove some of those cases later, e.g. once private class fields becomes generally available/usable in browsers.
2021-05-05 22:35:52 +02:00
Tim van der Meij
afb8c4fd25
Merge pull request #13327 from Snuffleupagus/split-fonts
Split the functionality in `src/core/fonts.js` into multiple files, and use standard classes
2021-05-05 20:16:24 +02:00
Tim van der Meij
2d24962bf7
Merge pull request #13339 from Snuffleupagus/textLayer-rm-closure
Remove unnecessary closure in `src/display/text_layer.js`, and use standard classes
2021-05-05 20:04:42 +02:00
Tim van der Meij
c110618a8d
Merge pull request #13340 from calixteman/fix_integration_test1
Fix integration test in the windows bot
2021-05-05 19:59:12 +02:00
Calixte Denizet
451091b89b Fix integration test in the windows bot 2021-05-05 19:05:08 +02:00
Jonas Jenwald
9a1758c6b8 Remove unnecessary closure in src/display/text_layer.js, and use standard classes
With modern JavaScript modules, where you explicitly list the properties that should be exported, it's no longer necessary to wrap all of the code in a closure.[1]

This patch also tries to clean-up/improve a couple of the existing JSDoc-comments.

---
[1] This reduces the size, even of the *built* `pdf.js` file, since there's now a lot less unnecessary whitespace.
2021-05-05 18:44:56 +02:00
Jonas Jenwald
ce14171cf0 Convert src/core/jpx.js to use standard classes
*Please note:* Ignoring whitespace-only changes is probably necessary in order to review this.
2021-05-05 14:02:21 +02:00
Jonas Jenwald
cb65b762eb Fix the remaining no-var failures, which couldn't be handled automatically, in the src/core/jpx.js file 2021-05-05 14:02:21 +02:00
Jonas Jenwald
a273599a12 Enable the no-var rule in the src/core/jpx.js file
These changes were made automatically, using `gulp lint --fix`.
2021-05-05 14:02:21 +02:00
Jonas Jenwald
69dea39a42 Convert src/core/jpg.js to use standard classes
*Please note:* Ignoring whitespace-only changes is probably necessary in order to review this.
2021-05-05 14:02:21 +02:00
Jonas Jenwald
d0a299713c Fix the remaining no-var failures, which couldn't be handled automatically, in the src/core/jpg.js file 2021-05-05 14:02:21 +02:00
Jonas Jenwald
1e5a179600 Enable the no-var rule in the src/core/jpg.js file
These changes were made automatically, using `gulp lint --fix`.
2021-05-05 14:02:21 +02:00
Jonas Jenwald
0addf3a0d4 Convert src/core/jbig2.js to use standard classes
*Please note:* Ignoring whitespace-only changes is probably necessary in order to review this.
2021-05-05 14:02:21 +02:00
Jonas Jenwald
d59c9ab3ab Fix the remaining no-var failures, which couldn't be handled automatically, in the src/core/jbig2.js file 2021-05-05 14:02:21 +02:00
Jonas Jenwald
7ca3a34e1f Enable the no-var rule in the src/core/jbig2.js file
These changes were made automatically, using `gulp lint --fix`.
2021-05-05 14:02:21 +02:00
calixteman
52961197d3
Merge pull request #13337 from Snuffleupagus/PredictorStream-super
[Regression] Move the `super`-call in the `PredictorStream`-constructor to prevent errors (PR 13303)
2021-05-05 13:58:21 +02:00
Jonas Jenwald
99fae47c8e [Regression] Move the super-call in the PredictorStream-constructor to prevent errors (PR 13303)
*My apologies for breaking this; thankfully PR 13303 hasn't reach mozilla-central yet.*

It's (obviously) necessary to initialize a `PredictorStream`-instance fully, since otherwise breakage may occur if there's errors during the actual stream parsing.
To reproduce this issue, try opening the PDF document from issue 13051 locally and observe the following message in the console:
```
Warning: Invalid stream: "ReferenceError: this hasn't been initialised - super() hasn't been called"
```
2021-05-05 13:24:12 +02:00
calixteman
a00913aeb2
Merge pull request #13333 from Snuffleupagus/debugger-no-var
[web/debugger.js] Enable the ESLint `no-var` rule
2021-05-05 09:41:09 +02:00
Brendan Dahl
226a049d54
Merge pull request #13274 from calixteman/issue13269
[JS] Fix several issues found in pdf in #13269
2021-05-04 18:40:59 -07:00
Calixte Denizet
3f29892d63 [JS] Fix several issues found in pdf in #13269
- app.alert and few other function can use an object as parameter ({cMsg: ...});
  - support app.alert with a question and a yes/no answer;
  - update field siblings when one is changed in an action;
  - stop calculation if calculate is set to false in the middle of calculations;
  - get a boolean for checkboxes when they've been set through annotationStorage instead of a string.
2021-05-04 19:21:51 +02:00
Jonas Jenwald
d99bc5091c [web/debugger.js] Enable the ESLint no-var rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:

```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
     }
     if ("length" in args) {
       // array
-      let simpleArgs = [],
-        i,
-        ii;
-      const MAX_ITEMS = 10;
+      const MAX_ITEMS = 10,
+        simpleArgs = [];
+      let i, ii;
       for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
         simpleArgs.push(simplifyArgs(args[i]));
       }
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
   return {
     tools: [FontInspector, StepperManager, Stats],
     enable(ids) {
-      let all = false,
-        tools = this.tools;
-      if (ids.length === 1 && ids[0] === "all") {
-        all = true;
-      }
+      const all = ids.length === 1 && ids[0] === "all";
+      const tools = this.tools;
       for (let i = 0; i < tools.length; ++i) {
         const tool = tools[i];
         if (all || ids.includes(tool.id)) {
```
2021-05-04 16:29:11 +02:00
Jonas Jenwald
82afa8ccf0 [web/debugger.js] Convert the Stepper to a standard class
Also, removes a couple of unnecessary local variables in the `Stepper.breakIt` method.

Finally, this patch also disables the ESLint `no-var` rule, in preparation for the next patch, for a couple of data-structures that need to remain globally available.
2021-05-04 16:25:20 +02:00
calixteman
3f187c2c6d
Merge pull request #13319 from calixteman/js_page
JS -- add support for page property in field
2021-05-03 16:25:58 +02:00
Calixte Denizet
549aae6c3d JS -- add support for page property in field 2021-05-03 15:46:29 +02:00
Jonas Jenwald
5e5daca407 Remove unnecessary MissingDataException check from getHeaderBlock
It shouldn't be possible for the `getBytes`-call to throw a `MissingDataException`, since all resources are loaded *before* e.g. font-parsing ever starts; see f0817015bd/src/core/object_loader.js (L111-L126)

Furthermore, even if we'd *somehow* re-throw a `MissingDataException` here that still won't help considering where the `Type1Font`-instance is created. Note how in the `Font`-constructor we simply catch any errors and fallback to a standard font, which means that a `MissingDataException` would just lead to rendering errors anyway; see f0817015bd/src/core/fonts.js (L648-L691)

All-in-all, it's not possible for a `MissingDataException` to be thrown in `getHeaderBlock` and this code-path can thus be removed.
2021-05-03 13:57:30 +02:00
Jonas Jenwald
b487edd05d Convert src/core/fonts.js to use standard classes
Obviously the `Font`-class is still *very* large, given particularly how TrueType fonts are handled, however this patch-series at least improves things by moving a number of functions/classes into their own files.
As a follow-up it might make sense to try and re-factor/extract the TrueType parsing into its own file, since all of this code is quite old, however that's probably best left for another time.

For e.g. `gulp mozcentral`, the *built* `pdf.worker.js` files decreases from `1 620 332` to `1 617 466` bytes with this patch-series.
2021-05-03 13:57:25 +02:00
Jonas Jenwald
cadc20d8b9 Fix the remaining no-var failures, which couldn't be handled automatically, in the src/core/fonts.js file 2021-05-02 21:00:29 +02:00
Jonas Jenwald
b9cd080c01 Enable the no-var rule in the src/core/fonts.js file
These changes were made automatically, using `gulp lint --fix`.
Given the large size of this patch, the manual fixes are done separately in the next commit.
2021-05-02 21:00:29 +02:00
Jonas Jenwald
f64b7922b3 Convert src/core/type1_font.js to use standard classes 2021-05-02 21:00:29 +02:00
Jonas Jenwald
4bd69556ab Enable the no-var rule in the src/core/type1_font.js file
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:

```diff
diff --git a/src/core/type1_font.js b/src/core/type1_font.js
index 50a3e49e6..55a2005fb 100644
--- a/src/core/type1_font.js
+++ b/src/core/type1_font.js
@@ -38,10 +38,9 @@ const Type1Font = (function Type1FontClosure() {
     const scanLength = streamBytesLength - signatureLength;

     let i = startIndex,
-      j,
       found = false;
     while (i < scanLength) {
-      j = 0;
+      let j = 0;
       while (j < signatureLength && streamBytes[i + j] === signature[j]) {
         j++;
       }
@@ -248,14 +247,14 @@ const Type1Font = (function Type1FontClosure() {
         return charCodeToGlyphId;
       }

-      let glyphNames = [".notdef"],
-        glyphId;
+      const glyphNames = [".notdef"];
+      let builtInEncoding, glyphId;
       for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
         glyphNames.push(charstrings[glyphId].glyphName);
       }
       const encoding = properties.builtInEncoding;
       if (encoding) {
-        var builtInEncoding = Object.create(null);
+        builtInEncoding = Object.create(null);
         for (const charCode in encoding) {
           glyphId = glyphNames.indexOf(encoding[charCode]);
           if (glyphId >= 0
```
2021-05-02 21:00:29 +02:00
Jonas Jenwald
ff85bcfc0e Move the Type1Font from src/core/fonts.js and into its own file 2021-05-02 21:00:29 +02:00
Jonas Jenwald
e803584fe7 Convert src/core/cff_font.js to use standard classes 2021-05-02 21:00:29 +02:00
Jonas Jenwald
542ee0d798 Enable the no-var rule in the src/core/cff_font.js file
These changes were made automatically, using `gulp lint --fix`.
2021-05-02 21:00:29 +02:00
Jonas Jenwald
d5d73e3168 Move the CFFFont from src/core/fonts.js and into its own file 2021-05-02 21:00:29 +02:00
Jonas Jenwald
d4606712f2 Enable the no-var rule in the src/core/fonts_utils.js file
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:

```diff
diff --git a/src/core/fonts_utils.js b/src/core/fonts_utils.js
index f88ce4a8c..c4b3f3808 100644
--- a/src/core/fonts_utils.js
+++ b/src/core/fonts_utils.js
@@ -167,8 +167,8 @@ function type1FontGlyphMapping(properties, builtInEncoding,
glyphNames) {
   }

   // Lastly, merge in the differences.
-  let differences = properties.differences,
-    glyphsUnicodeMap;
+  const differences = properties.differences;
+  let glyphsUnicodeMap;
   if (differences) {
     for (charCode in differences) {
       const glyphName = differences[charCode];
```
2021-05-02 21:00:29 +02:00
Jonas Jenwald
77b258440b Move some constants and helper functions from src/core/fonts.js and into their own file
- `FontFlags`, is used in both `src/core/fonts.js` and `src/core/evaluator.js`.
 - `getFontType`, same as the above.
 - `MacStandardGlyphOrdering`, is a fairly large data-structure and `src/core/fonts.js` is already a *very* large file.
 - `recoverGlyphName`, a dependency of `type1FontGlyphMapping`; please see below.
 - `SEAC_ANALYSIS_ENABLED`, is used by both `Type1Font`, `CFFFont`, and unit-tests; please see below.
 - `type1FontGlyphMapping`, is used by both `Type1Font` and `CFFFont` which a later patch will move to their own files.
2021-05-02 21:00:29 +02:00