pdfjs-dist 2.0.943 → 2.4.456

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 (192) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/README.md +4 -0
  3. package/bower.json +1 -1
  4. package/build/pdf.js +8286 -14230
  5. package/build/pdf.js.map +1 -1
  6. package/build/pdf.min.js +22 -1
  7. package/build/pdf.worker.entry.js +5 -3
  8. package/build/pdf.worker.js +25500 -26628
  9. package/build/pdf.worker.js.map +1 -1
  10. package/build/pdf.worker.min.js +22 -1
  11. package/es5/build/pdf.js +25473 -0
  12. package/es5/build/pdf.js.map +1 -0
  13. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  14. package/es5/build/pdf.worker.js +57878 -0
  15. package/es5/build/pdf.worker.js.map +1 -0
  16. package/es5/web/images/annotation-check.svg +11 -0
  17. package/es5/web/images/annotation-comment.svg +16 -0
  18. package/es5/web/images/annotation-help.svg +26 -0
  19. package/es5/web/images/annotation-insert.svg +10 -0
  20. package/es5/web/images/annotation-key.svg +11 -0
  21. package/es5/web/images/annotation-newparagraph.svg +11 -0
  22. package/es5/web/images/annotation-noicon.svg +7 -0
  23. package/es5/web/images/annotation-note.svg +42 -0
  24. package/es5/web/images/annotation-paragraph.svg +16 -0
  25. package/es5/web/images/loading-icon.gif +0 -0
  26. package/es5/web/images/shadow.png +0 -0
  27. package/es5/web/images/texture.png +0 -0
  28. package/es5/web/pdf_viewer.css +407 -0
  29. package/es5/web/pdf_viewer.js +7757 -0
  30. package/es5/web/pdf_viewer.js.map +1 -0
  31. package/image_decoders/pdf.image_decoders.js +2887 -4094
  32. package/image_decoders/pdf.image_decoders.js.map +1 -1
  33. package/image_decoders/pdf.image_decoders.min.js +22 -1
  34. package/lib/README.md +7 -0
  35. package/lib/core/annotation.js +855 -778
  36. package/lib/core/arithmetic_decoder.js +325 -311
  37. package/lib/core/bidi.js +117 -50
  38. package/lib/core/ccitt.js +251 -89
  39. package/lib/core/ccitt_stream.js +26 -16
  40. package/lib/core/cff_parser.js +525 -197
  41. package/lib/core/charsets.js +6 -5
  42. package/lib/core/chunked_stream.js +541 -406
  43. package/lib/core/cmap.js +368 -253
  44. package/lib/core/colorspace.js +781 -800
  45. package/lib/core/core_utils.js +152 -0
  46. package/lib/core/crypto.js +609 -422
  47. package/lib/core/document.js +649 -481
  48. package/lib/core/encodings.js +33 -24
  49. package/lib/core/evaluator.js +1471 -736
  50. package/lib/core/font_renderer.js +289 -149
  51. package/lib/core/fonts.js +1067 -413
  52. package/lib/core/function.js +517 -287
  53. package/lib/core/glyphlist.js +4529 -4527
  54. package/lib/core/image.js +232 -114
  55. package/lib/core/image_utils.js +94 -0
  56. package/lib/core/jbig2.js +711 -342
  57. package/lib/core/jbig2_stream.js +31 -19
  58. package/lib/core/jpeg_stream.js +151 -26
  59. package/lib/core/jpg.js +433 -181
  60. package/lib/core/jpx.js +551 -143
  61. package/lib/core/jpx_stream.js +40 -28
  62. package/lib/core/metrics.js +2931 -2931
  63. package/lib/core/murmurhash3.js +104 -97
  64. package/lib/core/obj.js +1561 -1053
  65. package/lib/core/operator_list.js +192 -64
  66. package/lib/core/parser.js +1162 -864
  67. package/lib/core/pattern.js +224 -75
  68. package/lib/core/pdf_manager.js +154 -285
  69. package/lib/core/primitives.js +145 -69
  70. package/lib/core/ps_parser.js +212 -162
  71. package/lib/core/standard_fonts.js +245 -244
  72. package/lib/core/stream.js +353 -81
  73. package/lib/core/type1_parser.js +218 -68
  74. package/lib/core/unicode.js +1682 -1655
  75. package/lib/core/worker.js +233 -302
  76. package/lib/core/worker_stream.js +168 -0
  77. package/lib/display/annotation_layer.js +808 -862
  78. package/lib/display/api.js +1778 -1462
  79. package/lib/display/api_compatibility.js +14 -9
  80. package/lib/display/canvas.js +463 -140
  81. package/lib/display/content_disposition.js +86 -58
  82. package/lib/display/display_utils.js +524 -0
  83. package/lib/display/fetch_stream.js +202 -274
  84. package/lib/display/font_loader.js +311 -333
  85. package/lib/display/metadata.js +98 -88
  86. package/lib/display/network.js +343 -347
  87. package/lib/display/network_utils.js +46 -26
  88. package/lib/display/node_stream.js +326 -404
  89. package/lib/display/pattern_helper.js +168 -69
  90. package/lib/display/svg.js +1296 -885
  91. package/lib/display/text_layer.js +229 -103
  92. package/lib/display/transport_stream.js +290 -250
  93. package/lib/display/webgl.js +116 -83
  94. package/lib/display/worker_options.js +6 -5
  95. package/lib/display/xml_parser.js +358 -337
  96. package/lib/examples/node/domstubs.js +95 -39
  97. package/lib/pdf.js +49 -31
  98. package/lib/pdf.worker.js +7 -5
  99. package/lib/shared/compatibility.js +3 -145
  100. package/lib/shared/is_node.js +8 -7
  101. package/lib/shared/message_handler.js +367 -314
  102. package/lib/shared/util.js +421 -415
  103. package/lib/test/unit/annotation_spec.js +1570 -690
  104. package/lib/test/unit/api_spec.js +855 -493
  105. package/lib/test/unit/bidi_spec.js +12 -12
  106. package/lib/test/unit/cff_parser_spec.js +88 -61
  107. package/lib/test/unit/clitests_helper.js +9 -12
  108. package/lib/test/unit/cmap_spec.js +140 -88
  109. package/lib/test/unit/colorspace_spec.js +204 -152
  110. package/lib/test/unit/core_utils_spec.js +211 -0
  111. package/lib/test/unit/crypto_spec.js +194 -182
  112. package/lib/test/unit/custom_spec.js +50 -64
  113. package/lib/test/unit/display_svg_spec.js +53 -38
  114. package/lib/test/unit/display_utils_spec.js +263 -0
  115. package/lib/test/unit/document_spec.js +17 -22
  116. package/lib/test/unit/encodings_spec.js +15 -57
  117. package/lib/test/unit/evaluator_spec.js +90 -83
  118. package/lib/test/unit/fetch_stream_spec.js +111 -0
  119. package/lib/test/unit/function_spec.js +219 -205
  120. package/lib/test/unit/jasmine-boot.js +68 -39
  121. package/lib/test/unit/message_handler_spec.js +187 -160
  122. package/lib/test/unit/metadata_spec.js +87 -34
  123. package/lib/test/unit/murmurhash3_spec.js +13 -13
  124. package/lib/test/unit/network_spec.js +26 -59
  125. package/lib/test/unit/network_utils_spec.js +187 -121
  126. package/lib/test/unit/node_stream_spec.js +98 -90
  127. package/lib/test/unit/parser_spec.js +173 -131
  128. package/lib/test/unit/pdf_find_controller_spec.js +148 -67
  129. package/lib/test/unit/pdf_find_utils_spec.js +35 -34
  130. package/lib/test/unit/pdf_history_spec.js +45 -33
  131. package/lib/test/unit/primitives_spec.js +161 -126
  132. package/lib/test/unit/stream_spec.js +22 -15
  133. package/lib/test/unit/test_utils.js +149 -98
  134. package/lib/test/unit/testreporter.js +36 -18
  135. package/lib/test/unit/type1_parser_spec.js +46 -44
  136. package/lib/test/unit/ui_utils_spec.js +388 -372
  137. package/lib/test/unit/unicode_spec.js +49 -46
  138. package/lib/test/unit/util_spec.js +144 -248
  139. package/lib/web/annotation_layer_builder.js +75 -95
  140. package/lib/web/app.js +1538 -1147
  141. package/lib/web/app_options.js +116 -104
  142. package/lib/web/base_viewer.js +950 -775
  143. package/lib/web/chromecom.js +217 -225
  144. package/lib/web/debugger.js +236 -148
  145. package/lib/web/download_manager.js +50 -50
  146. package/lib/web/firefox_print_service.js +51 -33
  147. package/lib/web/firefoxcom.js +225 -352
  148. package/lib/web/genericcom.js +30 -93
  149. package/lib/web/genericl10n.js +26 -143
  150. package/lib/web/grab_to_pan.js +57 -33
  151. package/lib/web/interfaces.js +105 -232
  152. package/lib/web/overlay_manager.js +73 -227
  153. package/lib/web/password_prompt.js +44 -62
  154. package/lib/web/pdf_attachment_viewer.js +118 -123
  155. package/lib/web/pdf_cursor_tools.js +89 -93
  156. package/lib/web/pdf_document_properties.js +242 -281
  157. package/lib/web/pdf_find_bar.js +157 -163
  158. package/lib/web/pdf_find_controller.js +598 -454
  159. package/lib/web/pdf_find_utils.js +32 -16
  160. package/lib/web/pdf_history.js +481 -355
  161. package/lib/web/pdf_link_service.js +355 -323
  162. package/lib/web/pdf_outline_viewer.js +167 -152
  163. package/lib/web/pdf_page_view.js +511 -457
  164. package/lib/web/pdf_presentation_mode.js +347 -335
  165. package/lib/web/pdf_print_service.js +133 -103
  166. package/lib/web/pdf_rendering_queue.js +98 -100
  167. package/lib/web/pdf_sidebar.js +323 -299
  168. package/lib/web/pdf_sidebar_resizer.js +107 -108
  169. package/lib/web/pdf_single_page_viewer.js +94 -146
  170. package/lib/web/pdf_thumbnail_view.js +319 -269
  171. package/lib/web/pdf_thumbnail_viewer.js +219 -199
  172. package/lib/web/pdf_viewer.component.js +111 -32
  173. package/lib/web/pdf_viewer.js +61 -101
  174. package/lib/web/preferences.js +87 -272
  175. package/lib/web/secondary_toolbar.js +207 -220
  176. package/lib/web/text_layer_builder.js +322 -322
  177. package/lib/web/toolbar.js +227 -180
  178. package/lib/web/ui_utils.js +476 -421
  179. package/lib/web/view_history.js +59 -208
  180. package/lib/web/viewer_compatibility.js +9 -6
  181. package/package.json +2 -9
  182. package/web/pdf_viewer.css +36 -22
  183. package/web/pdf_viewer.js +4407 -4516
  184. package/web/pdf_viewer.js.map +1 -1
  185. package/webpack.js +14 -5
  186. package/external/streams/streams-lib.js +0 -3962
  187. package/external/url/url-lib.js +0 -627
  188. package/lib/display/dom_utils.js +0 -441
  189. package/lib/shared/streams_polyfill.js +0 -39
  190. package/lib/shared/url_polyfill.js +0 -50
  191. package/lib/test/unit/dom_utils_spec.js +0 -89
  192. package/lib/web/dom_events.js +0 -140
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2018 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,69 +19,27 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
24
+ var _encodings = require("../../core/encodings.js");
25
25
 
