pdfjs-dist 2.2.228 → 2.6.347

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