pdfjs-dist 2.0.550 → 2.3.200

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