pdfjs-dist 2.6.347 → 2.7.570

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

Files changed (158) hide show
  1. package/README.md +3 -3
  2. package/bower.json +1 -1
  3. package/build/pdf.js +2050 -1087
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +18219 -10436
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/es5/build/pdf.d.ts +1 -0
  10. package/es5/build/pdf.js +6623 -6654
  11. package/es5/build/pdf.js.map +1 -1
  12. package/es5/build/pdf.min.js +1 -1
  13. package/es5/build/pdf.worker.js +20815 -13888
  14. package/es5/build/pdf.worker.js.map +1 -1
  15. package/es5/build/pdf.worker.min.js +1 -1
  16. package/es5/image_decoders/pdf.image_decoders.js +3817 -4946
  17. package/es5/image_decoders/pdf.image_decoders.js.map +1 -1
  18. package/es5/image_decoders/pdf.image_decoders.min.js +1 -1
  19. package/es5/web/pdf_viewer.css +18 -15
  20. package/es5/web/pdf_viewer.js +1094 -514
  21. package/es5/web/pdf_viewer.js.map +1 -1
  22. package/image_decoders/pdf.image_decoders.js +774 -168
  23. package/image_decoders/pdf.image_decoders.js.map +1 -1
  24. package/image_decoders/pdf.image_decoders.min.js +1 -1
  25. package/lib/core/annotation.js +556 -108
  26. package/lib/core/cff_parser.js +7 -1
  27. package/lib/core/charsets.js +1 -1
  28. package/lib/core/cmap.js +20 -1
  29. package/lib/core/core_utils.js +162 -3
  30. package/lib/core/crypto.js +1 -1
  31. package/lib/core/default_appearance.js +132 -0
  32. package/lib/core/document.js +115 -9
  33. package/lib/core/encodings.js +1 -1
  34. package/lib/core/evaluator.js +168 -74
  35. package/lib/core/fonts.js +97 -11
  36. package/lib/core/function.js +5 -10
  37. package/lib/core/glyphlist.js +11 -4529
  38. package/lib/core/image_utils.js +30 -1
  39. package/lib/core/jpg.js +1 -1
  40. package/lib/core/jpx.js +5 -5
  41. package/lib/core/murmurhash3.js +1 -1
  42. package/lib/core/obj.js +123 -39
  43. package/lib/core/pattern.js +4 -4
  44. package/lib/core/primitives.js +24 -5
  45. package/lib/core/standard_fonts.js +1 -1
  46. package/lib/core/stream.js +5 -1
  47. package/lib/core/unicode.js +15 -1387
  48. package/lib/core/worker.js +58 -17
  49. package/lib/core/writer.js +68 -4
  50. package/lib/display/annotation_layer.js +712 -119
  51. package/lib/display/annotation_storage.js +21 -4
  52. package/lib/display/api.js +88 -18
  53. package/lib/display/canvas.js +414 -375
  54. package/lib/display/display_utils.js +11 -4
  55. package/lib/display/fetch_stream.js +3 -3
  56. package/lib/display/font_loader.js +2 -3
  57. package/lib/display/metadata.js +54 -20
  58. package/lib/display/node_stream.js +1 -1
  59. package/lib/display/optional_content_config.js +1 -1
  60. package/lib/display/pattern_helper.js +109 -113
  61. package/lib/display/svg.js +5 -5
  62. package/lib/display/text_layer.js +54 -54
  63. package/lib/display/transport_stream.js +4 -4
  64. package/lib/display/webgl.js +65 -68
  65. package/lib/examples/node/domstubs.js +9 -4
  66. package/lib/pdf.js +2 -2
  67. package/lib/pdf.sandbox.js +311 -0
  68. package/lib/pdf.worker.js +2 -2
  69. package/lib/shared/scripting_utils.js +84 -0
  70. package/lib/shared/util.js +129 -14
  71. package/lib/{display → shared}/xml_parser.js +112 -4
  72. package/lib/test/unit/annotation_spec.js +831 -109
  73. package/lib/test/unit/annotation_storage_spec.js +28 -10
  74. package/lib/test/unit/api_spec.js +190 -160
  75. package/lib/test/unit/bidi_spec.js +6 -6
  76. package/lib/test/unit/cff_parser_spec.js +73 -73
  77. package/lib/test/unit/clitests_helper.js +2 -0
  78. package/lib/test/unit/cmap_spec.js +48 -74
  79. package/lib/test/unit/core_utils_spec.js +34 -0
  80. package/lib/test/unit/crypto_spec.js +162 -199
  81. package/lib/test/unit/custom_spec.js +7 -18
  82. package/lib/test/unit/default_appearance_spec.js +54 -0
  83. package/lib/test/unit/display_svg_spec.js +24 -19
  84. package/lib/test/unit/display_utils_spec.js +1 -1
  85. package/lib/test/unit/document_spec.js +187 -20
  86. package/lib/test/unit/evaluator_spec.js +30 -30
  87. package/lib/test/unit/function_spec.js +165 -165
  88. package/lib/test/unit/jasmine-boot.js +52 -53
  89. package/lib/test/unit/metadata_spec.js +2 -2
  90. package/lib/test/unit/murmurhash3_spec.js +29 -16
  91. package/lib/test/unit/network_spec.js +21 -21
  92. package/lib/test/unit/pdf_find_controller_spec.js +131 -69
  93. package/lib/test/unit/pdf_find_utils_spec.js +10 -10
  94. package/lib/test/unit/scripting_spec.js +1104 -0
  95. package/lib/test/unit/stream_spec.js +8 -8
  96. package/lib/test/unit/test_utils.js +16 -19
  97. package/lib/test/unit/testreporter.js +11 -4
  98. package/lib/test/unit/type1_parser_spec.js +23 -23
  99. package/lib/test/unit/ui_utils_spec.js +78 -35
  100. package/lib/test/unit/unicode_spec.js +7 -7
  101. package/lib/test/unit/util_spec.js +26 -3
  102. package/lib/test/unit/writer_spec.js +16 -1
  103. package/lib/test/unit/xml_spec.js +117 -0
  104. package/lib/web/annotation_layer_builder.js +18 -6
  105. package/lib/web/app.js +579 -161
  106. package/lib/web/app_options.js +14 -0
  107. package/lib/web/base_tree_viewer.js +50 -0
  108. package/lib/web/base_viewer.js +350 -14
  109. package/lib/web/chromecom.js +9 -1
  110. package/lib/web/debugger.js +1 -2
  111. package/lib/web/download_manager.js +0 -15
  112. package/lib/web/firefox_print_service.js +6 -4
  113. package/lib/web/firefoxcom.js +84 -69
  114. package/lib/web/generic_scripting.js +55 -0
  115. package/lib/web/genericcom.js +9 -1
  116. package/lib/web/grab_to_pan.js +1 -1
  117. package/lib/web/interfaces.js +9 -3
  118. package/lib/web/pdf_attachment_viewer.js +1 -3
  119. package/lib/web/pdf_cursor_tools.js +20 -13
  120. package/lib/web/pdf_document_properties.js +48 -61
  121. package/lib/web/pdf_find_bar.js +1 -3
  122. package/lib/web/pdf_find_controller.js +58 -12
  123. package/lib/web/pdf_history.js +43 -21
  124. package/lib/web/pdf_layer_viewer.js +1 -9
  125. package/lib/web/pdf_link_service.js +108 -78
  126. package/lib/web/pdf_outline_viewer.js +166 -10
  127. package/lib/web/pdf_page_view.js +14 -14
  128. package/lib/web/pdf_presentation_mode.js +21 -31
  129. package/lib/web/pdf_rendering_queue.js +8 -1
  130. package/lib/web/pdf_sidebar.js +62 -107
  131. package/lib/web/pdf_sidebar_resizer.js +11 -21
  132. package/lib/web/pdf_single_page_viewer.js +8 -0
  133. package/lib/web/pdf_thumbnail_view.js +26 -26
  134. package/lib/web/pdf_thumbnail_viewer.js +13 -2
  135. package/lib/web/pdf_viewer.component.js +2 -2
  136. package/lib/web/pdf_viewer.js +3 -1
  137. package/lib/web/preferences.js +33 -44
  138. package/lib/web/text_layer_builder.js +2 -9
  139. package/lib/web/ui_utils.js +78 -46
  140. package/lib/web/viewer_compatibility.js +1 -2
  141. package/package.json +4 -1
  142. package/types/display/annotation_layer.d.ts +18 -3
  143. package/types/display/api.d.ts +110 -54
  144. package/types/display/canvas.d.ts +1 -1
  145. package/types/display/display_utils.d.ts +96 -95
  146. package/types/display/fetch_stream.d.ts +2 -2
  147. package/types/display/metadata.d.ts +4 -0
  148. package/types/display/pattern_helper.d.ts +1 -1
  149. package/types/display/text_layer.d.ts +7 -7
  150. package/types/display/transport_stream.d.ts +1 -1
  151. package/types/shared/scripting_utils.d.ts +12 -0
  152. package/types/shared/util.d.ts +281 -250
  153. package/types/shared/xml_parser.d.ts +64 -0
  154. package/web/pdf_viewer.css +18 -15
  155. package/web/pdf_viewer.js +809 -408
  156. package/web/pdf_viewer.js.map +1 -1
  157. package/webpack.js +1 -1
  158. package/types/display/xml_parser.d.ts +0 -35
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @licstart The following is the entire license notice for the
3
+ * Javascript code in this page
4
+ *
5
+ * Copyright 2020 Mozilla Foundation
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ * @licend The above is the entire license notice for the
20
+ * Javascript code in this page
21
+ */
22
+ "use strict";
23
+
24
+ var _default_appearance = require("../../core/default_appearance.js");
25
+
26
+ var _primitives = require("../../core/primitives.js");
27
+
28
+ describe("Default appearance", function () {
29
+ describe("parseDefaultAppearance and createDefaultAppearance", function () {
30
+ it("should parse and create default appearance", function () {
31
+ const da = "/F1 12 Tf 0.10 0.20 0.30 rg";
32
+ const result = {
33
+ fontSize: 12,
34
+ fontName: _primitives.Name.get("F1"),
35
+ fontColor: new Uint8ClampedArray([26, 51, 76])
36
+ };
37
+ expect((0, _default_appearance.parseDefaultAppearance)(da)).toEqual(result);
38
+ expect((0, _default_appearance.createDefaultAppearance)(result)).toEqual(da);
39
+ expect((0, _default_appearance.parseDefaultAppearance)("0.1 0.2 0.3 rg /F1 12 Tf 0.3 0.2 0.1 rg /F2 13 Tf")).toEqual({
40
+ fontSize: 13,
41
+ fontName: _primitives.Name.get("F2"),
42
+ fontColor: new Uint8ClampedArray([76, 51, 26])
43
+ });
44
+ });
45
+ it("should parse default appearance with save/restore", function () {
46
+ const da = "q Q 0.10 0.20 0.30 rg /F1 12 Tf q 0.30 0.20 0.10 rg /F2 13 Tf Q";
47
+ expect((0, _default_appearance.parseDefaultAppearance)(da)).toEqual({
48
+ fontSize: 12,
49
+ fontName: _primitives.Name.get("F1"),
50
+ fontColor: new Uint8ClampedArray([26, 51, 76])
51
+ });
52
+ });
53
+ });
54
+ });
@@ -21,8 +21,6 @@
21
21
  */
