pdfjs-dist 2.1.266 → 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 (166) hide show
  1. package/CODE_OF_CONDUCT.md +15 -0
  2. package/bower.json +1 -1
  3. package/build/pdf.js +3349 -2324
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +2804 -1975
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/image_decoders/pdf.image_decoders.js +431 -511
  10. package/image_decoders/pdf.image_decoders.js.map +1 -1
  11. package/image_decoders/pdf.image_decoders.min.js +1 -1
  12. package/lib/core/annotation.js +294 -224
  13. package/lib/core/arithmetic_decoder.js +1 -1
  14. package/lib/core/bidi.js +1 -1
  15. package/lib/core/ccitt.js +1 -1
  16. package/lib/core/ccitt_stream.js +1 -1
  17. package/lib/core/cff_parser.js +61 -12
  18. package/lib/core/charsets.js +1 -1
  19. package/lib/core/chunked_stream.js +24 -14
  20. package/lib/core/cmap.js +17 -13
  21. package/lib/core/colorspace.js +1 -1
  22. package/lib/core/core_utils.js +147 -0
  23. package/lib/core/crypto.js +1 -1
  24. package/lib/core/document.js +47 -40
  25. package/lib/core/encodings.js +1 -1
  26. package/lib/core/evaluator.js +346 -279
  27. package/lib/core/font_renderer.js +1 -1
  28. package/lib/core/fonts.js +23 -11
  29. package/lib/core/function.js +1 -1
  30. package/lib/core/glyphlist.js +2 -2
  31. package/lib/core/image.js +2 -2
  32. package/lib/core/image_utils.js +111 -0
  33. package/lib/core/jbig2.js +1 -1
  34. package/lib/core/jbig2_stream.js +1 -1
  35. package/lib/core/jpeg_stream.js +1 -1
  36. package/lib/core/jpg.js +2 -1
  37. package/lib/core/jpx.js +1 -1
  38. package/lib/core/jpx_stream.js +1 -1
  39. package/lib/core/metrics.js +13 -13
  40. package/lib/core/murmurhash3.js +37 -33
  41. package/lib/core/obj.js +245 -41
  42. package/lib/core/operator_list.js +43 -32
  43. package/lib/core/parser.js +228 -133
  44. package/lib/core/pattern.js +4 -2
  45. package/lib/core/pdf_manager.js +17 -15
  46. package/lib/core/primitives.js +40 -6
  47. package/lib/core/ps_parser.js +1 -1
  48. package/lib/core/standard_fonts.js +9 -9
  49. package/lib/core/stream.js +1 -1
  50. package/lib/core/type1_parser.js +1 -1
  51. package/lib/core/unicode.js +2 -2
  52. package/lib/core/worker.js +54 -171
  53. package/lib/core/worker_stream.js +277 -0
  54. package/lib/display/annotation_layer.js +112 -33
  55. package/lib/display/api.js +211 -123
  56. package/lib/display/api_compatibility.js +1 -1
  57. package/lib/display/canvas.js +40 -19
  58. package/lib/display/content_disposition.js +1 -1
  59. package/lib/display/display_utils.js +747 -0
  60. package/lib/display/fetch_stream.js +19 -12
  61. package/lib/display/font_loader.js +11 -8
  62. package/lib/display/metadata.js +1 -1
  63. package/lib/display/network.js +563 -521
  64. package/lib/display/network_utils.js +1 -1
  65. package/lib/display/node_stream.js +21 -12
  66. package/lib/display/pattern_helper.js +24 -25
  67. package/lib/display/svg.js +1068 -565
  68. package/lib/display/text_layer.js +24 -14
  69. package/lib/display/transport_stream.js +192 -70
  70. package/lib/display/webgl.js +1 -1
  71. package/lib/display/worker_options.js +1 -1
  72. package/lib/display/xml_parser.js +1 -1
  73. package/lib/examples/node/domstubs.js +4 -1
  74. package/lib/pdf.js +20 -15
  75. package/lib/pdf.worker.js +3 -3
  76. package/lib/shared/compatibility.js +6 -6
  77. package/lib/shared/global_scope.js +1 -1
  78. package/lib/shared/is_node.js +2 -2
  79. package/lib/shared/message_handler.js +7 -7
  80. package/lib/shared/streams_polyfill.js +1 -1
  81. package/lib/shared/url_polyfill.js +1 -1
  82. package/lib/shared/util.js +13 -125
  83. package/lib/test/unit/annotation_spec.js +278 -93
  84. package/lib/test/unit/api_spec.js +198 -188
  85. package/lib/test/unit/bidi_spec.js +1 -1
  86. package/lib/test/unit/cff_parser_spec.js +15 -1
  87. package/lib/test/unit/clitests_helper.js +3 -3
  88. package/lib/test/unit/cmap_spec.js +20 -20
  89. package/lib/test/unit/colorspace_spec.js +17 -12
  90. package/lib/test/unit/core_utils_spec.js +191 -0
  91. package/lib/test/unit/crypto_spec.js +1 -1
  92. package/lib/test/unit/custom_spec.js +8 -8
  93. package/lib/test/unit/display_svg_spec.js +8 -8
  94. package/lib/test/unit/display_utils_spec.js +273 -0
  95. package/lib/test/unit/document_spec.js +7 -12
  96. package/lib/test/unit/encodings_spec.js +5 -5
  97. package/lib/test/unit/evaluator_spec.js +8 -10
  98. package/lib/test/unit/fetch_stream_spec.js +109 -0
  99. package/lib/test/unit/function_spec.js +1 -1
  100. package/lib/test/unit/jasmine-boot.js +4 -4
  101. package/lib/test/unit/message_handler_spec.js +1 -1
  102. package/lib/test/unit/metadata_spec.js +1 -1
  103. package/lib/test/unit/murmurhash3_spec.js +1 -1
  104. package/lib/test/unit/network_spec.js +5 -55
  105. package/lib/test/unit/network_utils_spec.js +51 -1
  106. package/lib/test/unit/node_stream_spec.js +8 -8
  107. package/lib/test/unit/parser_spec.js +150 -86
  108. package/lib/test/unit/pdf_find_controller_spec.js +1 -1
  109. package/lib/test/unit/pdf_find_utils_spec.js +1 -1
  110. package/lib/test/unit/pdf_history_spec.js +1 -1
  111. package/lib/test/unit/primitives_spec.js +30 -17
  112. package/lib/test/unit/stream_spec.js +1 -1
  113. package/lib/test/unit/test_utils.js +197 -43
  114. package/lib/test/unit/testreporter.js +1 -1
  115. package/lib/test/unit/type1_parser_spec.js +1 -1
  116. package/lib/test/unit/ui_utils_spec.js +20 -20
  117. package/lib/test/unit/unicode_spec.js +5 -5
  118. package/lib/test/unit/util_spec.js +1 -164
  119. package/lib/web/annotation_layer_builder.js +1 -1
  120. package/lib/web/app.js +104 -60
  121. package/lib/web/app_options.js +45 -37
  122. package/lib/web/base_viewer.js +7 -7
  123. package/lib/web/chromecom.js +8 -8
  124. package/lib/web/debugger.js +7 -7
  125. package/lib/web/download_manager.js +3 -2
  126. package/lib/web/firefox_print_service.js +4 -2
  127. package/lib/web/firefoxcom.js +50 -19
  128. package/lib/web/genericcom.js +8 -8
  129. package/lib/web/genericl10n.js +10 -10
  130. package/lib/web/grab_to_pan.js +3 -1
  131. package/lib/web/interfaces.js +13 -13
  132. package/lib/web/overlay_manager.js +10 -10
  133. package/lib/web/password_prompt.js +2 -2
  134. package/lib/web/pdf_attachment_viewer.js +1 -1
  135. package/lib/web/pdf_cursor_tools.js +1 -1
  136. package/lib/web/pdf_document_properties.js +188 -119
  137. package/lib/web/pdf_find_bar.js +1 -1
  138. package/lib/web/pdf_find_controller.js +3 -3
  139. package/lib/web/pdf_find_utils.js +1 -1
  140. package/lib/web/pdf_history.js +1 -1
  141. package/lib/web/pdf_link_service.js +2 -2
  142. package/lib/web/pdf_outline_viewer.js +53 -28
  143. package/lib/web/pdf_page_view.js +9 -18
  144. package/lib/web/pdf_presentation_mode.js +1 -1
  145. package/lib/web/pdf_print_service.js +5 -3
  146. package/lib/web/pdf_rendering_queue.js +4 -7
  147. package/lib/web/pdf_sidebar.js +24 -17
  148. package/lib/web/pdf_sidebar_resizer.js +1 -1
  149. package/lib/web/pdf_single_page_viewer.js +1 -1
  150. package/lib/web/pdf_thumbnail_view.js +2 -2
  151. package/lib/web/pdf_thumbnail_viewer.js +3 -3
  152. package/lib/web/pdf_viewer.component.js +3 -3
  153. package/lib/web/pdf_viewer.js +3 -3
  154. package/lib/web/preferences.js +30 -30
  155. package/lib/web/secondary_toolbar.js +1 -1
  156. package/lib/web/text_layer_builder.js +23 -45
  157. package/lib/web/toolbar.js +1 -1
  158. package/lib/web/ui_utils.js +14 -14
  159. package/lib/web/view_history.js +15 -15
  160. package/lib/web/viewer_compatibility.js +1 -1
  161. package/package.json +1 -1
  162. package/web/pdf_viewer.css +21 -10
  163. package/web/pdf_viewer.js +126 -194
  164. package/web/pdf_viewer.js.map +1 -1
  165. package/lib/display/dom_utils.js +0 -494
  166. package/lib/test/unit/dom_utils_spec.js +0 -89
