pdfjs-dist 2.3.200 → 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 (185) hide show
  1. package/README.md +4 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +6499 -17971
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +22 -1
  6. package/build/pdf.worker.entry.js +5 -3
  7. package/build/pdf.worker.js +19303 -29896
  8. package/build/pdf.worker.js.map +1 -1
  9. package/build/pdf.worker.min.js +22 -1
  10. package/es5/build/pdf.js +25473 -0
  11. package/es5/build/pdf.js.map +1 -0
  12. package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
  13. package/es5/build/pdf.worker.js +57878 -0
  14. package/es5/build/pdf.worker.js.map +1 -0
  15. package/es5/web/images/annotation-check.svg +11 -0
  16. package/es5/web/images/annotation-comment.svg +16 -0
  17. package/es5/web/images/annotation-help.svg +26 -0
  18. package/es5/web/images/annotation-insert.svg +10 -0
  19. package/es5/web/images/annotation-key.svg +11 -0
  20. package/es5/web/images/annotation-newparagraph.svg +11 -0
  21. package/es5/web/images/annotation-noicon.svg +7 -0
  22. package/es5/web/images/annotation-note.svg +42 -0
  23. package/es5/web/images/annotation-paragraph.svg +16 -0
  24. package/es5/web/images/loading-icon.gif +0 -0
  25. package/es5/web/images/shadow.png +0 -0
  26. package/es5/web/images/texture.png +0 -0
  27. package/es5/web/pdf_viewer.css +407 -0
  28. package/es5/web/pdf_viewer.js +7757 -0
  29. package/es5/web/pdf_viewer.js.map +1 -0
  30. package/image_decoders/pdf.image_decoders.js +1333 -4839
  31. package/image_decoders/pdf.image_decoders.js.map +1 -1
  32. package/image_decoders/pdf.image_decoders.min.js +22 -1
  33. package/lib/README.md +7 -0
  34. package/lib/core/annotation.js +683 -1066
  35. package/lib/core/arithmetic_decoder.js +81 -97
  36. package/lib/core/bidi.js +54 -46
  37. package/lib/core/ccitt.js +88 -81
  38. package/lib/core/ccitt_stream.js +15 -14
  39. package/lib/core/cff_parser.js +196 -193
  40. package/lib/core/charsets.js +4 -4
  41. package/lib/core/chunked_stream.js +441 -569
  42. package/lib/core/cmap.js +220 -279
  43. package/lib/core/colorspace.js +699 -863
  44. package/lib/core/core_utils.js +59 -80
  45. package/lib/core/crypto.js +379 -437
  46. package/lib/core/document.js +564 -673
  47. package/lib/core/encodings.js +15 -15
  48. package/lib/core/evaluator.js +983 -889
  49. package/lib/core/font_renderer.js +128 -171
  50. package/lib/core/fonts.js +451 -400
  51. package/lib/core/function.js +289 -285
  52. package/lib/core/glyphlist.js +4527 -4527
  53. package/lib/core/image.js +138 -117
  54. package/lib/core/image_utils.js +46 -63
  55. package/lib/core/jbig2.js +324 -332
  56. package/lib/core/jbig2_stream.js +18 -17
  57. package/lib/core/jpeg_stream.js +133 -24
  58. package/lib/core/jpg.js +238 -210
  59. package/lib/core/jpx.js +158 -157
  60. package/lib/core/jpx_stream.js +28 -28
  61. package/lib/core/metrics.js +2928 -2928
  62. package/lib/core/murmurhash3.js +87 -102
  63. package/lib/core/obj.js +1111 -1302
  64. package/lib/core/operator_list.js +55 -42
  65. package/lib/core/parser.js +956 -987
  66. package/lib/core/pattern.js +69 -69
  67. package/lib/core/pdf_manager.js +149 -316
  68. package/lib/core/primitives.js +45 -77
  69. package/lib/core/ps_parser.js +175 -214
  70. package/lib/core/standard_fonts.js +237 -236
  71. package/lib/core/stream.js +83 -77
  72. package/lib/core/type1_parser.js +78 -68
  73. package/lib/core/unicode.js +1654 -1654
  74. package/lib/core/worker.js +148 -196
  75. package/lib/core/worker_stream.js +101 -210
  76. package/lib/display/annotation_layer.js +733 -1155
  77. package/lib/display/api.js +1539 -1928
  78. package/lib/display/api_compatibility.js +10 -8
  79. package/lib/display/canvas.js +159 -158
  80. package/lib/display/content_disposition.js +36 -55
  81. package/lib/display/display_utils.js +298 -551
  82. package/lib/display/fetch_stream.js +181 -305
  83. package/lib/display/font_loader.js +273 -416
  84. package/lib/display/metadata.js +86 -98
  85. package/lib/display/network.js +376 -511
  86. package/lib/display/network_utils.js +20 -19
  87. package/lib/display/node_stream.js +276 -460
  88. package/lib/display/pattern_helper.js +76 -44
  89. package/lib/display/svg.js +1137 -1405
  90. package/lib/display/text_layer.js +75 -82
  91. package/lib/display/transport_stream.js +236 -374
  92. package/lib/display/webgl.js +70 -83
  93. package/lib/display/worker_options.js +3 -3
  94. package/lib/display/xml_parser.js +303 -392
  95. package/lib/examples/node/domstubs.js +37 -37
  96. package/lib/pdf.js +22 -21
  97. package/lib/pdf.worker.js +5 -5
  98. package/lib/shared/compatibility.js +2 -251
  99. package/lib/shared/is_node.js +7 -6
  100. package/lib/shared/message_handler.js +222 -194
  101. package/lib/shared/util.js +269 -405
  102. package/lib/test/unit/annotation_spec.js +1089 -1014
  103. package/lib/test/unit/api_spec.js +617 -544
  104. package/lib/test/unit/bidi_spec.js +7 -7
  105. package/lib/test/unit/cff_parser_spec.js +63 -62
  106. package/lib/test/unit/clitests_helper.js +7 -9
  107. package/lib/test/unit/cmap_spec.js +84 -86
  108. package/lib/test/unit/colorspace_spec.js +154 -154
  109. package/lib/test/unit/core_utils_spec.js +125 -105
  110. package/lib/test/unit/crypto_spec.js +181 -181
  111. package/lib/test/unit/custom_spec.js +22 -24
  112. package/lib/test/unit/display_svg_spec.js +35 -36
  113. package/lib/test/unit/display_utils_spec.js +139 -149
  114. package/lib/test/unit/document_spec.js +16 -16
  115. package/lib/test/unit/encodings_spec.js +12 -34
  116. package/lib/test/unit/evaluator_spec.js +81 -95
  117. package/lib/test/unit/fetch_stream_spec.js +30 -30
  118. package/lib/test/unit/function_spec.js +206 -204
  119. package/lib/test/unit/jasmine-boot.js +48 -32
  120. package/lib/test/unit/message_handler_spec.js +172 -162
  121. package/lib/test/unit/metadata_spec.js +69 -69
  122. package/lib/test/unit/murmurhash3_spec.js +12 -12
  123. package/lib/test/unit/network_spec.js +12 -12
  124. package/lib/test/unit/network_utils_spec.js +152 -152
  125. package/lib/test/unit/node_stream_spec.js +74 -90
  126. package/lib/test/unit/parser_spec.js +107 -113
  127. package/lib/test/unit/pdf_find_controller_spec.js +55 -86
  128. package/lib/test/unit/pdf_find_utils_spec.js +32 -32
  129. package/lib/test/unit/pdf_history_spec.js +32 -32
  130. package/lib/test/unit/primitives_spec.js +117 -115
  131. package/lib/test/unit/stream_spec.js +16 -14
  132. package/lib/test/unit/test_utils.js +119 -285
  133. package/lib/test/unit/testreporter.js +19 -19
  134. package/lib/test/unit/type1_parser_spec.js +41 -41
  135. package/lib/test/unit/ui_utils_spec.js +318 -426
  136. package/lib/test/unit/unicode_spec.js +42 -42
  137. package/lib/test/unit/util_spec.js +122 -143
  138. package/lib/web/annotation_layer_builder.js +66 -103
  139. package/lib/web/app.js +1166 -1196
  140. package/lib/web/app_options.js +61 -77
  141. package/lib/web/base_viewer.js +804 -850
  142. package/lib/web/chromecom.js +164 -249
  143. package/lib/web/debugger.js +149 -205
  144. package/lib/web/download_manager.js +38 -57
  145. package/lib/web/firefox_print_service.js +35 -30
  146. package/lib/web/firefoxcom.js +175 -374
  147. package/lib/web/genericcom.js +26 -108
  148. package/lib/web/genericl10n.js +24 -153
  149. package/lib/web/grab_to_pan.js +30 -30
  150. package/lib/web/interfaces.js +80 -258
  151. package/lib/web/overlay_manager.js +70 -246
  152. package/lib/web/password_prompt.js +38 -64
  153. package/lib/web/pdf_attachment_viewer.js +105 -130
  154. package/lib/web/pdf_cursor_tools.js +75 -102
  155. package/lib/web/pdf_document_properties.js +227 -376
  156. package/lib/web/pdf_find_bar.js +137 -171
  157. package/lib/web/pdf_find_controller.js +492 -549
  158. package/lib/web/pdf_find_utils.js +13 -13
  159. package/lib/web/pdf_history.js +395 -406
  160. package/lib/web/pdf_link_service.js +302 -349
  161. package/lib/web/pdf_outline_viewer.js +148 -209
  162. package/lib/web/pdf_page_view.js +449 -507
  163. package/lib/web/pdf_presentation_mode.js +304 -357
  164. package/lib/web/pdf_print_service.js +90 -104
  165. package/lib/web/pdf_rendering_queue.js +87 -108
  166. package/lib/web/pdf_sidebar.js +264 -304
  167. package/lib/web/pdf_sidebar_resizer.js +92 -119
  168. package/lib/web/pdf_single_page_viewer.js +77 -126
  169. package/lib/web/pdf_thumbnail_view.js +276 -297
  170. package/lib/web/pdf_thumbnail_viewer.js +186 -206
  171. package/lib/web/pdf_viewer.component.js +20 -21
  172. package/lib/web/pdf_viewer.js +55 -115
  173. package/lib/web/preferences.js +66 -273
  174. package/lib/web/secondary_toolbar.js +164 -196
  175. package/lib/web/text_layer_builder.js +284 -317
  176. package/lib/web/toolbar.js +216 -211
  177. package/lib/web/ui_utils.js +303 -404
  178. package/lib/web/view_history.js +49 -222
  179. package/lib/web/viewer_compatibility.js +7 -5
  180. package/package.json +2 -9
  181. package/web/pdf_viewer.css +25 -18
  182. package/web/pdf_viewer.js +3481 -4764
  183. package/web/pdf_viewer.js.map +1 -1
  184. package/webpack.js +14 -5
  185. package/lib/shared/streams_polyfill.js +0 -43
@@ -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 2019 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.
@@ -26,57 +26,45 @@ Object.defineProperty(exports, "__esModule", {
26
26
  });
27
27
  exports.Parser = exports.Linearization = exports.Lexer = void 0;
28
28
 
29
- var _stream = require("./stream");
29
+ var _stream = require("./stream.js");
30
30
 
31
- var _util = require("../shared/util");
31
+ var _util = require("../shared/util.js");
32
32
 
33
- var _primitives = require("./primitives");
33
+ var _primitives = require("./primitives.js");
34
34
 