22
22
  "use strict";
23
23
 
24
- var _domstubs = require("../../examples/node/domstubs.js");
25
-
26
24
  var _test_utils = require("./test_utils.js");
27
25
 
28
26
  var _api = require("../../display/api.js");
@@ -46,9 +44,9 @@ function withZlib(isZlibRequired, callback) {
46
44
  return callback();
47
45
  }
48
46
 
49
- var zlib = require("zlib");
47
+ const zlib = require("zlib");
50
48
 
51
- var deflateSync = zlib.deflateSync;
49
+ const deflateSync = zlib.deflateSync;
52
50
  zlib.deflateSync = disabledDeflateSync;
53
51
 
54
52
  function disabledDeflateSync() {
@@ -61,14 +59,14 @@ function withZlib(isZlibRequired, callback) {
61
59
  }
62
60
  }
63
61
 
64
- var promise = callback();
62
+ const promise = callback();
65
63
  promise.then(restoreDeflateSync, restoreDeflateSync);
66
64
  return promise;
67
65
  }
68
66
 
69
67
  describe("SVGGraphics", function () {
70
- var loadingTask;
71
- var page;
68
+ let loadingTask;
69
+ let page;
72
70
  beforeAll(function (done) {
73
71
  loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("xobject-image.pdf"));
74
72
  loadingTask.promise.then(function (doc) {
@@ -83,31 +81,39 @@ describe("SVGGraphics", function () {
83
81
  });
84
82
  describe("paintImageXObject", function () {
85
83
  function getSVGImage() {
86
- var svgGfx;
84
+ let svgGfx;
87
85
  return page.getOperatorList().then(function (opList) {
88
- var forceDataSchema = true;
86
+ const forceDataSchema = true;
89
87
  svgGfx = new _svg.SVGGraphics(page.commonObjs, page.objs, forceDataSchema);
90
88
  return svgGfx.loadDependencies(opList);
91
89
  }).then(function () {
92
- var svgImg;
93
- var elementContainer = {
90
+ let svgImg;
91
+ const elementContainer = {
94
92
  appendChild(element) {
95
93
  svgImg = element;
96
94
  }
97
95
 
98
96
  };
99
- var xobjectObjId = "img_p0_1";
97
+ const xobjectObjId = "img_p0_1";
100
98
 
101
99
  if (_is_node.isNodeJS) {
102
- (0, _domstubs.setStubs)(global);
100
+ const {
101
+ setStubs
102
+ } = require("../../examples/node/domstubs.js");
103
+
104
+ setStubs(global);
103
105
  }
104
106
 
105
107
  try {
106
- var imgData = svgGfx.objs.get(xobjectObjId);
108
+ const imgData = svgGfx.objs.get(xobjectObjId);
107
109
  svgGfx.paintInlineImageXObject(imgData, elementContainer);
108
110
  } finally {
109
111
  if (_is_node.isNodeJS) {
110
- (0, _domstubs.unsetStubs)(global);
112
+ const {
113
+ unsetStubs
114
+ } = require("../../examples/node/domstubs.js");
115
+
116
+ unsetStubs(global);
111
117
  }
112
118
  }
113
119
 
@@ -120,9 +126,8 @@ describe("SVGGraphics", function () {
120
126
  require("zlib");
121
127
  }
122
128
 
123
- expect(testFunc.toString()).toMatch(/\srequire\(["']zlib["']\)/);
124
-
125
129
  if (_is_node.isNodeJS) {
130
+ expect(testFunc.toString()).toMatch(/\srequire\(["']zlib["']\)/);
126
131
  expect(testFunc).not.toThrow();
127
132
  } else {
128
133
  expect(testFunc).toThrow();
@@ -137,7 +142,7 @@ describe("SVGGraphics", function () {
137
142
  expect(svgImg.nodeName).toBe("svg:image");
138
143
  expect(svgImg.getAttributeNS(null, "width")).toBe("200px");
139
144
  expect(svgImg.getAttributeNS(null, "height")).toBe("100px");
140
- var imgUrl = svgImg.getAttributeNS(XLINK_NS, "href");
145
+ const imgUrl = svgImg.getAttributeNS(XLINK_NS, "href");
141
146
  expect(imgUrl).toMatch(/^data:image\/png;base64,/);
142
147
  expect(imgUrl.length).toBeLessThan(367);
143
148
  }).then(done, done.fail);
@@ -147,7 +152,7 @@ describe("SVGGraphics", function () {
147
152
  expect(svgImg.nodeName).toBe("svg:image");
148
153
  expect(svgImg.getAttributeNS(null, "width")).toBe("200px");
149
154
  expect(svgImg.getAttributeNS(null, "height")).toBe("100px");
150
- var imgUrl = svgImg.getAttributeNS(XLINK_NS, "href");
155
+ const imgUrl = svgImg.getAttributeNS(XLINK_NS, "href");
151
156
  expect(imgUrl).toMatch(/^data:image\/png;base64,/);
152
157
  expect(imgUrl.length).toBe(80246);
153
158
  }).then(done, done.fail);
@@ -203,7 +203,7 @@ describe("display_utils", function () {
203
203
  undefined: null,
204
204
  null: null,
205
205
  42: null,
206
- "2019": null,
206
+ 2019: null,
207
207
  D2019: null,
208
208
  "D:": null,
209
209
  "D:201": null,
@@ -52,19 +52,37 @@ describe("document", function () {
52
52
  });
53
53
  });
54
54
  describe("PDFDocument", function () {
55
- const pdfManager = {
56
- get docId() {
57
- return "d0";
58
- }
59
-
60
- };
61
55
  const stream = new _stream.StringStream("Dummy_PDF_data");
62
56
 
63
- function getDocument(acroForm) {
64
- const pdfDocument = new _document.PDFDocument(pdfManager, stream);
65
- pdfDocument.catalog = {
57
+ function getDocument(acroForm, xref = new _test_utils.XRefMock()) {
58
+ const catalog = {
66
59
  acroForm
67
60
  };
61
+ const pdfManager = {
62
+ get docId() {
63
+ return "d0";
64
+ },
65
+
66
+ ensureCatalog(prop, args) {
67
+ return pdfManager.ensure(catalog, prop, args);
68
+ },
69
+
70
+ ensure(obj, prop, args) {
71
+ return new Promise(function (resolve) {
72
+ const value = obj[prop];
73
+
74
+ if (typeof value === "function") {
75
+ resolve(value.apply(obj, args));
76
+ } else {
77
+ resolve(value);
78
+ }
79
+ });
80
+ }
81
+
82
+ };
83
+ const pdfDocument = new _document.PDFDocument(pdfManager, stream);
84
+ pdfDocument.xref = xref;
85
+ pdfDocument.catalog = catalog;
68
86
  return pdfDocument;
69
87
  }
70
88
 
@@ -72,7 +90,8 @@ describe("document", function () {
72
90
  const pdfDocument = getDocument(null);
73
91
  expect(pdfDocument.formInfo).toEqual({
74
92
  hasAcroForm: false,
75
- hasXfa: false
93
+ hasXfa: false,
94
+ hasFields: false
76
95
  });
77
96
  });
78
97
  it("should get form info when XFA is present", function () {
@@ -81,25 +100,29 @@ describe("document", function () {
81
100
  let pdfDocument = getDocument(acroForm);
82
101
  expect(pdfDocument.formInfo).toEqual({
83
102
  hasAcroForm: false,
84
- hasXfa: false
103
+ hasXfa: false,
104
+ hasFields: false
85
105
  });
86
106
  acroForm.set("XFA", ["foo", "bar"]);
87
107
  pdfDocument = getDocument(acroForm);
88
108
  expect(pdfDocument.formInfo).toEqual({
89
109
  hasAcroForm: false,
90
- hasXfa: true
110
+ hasXfa: true,
111
+ hasFields: false
91
112
  });
92
113
  acroForm.set("XFA", new _stream.StringStream(""));
93
114
  pdfDocument = getDocument(acroForm);
94
115
  expect(pdfDocument.formInfo).toEqual({
95
116
  hasAcroForm: false,
96
- hasXfa: false
117
+ hasXfa: false,
118
+ hasFields: false
97
119
  });
98
120
  acroForm.set("XFA", new _stream.StringStream("non-empty"));
99
121
  pdfDocument = getDocument(acroForm);
100
122
  expect(pdfDocument.formInfo).toEqual({
101
123
  hasAcroForm: false,
102
- hasXfa: true
124
+ hasXfa: true,
125
+ hasFields: false
103
126
  });
104
127
  });
105
128
  it("should get form info when AcroForm is present", function () {
@@ -108,20 +131,23 @@ describe("document", function () {
108
131
  let pdfDocument = getDocument(acroForm);
109
132
  expect(pdfDocument.formInfo).toEqual({
110
133
  hasAcroForm: false,
111
- hasXfa: false
134
+ hasXfa: false,
135
+ hasFields: false
112
136
  });
113
137
  acroForm.set("Fields", ["foo", "bar"]);
114
138
  pdfDocument = getDocument(acroForm);
115
139
  expect(pdfDocument.formInfo).toEqual({
116
140
  hasAcroForm: true,
117
- hasXfa: false
141
+ hasXfa: false,
142
+ hasFields: true
118
143
  });
119
144
  acroForm.set("Fields", ["foo", "bar"]);
120
145
  acroForm.set("SigFlags", 2);
121
146
  pdfDocument = getDocument(acroForm);
122
147
  expect(pdfDocument.formInfo).toEqual({
123
148
  hasAcroForm: true,
124
- hasXfa: false
149
+ hasXfa: false,
150
+ hasFields: true
125
151
  });
126
152
  const annotationDict = new _primitives.Dict();
127
153
  annotationDict.set("FT", _primitives.Name.get("Sig"));
@@ -134,7 +160,7 @@ describe("document", function () {
134
160
 
135
161
  const kidsRef = _primitives.Ref.get(10, 0);
136
162
 
137
- pdfDocument.xref = new _test_utils.XRefMock([{
163
+ const xref = new _test_utils.XRefMock([{
138
164
  ref: annotationRef,
139
165
  data: annotationDict
140
166
  }, {
@@ -143,11 +169,152 @@ describe("document", function () {
143
169
  }]);
144
170
  acroForm.set("Fields", [kidsRef]);
145
171
  acroForm.set("SigFlags", 3);
146
- pdfDocument = getDocument(acroForm);
172
+ pdfDocument = getDocument(acroForm, xref);
147
173
  expect(pdfDocument.formInfo).toEqual({
148
174
  hasAcroForm: false,
149
- hasXfa: false
175
+ hasXfa: false,
176
+ hasFields: true
150
177
  });
151
178
  });
179
+ it("should get calculation order array or null", function () {
180
+ const acroForm = new _primitives.Dict();
181
+ let pdfDocument = getDocument(acroForm);
182
+ expect(pdfDocument.calculationOrderIds).toEqual(null);
183
+ acroForm.set("CO", [_primitives.Ref.get(1, 0), _primitives.Ref.get(2, 0), _primitives.Ref.get(3, 0)]);
184
+ pdfDocument = getDocument(acroForm);
185
+ expect(pdfDocument.calculationOrderIds).toEqual(["1R", "2R", "3R"]);
186
+ acroForm.set("CO", []);
187
+ pdfDocument = getDocument(acroForm);
188
+ expect(pdfDocument.calculationOrderIds).toEqual(null);
189
+ acroForm.set("CO", ["1", "2"]);
190
+ pdfDocument = getDocument(acroForm);
191
+ expect(pdfDocument.calculationOrderIds).toEqual(null);
192
+ acroForm.set("CO", ["1", _primitives.Ref.get(1, 0), "2"]);
193
+ pdfDocument = getDocument(acroForm);
194
+ expect(pdfDocument.calculationOrderIds).toEqual(["1R"]);
195
+ });
196
+ it("should get field objects array or null", async function () {
197
+ const acroForm = new _primitives.Dict();
198
+ let pdfDocument = getDocument(acroForm);
199
+ let fields = await pdfDocument.fieldObjects;
200
+ expect(fields).toEqual(null);
201
+ acroForm.set("Fields", []);
202
+ pdfDocument = getDocument(acroForm);
203
+ fields = await pdfDocument.fieldObjects;
204
+ expect(fields).toEqual(null);
205
+
206
+ const kid1Ref = _primitives.Ref.get(314, 0);
207
+
208
+ const kid11Ref = _primitives.Ref.get(159, 0);
209
+
210
+ const kid2Ref = _primitives.Ref.get(265, 0);
211
+
212
+ const kid2BisRef = _primitives.Ref.get(266, 0);
213
+
214
+ const parentRef = _primitives.Ref.get(358, 0);
215
+
216
+ const allFields = Object.create(null);
217
+
218
+ for (const name of ["parent", "kid1", "kid2", "kid11"]) {
219
+ const buttonWidgetDict = new _primitives.Dict();
220
+ buttonWidgetDict.set("Type", _primitives.Name.get("Annot"));
221
+ buttonWidgetDict.set("Subtype", _primitives.Name.get("Widget"));
222
+ buttonWidgetDict.set("FT", _primitives.Name.get("Btn"));
223
+ buttonWidgetDict.set("T", name);
224
+ allFields[name] = buttonWidgetDict;
225
+ }
226
+
227
+ allFields.kid1.set("Kids", [kid11Ref]);
228
+ allFields.parent.set("Kids", [kid1Ref, kid2Ref, kid2BisRef]);
229
+ const xref = new _test_utils.XRefMock([{
230
+ ref: parentRef,
231
+ data: allFields.parent
232
+ }, {
233
+ ref: kid1Ref,
234
+ data: allFields.kid1
235
+ }, {
236
+ ref: kid11Ref,
237
+ data: allFields.kid11
238
+ }, {
239
+ ref: kid2Ref,
240
+ data: allFields.kid2
241
+ }, {
242
+ ref: kid2BisRef,
243
+ data: allFields.kid2
244
+ }]);
245
+ acroForm.set("Fields", [parentRef]);
246
+ pdfDocument = getDocument(acroForm, xref);
247
+ fields = await pdfDocument.fieldObjects;
248
+
249
+ for (const [name, objs] of Object.entries(fields)) {
250
+ fields[name] = objs.map(obj => obj.id);
251
+ }
252
+
253
+ expect(fields["parent.kid1"]).toEqual(["314R"]);
254
+ expect(fields["parent.kid1.kid11"]).toEqual(["159R"]);
255
+ expect(fields["parent.kid2"]).toEqual(["265R", "266R"]);
256
+ expect(fields.parent).toEqual(["358R"]);
257
+ });
258
+ it("should check if fields have any actions", async function () {
259
+ const acroForm = new _primitives.Dict();
260
+ let pdfDocument = getDocument(acroForm);
261
+ let hasJSActions = await pdfDocument.hasJSActions;
262
+ expect(hasJSActions).toEqual(false);
263
+ acroForm.set("Fields", []);
264
+ pdfDocument = getDocument(acroForm);
265
+ hasJSActions = await pdfDocument.hasJSActions;
266
+ expect(hasJSActions).toEqual(false);
267
+
268
+ const kid1Ref = _primitives.Ref.get(314, 0);
269
+
270
+ const kid11Ref = _primitives.Ref.get(159, 0);
271
+
272
+ const kid2Ref = _primitives.Ref.get(265, 0);
273
+
274
+ const parentRef = _primitives.Ref.get(358, 0);
275
+
276
+ const allFields = Object.create(null);
277
+
278
+ for (const name of ["parent", "kid1", "kid2", "kid11"]) {
279
+ const buttonWidgetDict = new _primitives.Dict();
280
+ buttonWidgetDict.set("Type", _primitives.Name.get("Annot"));
281
+ buttonWidgetDict.set("Subtype", _primitives.Name.get("Widget"));
282
+ buttonWidgetDict.set("FT", _primitives.Name.get("Btn"));
283
+ buttonWidgetDict.set("T", name);
284
+ allFields[name] = buttonWidgetDict;
285
+ }
286
+
287
+ allFields.kid1.set("Kids", [kid11Ref]);
288
+ allFields.parent.set("Kids", [kid1Ref, kid2Ref]);
289
+ const xref = new _test_utils.XRefMock([{
290
+ ref: parentRef,
291
+ data: allFields.parent
292
+ }, {
293
+ ref: kid1Ref,
294
+ data: allFields.kid1
295
+ }, {
296
+ ref: kid11Ref,
297
+ data: allFields.kid11
298
+ }, {
299
+ ref: kid2Ref,
300
+ data: allFields.kid2
301
+ }]);
302
+ acroForm.set("Fields", [parentRef]);
303
+ pdfDocument = getDocument(acroForm, xref);
304
+ hasJSActions = await pdfDocument.hasJSActions;
305
+ expect(hasJSActions).toEqual(false);
306
+
307
+ const JS = _primitives.Name.get("JavaScript");
308
+
309
+ const additionalActionsDict = new _primitives.Dict();
310
+ const eDict = new _primitives.Dict();
311
+ eDict.set("JS", "hello()");
312
+ eDict.set("S", JS);
313
+ additionalActionsDict.set("E", eDict);
314
+ allFields.kid2.set("AA", additionalActionsDict);
315
+ pdfDocument = getDocument(acroForm, xref);
316
+ hasJSActions = await pdfDocument.hasJSActions;
317
+ expect(hasJSActions).toEqual(true);
318
+ });
152
319
  });
153
320
  });
@@ -60,8 +60,8 @@ describe("evaluator", function () {
60
60
  };
61
61
 
62
62
  function runOperatorListCheck(evaluator, stream, resources, callback) {
63
- var result = new _operator_list.OperatorList();
64
- var task = new _worker.WorkerTask("OperatorListCheck");
63
+ const result = new _operator_list.OperatorList();
64
+ const task = new _worker.WorkerTask("OperatorListCheck");
65
65
  evaluator.getOperatorList({
66
66
  stream,
67
67
  task,
@@ -74,7 +74,7 @@ describe("evaluator", function () {
74
74
  });
75
75
  }
76
76
 
77
- var partialEvaluator;
77
+ let partialEvaluator;
78
78
  beforeAll(function (done) {
79
79
  partialEvaluator = new _evaluator.PartialEvaluator({
80
80
  xref: new _test_utils.XRefMock(),
@@ -89,7 +89,7 @@ describe("evaluator", function () {
89
89
  });
90
90
  describe("splitCombinedOperations", function () {
91
91
  it("should reject unknown operations", function (done) {
92
- var stream = new _stream.StringStream("fTT");
92
+ const stream = new _stream.StringStream("fTT");
93
93
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
94
94
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
95
95
  expect(result.fnArray.length).toEqual(1);
@@ -99,7 +99,7 @@ describe("evaluator", function () {
99
99
  });
100
100
  });
101
101
  it("should handle one operation", function (done) {
102
- var stream = new _stream.StringStream("Q");
102
+ const stream = new _stream.StringStream("Q");
103
103
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
104
104
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
105
105
  expect(result.fnArray.length).toEqual(1);
@@ -118,7 +118,7 @@ describe("evaluator", function () {
118
118
  xObject.set("Res1", imgStream);
119
119
  const resources = new ResourcesMock();
120
120
  resources.XObject = xObject;
121
- var stream = new _stream.StringStream("/Res1 DoQ");
121
+ const stream = new _stream.StringStream("/Res1 DoQ");
122
122
  runOperatorListCheck(partialEvaluator, stream, resources, function (result) {
123
123
  expect(result.fnArray.length).toEqual(3);
124
124
  expect(result.fnArray[0]).toEqual(_util.OPS.dependency);
@@ -132,7 +132,7 @@ describe("evaluator", function () {
132
132
  });
133
133
  });
134
134
  it("should handle three glued operations", function (done) {
135
- var stream = new _stream.StringStream("fff");
135
+ const stream = new _stream.StringStream("fff");
136
136
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
137
137
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
138
138
  expect(result.fnArray.length).toEqual(3);
@@ -143,9 +143,9 @@ describe("evaluator", function () {
143
143
  });
144
144
  });
145
145
  it("should handle three glued operations #2", function (done) {
146
- var resources = new ResourcesMock();
146
+ const resources = new ResourcesMock();
147
147
  resources.Res1 = {};
148
- var stream = new _stream.StringStream("B*Bf*");
148
+ const stream = new _stream.StringStream("B*Bf*");
149
149
  runOperatorListCheck(partialEvaluator, stream, resources, function (result) {
150
150
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
151
151
  expect(result.fnArray.length).toEqual(3);
@@ -156,7 +156,7 @@ describe("evaluator", function () {
156
156
  });
157
157
  });
158
158
  it("should handle glued operations and operands", function (done) {
159
- var stream = new _stream.StringStream("f5 Ts");
159
+ const stream = new _stream.StringStream("f5 Ts");
160
160
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
161
161
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
162
162
  expect(result.fnArray.length).toEqual(2);
@@ -169,7 +169,7 @@ describe("evaluator", function () {
169
169
  });
170
170
  });
171
171
  it("should handle glued operations and literals", function (done) {
172
- var stream = new _stream.StringStream("trueifalserinulln");
172
+ const stream = new _stream.StringStream("trueifalserinulln");
173
173
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
174
174
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
175
175
  expect(result.fnArray.length).toEqual(3);
@@ -188,7 +188,7 @@ describe("evaluator", function () {
188
188
  });
189
189
  describe("validateNumberOfArgs", function () {
190
190
  it("should execute if correct number of arguments", function (done) {
191
- var stream = new _stream.StringStream("5 1 d0");
191
+ const stream = new _stream.StringStream("5 1 d0");
192
192
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
193
193
  expect(result.argsArray[0][0]).toEqual(5);
194
194
  expect(result.argsArray[0][1]).toEqual(1);
@@ -197,7 +197,7 @@ describe("evaluator", function () {
197
197
  });
198
198
  });
199
199
  it("should execute if too many arguments", function (done) {
200
- var stream = new _stream.StringStream("5 1 4 d0");
200
+ const stream = new _stream.StringStream("5 1 4 d0");
201
201
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
202
202
  expect(result.argsArray[0][0]).toEqual(1);
203
203
  expect(result.argsArray[0][1]).toEqual(4);
@@ -213,7 +213,7 @@ describe("evaluator", function () {
213
213
  extGState.set("GS2", gState);
214
214
  const resources = new ResourcesMock();
215
215
  resources.ExtGState = extGState;
216
- var stream = new _stream.StringStream("/F2 /GS2 gs 5.711 Tf");
216
+ const stream = new _stream.StringStream("/F2 /GS2 gs 5.711 Tf");
217
217
  runOperatorListCheck(partialEvaluator, stream, resources, function (result) {
218
218
  expect(result.fnArray.length).toEqual(3);
219
219
  expect(result.fnArray[0]).toEqual(_util.OPS.setGState);
@@ -227,7 +227,7 @@ describe("evaluator", function () {
227
227
  });
228
228
  });
229
229
  it("should skip if too few arguments", function (done) {
230
- var stream = new _stream.StringStream("5 d0");
230
+ const stream = new _stream.StringStream("5 d0");
231
231
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
232
232
  expect(result.argsArray).toEqual([]);
233
233
  expect(result.fnArray).toEqual([]);
@@ -253,7 +253,7 @@ describe("evaluator", function () {
253
253
  });
254
254
  });
255
255
  it("should close opened saves", function (done) {
256
- var stream = new _stream.StringStream("qq");
256
+ const stream = new _stream.StringStream("qq");
257
257
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
258
258
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
259
259
  expect(result.fnArray.length).toEqual(4);
@@ -265,7 +265,7 @@ describe("evaluator", function () {
265
265
  });
266
266
  });
267
267
  it("should error on paintXObject if name is missing", function (done) {
268
- var stream = new _stream.StringStream("/ Do");
268
+ const stream = new _stream.StringStream("/ Do");
269
269
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
270
270
  expect(result instanceof _util.FormatError).toEqual(true);
271
271
  expect(result.message).toEqual("XObject must be referred to by name.");
@@ -273,14 +273,14 @@ describe("evaluator", function () {
273
273
  });
274
274
  });
275
275
  it("should skip paintXObject if subtype is PS", function (done) {
276
- var xobjStreamDict = new _primitives.Dict();
276
+ const xobjStreamDict = new _primitives.Dict();
277
277
  xobjStreamDict.set("Subtype", _primitives.Name.get("PS"));
278
- var xobjStream = new _stream.Stream([], 0, 0, xobjStreamDict);
279
- var xobjs = new _primitives.Dict();
278
+ const xobjStream = new _stream.Stream([], 0, 0, xobjStreamDict);
279
+ const xobjs = new _primitives.Dict();
280
280
  xobjs.set("Res1", xobjStream);
281
- var resources = new _primitives.Dict();
281
+ const resources = new _primitives.Dict();
282
282
  resources.set("XObject", xobjs);
283
- var stream = new _stream.StringStream("/Res1 Do");
283
+ const stream = new _stream.StringStream("/Res1 Do");
284
284
  runOperatorListCheck(partialEvaluator, stream, resources, function (result) {
285
285
  expect(result.argsArray).toEqual([]);
286
286
  expect(result.fnArray).toEqual([]);
@@ -290,10 +290,10 @@ describe("evaluator", function () {
290
290
  });
291
291
  describe("thread control", function () {
292
292
  it("should abort operator list parsing", function (done) {
293
- var stream = new _stream.StringStream("qqQQ");
294
- var resources = new ResourcesMock();
295
- var result = new _operator_list.OperatorList();
296
- var task = new _worker.WorkerTask("OperatorListAbort");
293
+ const stream = new _stream.StringStream("qqQQ");
294
+ const resources = new ResourcesMock();
295
+ const result = new _operator_list.OperatorList();
296
+ const task = new _worker.WorkerTask("OperatorListAbort");
297
297
  task.terminate();
298
298
  partialEvaluator.getOperatorList({
299
299
  stream,
@@ -307,9 +307,9 @@ describe("evaluator", function () {
307
307
  });
308
308
  });
309
309
  it("should abort text parsing parsing", function (done) {
310
- var resources = new ResourcesMock();
311
- var stream = new _stream.StringStream("qqQQ");
312
- var task = new _worker.WorkerTask("TextContentAbort");
310
+ const resources = new ResourcesMock();
311
+ const stream = new _stream.StringStream("qqQQ");
312
+ const task = new _worker.WorkerTask("TextContentAbort");
313
313
  task.terminate();
314
314
  partialEvaluator.getTextContent({
315
315
  stream,
@@ -328,7 +328,7 @@ describe("evaluator", function () {
328
328
  }
329
329
 
330
330
  it("should get correct total length after flushing", function () {
331
- var operatorList = new _operator_list.OperatorList(null, new StreamSinkMock());
331
+ const operatorList = new _operator_list.OperatorList(null, new StreamSinkMock());
332
332
  operatorList.addOp(_util.OPS.save, null);
333
333
  operatorList.addOp(_util.OPS.restore, null);
334
334
  expect(operatorList.totalLength).toEqual(2);