package/lib/core/obj.js CHANGED
@@ -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 2018 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.
@@ -34,13 +34,15 @@ var _primitives = require("./primitives");
34
34
 
35
35
  var _parser = require("./parser");
36
36
 
37
+ var _core_utils = require("./core_utils");
38
+
37
39
  var _chunked_stream = require("./chunked_stream");
38
40
 
39
41
  var _crypto = require("./crypto");
40
42
 
41
43
  var _colorspace = require("./colorspace");
42
44
 
43
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
45
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
44
46
 
45
47
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
46
48
 
@@ -146,6 +148,7 @@ function () {
146
148
  var title = outlineDict.get('Title');
147
149
  var flags = outlineDict.get('F') || 0;
148
150
  var color = outlineDict.getArray('C');
151
+ var count = outlineDict.get('Count');
149
152
  var rgbColor = blackColor;
150
153
 
151
154
  if (Array.isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
@@ -159,7 +162,7 @@ function () {
159
162
  newWindow: data.newWindow,
160
163
  title: (0, _util.stringToPDFString)(title),
161
164
  color: rgbColor,
162
- count: outlineDict.get('Count'),
165
+ count: Number.isInteger(count) ? count : undefined,
163
166
  bold: !!(flags & 2),
164
167
  italic: !!(flags & 1),
165
168
  items: []
@@ -237,6 +240,8 @@ function () {
237
240
  } else if (this.catDict.has('Dests')) {
238
241
  return this.catDict.get('Dests');
239
242
  }
243
+
244
+ return undefined;
240
245
  }
241
246
  }, {
242
247
  key: "_readPageLabels",
@@ -311,7 +316,7 @@ function () {
311
316
 
312
317
  case 'R':
313
318
  case 'r':
314
- currentLabel = (0, _util.toRomanNumerals)(currentIndex, style === 'r');
319
+ currentLabel = (0, _core_utils.toRomanNumerals)(currentIndex, style === 'r');
315
320
  break;
316
321
 
317
322
  case 'A':
@@ -371,8 +376,8 @@ function () {
371
376
  _iteratorError = err;
372
377
  } finally {
373
378
  try {
374
- if (!_iteratorNormalCompletion && _iterator.return != null) {
375
- _iterator.return();
379
+ if (!_iteratorNormalCompletion && _iterator["return"] != null) {
380
+ _iterator["return"]();
376
381
  }
377
382
  } finally {
378
383
  if (_didIteratorError) {
@@ -387,6 +392,7 @@ function () {
387
392
  value: function cleanup() {
388
393
  var _this = this;
389
394
 
395
+ (0, _primitives.clearPrimitiveCaches)();
390
396
  this.pageKidsCountCache.clear();
391
397
  var promises = [];
392
398
  this.fontCache.forEach(function (promise) {
@@ -631,7 +637,7 @@ function () {
631
637
  try {
632
638
  metadata = (0, _util.stringToUTF8String)((0, _util.bytesToString)(stream.getBytes()));
633
639
  } catch (e) {
634
- if (e instanceof _util.MissingDataException) {
640
+ if (e instanceof _core_utils.MissingDataException) {
635
641
  throw e;
636
642
  }
637
643
 
@@ -661,7 +667,7 @@ function () {
661
667
  try {
662
668
  obj = this._readDocumentOutline();
663
669
  } catch (ex) {
664
- if (ex instanceof _util.MissingDataException) {
670
+ if (ex instanceof _core_utils.MissingDataException) {
665
671
  throw ex;
666
672
  }
667
673
 
@@ -678,7 +684,7 @@ function () {
678
684
  try {
679
685
  permissions = this._readPermissions();
680
686
  } catch (ex) {
681
- if (ex instanceof _util.MissingDataException) {
687
+ if (ex instanceof _core_utils.MissingDataException) {
682
688
  throw ex;
683
689
  }
684
690
 
@@ -728,7 +734,7 @@ function () {
728
734
  try {
729
735
  obj = this._readPageLabels();
730
736
  } catch (ex) {
731
- if (ex instanceof _util.MissingDataException) {
737
+ if (ex instanceof _core_utils.MissingDataException) {
732
738
  throw ex;
733
739
  }
734
740
 
@@ -737,6 +743,26 @@ function () {
737
743
 
738
744
  return (0, _util.shadow)(this, 'pageLabels', obj);
739
745
  }
746
+ }, {
747
+ key: "pageLayout",
748
+ get: function get() {
749
+ var obj = this.catDict.get('PageLayout');
750
+ var pageLayout = '';
751
+
752
+ if ((0, _primitives.isName)(obj)) {
753
+ switch (obj.name) {
754
+ case 'SinglePage':
755
+ case 'OneColumn':
756
+ case 'TwoColumnLeft':
757
+ case 'TwoColumnRight':
758
+ case 'TwoPageLeft':
759
+ case 'TwoPageRight':
760
+ pageLayout = obj.name;
761
+ }
762
+ }
763
+
764
+ return (0, _util.shadow)(this, 'pageLayout', pageLayout);
765
+ }
740
766
  }, {
741
767
  key: "pageMode",
742
768
  get: function get() {
@@ -757,6 +783,162 @@ function () {
757
783
 
758
784
  return (0, _util.shadow)(this, 'pageMode', pageMode);
759
785
  }
786
+ }, {
787
+ key: "viewerPreferences",
788
+ get: function get() {
789
+ var _this2 = this;
790
+
791
+ var ViewerPreferencesValidators = {
792
+ HideToolbar: _util.isBool,
793
+ HideMenubar: _util.isBool,
794
+ HideWindowUI: _util.isBool,
795
+ FitWindow: _util.isBool,
796
+ CenterWindow: _util.isBool,
797
+ DisplayDocTitle: _util.isBool,
798
+ NonFullScreenPageMode: _primitives.isName,
799
+ Direction: _primitives.isName,
800
+ ViewArea: _primitives.isName,
801
+ ViewClip: _primitives.isName,
802
+ PrintArea: _primitives.isName,
803
+ PrintClip: _primitives.isName,
804
+ PrintScaling: _primitives.isName,
805
+ Duplex: _primitives.isName,
806
+ PickTrayByPDFSize: _util.isBool,
807
+ PrintPageRange: Array.isArray,
808
+ NumCopies: Number.isInteger
809
+ };
810
+ var obj = this.catDict.get('ViewerPreferences');
811
+ var prefs = Object.create(null);
812
+
813
+ if ((0, _primitives.isDict)(obj)) {
814
+ for (var key in ViewerPreferencesValidators) {
815
+ if (!obj.has(key)) {
816
+ continue;
817
+ }
818
+
819
+ var value = obj.get(key);
820
+
821
+ if (!ViewerPreferencesValidators[key](value)) {
822
+ (0, _util.info)("Bad value in ViewerPreferences for \"".concat(key, "\"."));
823
+ continue;
824
+ }
825
+
826
+ var prefValue = void 0;
827
+
828
+ switch (key) {
829
+ case 'NonFullScreenPageMode':
830
+ switch (value.name) {
831
+ case 'UseNone':
832
+ case 'UseOutlines':
833
+ case 'UseThumbs':
834
+ case 'UseOC':
835
+ prefValue = value.name;
836
+ break;
837
+
838
+ default:
839
+ prefValue = 'UseNone';
840
+ }
841
+
842
+ break;
843
+
844
+ case 'Direction':
845
+ switch (value.name) {
846
+ case 'L2R':
847
+ case 'R2L':
848
+ prefValue = value.name;
849
+ break;
850
+
851
+ default:
852
+ prefValue = 'L2R';
853
+ }
854
+
855
+ break;
856
+
857
+ case 'ViewArea':
858
+ case 'ViewClip':
859
+ case 'PrintArea':
860
+ case 'PrintClip':
861
+ switch (value.name) {
862
+ case 'MediaBox':
863
+ case 'CropBox':
864
+ case 'BleedBox':
865
+ case 'TrimBox':
866
+ case 'ArtBox':
867
+ prefValue = value.name;
868
+ break;
869
+
870
+ default:
871
+ prefValue = 'CropBox';
872
+ }
873
+
874
+ break;
875
+
876
+ case 'PrintScaling':
877
+ switch (value.name) {
878
+ case 'None':
879
+ case 'AppDefault':
880
+ prefValue = value.name;
881
+ break;
882
+
883
+ default:
884
+ prefValue = 'AppDefault';
885
+ }
886
+
887
+ break;
888
+
889
+ case 'Duplex':
890
+ switch (value.name) {
891
+ case 'Simplex':
892
+ case 'DuplexFlipShortEdge':
893
+ case 'DuplexFlipLongEdge':
894
+ prefValue = value.name;
895
+ break;
896
+
897
+ default:
898
+ prefValue = 'None';
899
+ }
900
+
901
+ break;
902
+
903
+ case 'PrintPageRange':
904
+ var length = value.length;
905
+
906
+ if (length % 2 !== 0) {
907
+ break;
908
+ }
909
+
910
+ var isValid = value.every(function (page, i, arr) {
911
+ return Number.isInteger(page) && page > 0 && (i === 0 || page >= arr[i - 1]) && page <= _this2.numPages;
912
+ });
913
+
914
+ if (isValid) {
915
+ prefValue = value;
916
+ }
917
+
918
+ break;
919
+
920
+ case 'NumCopies':
921
+ if (value > 0) {
922
+ prefValue = value;
923
+ }
924
+
925
+ break;
926
+
927
+ default:
928
+ (0, _util.assert)(typeof value === 'boolean');
929
+ prefValue = value;
930
+ }
931
+
932
+ if (prefValue !== undefined) {
933
+ prefs[key] = prefValue;
934
+ } else {
935
+ (0, _util.info)("Bad value in ViewerPreferences for \"".concat(key, "\"."));
936
+ }
937
+ }
938
+ }
939
+
940
+ return (0, _util.shadow)(this, 'viewerPreferences', prefs);
941
+ }
760
942
  }, {
761
943
  key: "openActionDestination",
762
944
  get: function get() {
@@ -1075,7 +1257,7 @@ var XRef = function XRefClosure() {
1075
1257
  try {
1076
1258
  encrypt = trailerDict.get('Encrypt');
1077
1259
  } catch (ex) {
1078
- if (ex instanceof _util.MissingDataException) {
1260
+ if (ex instanceof _core_utils.MissingDataException) {
1079
1261
  throw ex;
1080
1262
  }
1081
1263
 
@@ -1094,7 +1276,7 @@ var XRef = function XRefClosure() {
1094
1276
  try {
1095
1277
  root = trailerDict.get('Root');
1096
1278
  } catch (ex) {
1097
- if (ex instanceof _util.MissingDataException) {
1279
+ if (ex instanceof _core_utils.MissingDataException) {
1098
1280
  throw ex;
1099
1281
  }
1100
1282
 
@@ -1105,7 +1287,7 @@ var XRef = function XRefClosure() {
1105
1287
  this.root = root;
1106
1288
  } else {
1107
1289
  if (!recoveryMode) {
1108
- throw new _util.XRefParseException();
1290
+ throw new _core_utils.XRefParseException();
1109
1291
  }
1110
1292
 
1111
1293
  throw new _util.FormatError('Invalid root reference');
@@ -1175,10 +1357,16 @@ var XRef = function XRefClosure() {
1175
1357
  entry.gen = parser.getObj();
1176
1358
  var type = parser.getObj();
1177
1359
 
1178
- if ((0, _primitives.isCmd)(type, 'f')) {
1179
- entry.free = true;
1180
- } else if ((0, _primitives.isCmd)(type, 'n')) {
1181
- entry.uncompressed = true;
1360
+ if (type instanceof _primitives.Cmd) {
1361
+ switch (type.cmd) {
1362
+ case 'f':
1363
+ entry.free = true;
1364
+ break;
1365
+
1366
+ case 'n':
1367
+ entry.uncompressed = true;
1368
+ break;
1369
+ }
1182
1370
  }
1183
1371
 
1184
1372
  if (!Number.isInteger(entry.offset) || !Number.isInteger(entry.gen) || !(entry.free || entry.uncompressed)) {
@@ -1462,7 +1650,12 @@ var XRef = function XRefClosure() {
1462
1650
 
1463
1651
  for (i = 0, ii = trailers.length; i < ii; ++i) {
1464
1652
  stream.pos = trailers[i];
1465
- var parser = new _parser.Parser(new _parser.Lexer(stream), true, this, true);
1653
+ var parser = new _parser.Parser({
1654
+ lexer: new _parser.Lexer(stream),
1655
+ xref: this,
1656
+ allowStreams: true,
1657
+ recoveryMode: true
1658
+ });
1466
1659
  var obj = parser.getObj();
1467
1660
 
1468
1661
  if (!(0, _primitives.isCmd)(obj, 'trailer')) {
@@ -1480,7 +1673,7 @@ var XRef = function XRefClosure() {
1480
1673
  try {
1481
1674
  rootDict = dict.get('Root');
1482
1675
  } catch (ex) {
1483
- if (ex instanceof _util.MissingDataException) {
1676
+ if (ex instanceof _core_utils.MissingDataException) {
1484
1677
  throw ex;
1485
1678
  }
1486
1679
 
@@ -1520,7 +1713,11 @@ var XRef = function XRefClosure() {
1520
1713
 
1521
1714
  startXRefParsedCache[startXRef] = true;
1522
1715
  stream.pos = startXRef + stream.start;
1523
- var parser = new _parser.Parser(new _parser.Lexer(stream), true, this);
1716
+ var parser = new _parser.Parser({
1717
+ lexer: new _parser.Lexer(stream),
1718
+ xref: this,
1719
+ allowStreams: true
1720
+ });
1524
1721
  var obj = parser.getObj();
1525
1722
  var dict;
1526
1723
 
@@ -1572,7 +1769,7 @@ var XRef = function XRefClosure() {
1572
1769
 
1573
1770
  return this.topDict;
1574
1771
  } catch (e) {
1575
- if (e instanceof _util.MissingDataException) {
1772
+ if (e instanceof _core_utils.MissingDataException) {
1576
1773
  throw e;
1577
1774
  }
1578
1775
 
@@ -1580,10 +1777,10 @@ var XRef = function XRefClosure() {
1580
1777
  }
1581
1778
 
1582
1779
  if (recoveryMode) {
1583
- return;
1780
+ return undefined;
1584
1781
  }
1585
1782
 
1586
- throw new _util.XRefParseException();
1783
+ throw new _core_utils.XRefParseException();
1587
1784
  },
1588
1785
  getEntry: function XRef_getEntry(i) {
1589
1786
  var xrefEntry = this.entries[i];
@@ -1644,11 +1841,15 @@ var XRef = function XRefClosure() {
1644
1841
  var num = ref.num;
1645
1842
 
1646
1843
  if (xrefEntry.gen !== gen) {
1647
- throw new _util.XRefEntryException("Inconsistent generation in XRef: ".concat(ref));
1844
+ throw new _core_utils.XRefEntryException("Inconsistent generation in XRef: ".concat(ref));
1648
1845
  }
1649
1846
 
1650
1847
  var stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start);
1651
- var parser = new _parser.Parser(new _parser.Lexer(stream), true, this);
1848
+ var parser = new _parser.Parser({
1849
+ lexer: new _parser.Lexer(stream),
1850
+ xref: this,
1851
+ allowStreams: true
1852
+ });
1652
1853
  var obj1 = parser.getObj();
1653
1854
  var obj2 = parser.getObj();
1654
1855
  var obj3 = parser.getObj();
@@ -1661,8 +1862,8 @@ var XRef = function XRefClosure() {
1661
1862
  obj2 = parseInt(obj2, 10);
1662
1863
  }
1663
1864
 
1664
- if (obj1 !== num || obj2 !== gen || !(0, _primitives.isCmd)(obj3)) {
1665
- throw new _util.XRefEntryException("Bad (uncompressed) XRef entry: ".concat(ref));
1865
+ if (obj1 !== num || obj2 !== gen || !(obj3 instanceof _primitives.Cmd)) {
1866
+ throw new _core_utils.XRefEntryException("Bad (uncompressed) XRef entry: ".concat(ref));
1666
1867
  }
1667
1868
 
1668
1869
  if (obj3.cmd !== 'obj') {
@@ -1674,7 +1875,7 @@ var XRef = function XRefClosure() {
1674
1875
  }
1675
1876
  }
1676
1877
 
1677
- throw new _util.XRefEntryException("Bad (uncompressed) XRef entry: ".concat(ref));
1878
+ throw new _core_utils.XRefEntryException("Bad (uncompressed) XRef entry: ".concat(ref));
1678
1879
  }
1679
1880
 
1680
1881
  if (this.encrypt && !suppressEncryption) {
@@ -1692,7 +1893,7 @@ var XRef = function XRefClosure() {
1692
1893
  fetchCompressed: function fetchCompressed(ref, xrefEntry) {
1693
1894
  var suppressEncryption = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1694
1895
  var tableOffset = xrefEntry.offset;
1695
- var stream = this.fetch(new _primitives.Ref(tableOffset, 0));
1896
+ var stream = this.fetch(_primitives.Ref.get(tableOffset, 0));
1696
1897
 
1697
1898
  if (!(0, _primitives.isStream)(stream)) {
1698
1899
  throw new _util.FormatError('bad ObjStm stream');
@@ -1705,8 +1906,11 @@ var XRef = function XRefClosure() {
1705
1906
  throw new _util.FormatError('invalid first and n parameters for ObjStm stream');
1706
1907
  }
1707
1908
 
1708
- var parser = new _parser.Parser(new _parser.Lexer(stream), false, this);
1709
- parser.allowStreams = true;
1909
+ var parser = new _parser.Parser({
1910
+ lexer: new _parser.Lexer(stream),
1911
+ xref: this,
1912
+ allowStreams: true
1913
+ });
1710
1914
  var i,
1711
1915
  entries = [],
1712
1916
  num,
@@ -1745,7 +1949,7 @@ var XRef = function XRefClosure() {
1745
1949
  xrefEntry = entries[xrefEntry.gen];
1746
1950
 
1747
1951
  if (xrefEntry === undefined) {
1748
- throw new _util.XRefEntryException("Bad (compressed) XRef entry: ".concat(ref));
1952
+ throw new _core_utils.XRefEntryException("Bad (compressed) XRef entry: ".concat(ref));
1749
1953
  }
1750
1954
 
1751
1955
  return xrefEntry;
@@ -1753,8 +1957,8 @@ var XRef = function XRefClosure() {
1753
1957
  fetchIfRefAsync: function () {
1754
1958
  var _fetchIfRefAsync = _asyncToGenerator(
1755
1959
  /*#__PURE__*/
1756
- _regenerator.default.mark(function _callee(obj, suppressEncryption) {
1757
- return _regenerator.default.wrap(function _callee$(_context) {
1960
+ _regenerator["default"].mark(function _callee(obj, suppressEncryption) {
1961
+ return _regenerator["default"].wrap(function _callee$(_context) {
1758
1962
  while (1) {
1759
1963
  switch (_context.prev = _context.next) {
1760
1964
  case 0:
@@ -1785,8 +1989,8 @@ var XRef = function XRefClosure() {
1785
1989
  fetchAsync: function () {
1786
1990
  var _fetchAsync = _asyncToGenerator(
1787
1991
  /*#__PURE__*/
1788
- _regenerator.default.mark(function _callee2(ref, suppressEncryption) {
1789
- return _regenerator.default.wrap(function _callee2$(_context2) {
1992
+ _regenerator["default"].mark(function _callee2(ref, suppressEncryption) {
1993
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
1790
1994
  while (1) {
1791
1995
  switch (_context2.prev = _context2.next) {
1792
1996
  case 0:
@@ -1797,7 +2001,7 @@ var XRef = function XRefClosure() {
1797
2001
  _context2.prev = 4;
1798
2002
  _context2.t0 = _context2["catch"](0);
1799
2003
 
1800
- if (_context2.t0 instanceof _util.MissingDataException) {
2004
+ if (_context2.t0 instanceof _core_utils.MissingDataException) {
1801
2005
  _context2.next = 8;
1802
2006
  break;
1803
2007
  }
@@ -2169,7 +2373,7 @@ var ObjectLoader = function () {
2169
2373
  return this.capability.promise;
2170
2374
  },
2171
2375
  _walk: function _walk(nodesToVisit) {
2172
- var _this2 = this;
2376
+ var _this3 = this;
2173
2377
 
2174
2378
  var nodesToRevisit = [];
2175
2379
  var pendingRequests = [];
@@ -2186,7 +2390,7 @@ var ObjectLoader = function () {
2186
2390
  this.refSet.put(currentNode);
2187
2391
  currentNode = this.xref.fetch(currentNode);
2188
2392
  } catch (ex) {
2189
- if (!(ex instanceof _util.MissingDataException)) {
2393
+ if (!(ex instanceof _core_utils.MissingDataException)) {
2190
2394
  throw ex;
2191
2395
  }
2192
2396
 
@@ -2228,11 +2432,11 @@ var ObjectLoader = function () {
2228
2432
  var node = nodesToRevisit[_i4];
2229
2433
 
2230
2434
  if ((0, _primitives.isRef)(node)) {
2231
- _this2.refSet.remove(node);
2435
+ _this3.refSet.remove(node);
2232
2436
  }
2233
2437
  }
2234
2438
 
2235
- _this2._walk(nodesToRevisit);
2439
+ _this3._walk(nodesToRevisit);
2236
2440
  }, this.capability.reject);
2237
2441
  return;
2238
2442
  }
@@ -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 2018 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.
@@ -81,6 +81,8 @@ var QueueOptimizer = function QueueOptimizerClosure() {
81
81
  case 3:
82
82
  return fnArray[i] === _util.OPS.restore;
83
83
  }
84
+
85
+ throw new Error("iterateInlineImageGroup - invalid pos: ".concat(pos));
84
86
  }, function foundInlineImageGroup(context, i) {
85
87
  var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
86
88
  var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
@@ -187,6 +189,8 @@ var QueueOptimizer = function QueueOptimizerClosure() {
187
189
  case 3:
188
190
  return fnArray[i] === _util.OPS.restore;
189
191
  }
192
+
193
+ throw new Error("iterateImageMaskGroup - invalid pos: ".concat(pos));
190
194
  }, function foundImageMaskGroup(context, i) {
191
195
  var MIN_IMAGES_IN_MASKS_BLOCK = 10;
192
196
  var MAX_IMAGES_IN_MASKS_BLOCK = 100;
@@ -269,7 +273,7 @@ var QueueOptimizer = function QueueOptimizerClosure() {
269
273
  var argsArray = context.argsArray;
270
274
  var iFirstTransform = context.iCurr - 2;
271
275
  return argsArray[iFirstTransform][1] === 0 && argsArray[iFirstTransform][2] === 0;
272
- }, function (context, i) {
276
+ }, function iterateImageGroup(context, i) {
273
277
  var fnArray = context.fnArray,
274
278
  argsArray = context.argsArray;
275
279
  var iFirstSave = context.iCurr - 3;
@@ -311,6 +315,8 @@ var QueueOptimizer = function QueueOptimizerClosure() {
311
315
  case 3:
312
316
  return fnArray[i] === _util.OPS.restore;
313
317
  }
318
+
319
+ throw new Error("iterateImageGroup - invalid pos: ".concat(pos));
314
320
  }, function (context, i) {
315
321
  var MIN_IMAGES_IN_BLOCK = 3;
316
322
  var MAX_IMAGES_IN_BLOCK = 1000;
@@ -343,7 +349,7 @@ var QueueOptimizer = function QueueOptimizerClosure() {
343
349
  argsArray.splice(iFirstSave, count * 4, args);
344
350
  return iFirstSave + 1;
345
351
  });
346
- addState(InitialState, [_util.OPS.beginText, _util.OPS.setFont, _util.OPS.setTextMatrix, _util.OPS.showText, _util.OPS.endText], null, function (context, i) {
352
+ addState(InitialState, [_util.OPS.beginText, _util.OPS.setFont, _util.OPS.setTextMatrix, _util.OPS.showText, _util.OPS.endText], null, function iterateShowTextGroup(context, i) {
347
353
  var fnArray = context.fnArray,
348
354
  argsArray = context.argsArray;
349
355
  var iFirstSave = context.iCurr - 4;
@@ -377,6 +383,8 @@ var QueueOptimizer = function QueueOptimizerClosure() {
377
383
  case 4:
378
384
  return fnArray[i] === _util.OPS.endText;
379
385
  }
386
+
387
+ throw new Error("iterateShowTextGroup - invalid pos: ".concat(pos));
380
388
  }, function (context, i) {
381
389
  var MIN_CHARS_IN_BLOCK = 3;
382
390
  var MAX_CHARS_IN_BLOCK = 1000;
@@ -518,7 +526,8 @@ var NullOptimizer = function NullOptimizerClosure() {
518
526
  this.queue.fnArray.push(fn);
519
527
  this.queue.argsArray.push(args);
520
528
  },
521
- flush: function flush() {}
529
+ flush: function flush() {},
530
+ reset: function reset() {}
522
531
  };
523
532
  return NullOptimizer;
524
533
  }();
@@ -527,36 +536,12 @@ var OperatorList = function OperatorListClosure() {
527
536
  var CHUNK_SIZE = 1000;
528
537
  var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5;
529
538
 
530
- function getTransfers(queue) {
531
- var transfers = [];
532
- var fnArray = queue.fnArray,
533
- argsArray = queue.argsArray;
534
-
535
- for (var i = 0, ii = queue.length; i < ii; i++) {
536
- switch (fnArray[i]) {
537
- case _util.OPS.paintInlineImageXObject:
538
- case _util.OPS.paintInlineImageXObjectGroup:
539
- case _util.OPS.paintImageMaskXObject:
540
- var arg = argsArray[i][0];
541
- ;
542
-
543
- if (!arg.cached) {
544
- transfers.push(arg.data.buffer);
545
- }
546
-
547
- break;
548
- }
549
- }
550
-
551
- return transfers;
552
- }
553
-
554
539
  function OperatorList(intent, messageHandler, pageIndex) {
555
540
  this.messageHandler = messageHandler;
556
541
  this.fnArray = [];
557
542
  this.argsArray = [];
558
543
 
559
- if (messageHandler && this.intent !== 'oplist') {
544
+ if (messageHandler && intent !== 'oplist') {
560
545
  this.optimizer = new QueueOptimizer(this);
561
546
  } else {
562
547
  this.optimizer = new NullOptimizer(this);
@@ -617,9 +602,35 @@ var OperatorList = function OperatorListClosure() {
617
602
  length: this.length
618
603
  };
619
604
  },
620
- flush: function flush(lastChunk) {
605
+
606
+ get _transfers() {
607
+ var transfers = [];
608
+ var fnArray = this.fnArray,
609
+ argsArray = this.argsArray,
610
+ length = this.length;
611
+
612
+ for (var i = 0; i < length; i++) {
613
+ switch (fnArray[i]) {
614
+ case _util.OPS.paintInlineImageXObject:
615
+ case _util.OPS.paintInlineImageXObjectGroup:
616
+ case _util.OPS.paintImageMaskXObject:
617
+ var arg = argsArray[i][0];
618
+ ;
619
+
620
+ if (!arg.cached) {
621
+ transfers.push(arg.data.buffer);
622
+ }
623
+
624
+ break;
625
+ }
626
+ }
627
+
628
+ return transfers;
629
+ },
630
+
631
+ flush: function flush() {
632
+ var lastChunk = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
621
633
  this.optimizer.flush();
622
- var transfers = getTransfers(this);
623
634
  var length = this.length;
624
635
  this._totalLength += length;
625
636
  this.messageHandler.send('RenderPageChunk', {
@@ -631,7 +642,7 @@ var OperatorList = function OperatorListClosure() {
631
642
  },
632
643
  pageIndex: this.pageIndex,
633
644
  intent: this.intent
634
- }, transfers);
645
+ }, this._transfers);
635
646
  this.dependencies = Object.create(null);
636
647
  this.fnArray.length = 0;
637
648
  this.argsArray.length = 0;