pdfjs-dist 2.0.487 → 2.1.266

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