35
- var _ccitt_stream = require("./ccitt_stream");
35
+ var _core_utils = require("./core_utils.js");
36
36
 
37
- var _jbig2_stream = require("./jbig2_stream");
37
+ var _ccitt_stream = require("./ccitt_stream.js");
38
38
 
39
- var _jpeg_stream = require("./jpeg_stream");
39
+ var _jbig2_stream = require("./jbig2_stream.js");
40
40
 
41
- var _jpx_stream = require("./jpx_stream");
41
+ var _jpeg_stream = require("./jpeg_stream.js");
42
42
 
43
- var _core_utils = require("./core_utils");
43
+ var _jpx_stream = require("./jpx_stream.js");
44
44
 
45
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
46
-
47
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
48
-
49
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
50
-
51
- var MAX_LENGTH_TO_CACHE = 1000;
52
- var MAX_ADLER32_LENGTH = 5552;
45
+ const MAX_LENGTH_TO_CACHE = 1000;
46
+ const MAX_ADLER32_LENGTH = 5552;
53
47
 
54
48
  function computeAdler32(bytes) {
55
- var bytesLength = bytes.length;
56
- var a = 1,
49
+ const bytesLength = bytes.length;
50
+ let a = 1,
57
51
  b = 0;
58
52
 
59
- for (var i = 0; i < bytesLength; ++i) {
60
- a += bytes[i] & 0xFF;
53
+ for (let i = 0; i < bytesLength; ++i) {
54
+ a += bytes[i] & 0xff;
61
55
  b += a;
62
56
  }
63
57
 
64
58
  return b % 65521 << 16 | a % 65521;
65
59
  }
66
60
 
67
- var Parser =
68
- /*#__PURE__*/
69
- function () {
70
- function Parser(_ref) {
71
- var lexer = _ref.lexer,
72
- xref = _ref.xref,
73
- _ref$allowStreams = _ref.allowStreams,
74
- allowStreams = _ref$allowStreams === void 0 ? false : _ref$allowStreams,
75
- _ref$recoveryMode = _ref.recoveryMode,
76
- recoveryMode = _ref$recoveryMode === void 0 ? false : _ref$recoveryMode;
77
-
78
- _classCallCheck(this, Parser);
79
-
61
+ class Parser {
62
+ constructor({
63
+ lexer,
64
+ xref,
65
+ allowStreams = false,
66
+ recoveryMode = false
67
+ }) {
80
68
  this.lexer = lexer;
81
69
  this.xref = xref;
82
70
  this.allowStreams = allowStreams;
@@ -85,1269 +73,1250 @@ function () {
85
73
  this.refill();
86
74
  }
87
75
 
88
- _createClass(Parser, [{
89
- key: "refill",
90
- value: function refill() {
91
- this.buf1 = this.lexer.getObj();
76
+ refill() {
77
+ this.buf1 = this.lexer.getObj();
78
+ this.buf2 = this.lexer.getObj();
79
+ }
80
+
81
+ shift() {
82
+ if (this.buf2 instanceof _primitives.Cmd && this.buf2.cmd === "ID") {
83
+ this.buf1 = this.buf2;
84
+ this.buf2 = null;
85
+ } else {
86
+ this.buf1 = this.buf2;
92
87
  this.buf2 = this.lexer.getObj();
93
88
  }
94
- }, {
95
- key: "shift",
96
- value: function shift() {
97
- if (this.buf2 instanceof _primitives.Cmd && this.buf2.cmd === 'ID') {
98
- this.buf1 = this.buf2;
99
- this.buf2 = null;
100
- } else {
101
- this.buf1 = this.buf2;
102
- this.buf2 = this.lexer.getObj();
103
- }
104
- }
105
- }, {
106
- key: "tryShift",
107
- value: function tryShift() {
108
- try {
109
- this.shift();
110
- return true;
111
- } catch (e) {
112
- if (e instanceof _core_utils.MissingDataException) {
113
- throw e;
114
- }
89
+ }
115
90
 
116
- return false;
91
+ tryShift() {
92
+ try {
93
+ this.shift();
94
+ return true;
95
+ } catch (e) {
96
+ if (e instanceof _core_utils.MissingDataException) {
97
+ throw e;
117
98
  }
99
+
100
+ return false;
118
101
  }
119
- }, {
120
- key: "getObj",
121
- value: function getObj() {
122
- var cipherTransform = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
123
- var buf1 = this.buf1;
124
- this.shift();
102
+ }
125
103
 
126
- if (buf1 instanceof _primitives.Cmd) {
127
- switch (buf1.cmd) {
128
- case 'BI':
129
- return this.makeInlineImage(cipherTransform);
104
+ getObj(cipherTransform = null) {
105
+ const buf1 = this.buf1;
106
+ this.shift();
130
107
 
131
- case '[':
132
- var array = [];
108
+ if (buf1 instanceof _primitives.Cmd) {
109
+ switch (buf1.cmd) {
110
+ case "BI":
111
+ return this.makeInlineImage(cipherTransform);
133
112
 
134
- while (!(0, _primitives.isCmd)(this.buf1, ']') && !(0, _primitives.isEOF)(this.buf1)) {
135
- array.push(this.getObj(cipherTransform));
136
- }
113
+ case "[":
114
+ const array = [];
137
115
 
138
- if ((0, _primitives.isEOF)(this.buf1)) {
139
- if (!this.recoveryMode) {
140
- throw new _util.FormatError('End of file inside array');
141
- }
116
+ while (!(0, _primitives.isCmd)(this.buf1, "]") && !(0, _primitives.isEOF)(this.buf1)) {
117
+ array.push(this.getObj(cipherTransform));
118
+ }
142
119
 
143
- return array;
120
+ if ((0, _primitives.isEOF)(this.buf1)) {
121
+ if (!this.recoveryMode) {
122
+ throw new _util.FormatError("End of file inside array");
144
123
  }
145
124
 
146
- this.shift();
147
125
  return array;
126
+ }
148
127
 
149
- case '<<':
150
- var dict = new _primitives.Dict(this.xref);
128
+ this.shift();
129
+ return array;
151
130
 
152
- while (!(0, _primitives.isCmd)(this.buf1, '>>') && !(0, _primitives.isEOF)(this.buf1)) {
153
- if (!(0, _primitives.isName)(this.buf1)) {
154
- (0, _util.info)('Malformed dictionary: key must be a name object');
155
- this.shift();
156
- continue;
157
- }
131
+ case "<<":
132
+ const dict = new _primitives.Dict(this.xref);
158
133
 
159
- var key = this.buf1.name;
134
+ while (!(0, _primitives.isCmd)(this.buf1, ">>") && !(0, _primitives.isEOF)(this.buf1)) {
135
+ if (!(0, _primitives.isName)(this.buf1)) {
136
+ (0, _util.info)("Malformed dictionary: key must be a name object");
160
137
  this.shift();
161
-
162
- if ((0, _primitives.isEOF)(this.buf1)) {
163
- break;
164
- }
165
-
166
- dict.set(key, this.getObj(cipherTransform));
138
+ continue;
167
139
  }
168
140
 
169
- if ((0, _primitives.isEOF)(this.buf1)) {
170
- if (!this.recoveryMode) {
171
- throw new _util.FormatError('End of file inside dictionary');
172
- }
141
+ const key = this.buf1.name;
142
+ this.shift();
173
143
 
174
- return dict;
144
+ if ((0, _primitives.isEOF)(this.buf1)) {
145
+ break;
175
146
  }
176
147
 
177
- if ((0, _primitives.isCmd)(this.buf2, 'stream')) {
178
- return this.allowStreams ? this.makeStream(dict, cipherTransform) : dict;
148
+ dict.set(key, this.getObj(cipherTransform));
149
+ }
150
+
151
+ if ((0, _primitives.isEOF)(this.buf1)) {
152
+ if (!this.recoveryMode) {
153
+ throw new _util.FormatError("End of file inside dictionary");
179
154
  }
180
155
 
181
- this.shift();
182
156
  return dict;
157
+ }
183
158
 
184
- default:
185
- return buf1;
186
- }
187
- }
188
-
189
- if (Number.isInteger(buf1)) {
190
- if (Number.isInteger(this.buf1) && (0, _primitives.isCmd)(this.buf2, 'R')) {
191
- var ref = _primitives.Ref.get(buf1, this.buf1);
159
+ if ((0, _primitives.isCmd)(this.buf2, "stream")) {
160
+ return this.allowStreams ? this.makeStream(dict, cipherTransform) : dict;
161
+ }
192
162
 
193
163
  this.shift();
194
- this.shift();
195
- return ref;
196
- }
164
+ return dict;
197
165
 
198
- return buf1;
166
+ default:
167
+ return buf1;
199
168
  }
169
+ }
200
170
 
201
- if (typeof buf1 === 'string') {
202
- if (cipherTransform) {
203
- return cipherTransform.decryptString(buf1);
204
- }
171
+ if (Number.isInteger(buf1)) {
172
+ if (Number.isInteger(this.buf1) && (0, _primitives.isCmd)(this.buf2, "R")) {
173
+ const ref = _primitives.Ref.get(buf1, this.buf1);
205
174
 
206
- return buf1;
175
+ this.shift();
176
+ this.shift();
177
+ return ref;
207
178
  }
208
179
 
209
180
  return buf1;
210
181
  }
211
- }, {
212
- key: "findDefaultInlineStreamEnd",
213
- value: function findDefaultInlineStreamEnd(stream) {
214
- var E = 0x45,
182
+
183
+ if (typeof buf1 === "string") {
184
+ if (cipherTransform) {
185
+ return cipherTransform.decryptString(buf1);
186
+ }
187
+
188
+ return buf1;
189
+ }
190
+
191
+ return buf1;
192
+ }
193
+
194
+ findDefaultInlineStreamEnd(stream) {
195
+ const E = 0x45,
215
196
  I = 0x49,
216
197
  SPACE = 0x20,
217
- LF = 0xA,
218
- CR = 0xD;
219
- var n = 10,
198
+ LF = 0xa,
199
+ CR = 0xd;
200
+ const n = 10,
220
201
  NUL = 0x0;
221
- var startPos = stream.pos,
222
- state = 0,
223
- ch,
224
- maybeEIPos;
225
-
226
- while ((ch = stream.getByte()) !== -1) {
227
- if (state === 0) {
228
- state = ch === E ? 1 : 0;
229
- } else if (state === 1) {
230
- state = ch === I ? 2 : 0;
231
- } else {
232
- (0, _util.assert)(state === 2);
233
-
234
- if (ch === SPACE || ch === LF || ch === CR) {
235
- maybeEIPos = stream.pos;
236
- var followingBytes = stream.peekBytes(n);
202
+ const startPos = stream.pos;
203
+ let state = 0,
204
+ ch,
205
+ maybeEIPos;
206
+
207
+ while ((ch = stream.getByte()) !== -1) {
208
+ if (state === 0) {
209
+ state = ch === E ? 1 : 0;
210
+ } else if (state === 1) {
211
+ state = ch === I ? 2 : 0;
212
+ } else {
213
+ (0, _util.assert)(state === 2);
237
214
 
238
- for (var i = 0, ii = followingBytes.length; i < ii; i++) {
239
- ch = followingBytes[i];
215
+ if (ch === SPACE || ch === LF || ch === CR) {
216
+ maybeEIPos = stream.pos;
217
+ const followingBytes = stream.peekBytes(n);
240
218
 
241
- if (ch === NUL && followingBytes[i + 1] !== NUL) {
242
- continue;
243
- }
219
+ for (let i = 0, ii = followingBytes.length; i < ii; i++) {
220
+ ch = followingBytes[i];
244
221
 
245
- if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
246
- state = 0;
247
- break;
248
- }
222
+ if (ch === NUL && followingBytes[i + 1] !== NUL) {
223
+ continue;
249
224
  }
250
225
 
251
- if (state === 2) {
226
+ if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7f)) {
227
+ state = 0;
252
228
  break;
253
229
  }
254
- } else {
255
- state = 0;
256
230
  }
257
- }
258
- }
259
231
 
260
- if (ch === -1) {
261
- (0, _util.warn)('findDefaultInlineStreamEnd: ' + 'Reached the end of the stream without finding a valid EI marker');
262
-
263
- if (maybeEIPos) {
264
- (0, _util.warn)('... trying to recover by using the last "EI" occurrence.');
265
- stream.skip(-(stream.pos - maybeEIPos));
232
+ if (state === 2) {
233
+ break;
234
+ }
235
+ } else {
236
+ state = 0;
266
237
  }
267
238
  }
239
+ }
268
240
 
269
- var endOffset = 4;
270
- stream.skip(-endOffset);
271
- ch = stream.peekByte();
272
- stream.skip(endOffset);
241
+ if (ch === -1) {
242
+ (0, _util.warn)("findDefaultInlineStreamEnd: " + "Reached the end of the stream without finding a valid EI marker");
273
243
 
274
- if (!(0, _util.isSpace)(ch)) {
275
- endOffset--;
244
+ if (maybeEIPos) {
245
+ (0, _util.warn)('... trying to recover by using the last "EI" occurrence.');
246
+ stream.skip(-(stream.pos - maybeEIPos));
276
247
  }
248
+ }
249
+
250
+ let endOffset = 4;
251
+ stream.skip(-endOffset);
252
+ ch = stream.peekByte();
253
+ stream.skip(endOffset);
277
254
 
278
- return stream.pos - endOffset - startPos;
255
+ if (!(0, _core_utils.isWhiteSpace)(ch)) {
256
+ endOffset--;
279
257
  }
280
- }, {
281
- key: "findDCTDecodeInlineStreamEnd",
282
- value: function findDCTDecodeInlineStreamEnd(stream) {
283
- var startPos = stream.pos,
284
- foundEOI = false,
285
- b,
286
- markerLength,
287
- length;
288
-
289
- while ((b = stream.getByte()) !== -1) {
290
- if (b !== 0xFF) {
291
- continue;
292
- }
293
258
 
294
- switch (stream.getByte()) {
295
- case 0x00:
296
- break;
259
+ return stream.pos - endOffset - startPos;
260
+ }
297
261
 
298
- case 0xFF:
299
- stream.skip(-1);
300
- break;
262
+ findDCTDecodeInlineStreamEnd(stream) {
263
+ const startPos = stream.pos;
264
+ let foundEOI = false,
265
+ b,
266
+ markerLength;
301
267
 
302
- case 0xD9:
303
- foundEOI = true;
304
- break;
268
+ while ((b = stream.getByte()) !== -1) {
269
+ if (b !== 0xff) {
270
+ continue;
271
+ }
305
272
 
306
- case 0xC0:
307
- case 0xC1:
308
- case 0xC2:
309
- case 0xC3:
310
- case 0xC5:
311
- case 0xC6:
312
- case 0xC7:
313
- case 0xC9:
314
- case 0xCA:
315
- case 0xCB:
316
- case 0xCD:
317
- case 0xCE:
318
- case 0xCF:
319
- case 0xC4:
320
- case 0xCC:
321
- case 0xDA:
322
- case 0xDB:
323
- case 0xDC:
324
- case 0xDD:
325
- case 0xDE:
326
- case 0xDF:
327
- case 0xE0:
328
- case 0xE1:
329
- case 0xE2:
330
- case 0xE3:
331
- case 0xE4:
332
- case 0xE5:
333
- case 0xE6:
334
- case 0xE7:
335
- case 0xE8:
336
- case 0xE9:
337
- case 0xEA:
338
- case 0xEB:
339
- case 0xEC:
340
- case 0xED:
341
- case 0xEE:
342
- case 0xEF:
343
- case 0xFE:
344
- markerLength = stream.getUint16();
345
-
346
- if (markerLength > 2) {
347
- stream.skip(markerLength - 2);
348
- } else {
349
- stream.skip(-2);
350
- }
273
+ switch (stream.getByte()) {
274
+ case 0x00:
275
+ break;
351
276
 
352
- break;
353
- }
277
+ case 0xff:
278
+ stream.skip(-1);
279
+ break;
354
280
 
355
- if (foundEOI) {
281
+ case 0xd9:
282
+ foundEOI = true;
356
283
  break;
357
- }
358
- }
359
284
 
360
- length = stream.pos - startPos;
285
+ case 0xc0:
286
+ case 0xc1:
287
+ case 0xc2:
288
+ case 0xc3:
289
+ case 0xc5:
290
+ case 0xc6:
291
+ case 0xc7:
292
+ case 0xc9:
293
+ case 0xca:
294
+ case 0xcb:
295
+ case 0xcd:
296
+ case 0xce:
297
+ case 0xcf:
298
+ case 0xc4:
299
+ case 0xcc:
300
+ case 0xda:
301
+ case 0xdb:
302
+ case 0xdc:
303
+ case 0xdd:
304
+ case 0xde:
305
+ case 0xdf:
306
+ case 0xe0:
307
+ case 0xe1:
308
+ case 0xe2:
309
+ case 0xe3:
310
+ case 0xe4:
311
+ case 0xe5:
312
+ case 0xe6:
313
+ case 0xe7:
314
+ case 0xe8:
315
+ case 0xe9:
316
+ case 0xea:
317
+ case 0xeb:
318
+ case 0xec:
319
+ case 0xed:
320
+ case 0xee:
321
+ case 0xef:
322
+ case 0xfe:
323
+ markerLength = stream.getUint16();
324
+
325
+ if (markerLength > 2) {
326
+ stream.skip(markerLength - 2);
327
+ } else {
328
+ stream.skip(-2);
329
+ }
330
+
331
+ break;
332
+ }
361
333
 
362
- if (b === -1) {
363
- (0, _util.warn)('Inline DCTDecode image stream: ' + 'EOI marker not found, searching for /EI/ instead.');
364
- stream.skip(-length);
365
- return this.findDefaultInlineStreamEnd(stream);
334
+ if (foundEOI) {
335
+ break;
366
336
  }
337
+ }
338
+
339
+ const length = stream.pos - startPos;
367
340
 
368
- this.inlineStreamSkipEI(stream);
369
- return length;
341
+ if (b === -1) {
342
+ (0, _util.warn)("Inline DCTDecode image stream: " + "EOI marker not found, searching for /EI/ instead.");
343
+ stream.skip(-length);
344
+ return this.findDefaultInlineStreamEnd(stream);
370
345
  }
371
- }, {
372
- key: "findASCII85DecodeInlineStreamEnd",
373
- value: function findASCII85DecodeInlineStreamEnd(stream) {
374
- var TILDE = 0x7E,
375
- GT = 0x3E;
376
- var startPos = stream.pos,
377
- ch,
378
- length;
379
-
380
- while ((ch = stream.getByte()) !== -1) {
381
- if (ch === TILDE) {
346
+
347
+ this.inlineStreamSkipEI(stream);
348
+ return length;
349
+ }
350
+
351
+ findASCII85DecodeInlineStreamEnd(stream) {
352
+ const TILDE = 0x7e,
353
+ GT = 0x3e;
354
+ const startPos = stream.pos;
355
+ let ch;
356
+
357
+ while ((ch = stream.getByte()) !== -1) {
358
+ if (ch === TILDE) {
359
+ const tildePos = stream.pos;
360
+ ch = stream.peekByte();
361
+
362
+ while ((0, _core_utils.isWhiteSpace)(ch)) {
363
+ stream.skip();
382
364
  ch = stream.peekByte();
365
+ }
383
366
 
384
- while ((0, _util.isSpace)(ch)) {
385
- stream.skip();
386
- ch = stream.peekByte();
387
- }
367
+ if (ch === GT) {
368
+ stream.skip();
369
+ break;
370
+ }
388
371
 
389
- if (ch === GT) {
390
- stream.skip();
372
+ if (stream.pos > tildePos) {
373
+ const maybeEI = stream.peekBytes(2);
374
+
375
+ if (maybeEI[0] === 0x45 && maybeEI[1] === 0x49) {
391
376
  break;
392
377
  }
393
378
  }
394
379
  }
380
+ }
395
381
 
396
- length = stream.pos - startPos;
397
-
398
- if (ch === -1) {
399
- (0, _util.warn)('Inline ASCII85Decode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
400
- stream.skip(-length);
401
- return this.findDefaultInlineStreamEnd(stream);
402
- }
382
+ const length = stream.pos - startPos;
403
383
 
404
- this.inlineStreamSkipEI(stream);
405
- return length;
384
+ if (ch === -1) {
385
+ (0, _util.warn)("Inline ASCII85Decode image stream: " + "EOD marker not found, searching for /EI/ instead.");
386
+ stream.skip(-length);
387
+ return this.findDefaultInlineStreamEnd(stream);
406
388
  }
407
- }, {
408
- key: "findASCIIHexDecodeInlineStreamEnd",
409
- value: function findASCIIHexDecodeInlineStreamEnd(stream) {
410
- var GT = 0x3E;
411
- var startPos = stream.pos,
412
- ch,
413
- length;
414
-
415
- while ((ch = stream.getByte()) !== -1) {
416
- if (ch === GT) {
417
- break;
418
- }
419
- }
420
389
 
421
- length = stream.pos - startPos;
390
+ this.inlineStreamSkipEI(stream);
391
+ return length;
392
+ }
393
+
394
+ findASCIIHexDecodeInlineStreamEnd(stream) {
395
+ const GT = 0x3e;
396
+ const startPos = stream.pos;
397
+ let ch;
422
398
 
423
- if (ch === -1) {
424
- (0, _util.warn)('Inline ASCIIHexDecode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
425
- stream.skip(-length);
426
- return this.findDefaultInlineStreamEnd(stream);
399
+ while ((ch = stream.getByte()) !== -1) {
400
+ if (ch === GT) {
401
+ break;
427
402
  }
403
+ }
404
+
405
+ const length = stream.pos - startPos;
428
406
 
429
- this.inlineStreamSkipEI(stream);
430
- return length;
407
+ if (ch === -1) {
408
+ (0, _util.warn)("Inline ASCIIHexDecode image stream: " + "EOD marker not found, searching for /EI/ instead.");
409
+ stream.skip(-length);
410
+ return this.findDefaultInlineStreamEnd(stream);
431
411
  }
432
- }, {
433
- key: "inlineStreamSkipEI",
434
- value: function inlineStreamSkipEI(stream) {
435
- var E = 0x45,
412
+
413
+ this.inlineStreamSkipEI(stream);
414
+ return length;
415
+ }
416
+
417
+ inlineStreamSkipEI(stream) {
418
+ const E = 0x45,
436
419
  I = 0x49;
437
- var state = 0,
438
- ch;
439
-
440
- while ((ch = stream.getByte()) !== -1) {
441
- if (state === 0) {
442
- state = ch === E ? 1 : 0;
443
- } else if (state === 1) {
444
- state = ch === I ? 2 : 0;
445
- } else if (state === 2) {
446
- break;
447
- }
420
+ let state = 0,
421
+ ch;
422
+
423
+ while ((ch = stream.getByte()) !== -1) {
424
+ if (state === 0) {
425
+ state = ch === E ? 1 : 0;
426
+ } else if (state === 1) {
427
+ state = ch === I ? 2 : 0;
428
+ } else if (state === 2) {
429
+ break;
448
430
  }
449
431
  }
450
- }, {
451
- key: "makeInlineImage",
452
- value: function makeInlineImage(cipherTransform) {
453
- var lexer = this.lexer;
454
- var stream = lexer.stream;
455
- var dict = new _primitives.Dict(this.xref);
456
- var dictLength;
457
-
458
- while (!(0, _primitives.isCmd)(this.buf1, 'ID') && !(0, _primitives.isEOF)(this.buf1)) {
459
- if (!(0, _primitives.isName)(this.buf1)) {
460
- throw new _util.FormatError('Dictionary key must be a name object');
461
- }
462
-
463
- var key = this.buf1.name;
464
- this.shift();
432
+ }
465
433
 
466
- if ((0, _primitives.isEOF)(this.buf1)) {
467
- break;
468
- }
434
+ makeInlineImage(cipherTransform) {
435
+ const lexer = this.lexer;
436
+ const stream = lexer.stream;
437
+ const dict = new _primitives.Dict(this.xref);
438
+ let dictLength;
469
439
 
470
- dict.set(key, this.getObj(cipherTransform));
440
+ while (!(0, _primitives.isCmd)(this.buf1, "ID") && !(0, _primitives.isEOF)(this.buf1)) {
441
+ if (!(0, _primitives.isName)(this.buf1)) {
442
+ throw new _util.FormatError("Dictionary key must be a name object");
471
443
  }
472
444
 
473
- if (lexer.beginInlineImagePos !== -1) {
474
- dictLength = stream.pos - lexer.beginInlineImagePos;
445
+ const key = this.buf1.name;
446
+ this.shift();
447
+
448
+ if ((0, _primitives.isEOF)(this.buf1)) {
449
+ break;
475
450
  }
476
451
 
477
- var filter = dict.get('Filter', 'F');
478
- var filterName;
452
+ dict.set(key, this.getObj(cipherTransform));
453
+ }
479
454
 
480
- if ((0, _primitives.isName)(filter)) {
481
- filterName = filter.name;
482
- } else if (Array.isArray(filter)) {
483
- var filterZero = this.xref.fetchIfRef(filter[0]);
455
+ if (lexer.beginInlineImagePos !== -1) {
456
+ dictLength = stream.pos - lexer.beginInlineImagePos;
457
+ }
484
458
 
485
- if ((0, _primitives.isName)(filterZero)) {
486
- filterName = filterZero.name;
487
- }
488
- }
459
+ const filter = dict.get("Filter", "F");
460
+ let filterName;
489
461
 
490
- var startPos = stream.pos;
491
- var length;
462
+ if ((0, _primitives.isName)(filter)) {
463
+ filterName = filter.name;
464
+ } else if (Array.isArray(filter)) {
465
+ const filterZero = this.xref.fetchIfRef(filter[0]);
492
466
 
493
- if (filterName === 'DCTDecode' || filterName === 'DCT') {
494
- length = this.findDCTDecodeInlineStreamEnd(stream);
495
- } else if (filterName === 'ASCII85Decode' || filterName === 'A85') {
496
- length = this.findASCII85DecodeInlineStreamEnd(stream);
497
- } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
498
- length = this.findASCIIHexDecodeInlineStreamEnd(stream);
499
- } else {
500
- length = this.findDefaultInlineStreamEnd(stream);
467
+ if ((0, _primitives.isName)(filterZero)) {
468
+ filterName = filterZero.name;
501
469
  }
470
+ }
502
471
 
503
- var imageStream = stream.makeSubStream(startPos, length, dict);
504
- var cacheKey;
505
-
506
- if (length < MAX_LENGTH_TO_CACHE && dictLength < MAX_ADLER32_LENGTH) {
507
- var imageBytes = imageStream.getBytes();
508
- imageStream.reset();
509
- var initialStreamPos = stream.pos;
510
- stream.pos = lexer.beginInlineImagePos;
511
- var dictBytes = stream.getBytes(dictLength);
512
- stream.pos = initialStreamPos;
513
- cacheKey = computeAdler32(imageBytes) + '_' + computeAdler32(dictBytes);
514
- var cacheEntry = this.imageCache[cacheKey];
515
-
516
- if (cacheEntry !== undefined) {
517
- this.buf2 = _primitives.Cmd.get('EI');
518
- this.shift();
519
- cacheEntry.reset();
520
- return cacheEntry;
521
- }
522
- }
472
+ const startPos = stream.pos;
473
+ let length;
474
+
475
+ if (filterName === "DCTDecode" || filterName === "DCT") {
476
+ length = this.findDCTDecodeInlineStreamEnd(stream);
477
+ } else if (filterName === "ASCII85Decode" || filterName === "A85") {
478
+ length = this.findASCII85DecodeInlineStreamEnd(stream);
479
+ } else if (filterName === "ASCIIHexDecode" || filterName === "AHx") {
480
+ length = this.findASCIIHexDecodeInlineStreamEnd(stream);
481
+ } else {
482
+ length = this.findDefaultInlineStreamEnd(stream);
483
+ }
523
484
 
524
- if (cipherTransform) {
525
- imageStream = cipherTransform.createStream(imageStream, length);
485
+ let imageStream = stream.makeSubStream(startPos, length, dict);
486
+ let cacheKey;
487
+
488
+ if (length < MAX_LENGTH_TO_CACHE && dictLength < MAX_ADLER32_LENGTH) {
489
+ const imageBytes = imageStream.getBytes();
490
+ imageStream.reset();
491
+ const initialStreamPos = stream.pos;
492
+ stream.pos = lexer.beginInlineImagePos;
493
+ const dictBytes = stream.getBytes(dictLength);
494
+ stream.pos = initialStreamPos;
495
+ cacheKey = computeAdler32(imageBytes) + "_" + computeAdler32(dictBytes);
496
+ const cacheEntry = this.imageCache[cacheKey];
497
+
498
+ if (cacheEntry !== undefined) {
499
+ this.buf2 = _primitives.Cmd.get("EI");
500
+ this.shift();
501
+ cacheEntry.reset();
502
+ return cacheEntry;
526
503
  }
504
+ }
527
505
 
528
- imageStream = this.filter(imageStream, dict, length);
529
- imageStream.dict = dict;
506
+ if (cipherTransform) {
507
+ imageStream = cipherTransform.createStream(imageStream, length);
508
+ }
530
509
 
531
- if (cacheKey !== undefined) {
532
- imageStream.cacheKey = "inline_".concat(length, "_").concat(cacheKey);
533
- this.imageCache[cacheKey] = imageStream;
534
- }
510
+ imageStream = this.filter(imageStream, dict, length);
511
+ imageStream.dict = dict;
535
512
 
536
- this.buf2 = _primitives.Cmd.get('EI');
537
- this.shift();
538
- return imageStream;
513
+ if (cacheKey !== undefined) {
514
+ imageStream.cacheKey = `inline_${length}_${cacheKey}`;
515
+ this.imageCache[cacheKey] = imageStream;
539
516
  }
540
- }, {
541
- key: "_findStreamLength",
542
- value: function _findStreamLength(startPos, signature) {
543
- var stream = this.lexer.stream;
544
- stream.pos = startPos;
545
- var SCAN_BLOCK_LENGTH = 2048;
546
- var signatureLength = signature.length;
547
-
548
- while (stream.pos < stream.end) {
549
- var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
550
- var scanLength = scanBytes.length - signatureLength;
551
-
552
- if (scanLength <= 0) {
553
- break;
554
- }
555
517
 
556
- var pos = 0;
518
+ this.buf2 = _primitives.Cmd.get("EI");
519
+ this.shift();
520
+ return imageStream;
521
+ }
557
522
 
558
- while (pos < scanLength) {
559
- var j = 0;
523
+ _findStreamLength(startPos, signature) {
524
+ const {
525
+ stream
526
+ } = this.lexer;
527
+ stream.pos = startPos;
528
+ const SCAN_BLOCK_LENGTH = 2048;
529
+ const signatureLength = signature.length;
560
530
 
561
- while (j < signatureLength && scanBytes[pos + j] === signature[j]) {
562
- j++;
563
- }
531
+ while (stream.pos < stream.end) {
532
+ const scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
533
+ const scanLength = scanBytes.length - signatureLength;
564
534
 
565
- if (j >= signatureLength) {
566
- stream.pos += pos;
567
- return stream.pos - startPos;
568
- }
535
+ if (scanLength <= 0) {
536
+ break;
537
+ }
538
+
539
+ let pos = 0;
569
540
 
570
- pos++;
541
+ while (pos < scanLength) {
542
+ let j = 0;
543
+
544
+ while (j < signatureLength && scanBytes[pos + j] === signature[j]) {
545
+ j++;
546
+ }
547
+
548
+ if (j >= signatureLength) {
549
+ stream.pos += pos;
550
+ return stream.pos - startPos;
571
551
  }
572
552
 
573
- stream.pos += scanLength;
553
+ pos++;
574
554
  }
575
555
 
576
- return -1;
556
+ stream.pos += scanLength;
577
557
  }
578
- }, {
579
- key: "makeStream",
580
- value: function makeStream(dict, cipherTransform) {
581
- var lexer = this.lexer;
582
- var stream = lexer.stream;
583
- lexer.skipToNextLine();
584
- var startPos = stream.pos - 1;
585
- var length = dict.get('Length');
586
-
587
- if (!Number.isInteger(length)) {
588
- (0, _util.info)("Bad length \"".concat(length, "\" in stream"));
589
- length = 0;
590
- }
591
558
 
592
- stream.pos = startPos + length;
593
- lexer.nextChar();
559
+ return -1;
560
+ }
594
561
 
595
- if (this.tryShift() && (0, _primitives.isCmd)(this.buf2, 'endstream')) {
596
- this.shift();
597
- } else {
598
- var ENDSTREAM_SIGNATURE = new Uint8Array([0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6D]);
562
+ makeStream(dict, cipherTransform) {
563
+ const lexer = this.lexer;
564
+ let stream = lexer.stream;
565
+ lexer.skipToNextLine();
566
+ const startPos = stream.pos - 1;
567
+ let length = dict.get("Length");
599
568
 
600
- var actualLength = this._findStreamLength(startPos, ENDSTREAM_SIGNATURE);
569
+ if (!Number.isInteger(length)) {
570
+ (0, _util.info)(`Bad length "${length}" in stream`);
571
+ length = 0;
572
+ }
601
573
 
602
- if (actualLength < 0) {
603
- var MAX_TRUNCATION = 1;
574
+ stream.pos = startPos + length;
575
+ lexer.nextChar();
604
576
 
605
- for (var i = 1; i <= MAX_TRUNCATION; i++) {
606
- var end = ENDSTREAM_SIGNATURE.length - i;
607
- var TRUNCATED_SIGNATURE = ENDSTREAM_SIGNATURE.slice(0, end);
577
+ if (this.tryShift() && (0, _primitives.isCmd)(this.buf2, "endstream")) {
578
+ this.shift();
579
+ } else {
580
+ const ENDSTREAM_SIGNATURE = new Uint8Array([0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6D]);
608
581
 
609
- var maybeLength = this._findStreamLength(startPos, TRUNCATED_SIGNATURE);
582
+ let actualLength = this._findStreamLength(startPos, ENDSTREAM_SIGNATURE);
610
583
 
611
- if (maybeLength >= 0) {
612
- var lastByte = stream.peekBytes(end + 1)[end];
584
+ if (actualLength < 0) {
585
+ const MAX_TRUNCATION = 1;
613
586
 
614
- if (!(0, _util.isSpace)(lastByte)) {
615
- break;
616
- }
587
+ for (let i = 1; i <= MAX_TRUNCATION; i++) {
588
+ const end = ENDSTREAM_SIGNATURE.length - i;
589
+ const TRUNCATED_SIGNATURE = ENDSTREAM_SIGNATURE.slice(0, end);
590
+
591
+ const maybeLength = this._findStreamLength(startPos, TRUNCATED_SIGNATURE);
617
592
 
618
- (0, _util.info)("Found \"".concat((0, _util.bytesToString)(TRUNCATED_SIGNATURE), "\" when ") + 'searching for endstream command.');
619
- actualLength = maybeLength;
593
+ if (maybeLength >= 0) {
594
+ const lastByte = stream.peekBytes(end + 1)[end];
595
+
596
+ if (!(0, _core_utils.isWhiteSpace)(lastByte)) {
620
597
  break;
621
598
  }
622
- }
623
599
 
624
- if (actualLength < 0) {
625
- throw new _util.FormatError('Missing endstream command.');
600
+ (0, _util.info)(`Found "${(0, _util.bytesToString)(TRUNCATED_SIGNATURE)}" when ` + "searching for endstream command.");
601
+ actualLength = maybeLength;
602
+ break;
626
603
  }
627
604
  }
628
605
 
629
- length = actualLength;
630
- lexer.nextChar();
631
- this.shift();
632
- this.shift();
606
+ if (actualLength < 0) {
607
+ throw new _util.FormatError("Missing endstream command.");
608
+ }
633
609
  }
634
610
 
611
+ length = actualLength;
612
+ lexer.nextChar();
613
+ this.shift();
635
614
  this.shift();
636
- stream = stream.makeSubStream(startPos, length, dict);
615
+ }
637
616
 
638
- if (cipherTransform) {
639
- stream = cipherTransform.createStream(stream, length);
640
- }
617
+ this.shift();
618
+ stream = stream.makeSubStream(startPos, length, dict);
641
619
 
642
- stream = this.filter(stream, dict, length);
643
- stream.dict = dict;
644
- return stream;
620
+ if (cipherTransform) {
621
+ stream = cipherTransform.createStream(stream, length);
645
622
  }
646
- }, {
647
- key: "filter",
648
- value: function filter(stream, dict, length) {
649
- var filter = dict.get('Filter', 'F');
650
- var params = dict.get('DecodeParms', 'DP');
651
-
652
- if ((0, _primitives.isName)(filter)) {
653
- if (Array.isArray(params)) {
654
- (0, _util.warn)('/DecodeParms should not contain an Array, ' + 'when /Filter contains a Name.');
655
- }
656
623
 
657
- return this.makeFilter(stream, filter.name, length, params);
624
+ stream = this.filter(stream, dict, length);
625
+ stream.dict = dict;
626
+ return stream;
627
+ }
628
+
629
+ filter(stream, dict, length) {
630
+ let filter = dict.get("Filter", "F");
631
+ let params = dict.get("DecodeParms", "DP");
632
+
633
+ if ((0, _primitives.isName)(filter)) {
634
+ if (Array.isArray(params)) {
635
+ (0, _util.warn)("/DecodeParms should not contain an Array, " + "when /Filter contains a Name.");
658
636
  }
659
637
 
660
- var maybeLength = length;
638
+ return this.makeFilter(stream, filter.name, length, params);
639
+ }
661
640
 
662
- if (Array.isArray(filter)) {
663
- var filterArray = filter;
664
- var paramsArray = params;
641
+ let maybeLength = length;
665
642
 
666
- for (var i = 0, ii = filterArray.length; i < ii; ++i) {
667
- filter = this.xref.fetchIfRef(filterArray[i]);
643
+ if (Array.isArray(filter)) {
644
+ const filterArray = filter;
645
+ const paramsArray = params;
668
646
 
669
- if (!(0, _primitives.isName)(filter)) {
670
- throw new _util.FormatError("Bad filter name \"".concat(filter, "\""));
671
- }
647
+ for (let i = 0, ii = filterArray.length; i < ii; ++i) {
648
+ filter = this.xref.fetchIfRef(filterArray[i]);
672
649
 
673
- params = null;
650
+ if (!(0, _primitives.isName)(filter)) {
651
+ throw new _util.FormatError(`Bad filter name "${filter}"`);
652
+ }
674
653
 
675
- if (Array.isArray(paramsArray) && i in paramsArray) {
676
- params = this.xref.fetchIfRef(paramsArray[i]);
677
- }
654
+ params = null;
678
655
 
679
- stream = this.makeFilter(stream, filter.name, maybeLength, params);
680
- maybeLength = null;
656
+ if (Array.isArray(paramsArray) && i in paramsArray) {
657
+ params = this.xref.fetchIfRef(paramsArray[i]);
681
658
  }
682
- }
683
659
 
684
- return stream;
685
- }
686
- }, {
687
- key: "makeFilter",
688
- value: function makeFilter(stream, name, maybeLength, params) {
689
- if (maybeLength === 0) {
690
- (0, _util.warn)("Empty \"".concat(name, "\" stream."));
691
- return new _stream.NullStream();
660
+ stream = this.makeFilter(stream, filter.name, maybeLength, params);
661
+ maybeLength = null;
692
662
  }
663
+ }
664
+
665
+ return stream;
666
+ }
693
667
 
694
- try {
695
- var xrefStreamStats = this.xref.stats.streamTypes;
668
+ makeFilter(stream, name, maybeLength, params) {
669
+ if (maybeLength === 0) {
670
+ (0, _util.warn)(`Empty "${name}" stream.`);
671
+ return new _stream.NullStream();
672
+ }
696
673
 
697
- if (name === 'FlateDecode' || name === 'Fl') {
698
- xrefStreamStats[_util.StreamType.FLATE] = true;
674
+ try {
675
+ const xrefStreamStats = this.xref.stats.streamTypes;
699
676
 
700
- if (params) {
701
- return new _stream.PredictorStream(new _stream.FlateStream(stream, maybeLength), maybeLength, params);
702
- }
677
+ if (name === "FlateDecode" || name === "Fl") {
678
+ xrefStreamStats[_util.StreamType.FLATE] = true;
703
679
 
704
- return new _stream.FlateStream(stream, maybeLength);
680
+ if (params) {
681
+ return new _stream.PredictorStream(new _stream.FlateStream(stream, maybeLength), maybeLength, params);
705
682
  }
706
683
 
707
- if (name === 'LZWDecode' || name === 'LZW') {
708
- xrefStreamStats[_util.StreamType.LZW] = true;
709
- var earlyChange = 1;
684
+ return new _stream.FlateStream(stream, maybeLength);
685
+ }
710
686
 
711
- if (params) {
712
- if (params.has('EarlyChange')) {
713
- earlyChange = params.get('EarlyChange');
714
- }
687
+ if (name === "LZWDecode" || name === "LZW") {
688
+ xrefStreamStats[_util.StreamType.LZW] = true;
689
+ let earlyChange = 1;
715
690
 
716
- return new _stream.PredictorStream(new _stream.LZWStream(stream, maybeLength, earlyChange), maybeLength, params);
691
+ if (params) {
692
+ if (params.has("EarlyChange")) {
693
+ earlyChange = params.get("EarlyChange");
717
694
  }
718
695
 
719
- return new _stream.LZWStream(stream, maybeLength, earlyChange);
696
+ return new _stream.PredictorStream(new _stream.LZWStream(stream, maybeLength, earlyChange), maybeLength, params);
720
697
  }
721
698
 
722
- if (name === 'DCTDecode' || name === 'DCT') {
723
- xrefStreamStats[_util.StreamType.DCT] = true;
724
- return new _jpeg_stream.JpegStream(stream, maybeLength, stream.dict, params);
725
- }
699
+ return new _stream.LZWStream(stream, maybeLength, earlyChange);
700
+ }
726
701
 
727
- if (name === 'JPXDecode' || name === 'JPX') {
728
- xrefStreamStats[_util.StreamType.JPX] = true;
729
- return new _jpx_stream.JpxStream(stream, maybeLength, stream.dict, params);
730
- }
702
+ if (name === "DCTDecode" || name === "DCT") {
703
+ xrefStreamStats[_util.StreamType.DCT] = true;
704
+ return new _jpeg_stream.JpegStream(stream, maybeLength, stream.dict, params);
705
+ }
731
706
 
732
- if (name === 'ASCII85Decode' || name === 'A85') {
733
- xrefStreamStats[_util.StreamType.A85] = true;
734
- return new _stream.Ascii85Stream(stream, maybeLength);
735
- }
707
+ if (name === "JPXDecode" || name === "JPX") {
708
+ xrefStreamStats[_util.StreamType.JPX] = true;
709
+ return new _jpx_stream.JpxStream(stream, maybeLength, stream.dict, params);
710
+ }
736
711
 
737
- if (name === 'ASCIIHexDecode' || name === 'AHx') {
738
- xrefStreamStats[_util.StreamType.AHX] = true;
739
- return new _stream.AsciiHexStream(stream, maybeLength);
740
- }
712
+ if (name === "ASCII85Decode" || name === "A85") {
713
+ xrefStreamStats[_util.StreamType.A85] = true;
714
+ return new _stream.Ascii85Stream(stream, maybeLength);
715
+ }
741
716
 
742
- if (name === 'CCITTFaxDecode' || name === 'CCF') {
743
- xrefStreamStats[_util.StreamType.CCF] = true;
744
- return new _ccitt_stream.CCITTFaxStream(stream, maybeLength, params);
745
- }
717
+ if (name === "ASCIIHexDecode" || name === "AHx") {
718
+ xrefStreamStats[_util.StreamType.AHX] = true;
719
+ return new _stream.AsciiHexStream(stream, maybeLength);
720
+ }
746
721
 
747
- if (name === 'RunLengthDecode' || name === 'RL') {
748
- xrefStreamStats[_util.StreamType.RLX] = true;
749
- return new _stream.RunLengthStream(stream, maybeLength);
750
- }
722
+ if (name === "CCITTFaxDecode" || name === "CCF") {
723
+ xrefStreamStats[_util.StreamType.CCF] = true;
724
+ return new _ccitt_stream.CCITTFaxStream(stream, maybeLength, params);
725
+ }
751
726
 
752
- if (name === 'JBIG2Decode') {
753
- xrefStreamStats[_util.StreamType.JBIG] = true;
754
- return new _jbig2_stream.Jbig2Stream(stream, maybeLength, stream.dict, params);
755
- }
727
+ if (name === "RunLengthDecode" || name === "RL") {
728
+ xrefStreamStats[_util.StreamType.RLX] = true;
729
+ return new _stream.RunLengthStream(stream, maybeLength);
730
+ }
756
731
 
757
- (0, _util.warn)("Filter \"".concat(name, "\" is not supported."));
758
- return stream;
759
- } catch (ex) {
760
- if (ex instanceof _core_utils.MissingDataException) {
761
- throw ex;
762
- }
732
+ if (name === "JBIG2Decode") {
733
+ xrefStreamStats[_util.StreamType.JBIG] = true;
734
+ return new _jbig2_stream.Jbig2Stream(stream, maybeLength, stream.dict, params);
735
+ }
763
736
 
764
- (0, _util.warn)("Invalid stream: \"".concat(ex, "\""));
765
- return new _stream.NullStream();
737
+ (0, _util.warn)(`Filter "${name}" is not supported.`);
738
+ return stream;
739
+ } catch (ex) {
740
+ if (ex instanceof _core_utils.MissingDataException) {
741
+ throw ex;
766
742
  }
743
+
744
+ (0, _util.warn)(`Invalid stream: "${ex}"`);
745
+ return new _stream.NullStream();
767
746
  }
768
- }]);
747
+ }
769
748
 
770
- return Parser;
771
- }();
749
+ }
772
750
 
773
751
  exports.Parser = Parser;
774
- var specialChars = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
752
+ const specialChars = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
775
753
 
776
754
  function toHexDigit(ch) {
777
755
  if (ch >= 0x30 && ch <= 0x39) {
778
- return ch & 0x0F;
756
+ return ch & 0x0f;
779
757
  }
780
758
 
781
759
  if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
782
- return (ch & 0x0F) + 9;
760
+ return (ch & 0x0f) + 9;
783
761
  }
784
762
 
785
763
  return -1;
786
764
  }
787
765
 
788
- var Lexer =
789
- /*#__PURE__*/
790
- function () {
791
- function Lexer(stream) {
792
- var knownCommands = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
793
-
794
- _classCallCheck(this, Lexer);
795
-
766
+ class Lexer {
767
+ constructor(stream, knownCommands = null) {
796
768
  this.stream = stream;
797
769
  this.nextChar();
798
770
  this.strBuf = [];
799
771
  this.knownCommands = knownCommands;
772
+ this._hexStringNumWarn = 0;
800
773
  this.beginInlineImagePos = -1;
801
774
  }
802
775
 
803
- _createClass(Lexer, [{
804
- key: "nextChar",
805
- value: function nextChar() {
806
- return this.currentChar = this.stream.getByte();
807
- }
808
- }, {
809
- key: "peekChar",
810
- value: function peekChar() {
811
- return this.stream.peekByte();
812
- }
813
- }, {
814
- key: "getNumber",
815
- value: function getNumber() {
816
- var ch = this.currentChar;
817
- var eNotation = false;
818
- var divideBy = 0;
819
- var sign = 0;
820
-
821
- if (ch === 0x2D) {
822
- sign = -1;
823
- ch = this.nextChar();
776
+ nextChar() {
777
+ return this.currentChar = this.stream.getByte();
778
+ }
824
779
 
825
- if (ch === 0x2D) {
826
- ch = this.nextChar();
827
- }
828
- } else if (ch === 0x2B) {
829
- sign = 1;
830
- ch = this.nextChar();
831
- }
780
+ peekChar() {
781
+ return this.stream.peekByte();
782
+ }
832
783
 
833
- if (ch === 0x0A || ch === 0x0D) {
834
- do {
835
- ch = this.nextChar();
836
- } while (ch === 0x0A || ch === 0x0D);
837
- }
784
+ getNumber() {
785
+ let ch = this.currentChar;
786
+ let eNotation = false;
787
+ let divideBy = 0;
788
+ let sign = 0;
789
+
790
+ if (ch === 0x2d) {
791
+ sign = -1;
792
+ ch = this.nextChar();
838
793
 
839
- if (ch === 0x2E) {
840
- divideBy = 10;
794
+ if (ch === 0x2d) {
841
795
  ch = this.nextChar();
842
796
  }
797
+ } else if (ch === 0x2b) {
798
+ sign = 1;
799
+ ch = this.nextChar();
800
+ }
843
801
 
844
- if (ch < 0x30 || ch > 0x39) {
845
- if (divideBy === 10 && sign === 0 && ((0, _util.isSpace)(ch) || ch === -1)) {
846
- (0, _util.warn)('Lexer.getNumber - treating a single decimal point as zero.');
847
- return 0;
848
- }
802
+ if (ch === 0x0a || ch === 0x0d) {
803
+ do {
804
+ ch = this.nextChar();
805
+ } while (ch === 0x0a || ch === 0x0d);
806
+ }
849
807
 
850
- throw new _util.FormatError("Invalid number: ".concat(String.fromCharCode(ch), " (charCode ").concat(ch, ")"));
851
- }
808
+ if (ch === 0x2e) {
809
+ divideBy = 10;
810
+ ch = this.nextChar();
811
+ }
852
812
 
853
- sign = sign || 1;
854
- var baseValue = ch - 0x30;
855
- var powerValue = 0;
856
- var powerValueSign = 1;
813
+ if (ch < 0x30 || ch > 0x39) {
814
+ if (divideBy === 10 && sign === 0 && ((0, _core_utils.isWhiteSpace)(ch) || ch === -1)) {
815
+ (0, _util.warn)("Lexer.getNumber - treating a single decimal point as zero.");
816
+ return 0;
817
+ }
857
818
 
858
- while ((ch = this.nextChar()) >= 0) {
859
- if (0x30 <= ch && ch <= 0x39) {
860
- var currentDigit = ch - 0x30;
819
+ throw new _util.FormatError(`Invalid number: ${String.fromCharCode(ch)} (charCode ${ch})`);
820
+ }
861
821
 
862
- if (eNotation) {
863
- powerValue = powerValue * 10 + currentDigit;
864
- } else {
865
- if (divideBy !== 0) {
866
- divideBy *= 10;
867
- }
822
+ sign = sign || 1;
823
+ let baseValue = ch - 0x30;
824
+ let powerValue = 0;
825
+ let powerValueSign = 1;
868
826
 
869
- baseValue = baseValue * 10 + currentDigit;
870
- }
871
- } else if (ch === 0x2E) {
872
- if (divideBy === 0) {
873
- divideBy = 1;
874
- } else {
875
- break;
876
- }
877
- } else if (ch === 0x2D) {
878
- (0, _util.warn)('Badly formatted number: minus sign in the middle');
879
- } else if (ch === 0x45 || ch === 0x65) {
880
- ch = this.peekChar();
827
+ while ((ch = this.nextChar()) >= 0) {
828
+ if (ch >= 0x30 && ch <= 0x39) {
829
+ const currentDigit = ch - 0x30;
881
830
 
882
- if (ch === 0x2B || ch === 0x2D) {
883
- powerValueSign = ch === 0x2D ? -1 : 1;
884
- this.nextChar();
885
- } else if (ch < 0x30 || ch > 0x39) {
886
- break;
831
+ if (eNotation) {
832
+ powerValue = powerValue * 10 + currentDigit;
833
+ } else {
834
+ if (divideBy !== 0) {
835
+ divideBy *= 10;
887
836
  }
888
837
 
889
- eNotation = true;
838
+ baseValue = baseValue * 10 + currentDigit;
839
+ }
840
+ } else if (ch === 0x2e) {
841
+ if (divideBy === 0) {
842
+ divideBy = 1;
890
843
  } else {
891
844
  break;
892
845
  }
893
- }
846
+ } else if (ch === 0x2d) {
847
+ (0, _util.warn)("Badly formatted number: minus sign in the middle");
848
+ } else if (ch === 0x45 || ch === 0x65) {
849
+ ch = this.peekChar();
894
850
 
895
- if (divideBy !== 0) {
896
- baseValue /= divideBy;
897
- }
851
+ if (ch === 0x2b || ch === 0x2d) {
852
+ powerValueSign = ch === 0x2d ? -1 : 1;
853
+ this.nextChar();
854
+ } else if (ch < 0x30 || ch > 0x39) {
855
+ break;
856
+ }
898
857
 
899
- if (eNotation) {
900
- baseValue *= Math.pow(10, powerValueSign * powerValue);
858
+ eNotation = true;
859
+ } else {
860
+ break;
901
861
  }
902
-
903
- return sign * baseValue;
904
862
  }
905
- }, {
906
- key: "getString",
907
- value: function getString() {
908
- var numParen = 1;
909
- var done = false;
910
- var strBuf = this.strBuf;
911
- strBuf.length = 0;
912
- var ch = this.nextChar();
913
-
914
- while (true) {
915
- var charBuffered = false;
916
-
917
- switch (ch | 0) {
918
- case -1:
919
- (0, _util.warn)('Unterminated string');
920
- done = true;
921
- break;
922
863
 
923
- case 0x28:
924
- ++numParen;
925
- strBuf.push('(');
926
- break;
864
+ if (divideBy !== 0) {
865
+ baseValue /= divideBy;
866
+ }
927
867
 
928
- case 0x29:
929
- if (--numParen === 0) {
930
- this.nextChar();
931
- done = true;
932
- } else {
933
- strBuf.push(')');
934
- }
868
+ if (eNotation) {
869
+ baseValue *= 10 ** (powerValueSign * powerValue);
870
+ }
935
871
 
936
- break;
872
+ return sign * baseValue;
873
+ }
937
874
 
938
- case 0x5C:
939
- ch = this.nextChar();
875
+ getString() {
876
+ let numParen = 1;
877
+ let done = false;
878
+ const strBuf = this.strBuf;
879
+ strBuf.length = 0;
880
+ let ch = this.nextChar();
940
881
 
941
- switch (ch) {
942
- case -1:
943
- (0, _util.warn)('Unterminated string');
944
- done = true;
945
- break;
946
-
947
- case 0x6E:
948
- strBuf.push('\n');
949
- break;
950
-
951
- case 0x72:
952
- strBuf.push('\r');
953
- break;
954
-
955
- case 0x74:
956
- strBuf.push('\t');
957
- break;
958
-
959
- case 0x62:
960
- strBuf.push('\b');
961
- break;
962
-
963
- case 0x66:
964
- strBuf.push('\f');
965
- break;
966
-
967
- case 0x5C:
968
- case 0x28:
969
- case 0x29:
970
- strBuf.push(String.fromCharCode(ch));
971
- break;
972
-
973
- case 0x30:
974
- case 0x31:
975
- case 0x32:
976
- case 0x33:
977
- case 0x34:
978
- case 0x35:
979
- case 0x36:
980
- case 0x37:
981
- var x = ch & 0x0F;
982
- ch = this.nextChar();
983
- charBuffered = true;
882
+ while (true) {
883
+ let charBuffered = false;
984
884
 
985
- if (ch >= 0x30 && ch <= 0x37) {
986
- x = (x << 3) + (ch & 0x0F);
987
- ch = this.nextChar();
885
+ switch (ch | 0) {
886
+ case -1:
887
+ (0, _util.warn)("Unterminated string");
888
+ done = true;
889
+ break;
988
890
 
989
- if (ch >= 0x30 && ch <= 0x37) {
990
- charBuffered = false;
991
- x = (x << 3) + (ch & 0x0F);
992
- }
993
- }
891
+ case 0x28:
892
+ ++numParen;
893
+ strBuf.push("(");
894
+ break;
994
895
 
995
- strBuf.push(String.fromCharCode(x));
996
- break;
896
+ case 0x29:
897
+ if (--numParen === 0) {
898
+ this.nextChar();
899
+ done = true;
900
+ } else {
901
+ strBuf.push(")");
902
+ }
997
903
 
998
- case 0x0D:
999
- if (this.peekChar() === 0x0A) {
1000
- this.nextChar();
1001
- }
904
+ break;
1002
905
 
1003
- break;
906
+ case 0x5c:
907
+ ch = this.nextChar();
1004
908
 
1005
- case 0x0A:
1006
- break;
909
+ switch (ch) {
910
+ case -1:
911
+ (0, _util.warn)("Unterminated string");
912
+ done = true;
913
+ break;
1007
914
 
1008
- default:
1009
- strBuf.push(String.fromCharCode(ch));
1010
- break;
1011
- }
915
+ case 0x6e:
916
+ strBuf.push("\n");
917
+ break;
1012
918
 
1013
- break;
919
+ case 0x72:
920
+ strBuf.push("\r");
921
+ break;
1014
922
 
1015
- default:
1016
- strBuf.push(String.fromCharCode(ch));
1017
- break;
1018
- }
923
+ case 0x74:
924
+ strBuf.push("\t");
925
+ break;
1019
926
 
1020
- if (done) {
1021
- break;
1022
- }
927
+ case 0x62:
928
+ strBuf.push("\b");
929
+ break;
1023
930
 
1024
- if (!charBuffered) {
1025
- ch = this.nextChar();
1026
- }
1027
- }
931
+ case 0x66:
932
+ strBuf.push("\f");
933
+ break;
1028
934
 
1029
- return strBuf.join('');
1030
- }
1031
- }, {
1032
- key: "getName",
1033
- value: function getName() {
1034
- var ch, previousCh;
1035
- var strBuf = this.strBuf;
1036
- strBuf.length = 0;
1037
-
1038
- while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
1039
- if (ch === 0x23) {
1040
- ch = this.nextChar();
935
+ case 0x5c:
936
+ case 0x28:
937
+ case 0x29:
938
+ strBuf.push(String.fromCharCode(ch));
939
+ break;
1041
940
 
1042
- if (specialChars[ch]) {
1043
- (0, _util.warn)('Lexer_getName: ' + 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
1044
- strBuf.push('#');
1045
- break;
1046
- }
941
+ case 0x30:
942
+ case 0x31:
943
+ case 0x32:
944
+ case 0x33:
945
+ case 0x34:
946
+ case 0x35:
947
+ case 0x36:
948
+ case 0x37:
949
+ let x = ch & 0x0f;
950
+ ch = this.nextChar();
951
+ charBuffered = true;
1047
952
 
1048
- var x = toHexDigit(ch);
953
+ if (ch >= 0x30 && ch <= 0x37) {
954
+ x = (x << 3) + (ch & 0x0f);
955
+ ch = this.nextChar();
1049
956
 
1050
- if (x !== -1) {
1051
- previousCh = ch;
1052
- ch = this.nextChar();
1053
- var x2 = toHexDigit(ch);
957
+ if (ch >= 0x30 && ch <= 0x37) {
958
+ charBuffered = false;
959
+ x = (x << 3) + (ch & 0x0f);
960
+ }
961
+ }
1054
962
 
1055
- if (x2 === -1) {
1056
- (0, _util.warn)("Lexer_getName: Illegal digit (".concat(String.fromCharCode(ch), ") ") + 'in hexadecimal number.');
1057
- strBuf.push('#', String.fromCharCode(previousCh));
963
+ strBuf.push(String.fromCharCode(x));
964
+ break;
1058
965
 
1059
- if (specialChars[ch]) {
1060
- break;
966
+ case 0x0d:
967
+ if (this.peekChar() === 0x0a) {
968
+ this.nextChar();
1061
969
  }
1062
970
 
1063
- strBuf.push(String.fromCharCode(ch));
1064
- continue;
1065
- }
971
+ break;
1066
972
 
1067
- strBuf.push(String.fromCharCode(x << 4 | x2));
1068
- } else {
1069
- strBuf.push('#', String.fromCharCode(ch));
973
+ case 0x0a:
974
+ break;
975
+
976
+ default:
977
+ strBuf.push(String.fromCharCode(ch));
978
+ break;
1070
979
  }
1071
- } else {
980
+
981
+ break;
982
+
983
+ default:
1072
984
  strBuf.push(String.fromCharCode(ch));
1073
- }
985
+ break;
1074
986
  }
1075
987
 
1076
- if (strBuf.length > 127) {
1077
- (0, _util.warn)("Name token is longer than allowed by the spec: ".concat(strBuf.length));
988
+ if (done) {
989
+ break;
1078
990
  }
1079
991
 
1080
- return _primitives.Name.get(strBuf.join(''));
992
+ if (!charBuffered) {
993
+ ch = this.nextChar();
994
+ }
1081
995
  }
1082
- }, {
1083
- key: "getHexString",
1084
- value: function getHexString() {
1085
- var strBuf = this.strBuf;
1086
- strBuf.length = 0;
1087
- var ch = this.currentChar;
1088
- var isFirstHex = true;
1089
- var firstDigit, secondDigit;
1090
-
1091
- while (true) {
1092
- if (ch < 0) {
1093
- (0, _util.warn)('Unterminated hex string');
1094
- break;
1095
- } else if (ch === 0x3E) {
1096
- this.nextChar();
996
+
997
+ return strBuf.join("");
998
+ }
999
+
1000
+ getName() {
1001
+ let ch, previousCh;
1002
+ const strBuf = this.strBuf;
1003
+ strBuf.length = 0;
1004
+
1005
+ while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
1006
+ if (ch === 0x23) {
1007
+ ch = this.nextChar();
1008
+
1009
+ if (specialChars[ch]) {
1010
+ (0, _util.warn)("Lexer_getName: " + "NUMBER SIGN (#) should be followed by a hexadecimal number.");
1011
+ strBuf.push("#");
1097
1012
  break;
1098
- } else if (specialChars[ch] === 1) {
1013
+ }
1014
+
1015
+ const x = toHexDigit(ch);
1016
+
1017
+ if (x !== -1) {
1018
+ previousCh = ch;
1099
1019
  ch = this.nextChar();
1100
- continue;
1101
- } else {
1102
- if (isFirstHex) {
1103
- firstDigit = toHexDigit(ch);
1020
+ const x2 = toHexDigit(ch);
1104
1021
 
1105
- if (firstDigit === -1) {
1106
- (0, _util.warn)("Ignoring invalid character \"".concat(ch, "\" in hex string"));
1107
- ch = this.nextChar();
1108
- continue;
1109
- }
1110
- } else {
1111
- secondDigit = toHexDigit(ch);
1022
+ if (x2 === -1) {
1023
+ (0, _util.warn)(`Lexer_getName: Illegal digit (${String.fromCharCode(ch)}) ` + "in hexadecimal number.");
1024
+ strBuf.push("#", String.fromCharCode(previousCh));
1112
1025
 
1113
- if (secondDigit === -1) {
1114
- (0, _util.warn)("Ignoring invalid character \"".concat(ch, "\" in hex string"));
1115
- ch = this.nextChar();
1116
- continue;
1026
+ if (specialChars[ch]) {
1027
+ break;
1117
1028
  }
1118
1029
 
1119
- strBuf.push(String.fromCharCode(firstDigit << 4 | secondDigit));
1030
+ strBuf.push(String.fromCharCode(ch));
1031
+ continue;
1120
1032
  }
1121
1033
 
1122
- isFirstHex = !isFirstHex;
1123
- ch = this.nextChar();
1034
+ strBuf.push(String.fromCharCode(x << 4 | x2));
1035
+ } else {
1036
+ strBuf.push("#", String.fromCharCode(ch));
1124
1037
  }
1038
+ } else {
1039
+ strBuf.push(String.fromCharCode(ch));
1125
1040
  }
1126
-
1127
- return strBuf.join('');
1128
1041
  }
1129
- }, {
1130
- key: "getObj",
1131
- value: function getObj() {
1132
- var comment = false;
1133
- var ch = this.currentChar;
1134
-
1135
- while (true) {
1136
- if (ch < 0) {
1137
- return _primitives.EOF;
1138
- }
1139
1042
 
1140
- if (comment) {
1141
- if (ch === 0x0A || ch === 0x0D) {
1142
- comment = false;
1143
- }
1144
- } else if (ch === 0x25) {
1145
- comment = true;
1146
- } else if (specialChars[ch] !== 1) {
1147
- break;
1148
- }
1043
+ if (strBuf.length > 127) {
1044
+ (0, _util.warn)(`Name token is longer than allowed by the spec: ${strBuf.length}`);
1045
+ }
1149
1046
 
1150
- ch = this.nextChar();
1151
- }
1047
+ return _primitives.Name.get(strBuf.join(""));
1048
+ }
1152
1049
 
1153
- switch (ch | 0) {
1154
- case 0x30:
1155
- case 0x31:
1156
- case 0x32:
1157
- case 0x33:
1158
- case 0x34:
1159
- case 0x35:
1160
- case 0x36:
1161
- case 0x37:
1162
- case 0x38:
1163
- case 0x39:
1164
- case 0x2B:
1165
- case 0x2D:
1166
- case 0x2E:
1167
- return this.getNumber();
1050
+ _hexStringWarn(ch) {
1051
+ const MAX_HEX_STRING_NUM_WARN = 5;
1168
1052
 
1169
- case 0x28:
1170
- return this.getString();
1053
+ if (this._hexStringNumWarn++ === MAX_HEX_STRING_NUM_WARN) {
1054
+ (0, _util.warn)("getHexString - ignoring additional invalid characters.");
1055
+ return;
1056
+ }
1171
1057
 
1172
- case 0x2F:
1173
- return this.getName();
1058
+ if (this._hexStringNumWarn > MAX_HEX_STRING_NUM_WARN) {
1059
+ return;
1060
+ }
1174
1061
 
1175
- case 0x5B:
1176
- this.nextChar();
1177
- return _primitives.Cmd.get('[');
1062
+ (0, _util.warn)(`getHexString - ignoring invalid character: ${ch}`);
1063
+ }
1178
1064
 
1179
- case 0x5D:
1180
- this.nextChar();
1181
- return _primitives.Cmd.get(']');
1065
+ getHexString() {
1066
+ const strBuf = this.strBuf;
1067
+ strBuf.length = 0;
1068
+ let ch = this.currentChar;
1069
+ let isFirstHex = true;
1070
+ let firstDigit, secondDigit;
1071
+ this._hexStringNumWarn = 0;
1072
+
1073
+ while (true) {
1074
+ if (ch < 0) {
1075
+ (0, _util.warn)("Unterminated hex string");
1076
+ break;
1077
+ } else if (ch === 0x3e) {
1078
+ this.nextChar();
1079
+ break;
1080
+ } else if (specialChars[ch] === 1) {
1081
+ ch = this.nextChar();
1082
+ continue;
1083
+ } else {
1084
+ if (isFirstHex) {
1085
+ firstDigit = toHexDigit(ch);
1182
1086
 
1183
- case 0x3C:
1184
- ch = this.nextChar();
1087
+ if (firstDigit === -1) {
1088
+ this._hexStringWarn(ch);
1185
1089
 
1186
- if (ch === 0x3C) {
1187
- this.nextChar();
1188
- return _primitives.Cmd.get('<<');
1090
+ ch = this.nextChar();
1091
+ continue;
1189
1092
  }
1093
+ } else {
1094
+ secondDigit = toHexDigit(ch);
1190
1095
 
1191
- return this.getHexString();
1192
-
1193
- case 0x3E:
1194
- ch = this.nextChar();
1096
+ if (secondDigit === -1) {
1097
+ this._hexStringWarn(ch);
1195
1098
 
1196
- if (ch === 0x3E) {
1197
- this.nextChar();
1198
- return _primitives.Cmd.get('>>');
1099
+ ch = this.nextChar();
1100
+ continue;
1199
1101
  }
1200
1102
 
1201
- return _primitives.Cmd.get('>');
1103
+ strBuf.push(String.fromCharCode(firstDigit << 4 | secondDigit));
1104
+ }
1202
1105
 
1203
- case 0x7B:
1204
- this.nextChar();
1205
- return _primitives.Cmd.get('{');
1106
+ isFirstHex = !isFirstHex;
1107
+ ch = this.nextChar();
1108
+ }
1109
+ }
1206
1110
 
1207
- case 0x7D:
1208
- this.nextChar();
1209
- return _primitives.Cmd.get('}');
1111
+ return strBuf.join("");
1112
+ }
1210
1113
 
1211
- case 0x29:
1212
- this.nextChar();
1213
- throw new _util.FormatError("Illegal character: ".concat(ch));
1114
+ getObj() {
1115
+ let comment = false;
1116
+ let ch = this.currentChar;
1117
+
1118
+ while (true) {
1119
+ if (ch < 0) {
1120
+ return _primitives.EOF;
1214
1121
  }
1215
1122
 
1216
- var str = String.fromCharCode(ch);
1217
- var knownCommands = this.knownCommands;
1218
- var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
1123
+ if (comment) {
1124
+ if (ch === 0x0a || ch === 0x0d) {
1125
+ comment = false;
1126
+ }
1127
+ } else if (ch === 0x25) {
1128
+ comment = true;
1129
+ } else if (specialChars[ch] !== 1) {
1130
+ break;
1131
+ }
1219
1132
 
1220
- while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
1221
- var possibleCommand = str + String.fromCharCode(ch);
1133
+ ch = this.nextChar();
1134
+ }
1222
1135
 
1223
- if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
1224
- break;
1136
+ switch (ch | 0) {
1137
+ case 0x30:
1138
+ case 0x31:
1139
+ case 0x32:
1140
+ case 0x33:
1141
+ case 0x34:
1142
+ case 0x35:
1143
+ case 0x36:
1144
+ case 0x37:
1145
+ case 0x38:
1146
+ case 0x39:
1147
+ case 0x2b:
1148
+ case 0x2d:
1149
+ case 0x2e:
1150
+ return this.getNumber();
1151
+
1152
+ case 0x28:
1153
+ return this.getString();
1154
+
1155
+ case 0x2f:
1156
+ return this.getName();
1157
+
1158
+ case 0x5b:
1159
+ this.nextChar();
1160
+ return _primitives.Cmd.get("[");
1161
+
1162
+ case 0x5d:
1163
+ this.nextChar();
1164
+ return _primitives.Cmd.get("]");
1165
+
1166
+ case 0x3c:
1167
+ ch = this.nextChar();
1168
+
1169
+ if (ch === 0x3c) {
1170
+ this.nextChar();
1171
+ return _primitives.Cmd.get("<<");
1225
1172
  }
1226
1173
 
1227
- if (str.length === 128) {
1228
- throw new _util.FormatError("Command token too long: ".concat(str.length));
1174
+ return this.getHexString();
1175
+
1176
+ case 0x3e:
1177
+ ch = this.nextChar();
1178
+
1179
+ if (ch === 0x3e) {
1180
+ this.nextChar();
1181
+ return _primitives.Cmd.get(">>");
1229
1182
  }
1230
1183
 
1231
- str = possibleCommand;
1232
- knownCommandFound = knownCommands && knownCommands[str] !== undefined;
1233
- }
1184
+ return _primitives.Cmd.get(">");
1234
1185
 
1235
- if (str === 'true') {
1236
- return true;
1237
- }
1186
+ case 0x7b:
1187
+ this.nextChar();
1188
+ return _primitives.Cmd.get("{");
1238
1189
 
1239
- if (str === 'false') {
1240
- return false;
1241
- }
1190
+ case 0x7d:
1191
+ this.nextChar();
1192
+ return _primitives.Cmd.get("}");
1193
+
1194
+ case 0x29:
1195
+ this.nextChar();
1196
+ throw new _util.FormatError(`Illegal character: ${ch}`);
1197
+ }
1198
+
1199
+ let str = String.fromCharCode(ch);
1200
+ const knownCommands = this.knownCommands;
1201
+ let knownCommandFound = knownCommands && knownCommands[str] !== undefined;
1202
+
1203
+ while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
1204
+ const possibleCommand = str + String.fromCharCode(ch);
1242
1205
 
1243
- if (str === 'null') {
1244
- return null;
1206
+ if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
1207
+ break;
1245
1208
  }
1246
1209
 
1247
- if (str === 'BI') {
1248
- this.beginInlineImagePos = this.stream.pos;
1210
+ if (str.length === 128) {
1211
+ throw new _util.FormatError(`Command token too long: ${str.length}`);
1249
1212
  }
1250
1213
 
1251
- return _primitives.Cmd.get(str);
1214
+ str = possibleCommand;
1215
+ knownCommandFound = knownCommands && knownCommands[str] !== undefined;
1252
1216
  }
1253
- }, {
1254
- key: "skipToNextLine",
1255
- value: function skipToNextLine() {
1256
- var ch = this.currentChar;
1257
1217
 
1258
- while (ch >= 0) {
1259
- if (ch === 0x0D) {
1260
- ch = this.nextChar();
1218
+ if (str === "true") {
1219
+ return true;
1220
+ }
1261
1221
 
1262
- if (ch === 0x0A) {
1263
- this.nextChar();
1264
- }
1222
+ if (str === "false") {
1223
+ return false;
1224
+ }
1265
1225
 
1266
- break;
1267
- } else if (ch === 0x0A) {
1226
+ if (str === "null") {
1227
+ return null;
1228
+ }
1229
+
1230
+ if (str === "BI") {
1231
+ this.beginInlineImagePos = this.stream.pos;
1232
+ }
1233
+
1234
+ return _primitives.Cmd.get(str);
1235
+ }
1236
+
1237
+ skipToNextLine() {
1238
+ let ch = this.currentChar;
1239
+
1240
+ while (ch >= 0) {
1241
+ if (ch === 0x0d) {
1242
+ ch = this.nextChar();
1243
+
1244
+ if (ch === 0x0a) {
1268
1245
  this.nextChar();
1269
- break;
1270
1246
  }
1271
1247
 
1272
- ch = this.nextChar();
1248
+ break;
1249
+ } else if (ch === 0x0a) {
1250
+ this.nextChar();
1251
+ break;
1273
1252
  }
1253
+
1254
+ ch = this.nextChar();
1274
1255
  }
1275
- }]);
1256
+ }
1276
1257
 
1277
- return Lexer;
1278
- }();
1258
+ }
1279
1259
 
1280
1260
  exports.Lexer = Lexer;
1281
1261
 
1282
- var Linearization =
1283
- /*#__PURE__*/
1284
- function () {
1285
- function Linearization() {
1286
- _classCallCheck(this, Linearization);
1287
- }
1288
-
1289
- _createClass(Linearization, null, [{
1290
- key: "create",
1291
- value: function create(stream) {
1292
- function getInt(linDict, name) {
1293
- var allowZeroValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1294
- var obj = linDict.get(name);
1295
-
1296
- if (Number.isInteger(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
1297
- return obj;
1298
- }
1262
+ class Linearization {
1263
+ static create(stream) {
1264
+ function getInt(linDict, name, allowZeroValue = false) {
1265
+ const obj = linDict.get(name);
1299
1266
 
1300
- throw new Error("The \"".concat(name, "\" parameter in the linearization ") + 'dictionary is invalid.');
1267
+ if (Number.isInteger(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
1268
+ return obj;
1301
1269
  }
1302
1270
 
1303
- function getHints(linDict) {
1304
- var hints = linDict.get('H');
1305
- var hintsLength;
1271
+ throw new Error(`The "${name}" parameter in the linearization ` + "dictionary is invalid.");
1272
+ }
1306
1273
 
1307
- if (Array.isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
1308
- for (var index = 0; index < hintsLength; index++) {
1309
- var hint = hints[index];
1274
+ function getHints(linDict) {
1275
+ const hints = linDict.get("H");
1276
+ let hintsLength;
1310
1277
 
1311
- if (!(Number.isInteger(hint) && hint > 0)) {
1312
- throw new Error("Hint (".concat(index, ") in the linearization dictionary ") + 'is invalid.');
1313
- }
1314
- }
1278
+ if (Array.isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
1279
+ for (let index = 0; index < hintsLength; index++) {
1280
+ const hint = hints[index];
1315
1281
 
1316
- return hints;
1282
+ if (!(Number.isInteger(hint) && hint > 0)) {
1283
+ throw new Error(`Hint (${index}) in the linearization dictionary is invalid.`);
1284
+ }
1317
1285
  }
1318
1286
 
1319
- throw new Error('Hint array in the linearization dictionary is invalid.');
1287
+ return hints;
1320
1288
  }
1321
1289
 
1322
- var parser = new Parser({
1323
- lexer: new Lexer(stream),
1324
- xref: null
1325
- });
1326
- var obj1 = parser.getObj();
1327
- var obj2 = parser.getObj();
1328
- var obj3 = parser.getObj();
1329
- var linDict = parser.getObj();
1330
- var obj, length;
1331
-
1332
- if (!(Number.isInteger(obj1) && Number.isInteger(obj2) && (0, _primitives.isCmd)(obj3, 'obj') && (0, _primitives.isDict)(linDict) && (0, _util.isNum)(obj = linDict.get('Linearized')) && obj > 0)) {
1333
- return null;
1334
- } else if ((length = getInt(linDict, 'L')) !== stream.length) {
1335
- throw new Error('The "L" parameter in the linearization dictionary ' + 'does not equal the stream length.');
1336
- }
1290
+ throw new Error("Hint array in the linearization dictionary is invalid.");
1291
+ }
1337
1292
 
1338
- return {
1339
- length: length,
1340
- hints: getHints(linDict),
1341
- objectNumberFirst: getInt(linDict, 'O'),
1342
- endFirst: getInt(linDict, 'E'),
1343
- numPages: getInt(linDict, 'N'),
1344
- mainXRefEntriesOffset: getInt(linDict, 'T'),
1345
- pageFirst: linDict.has('P') ? getInt(linDict, 'P', true) : 0
1346
- };
1293
+ const parser = new Parser({
1294
+ lexer: new Lexer(stream),
1295
+ xref: null
1296
+ });
1297
+ const obj1 = parser.getObj();
1298
+ const obj2 = parser.getObj();
1299
+ const obj3 = parser.getObj();
1300
+ const linDict = parser.getObj();
1301
+ let obj, length;
1302
+
1303
+ if (!(Number.isInteger(obj1) && Number.isInteger(obj2) && (0, _primitives.isCmd)(obj3, "obj") && (0, _primitives.isDict)(linDict) && (0, _util.isNum)(obj = linDict.get("Linearized")) && obj > 0)) {
1304
+ return null;
1305
+ } else if ((length = getInt(linDict, "L")) !== stream.length) {
1306
+ throw new Error('The "L" parameter in the linearization dictionary ' + "does not equal the stream length.");
1347
1307
  }
1348
- }]);
1349
1308
 
1350
- return Linearization;
1351
- }();
1309
+ return {
1310
+ length,
1311
+ hints: getHints(linDict),
1312
+ objectNumberFirst: getInt(linDict, "O"),
1313
+ endFirst: getInt(linDict, "E"),
1314
+ numPages: getInt(linDict, "N"),
1315
+ mainXRefEntriesOffset: getInt(linDict, "T"),
1316
+ pageFirst: linDict.has("P") ? getInt(linDict, "P", true) : 0
1317
+ };
1318
+ }
1319
+
1320
+ }
1352
1321
 
1353
1322
  exports.Linearization = Linearization;