26
- var _encodings = require('../../core/encodings');
26
+ describe("encodings", function () {
27
+ describe("getEncoding", function () {
28
+ it("fetches a valid array for known encoding names", function () {
29
+ const knownEncodingNames = ["ExpertEncoding", "MacExpertEncoding", "MacRomanEncoding", "StandardEncoding", "SymbolSetEncoding", "WinAnsiEncoding", "ZapfDingbatsEncoding"];
27
30
 
28
- describe('encodings', function () {
29
- describe('getEncoding', function () {
30
- it('fetches a valid array for known encoding names', function () {
31
- var knownEncodingNames = ['ExpertEncoding', 'MacExpertEncoding', 'MacRomanEncoding', 'StandardEncoding', 'SymbolSetEncoding', 'WinAnsiEncoding', 'ZapfDingbatsEncoding'];
32
- var _iteratorNormalCompletion = true;
33
- var _didIteratorError = false;
34
- var _iteratorError = undefined;
31
+ for (const knownEncodingName of knownEncodingNames) {
32
+ const encoding = (0, _encodings.getEncoding)(knownEncodingName);
33
+ expect(Array.isArray(encoding)).toEqual(true);
34
+ expect(encoding.length).toEqual(256);
35
35
 
36
- try {
37
- for (var _iterator = knownEncodingNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
38
- var knownEncodingName = _step.value;
39
-
40
- var encoding = (0, _encodings.getEncoding)(knownEncodingName);
41
- expect(Array.isArray(encoding)).toEqual(true);
42
- expect(encoding.length).toEqual(256);
43
- var _iteratorNormalCompletion2 = true;
44
- var _didIteratorError2 = false;
45
- var _iteratorError2 = undefined;
46
-
47
- try {
48
- for (var _iterator2 = encoding[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
49
- var item = _step2.value;
50
-
51
- expect(typeof item === 'undefined' ? 'undefined' : _typeof(item)).toEqual('string');
52
- }
53
- } catch (err) {
54
- _didIteratorError2 = true;
55
- _iteratorError2 = err;
56
- } finally {
57
- try {
58
- if (!_iteratorNormalCompletion2 && _iterator2.return) {
59
- _iterator2.return();
60
- }
61
- } finally {
62
- if (_didIteratorError2) {
63
- throw _iteratorError2;
64
- }
65
- }
66
- }
67
- }
68
- } catch (err) {
69
- _didIteratorError = true;
70
- _iteratorError = err;
71
- } finally {
72
- try {
73
- if (!_iteratorNormalCompletion && _iterator.return) {
74
- _iterator.return();
75
- }
76
- } finally {
77
- if (_didIteratorError) {
78
- throw _iteratorError;
79
- }
36
+ for (const item of encoding) {
37
+ expect(typeof item).toEqual("string");
80
38
  }
81
39
  }
82
40
  });
83
- it('fetches `null` for unknown encoding names', function () {
84
- expect((0, _encodings.getEncoding)('FooBarEncoding')).toEqual(null);
41
+ it("fetches `null` for unknown encoding names", function () {
42
+ expect((0, _encodings.getEncoding)("FooBarEncoding")).toEqual(null);
85
43
  });
86
44
  });
87
45
  });
@@ -2,7 +2,7 @@
2
2
  * @licstart The following is the entire license notice for the
3
3
  * Javascript code in this page
4
4
  *
5
- * Copyright 2018 Mozilla Foundation
5
+ * Copyright 2020 Mozilla Foundation
6
6
  *
7
7
  * Licensed under the Apache License, Version 2.0 (the "License");
8
8
  * you may not use this file except in compliance with the License.
@@ -19,48 +19,53 @@
19
19
  * @licend The above is the entire license notice for the
20
20
  * Javascript code in this page
21
21
  */
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _primitives = require('../../core/primitives');
24
+ var _test_utils = require("./test_utils.js");
25
25
 
26
- var _util = require('../../shared/util');
26
+ var _primitives = require("../../core/primitives.js");
27
27
 
28
- var _stream = require('../../core/stream');
28
+ var _util = require("../../shared/util.js");
29
29
 
30
- var _operator_list = require('../../core/operator_list');
30
+ var _stream = require("../../core/stream.js");
31
31
 
32
- var _evaluator = require('../../core/evaluator');
32
+ var _operator_list = require("../../core/operator_list.js");
33
33
 
34
- var _worker = require('../../core/worker');
34
+ var _evaluator = require("../../core/evaluator.js");
35
35
 
36
- var _test_utils = require('./test_utils');
36
+ var _worker = require("../../core/worker.js");
37
37
 
38
- describe('evaluator', function () {
38
+ describe("evaluator", function () {
39
39
  function HandlerMock() {
40
40
  this.inputs = [];
41
41
  }
42
+
42
43
  HandlerMock.prototype = {
43
- send: function send(name, data) {
44
+ send(name, data) {
44
45
  this.inputs.push({
45
- name: name,
46
- data: data
46
+ name,
47
+ data
47
48
  });
48
49
  }
50
+
49
51
  };
52
+
50
53
  function ResourcesMock() {}
54
+
51
55
  ResourcesMock.prototype = {
52
- get: function get(name) {
56
+ get(name) {
53
57
  return this[name];
54
58
  }
59
+
55
60
  };
56
- function PdfManagerMock() {}
61
+
57
62
  function runOperatorListCheck(evaluator, stream, resources, callback) {
58
63
  var result = new _operator_list.OperatorList();
59
- var task = new _worker.WorkerTask('OperatorListCheck');
64
+ var task = new _worker.WorkerTask("OperatorListCheck");
60
65
  evaluator.getOperatorList({
61
- stream: stream,
62
- task: task,
63
- resources: resources,
66
+ stream,
67
+ task,
68
+ resources,
64
69
  operatorList: result
65
70
  }).then(function () {
66
71
  callback(result);
@@ -68,22 +73,23 @@ describe('evaluator', function () {
68
73
  callback(reason);
69
74
  });
70
75
  }
76
+
71
77
  var partialEvaluator;
72
78
  beforeAll(function (done) {
73
79
  partialEvaluator = new _evaluator.PartialEvaluator({
74
- pdfManager: new PdfManagerMock(),
75
80
  xref: new _test_utils.XRefMock(),
76
81
  handler: new HandlerMock(),
77
- pageIndex: 0
82
+ pageIndex: 0,
83
+ idFactory: (0, _test_utils.createIdFactory)(0)
78
84
  });
79
85
  done();
80
86
  });
81
87
  afterAll(function () {
82
88
  partialEvaluator = null;
83
89
  });
84
- describe('splitCombinedOperations', function () {
85
- it('should reject unknown operations', function (done) {
86
- var stream = new _stream.StringStream('fTT');
90
+ describe("splitCombinedOperations", function () {
91
+ it("should reject unknown operations", function (done) {
92
+ var stream = new _stream.StringStream("fTT");
87
93
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
88
94
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
89
95
  expect(result.fnArray.length).toEqual(1);
@@ -92,8 +98,8 @@ describe('evaluator', function () {
92
98
  done();
93
99
  });
94
100
  });
95
- it('should handle one operation', function (done) {
96
- var stream = new _stream.StringStream('Q');
101
+ it("should handle one operation", function (done) {
102
+ var stream = new _stream.StringStream("Q");
97
103
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
98
104
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
99
105
  expect(result.fnArray.length).toEqual(1);
@@ -101,10 +107,10 @@ describe('evaluator', function () {
101
107
  done();
102
108
  });
103
109
  });
104
- it('should handle two glued operations', function (done) {
110
+ it("should handle two glued operations", function (done) {
105
111
  var resources = new ResourcesMock();
106
112
  resources.Res1 = {};
107
- var stream = new _stream.StringStream('/Res1 DoQ');
113
+ var stream = new _stream.StringStream("/Res1 DoQ");
108
114
  runOperatorListCheck(partialEvaluator, stream, resources, function (result) {
109
115
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
110
116
  expect(result.fnArray.length).toEqual(2);
@@ -113,8 +119,8 @@ describe('evaluator', function () {
113
119
  done();
114
120
  });
115
121
  });
116
- it('should handle three glued operations', function (done) {
117
- var stream = new _stream.StringStream('fff');
122
+ it("should handle three glued operations", function (done) {
123
+ var stream = new _stream.StringStream("fff");
118
124
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
119
125
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
120
126
  expect(result.fnArray.length).toEqual(3);
@@ -124,10 +130,10 @@ describe('evaluator', function () {
124
130
  done();
125
131
  });
126
132
  });
127
- it('should handle three glued operations #2', function (done) {
133
+ it("should handle three glued operations #2", function (done) {
128
134
  var resources = new ResourcesMock();
129
135
  resources.Res1 = {};
130
- var stream = new _stream.StringStream('B*Bf*');
136
+ var stream = new _stream.StringStream("B*Bf*");
131
137
  runOperatorListCheck(partialEvaluator, stream, resources, function (result) {
132
138
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
133
139
  expect(result.fnArray.length).toEqual(3);
@@ -137,8 +143,8 @@ describe('evaluator', function () {
137
143
  done();
138
144
  });
139
145
  });
140
- it('should handle glued operations and operands', function (done) {
141
- var stream = new _stream.StringStream('f5 Ts');
146
+ it("should handle glued operations and operands", function (done) {
147
+ var stream = new _stream.StringStream("f5 Ts");
142
148
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
143
149
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
144
150
  expect(result.fnArray.length).toEqual(2);
@@ -150,8 +156,8 @@ describe('evaluator', function () {
150
156
  done();
151
157
  });
152
158
  });
153
- it('should handle glued operations and literals', function (done) {
154
- var stream = new _stream.StringStream('trueifalserinulln');
159
+ it("should handle glued operations and literals", function (done) {
160
+ var stream = new _stream.StringStream("trueifalserinulln");
155
161
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
156
162
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
157
163
  expect(result.fnArray.length).toEqual(3);
@@ -168,9 +174,9 @@ describe('evaluator', function () {
168
174
  });
169
175
  });
170
176
  });
171
- describe('validateNumberOfArgs', function () {
172
- it('should execute if correct number of arguments', function (done) {
173
- var stream = new _stream.StringStream('5 1 d0');
177
+ describe("validateNumberOfArgs", function () {
178
+ it("should execute if correct number of arguments", function (done) {
179
+ var stream = new _stream.StringStream("5 1 d0");
174
180
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
175
181
  expect(result.argsArray[0][0]).toEqual(5);
176
182
  expect(result.argsArray[0][1]).toEqual(1);
@@ -178,8 +184,8 @@ describe('evaluator', function () {
178
184
  done();
179
185
  });
180
186
  });
181
- it('should execute if too many arguments', function (done) {
182
- var stream = new _stream.StringStream('5 1 4 d0');
187
+ it("should execute if too many arguments", function (done) {
188
+ var stream = new _stream.StringStream("5 1 4 d0");
183
189
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
184
190
  expect(result.argsArray[0][0]).toEqual(1);
185
191
  expect(result.argsArray[0][1]).toEqual(4);
@@ -187,8 +193,8 @@ describe('evaluator', function () {
187
193
  done();
188
194
  });
189
195
  });
190
- it('should execute if nested commands', function (done) {
191
- var stream = new _stream.StringStream('/F2 /GS2 gs 5.711 Tf');
196
+ it("should execute if nested commands", function (done) {
197
+ var stream = new _stream.StringStream("/F2 /GS2 gs 5.711 Tf");
192
198
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
193
199
  expect(result.fnArray.length).toEqual(3);
194
200
  expect(result.fnArray[0]).toEqual(_util.OPS.setGState);
@@ -201,34 +207,34 @@ describe('evaluator', function () {
201
207
  done();
202
208
  });
203
209
  });
204
- it('should skip if too few arguments', function (done) {
205
- var stream = new _stream.StringStream('5 d0');
210
+ it("should skip if too few arguments", function (done) {
211
+ var stream = new _stream.StringStream("5 d0");
206
212
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
207
213
  expect(result.argsArray).toEqual([]);
208
214
  expect(result.fnArray).toEqual([]);
209
215
  done();
210
216
  });
211
217
  });
212
- it('should error if (many) path operators have too few arguments ' + '(bug 1443140)', function (done) {
213
- var NUM_INVALID_OPS = 25;
214
- var tempArr = new Array(NUM_INVALID_OPS + 1);
215
- var invalidMoveText = tempArr.join('10 Td\n');
216
- var moveTextStream = new _stream.StringStream(invalidMoveText);
218
+ it("should error if (many) path operators have too few arguments " + "(bug 1443140)", function (done) {
219
+ const NUM_INVALID_OPS = 25;
220
+ const tempArr = new Array(NUM_INVALID_OPS + 1);
221
+ const invalidMoveText = tempArr.join("10 Td\n");
222
+ const moveTextStream = new _stream.StringStream(invalidMoveText);
217
223
  runOperatorListCheck(partialEvaluator, moveTextStream, new ResourcesMock(), function (result) {
218
224
  expect(result.argsArray).toEqual([]);
219
225
  expect(result.fnArray).toEqual([]);
220
226
  done();
221
227
  });
222
- var invalidLineTo = tempArr.join('20 l\n');
223
- var lineToStream = new _stream.StringStream(invalidLineTo);
228
+ const invalidLineTo = tempArr.join("20 l\n");
229
+ const lineToStream = new _stream.StringStream(invalidLineTo);
224
230
  runOperatorListCheck(partialEvaluator, lineToStream, new ResourcesMock(), function (error) {
225
231
  expect(error instanceof _util.FormatError).toEqual(true);
226
- expect(error.message).toEqual('Invalid command l: expected 2 args, but received 1 args.');
232
+ expect(error.message).toEqual("Invalid command l: expected 2 args, but received 1 args.");
227
233
  done();
228
234
  });
229
235
  });
230
- it('should close opened saves', function (done) {
231
- var stream = new _stream.StringStream('qq');
236
+ it("should close opened saves", function (done) {
237
+ var stream = new _stream.StringStream("qq");
232
238
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
233
239
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
234
240
  expect(result.fnArray.length).toEqual(4);
@@ -239,23 +245,23 @@ describe('evaluator', function () {
239
245
  done();
240
246
  });
241
247
  });
242
- it('should skip paintXObject if name is missing', function (done) {
243
- var stream = new _stream.StringStream('/ Do');
248
+ it("should error on paintXObject if name is missing", function (done) {
249
+ var stream = new _stream.StringStream("/ Do");
244
250
  runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
245
251
  expect(result instanceof _util.FormatError).toEqual(true);
246
- expect(result.message).toEqual('XObject must be referred to by name.');
252
+ expect(result.message).toEqual("XObject must be referred to by name.");
247
253
  done();
248
254
  });
249
255
  });
250
- it('should skip paintXObject if subtype is PS', function (done) {
256
+ it("should skip paintXObject if subtype is PS", function (done) {
251
257
  var xobjStreamDict = new _primitives.Dict();
252
- xobjStreamDict.set('Subtype', _primitives.Name.get('PS'));
258
+ xobjStreamDict.set("Subtype", _primitives.Name.get("PS"));
253
259
  var xobjStream = new _stream.Stream([], 0, 0, xobjStreamDict);
254
260
  var xobjs = new _primitives.Dict();
255
- xobjs.set('Res1', xobjStream);
261
+ xobjs.set("Res1", xobjStream);
256
262
  var resources = new _primitives.Dict();
257
- resources.set('XObject', xobjs);
258
- var stream = new _stream.StringStream('/Res1 Do');
263
+ resources.set("XObject", xobjs);
264
+ var stream = new _stream.StringStream("/Res1 Do");
259
265
  runOperatorListCheck(partialEvaluator, stream, resources, function (result) {
260
266
  expect(result.argsArray).toEqual([]);
261
267
  expect(result.fnArray).toEqual([]);
@@ -263,17 +269,17 @@ describe('evaluator', function () {
263
269
  });
264
270
  });
265
271
  });
266
- describe('thread control', function () {
267
- it('should abort operator list parsing', function (done) {
268
- var stream = new _stream.StringStream('qqQQ');
272
+ describe("thread control", function () {
273
+ it("should abort operator list parsing", function (done) {
274
+ var stream = new _stream.StringStream("qqQQ");
269
275
  var resources = new ResourcesMock();
270
276
  var result = new _operator_list.OperatorList();
271
- var task = new _worker.WorkerTask('OperatorListAbort');
277
+ var task = new _worker.WorkerTask("OperatorListAbort");
272
278
  task.terminate();
273
279
  partialEvaluator.getOperatorList({
274
- stream: stream,
275
- task: task,
276
- resources: resources,
280
+ stream,
281
+ task,
282
+ resources,
277
283
  operatorList: result
278
284
  }).catch(function () {
279
285
  expect(!!result.fnArray && !!result.argsArray).toEqual(true);
@@ -281,28 +287,29 @@ describe('evaluator', function () {
281
287
  done();
282
288
  });
283
289
  });
284
- it('should abort text parsing parsing', function (done) {
290
+ it("should abort text parsing parsing", function (done) {
285
291
  var resources = new ResourcesMock();
286
- var stream = new _stream.StringStream('qqQQ');
287
- var task = new _worker.WorkerTask('TextContentAbort');
292
+ var stream = new _stream.StringStream("qqQQ");
293
+ var task = new _worker.WorkerTask("TextContentAbort");
288
294
  task.terminate();
289
295
  partialEvaluator.getTextContent({
290
- stream: stream,
291
- task: task,
292
- resources: resources
296
+ stream,
297
+ task,
298
+ resources
293
299
  }).catch(function () {
294
300
  expect(true).toEqual(true);
295
301
  done();
296
302
  });
297
303
  });
298
304
  });
299
- describe('operator list', function () {
300
- function MessageHandlerMock() {}
301
- MessageHandlerMock.prototype = {
302
- send: function send() {}
303
- };
304
- it('should get correct total length after flushing', function () {
305
- var operatorList = new _operator_list.OperatorList(null, new MessageHandlerMock());
305
+ describe("operator list", function () {
306
+ class StreamSinkMock {
307
+ enqueue() {}
308
+
309
+ }
310
+
311
+ it("should get correct total length after flushing", function () {
312
+ var operatorList = new _operator_list.OperatorList(null, new StreamSinkMock());
306
313
  operatorList.addOp(_util.OPS.save, null);
307
314
  operatorList.addOp(_util.OPS.restore, null);
308
315
  expect(operatorList.totalLength).toEqual(2);
@@ -0,0 +1,111 @@
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 _util = require("../../shared/util.js");
25
+
26
+ var _fetch_stream = require("../../display/fetch_stream.js");
27
+
28
+ describe("fetch_stream", function () {
29
+ const pdfUrl = new URL("../pdfs/tracemonkey.pdf", window.location).href;
30
+ const pdfLength = 1016315;
31
+ it("read with streaming", function (done) {
32
+ const stream = new _fetch_stream.PDFFetchStream({
33
+ url: pdfUrl,
34
+ disableStream: false,
35
+ disableRange: true
36
+ });
37
+ const fullReader = stream.getFullReader();
38
+ let isStreamingSupported, isRangeSupported;
39
+ const promise = fullReader.headersReady.then(function () {
40
+ isStreamingSupported = fullReader.isStreamingSupported;
41
+ isRangeSupported = fullReader.isRangeSupported;
42
+ });
43
+ let len = 0;
44
+
45
+ const read = function () {
46
+ return fullReader.read().then(function (result) {
47
+ if (result.done) {
48
+ return undefined;
49
+ }
50
+
51
+ len += result.value.byteLength;
52
+ return read();
53
+ });
54
+ };
55
+
56
+ const readPromise = Promise.all([read(), promise]);
57
+ readPromise.then(function () {
58
+ expect(len).toEqual(pdfLength);
59
+ expect(isStreamingSupported).toEqual(true);
60
+ expect(isRangeSupported).toEqual(false);
61
+ done();
62
+ }).catch(done.fail);
63
+ });
64
+ it("read ranges with streaming", function (done) {
65
+ const rangeSize = 32768;
66
+ const stream = new _fetch_stream.PDFFetchStream({
67
+ url: pdfUrl,
68
+ rangeChunkSize: rangeSize,
69
+ disableStream: false,
70
+ disableRange: false
71
+ });
72
+ const fullReader = stream.getFullReader();
73
+ let isStreamingSupported, isRangeSupported, fullReaderCancelled;
74
+ const promise = fullReader.headersReady.then(function () {
75
+ isStreamingSupported = fullReader.isStreamingSupported;
76
+ isRangeSupported = fullReader.isRangeSupported;
77
+ fullReader.cancel(new _util.AbortException("Don't need fullReader."));
78
+ fullReaderCancelled = true;
79
+ });
80
+ const tailSize = pdfLength % rangeSize || rangeSize;
81
+ const rangeReader1 = stream.getRangeReader(pdfLength - tailSize - rangeSize, pdfLength - tailSize);
82
+ const rangeReader2 = stream.getRangeReader(pdfLength - tailSize, pdfLength);
83
+ const result1 = {
84
+ value: 0
85
+ },
86
+ result2 = {
87
+ value: 0
88
+ };
89
+
90
+ const read = function (reader, lenResult) {
91
+ return reader.read().then(function (result) {
92
+ if (result.done) {
93
+ return undefined;
94
+ }
95
+
96
+ lenResult.value += result.value.byteLength;
97
+ return read(reader, lenResult);
98
+ });
99
+ };
100
+
101
+ const readPromise = Promise.all([read(rangeReader1, result1), read(rangeReader2, result2), promise]);
102
+ readPromise.then(function () {
103
+ expect(isStreamingSupported).toEqual(true);
104
+ expect(isRangeSupported).toEqual(true);
105
+ expect(fullReaderCancelled).toEqual(true);
106
+ expect(result1.value).toEqual(rangeSize);
107
+ expect(result2.value).toEqual(tailSize);
108
+ done();
109
+ }).catch(done.fail);
110
+ });
111
+ });