pdfjs-dist 2.0.489 → 2.2.228

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