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