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.
- package/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8816 -19300
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +27185 -35746
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +26665 -0
- package/es5/build/pdf.js.map +1 -0
- package/es5/build/pdf.min.js +22 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +61231 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/build/pdf.worker.min.js +22 -0
- package/es5/image_decoders/pdf.image_decoders.js +12529 -0
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
- package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/pdf_viewer.css +406 -0
- package/es5/web/pdf_viewer.js +7886 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1498 -4832
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +1144 -927
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +747 -716
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +462 -553
- package/lib/core/cmap.js +231 -277
- package/lib/core/colorspace.js +715 -857
- package/lib/core/core_utils.js +57 -52
- package/lib/core/crypto.js +416 -437
- package/lib/core/document.js +629 -670
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +3229 -2800
- package/lib/core/font_renderer.js +135 -178
- package/lib/core/fonts.js +602 -534
- package/lib/core/function.js +355 -279
- package/lib/core/glyphlist.js +4527 -4526
- package/lib/core/image.js +442 -439
- package/lib/core/image_utils.js +221 -61
- package/lib/core/jbig2.js +325 -316
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +21 -26
- package/lib/core/jpg.js +289 -233
- package/lib/core/jpx.js +161 -143
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1343 -1300
- package/lib/core/operator_list.js +90 -67
- package/lib/core/parser.js +990 -987
- package/lib/core/pattern.js +105 -77
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +156 -104
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +94 -74
- package/lib/core/type1_parser.js +89 -69
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +275 -290
- package/lib/core/worker_stream.js +101 -210
- package/lib/core/writer.js +242 -0
- package/lib/display/annotation_layer.js +772 -1041
- package/lib/display/annotation_storage.js +89 -0
- package/lib/display/api.js +1575 -1868
- package/lib/display/api_compatibility.js +12 -17
- package/lib/display/canvas.js +370 -222
- package/lib/display/content_disposition.js +40 -59
- package/lib/display/display_utils.js +341 -536
- package/lib/display/fetch_stream.js +188 -304
- package/lib/display/font_loader.js +282 -414
- package/lib/display/metadata.js +81 -99
- package/lib/display/network.js +362 -511
- package/lib/display/network_utils.js +25 -18
- package/lib/display/node_stream.js +283 -465
- package/lib/display/node_utils.js +87 -0
- package/lib/display/optional_content_config.js +184 -0
- package/lib/display/pattern_helper.js +93 -44
- package/lib/display/svg.js +1163 -1401
- package/lib/display/text_layer.js +154 -137
- package/lib/display/transport_stream.js +237 -375
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +220 -58
- package/lib/pdf.worker.js +14 -6
- package/lib/shared/compatibility.js +3 -246
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +327 -332
- package/lib/shared/util.js +271 -306
- package/lib/test/unit/annotation_spec.js +1902 -763
- package/lib/test/unit/annotation_storage_spec.js +83 -0
- package/lib/test/unit/api_spec.js +790 -592
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +73 -72
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +86 -88
- package/lib/test/unit/colorspace_spec.js +346 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +232 -185
- package/lib/test/unit/custom_spec.js +150 -24
- package/lib/test/unit/display_svg_spec.js +34 -39
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +128 -17
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +112 -91
- package/lib/test/unit/fetch_stream_spec.js +31 -29
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +173 -159
- package/lib/test/unit/metadata_spec.js +71 -71
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +13 -11
- package/lib/test/unit/network_utils_spec.js +158 -144
- package/lib/test/unit/node_stream_spec.js +76 -90
- package/lib/test/unit/parser_spec.js +108 -114
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +337 -156
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +91 -304
- package/lib/test/unit/testreporter.js +33 -22
- package/lib/test/unit/type1_parser_spec.js +42 -42
- package/lib/test/unit/ui_utils_spec.js +299 -461
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +129 -149
- package/lib/test/unit/writer_spec.js +84 -0
- package/lib/web/annotation_layer_builder.js +78 -111
- package/lib/web/app.js +1542 -1267
- package/lib/web/app_options.js +76 -91
- package/lib/web/base_tree_viewer.js +100 -0
- package/lib/web/base_viewer.js +869 -834
- package/lib/web/chromecom.js +165 -252
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +34 -58
- package/lib/web/firefox_print_service.js +62 -34
- package/lib/web/firefoxcom.js +206 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -254
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +150 -126
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +229 -383
- package/lib/web/pdf_find_bar.js +136 -170
- package/lib/web/pdf_find_controller.js +492 -548
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +397 -406
- package/lib/web/pdf_layer_viewer.js +208 -0
- package/lib/web/pdf_link_service.js +304 -348
- package/lib/web/pdf_outline_viewer.js +119 -212
- package/lib/web/pdf_page_view.js +474 -513
- package/lib/web/pdf_presentation_mode.js +308 -357
- package/lib/web/pdf_print_service.js +96 -110
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +286 -302
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +289 -297
- package/lib/web/pdf_thumbnail_viewer.js +202 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +69 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -319
- package/lib/web/toolbar.js +217 -210
- package/lib/web/ui_utils.js +274 -421
- package/lib/web/view_history.js +52 -226
- package/lib/web/viewer_compatibility.js +21 -6
- package/package.json +4 -9
- package/types/display/annotation_layer.d.ts +61 -0
- package/types/display/annotation_storage.d.ts +36 -0
- package/types/display/api.d.ts +1107 -0
- package/types/display/api_compatibility.d.ts +1 -0
- package/types/display/canvas.d.ts +4 -0
- package/types/display/content_disposition.d.ts +7 -0
- package/types/display/display_utils.d.ts +243 -0
- package/types/display/fetch_stream.d.ts +67 -0
- package/types/display/font_loader.d.ts +19 -0
- package/types/display/metadata.d.ts +9 -0
- package/types/display/network.d.ts +80 -0
- package/types/display/network_utils.d.ts +14 -0
- package/types/display/node_stream.d.ts +72 -0
- package/types/display/node_utils.d.ts +6 -0
- package/types/display/optional_content_config.d.ts +12 -0
- package/types/display/pattern_helper.d.ts +5 -0
- package/types/display/svg.d.ts +2 -0
- package/types/display/text_layer.d.ts +83 -0
- package/types/display/transport_stream.d.ts +57 -0
- package/types/display/webgl.d.ts +20 -0
- package/types/display/worker_options.d.ts +27 -0
- package/types/display/xml_parser.d.ts +35 -0
- package/types/pdf.d.ts +33 -0
- package/types/shared/compatibility.d.ts +1 -0
- package/types/shared/is_node.d.ts +1 -0
- package/types/shared/message_handler.d.ts +62 -0
- package/types/shared/util.d.ts +421 -0
- package/web/images/shadow.png +0 -0
- package/web/pdf_viewer.css +29 -27
- package/web/pdf_viewer.js +3524 -4746
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +6 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/shared/streams_polyfill.js +0 -43
- package/lib/shared/url_polyfill.js +0 -56
- package/web/images/texture.png +0 -0
package/lib/core/parser.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
|
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
|
35
|
+
var _core_utils = require("./core_utils.js");
|
36
36
|
|
37
|
-
var
|
37
|
+
var _ccitt_stream = require("./ccitt_stream.js");
|
38
38
|
|
39
|
-
var
|
39
|
+
var _jbig2_stream = require("./jbig2_stream.js");
|
40
40
|
|
41
|
-
var
|
41
|
+
var _jpeg_stream = require("./jpeg_stream.js");
|
42
42
|
|
43
|
-
var
|
43
|
+
var _jpx_stream = require("./jpx_stream.js");
|
44
44
|
|
45
|
-
|
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
|
-
|
56
|
-
|
49
|
+
const bytesLength = bytes.length;
|
50
|
+
let a = 1,
|
57
51
|
b = 0;
|
58
52
|
|
59
|
-
for (
|
60
|
-
a += bytes[i] &
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
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
|
-
|
126
|
-
|
127
|
-
|
128
|
-
return this.makeInlineImage(cipherTransform);
|
104
|
+
getObj(cipherTransform = null) {
|
105
|
+
const buf1 = this.buf1;
|
106
|
+
this.shift();
|
129
107
|
|
130
|
-
|
131
|
-
|
108
|
+
if (buf1 instanceof _primitives.Cmd) {
|
109
|
+
switch (buf1.cmd) {
|
110
|
+
case "BI":
|
111
|
+
return this.makeInlineImage(cipherTransform);
|
132
112
|
|
133
|
-
|
134
|
-
|
135
|
-
}
|
113
|
+
case "[":
|
114
|
+
const array = [];
|
136
115
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
}
|
116
|
+
while (!(0, _primitives.isCmd)(this.buf1, "]") && !(0, _primitives.isEOF)(this.buf1)) {
|
117
|
+
array.push(this.getObj(cipherTransform));
|
118
|
+
}
|
141
119
|
|
142
|
-
|
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
|
-
|
149
|
-
|
128
|
+
this.shift();
|
129
|
+
return array;
|
150
130
|
|
151
|
-
|
152
|
-
|
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
|
-
|
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
|
-
|
169
|
-
|
170
|
-
throw new _util.FormatError('End of file inside dictionary');
|
171
|
-
}
|
141
|
+
const key = this.buf1.name;
|
142
|
+
this.shift();
|
172
143
|
|
173
|
-
|
144
|
+
if ((0, _primitives.isEOF)(this.buf1)) {
|
145
|
+
break;
|
174
146
|
}
|
175
147
|
|
176
|
-
|
177
|
-
|
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
|
-
|
184
|
-
return
|
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
|
-
|
196
|
-
return ref;
|
197
|
-
}
|
164
|
+
return dict;
|
198
165
|
|
199
|
-
|
166
|
+
default:
|
167
|
+
return buf1;
|
200
168
|
}
|
169
|
+
}
|
201
170
|
|
202
|
-
|
203
|
-
|
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
|
-
|
206
|
-
|
207
|
-
|
175
|
+
this.shift();
|
176
|
+
this.shift();
|
177
|
+
return ref;
|
178
|
+
}
|
179
|
+
|
180
|
+
return buf1;
|
181
|
+
}
|
208
182
|
|
209
|
-
|
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
|
-
|
216
|
-
|
217
|
-
|
190
|
+
|
191
|
+
return buf1;
|
192
|
+
}
|
193
|
+
|
194
|
+
findDefaultInlineStreamEnd(stream) {
|
195
|
+
const E = 0x45,
|
218
196
|
I = 0x49,
|
219
197
|
SPACE = 0x20,
|
220
|
-
LF =
|
221
|
-
CR =
|
222
|
-
var n = 10,
|
198
|
+
LF = 0xa,
|
199
|
+
CR = 0xd,
|
223
200
|
NUL = 0x0;
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
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
|
-
|
238
|
-
|
239
|
-
|
216
|
+
if (ch === SPACE || ch === LF || ch === CR) {
|
217
|
+
maybeEIPos = stream.pos;
|
218
|
+
const followingBytes = stream.peekBytes(n);
|
240
219
|
|
241
|
-
|
242
|
-
|
220
|
+
for (let i = 0, ii = followingBytes.length; i < ii; i++) {
|
221
|
+
ch = followingBytes[i];
|
243
222
|
|
244
|
-
|
245
|
-
|
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 (
|
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
|
-
|
264
|
-
|
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
|
-
|
267
|
-
|
268
|
-
|
247
|
+
if (state === 2) {
|
248
|
+
break;
|
249
|
+
}
|
250
|
+
} else {
|
251
|
+
state = 0;
|
269
252
|
}
|
270
253
|
}
|
254
|
+
}
|
271
255
|
|
272
|
-
|
273
|
-
|
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 (
|
278
|
-
|
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
|
-
|
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
|
-
|
298
|
-
|
299
|
-
break;
|
274
|
+
return stream.pos - endOffset - startPos;
|
275
|
+
}
|
300
276
|
|
301
|
-
|
302
|
-
|
303
|
-
|
277
|
+
findDCTDecodeInlineStreamEnd(stream) {
|
278
|
+
const startPos = stream.pos;
|
279
|
+
let foundEOI = false,
|
280
|
+
b,
|
281
|
+
markerLength;
|
304
282
|
|
305
|
-
|
306
|
-
|
307
|
-
|
283
|
+
while ((b = stream.getByte()) !== -1) {
|
284
|
+
if (b !== 0xff) {
|
285
|
+
continue;
|
286
|
+
}
|
308
287
|
|
309
|
-
|
310
|
-
|
311
|
-
|
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
|
-
|
356
|
-
|
292
|
+
case 0xff:
|
293
|
+
stream.skip(-1);
|
294
|
+
break;
|
357
295
|
|
358
|
-
|
296
|
+
case 0xd9:
|
297
|
+
foundEOI = true;
|
359
298
|
break;
|
360
|
-
}
|
361
|
-
}
|
362
299
|
|
363
|
-
|
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
|
-
|
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
|
-
|
372
|
-
|
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
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
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
|
-
|
388
|
-
|
389
|
-
|
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 (
|
393
|
-
stream.skip();
|
390
|
+
if (maybeEI[0] === 0x45 && maybeEI[1] === 0x49) {
|
394
391
|
break;
|
395
392
|
}
|
396
393
|
}
|
397
394
|
}
|
395
|
+
}
|
398
396
|
|
399
|
-
|
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
|
-
|
408
|
-
|
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
|
-
|
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
|
-
|
427
|
-
|
428
|
-
|
429
|
-
return this.findDefaultInlineStreamEnd(stream);
|
414
|
+
while ((ch = stream.getByte()) !== -1) {
|
415
|
+
if (ch === GT) {
|
416
|
+
break;
|
430
417
|
}
|
418
|
+
}
|
431
419
|
|
432
|
-
|
433
|
-
|
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
|
-
|
437
|
-
|
438
|
-
|
427
|
+
|
428
|
+
this.inlineStreamSkipEI(stream);
|
429
|
+
return length;
|
430
|
+
}
|
431
|
+
|
432
|
+
inlineStreamSkipEI(stream) {
|
433
|
+
const E = 0x45,
|
439
434
|
I = 0x49;
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
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
|
-
|
467
|
-
|
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
|
-
|
470
|
-
|
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
|
-
|
477
|
-
|
460
|
+
const key = this.buf1.name;
|
461
|
+
this.shift();
|
462
|
+
|
463
|
+
if ((0, _primitives.isEOF)(this.buf1)) {
|
464
|
+
break;
|
478
465
|
}
|
479
466
|
|
480
|
-
|
481
|
-
|
467
|
+
dict.set(key, this.getObj(cipherTransform));
|
468
|
+
}
|
482
469
|
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
var filterZero = this.xref.fetchIfRef(filter[0]);
|
470
|
+
if (lexer.beginInlineImagePos !== -1) {
|
471
|
+
dictLength = stream.pos - lexer.beginInlineImagePos;
|
472
|
+
}
|
487
473
|
|
488
|
-
|
489
|
-
|
490
|
-
}
|
491
|
-
}
|
474
|
+
const filter = dict.get("Filter", "F");
|
475
|
+
let filterName;
|
492
476
|
|
493
|
-
|
494
|
-
|
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 (
|
497
|
-
|
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
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
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
|
-
|
528
|
-
|
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
|
-
|
532
|
-
imageStream
|
521
|
+
if (cipherTransform) {
|
522
|
+
imageStream = cipherTransform.createStream(imageStream, length);
|
523
|
+
}
|
533
524
|
|
534
|
-
|
535
|
-
|
536
|
-
this.imageCache[cacheKey] = imageStream;
|
537
|
-
}
|
525
|
+
imageStream = this.filter(imageStream, dict, length);
|
526
|
+
imageStream.dict = dict;
|
538
527
|
|
539
|
-
|
540
|
-
|
541
|
-
|
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
|
-
|
533
|
+
this.buf2 = _primitives.Cmd.get("EI");
|
534
|
+
this.shift();
|
535
|
+
return imageStream;
|
536
|
+
}
|
560
537
|
|
561
|
-
|
562
|
-
|
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
|
-
|
565
|
-
|
566
|
-
|
546
|
+
while (stream.pos < stream.end) {
|
547
|
+
const scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
|
548
|
+
const scanLength = scanBytes.length - signatureLength;
|
567
549
|
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
550
|
+
if (scanLength <= 0) {
|
551
|
+
break;
|
552
|
+
}
|
553
|
+
|
554
|
+
let pos = 0;
|
572
555
|
|
573
|
-
|
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
|
-
|
563
|
+
if (j >= signatureLength) {
|
564
|
+
stream.pos += pos;
|
565
|
+
return stream.pos - startPos;
|
566
|
+
}
|
567
|
+
|
568
|
+
pos++;
|
577
569
|
}
|
578
570
|
|
579
|
-
|
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
|
-
|
596
|
-
|
574
|
+
return -1;
|
575
|
+
}
|
597
576
|
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
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
|
-
|
584
|
+
if (!Number.isInteger(length)) {
|
585
|
+
(0, _util.info)(`Bad length "${length}" in stream`);
|
586
|
+
length = 0;
|
587
|
+
}
|
604
588
|
|
605
|
-
|
606
|
-
|
589
|
+
stream.pos = startPos + length;
|
590
|
+
lexer.nextChar();
|
607
591
|
|
608
|
-
|
609
|
-
|
610
|
-
|
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
|
-
|
597
|
+
let actualLength = this._findStreamLength(startPos, ENDSTREAM_SIGNATURE);
|
613
598
|
|
614
|
-
|
615
|
-
|
599
|
+
if (actualLength < 0) {
|
600
|
+
const MAX_TRUNCATION = 1;
|
616
601
|
|
617
|
-
|
618
|
-
|
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
|
-
|
622
|
-
|
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
|
-
|
628
|
-
|
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
|
-
|
633
|
-
|
634
|
-
|
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
|
-
|
629
|
+
this.shift();
|
630
|
+
}
|
640
631
|
|
641
|
-
|
642
|
-
|
643
|
-
}
|
632
|
+
this.shift();
|
633
|
+
stream = stream.makeSubStream(startPos, length, dict);
|
644
634
|
|
645
|
-
|
646
|
-
stream
|
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
|
-
|
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
|
-
|
653
|
+
return this.makeFilter(stream, filter.name, length, params);
|
654
|
+
}
|
664
655
|
|
665
|
-
|
666
|
-
var filterArray = filter;
|
667
|
-
var paramsArray = params;
|
656
|
+
let maybeLength = length;
|
668
657
|
|
669
|
-
|
670
|
-
|
658
|
+
if (Array.isArray(filter)) {
|
659
|
+
const filterArray = filter;
|
660
|
+
const paramsArray = params;
|
671
661
|
|
672
|
-
|
673
|
-
|
674
|
-
}
|
662
|
+
for (let i = 0, ii = filterArray.length; i < ii; ++i) {
|
663
|
+
filter = this.xref.fetchIfRef(filterArray[i]);
|
675
664
|
|
676
|
-
|
665
|
+
if (!(0, _primitives.isName)(filter)) {
|
666
|
+
throw new _util.FormatError(`Bad filter name "${filter}"`);
|
667
|
+
}
|
677
668
|
|
678
|
-
|
679
|
-
params = this.xref.fetchIfRef(paramsArray[i]);
|
680
|
-
}
|
669
|
+
params = null;
|
681
670
|
|
682
|
-
|
683
|
-
|
671
|
+
if (Array.isArray(paramsArray) && i in paramsArray) {
|
672
|
+
params = this.xref.fetchIfRef(paramsArray[i]);
|
684
673
|
}
|
685
|
-
}
|
686
674
|
|
687
|
-
|
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
|
-
|
698
|
-
|
680
|
+
return stream;
|
681
|
+
}
|
699
682
|
|
700
|
-
|
701
|
-
|
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
|
-
|
704
|
-
|
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
|
-
|
695
|
+
if (params) {
|
696
|
+
return new _stream.PredictorStream(new _stream.FlateStream(stream, maybeLength), maybeLength, params);
|
708
697
|
}
|
709
698
|
|
710
|
-
|
711
|
-
|
712
|
-
var earlyChange = 1;
|
699
|
+
return new _stream.FlateStream(stream, maybeLength);
|
700
|
+
}
|
713
701
|
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
}
|
702
|
+
if (name === "LZWDecode" || name === "LZW") {
|
703
|
+
xrefStreamStats[_util.StreamType.LZW] = true;
|
704
|
+
let earlyChange = 1;
|
718
705
|
|
719
|
-
|
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
|
-
|
726
|
-
|
727
|
-
return new _jpeg_stream.JpegStream(stream, maybeLength, stream.dict, params);
|
728
|
-
}
|
714
|
+
return new _stream.LZWStream(stream, maybeLength, earlyChange);
|
715
|
+
}
|
729
716
|
|
730
|
-
|
731
|
-
|
732
|
-
|
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
|
-
|
736
|
-
|
737
|
-
|
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
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
727
|
+
if (name === "ASCII85Decode" || name === "A85") {
|
728
|
+
xrefStreamStats[_util.StreamType.A85] = true;
|
729
|
+
return new _stream.Ascii85Stream(stream, maybeLength);
|
730
|
+
}
|
744
731
|
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
732
|
+
if (name === "ASCIIHexDecode" || name === "AHx") {
|
733
|
+
xrefStreamStats[_util.StreamType.AHX] = true;
|
734
|
+
return new _stream.AsciiHexStream(stream, maybeLength);
|
735
|
+
}
|
749
736
|
|
750
|
-
|
751
|
-
|
752
|
-
|
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
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
742
|
+
if (name === "RunLengthDecode" || name === "RL") {
|
743
|
+
xrefStreamStats[_util.StreamType.RLX] = true;
|
744
|
+
return new _stream.RunLengthStream(stream, maybeLength);
|
745
|
+
}
|
759
746
|
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
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
|
-
|
768
|
-
|
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
|
-
|
774
|
-
}();
|
764
|
+
}
|
775
765
|
|
776
766
|
exports.Parser = Parser;
|
777
|
-
|
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 &
|
771
|
+
return ch & 0x0f;
|
782
772
|
}
|
783
773
|
|
784
774
|
if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
|
785
|
-
return (ch &
|
775
|
+
return (ch & 0x0f) + 9;
|
786
776
|
}
|
787
777
|
|
788
778
|
return -1;
|
789
779
|
}
|
790
780
|
|
791
|
-
|
792
|
-
|
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
|
-
|
807
|
-
|
808
|
-
|
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
|
-
|
829
|
-
|
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
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
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 ===
|
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
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
817
|
+
if (ch === 0x0a || ch === 0x0d) {
|
818
|
+
do {
|
819
|
+
ch = this.nextChar();
|
820
|
+
} while (ch === 0x0a || ch === 0x0d);
|
821
|
+
}
|
852
822
|
|
853
|
-
|
854
|
-
|
823
|
+
if (ch === 0x2e) {
|
824
|
+
divideBy = 10;
|
825
|
+
ch = this.nextChar();
|
826
|
+
}
|
855
827
|
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
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
|
-
|
862
|
-
|
863
|
-
var currentDigit = ch - 0x30;
|
834
|
+
throw new _util.FormatError(`Invalid number: ${String.fromCharCode(ch)} (charCode ${ch})`);
|
835
|
+
}
|
864
836
|
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
divideBy *= 10;
|
870
|
-
}
|
837
|
+
sign = sign || 1;
|
838
|
+
let baseValue = ch - 0x30;
|
839
|
+
let powerValue = 0;
|
840
|
+
let powerValueSign = 1;
|
871
841
|
|
872
|
-
|
873
|
-
|
874
|
-
|
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
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
846
|
+
if (eNotation) {
|
847
|
+
powerValue = powerValue * 10 + currentDigit;
|
848
|
+
} else {
|
849
|
+
if (divideBy !== 0) {
|
850
|
+
divideBy *= 10;
|
890
851
|
}
|
891
852
|
|
892
|
-
|
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
|
-
|
899
|
-
|
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
|
-
|
903
|
-
|
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
|
-
|
927
|
-
|
928
|
-
|
929
|
-
break;
|
879
|
+
if (divideBy !== 0) {
|
880
|
+
baseValue /= divideBy;
|
881
|
+
}
|
930
882
|
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
done = true;
|
935
|
-
} else {
|
936
|
-
strBuf.push(')');
|
937
|
-
}
|
883
|
+
if (eNotation) {
|
884
|
+
baseValue *= 10 ** (powerValueSign * powerValue);
|
885
|
+
}
|
938
886
|
|
939
|
-
|
887
|
+
return sign * baseValue;
|
888
|
+
}
|
940
889
|
|
941
|
-
|
942
|
-
|
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
|
-
|
945
|
-
|
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
|
-
|
989
|
-
|
990
|
-
|
900
|
+
switch (ch | 0) {
|
901
|
+
case -1:
|
902
|
+
(0, _util.warn)("Unterminated string");
|
903
|
+
done = true;
|
904
|
+
break;
|
991
905
|
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
}
|
906
|
+
case 0x28:
|
907
|
+
++numParen;
|
908
|
+
strBuf.push("(");
|
909
|
+
break;
|
997
910
|
|
998
|
-
|
999
|
-
|
911
|
+
case 0x29:
|
912
|
+
if (--numParen === 0) {
|
913
|
+
this.nextChar();
|
914
|
+
done = true;
|
915
|
+
} else {
|
916
|
+
strBuf.push(")");
|
917
|
+
}
|
1000
918
|
|
1001
|
-
|
1002
|
-
if (this.peekChar() === 0x0A) {
|
1003
|
-
this.nextChar();
|
1004
|
-
}
|
919
|
+
break;
|
1005
920
|
|
1006
|
-
|
921
|
+
case 0x5c:
|
922
|
+
ch = this.nextChar();
|
1007
923
|
|
1008
|
-
|
1009
|
-
|
924
|
+
switch (ch) {
|
925
|
+
case -1:
|
926
|
+
(0, _util.warn)("Unterminated string");
|
927
|
+
done = true;
|
928
|
+
break;
|
1010
929
|
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
}
|
930
|
+
case 0x6e:
|
931
|
+
strBuf.push("\n");
|
932
|
+
break;
|
1015
933
|
|
1016
|
-
|
934
|
+
case 0x72:
|
935
|
+
strBuf.push("\r");
|
936
|
+
break;
|
1017
937
|
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
}
|
938
|
+
case 0x74:
|
939
|
+
strBuf.push("\t");
|
940
|
+
break;
|
1022
941
|
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
942
|
+
case 0x62:
|
943
|
+
strBuf.push("\b");
|
944
|
+
break;
|
1026
945
|
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
}
|
946
|
+
case 0x66:
|
947
|
+
strBuf.push("\f");
|
948
|
+
break;
|
1031
949
|
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
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
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
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
|
-
|
968
|
+
if (ch >= 0x30 && ch <= 0x37) {
|
969
|
+
x = (x << 3) + (ch & 0x0f);
|
970
|
+
ch = this.nextChar();
|
1052
971
|
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
972
|
+
if (ch >= 0x30 && ch <= 0x37) {
|
973
|
+
charBuffered = false;
|
974
|
+
x = (x << 3) + (ch & 0x0f);
|
975
|
+
}
|
976
|
+
}
|
1057
977
|
|
1058
|
-
|
1059
|
-
|
1060
|
-
strBuf.push('#', String.fromCharCode(previousCh));
|
978
|
+
strBuf.push(String.fromCharCode(x));
|
979
|
+
break;
|
1061
980
|
|
1062
|
-
|
1063
|
-
|
981
|
+
case 0x0d:
|
982
|
+
if (this.peekChar() === 0x0a) {
|
983
|
+
this.nextChar();
|
1064
984
|
}
|
1065
985
|
|
1066
|
-
|
1067
|
-
continue;
|
1068
|
-
}
|
986
|
+
break;
|
1069
987
|
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
988
|
+
case 0x0a:
|
989
|
+
break;
|
990
|
+
|
991
|
+
default:
|
992
|
+
strBuf.push(String.fromCharCode(ch));
|
993
|
+
break;
|
1073
994
|
}
|
1074
|
-
|
995
|
+
|
996
|
+
break;
|
997
|
+
|
998
|
+
default:
|
1075
999
|
strBuf.push(String.fromCharCode(ch));
|
1076
|
-
|
1000
|
+
break;
|
1077
1001
|
}
|
1078
1002
|
|
1079
|
-
if (
|
1080
|
-
|
1003
|
+
if (done) {
|
1004
|
+
break;
|
1081
1005
|
}
|
1082
1006
|
|
1083
|
-
|
1007
|
+
if (!charBuffered) {
|
1008
|
+
ch = this.nextChar();
|
1009
|
+
}
|
1084
1010
|
}
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
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
|
-
}
|
1028
|
+
}
|
1029
|
+
|
1030
|
+
const x = toHexDigit(ch);
|
1031
|
+
|
1032
|
+
if (x !== -1) {
|
1033
|
+
previousCh = ch;
|
1102
1034
|
ch = this.nextChar();
|
1103
|
-
|
1104
|
-
} else {
|
1105
|
-
if (isFirstHex) {
|
1106
|
-
firstDigit = toHexDigit(ch);
|
1035
|
+
const x2 = toHexDigit(ch);
|
1107
1036
|
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
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 (
|
1117
|
-
|
1118
|
-
ch = this.nextChar();
|
1119
|
-
continue;
|
1041
|
+
if (specialChars[ch]) {
|
1042
|
+
break;
|
1120
1043
|
}
|
1121
1044
|
|
1122
|
-
strBuf.push(String.fromCharCode(
|
1045
|
+
strBuf.push(String.fromCharCode(ch));
|
1046
|
+
continue;
|
1123
1047
|
}
|
1124
1048
|
|
1125
|
-
|
1126
|
-
|
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
|
-
|
1144
|
-
|
1145
|
-
|
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
|
-
|
1154
|
-
|
1062
|
+
return _primitives.Name.get(strBuf.join(""));
|
1063
|
+
}
|
1155
1064
|
|
1156
|
-
|
1157
|
-
|
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
|
-
|
1173
|
-
|
1068
|
+
if (this._hexStringNumWarn++ === MAX_HEX_STRING_NUM_WARN) {
|
1069
|
+
(0, _util.warn)("getHexString - ignoring additional invalid characters.");
|
1070
|
+
return;
|
1071
|
+
}
|
1174
1072
|
|
1175
|
-
|
1176
|
-
|
1073
|
+
if (this._hexStringNumWarn > MAX_HEX_STRING_NUM_WARN) {
|
1074
|
+
return;
|
1075
|
+
}
|
1177
1076
|
|
1178
|
-
|
1179
|
-
|
1180
|
-
return _primitives.Cmd.get('[');
|
1077
|
+
(0, _util.warn)(`getHexString - ignoring invalid character: ${ch}`);
|
1078
|
+
}
|
1181
1079
|
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
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
|
-
|
1187
|
-
|
1102
|
+
if (firstDigit === -1) {
|
1103
|
+
this._hexStringWarn(ch);
|
1188
1104
|
|
1189
|
-
|
1190
|
-
|
1191
|
-
return _primitives.Cmd.get('<<');
|
1105
|
+
ch = this.nextChar();
|
1106
|
+
continue;
|
1192
1107
|
}
|
1108
|
+
} else {
|
1109
|
+
secondDigit = toHexDigit(ch);
|
1193
1110
|
|
1194
|
-
|
1195
|
-
|
1196
|
-
case 0x3E:
|
1197
|
-
ch = this.nextChar();
|
1111
|
+
if (secondDigit === -1) {
|
1112
|
+
this._hexStringWarn(ch);
|
1198
1113
|
|
1199
|
-
|
1200
|
-
|
1201
|
-
return _primitives.Cmd.get('>>');
|
1114
|
+
ch = this.nextChar();
|
1115
|
+
continue;
|
1202
1116
|
}
|
1203
1117
|
|
1204
|
-
|
1118
|
+
strBuf.push(String.fromCharCode(firstDigit << 4 | secondDigit));
|
1119
|
+
}
|
1205
1120
|
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1121
|
+
isFirstHex = !isFirstHex;
|
1122
|
+
ch = this.nextChar();
|
1123
|
+
}
|
1124
|
+
}
|
1209
1125
|
|
1210
|
-
|
1211
|
-
|
1212
|
-
return _primitives.Cmd.get('}');
|
1126
|
+
return strBuf.join("");
|
1127
|
+
}
|
1213
1128
|
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
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
|
-
|
1220
|
-
|
1221
|
-
|
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
|
-
|
1224
|
-
|
1148
|
+
ch = this.nextChar();
|
1149
|
+
}
|
1225
1150
|
|
1226
|
-
|
1227
|
-
|
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
|
-
|
1231
|
-
|
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
|
-
|
1235
|
-
knownCommandFound = knownCommands && knownCommands[str] !== undefined;
|
1236
|
-
}
|
1199
|
+
return _primitives.Cmd.get(">");
|
1237
1200
|
|
1238
|
-
|
1239
|
-
|
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
|
-
|
1243
|
-
|
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 ===
|
1247
|
-
|
1225
|
+
if (str.length === 128) {
|
1226
|
+
throw new _util.FormatError(`Command token too long: ${str.length}`);
|
1248
1227
|
}
|
1249
1228
|
|
1250
|
-
|
1251
|
-
|
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
|
-
|
1265
|
+
(0, _util.warn)(`peekObj: ${ex}`);
|
1255
1266
|
}
|
1256
|
-
}, {
|
1257
|
-
key: "skipToNextLine",
|
1258
|
-
value: function skipToNextLine() {
|
1259
|
-
var ch = this.currentChar;
|
1260
1267
|
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1268
|
+
this.stream.pos = streamPos;
|
1269
|
+
this.currentChar = currentChar;
|
1270
|
+
this.beginInlineImagePos = beginInlineImagePos;
|
1271
|
+
return nextObj;
|
1272
|
+
}
|
1264
1273
|
|
1265
|
-
|
1266
|
-
|
1267
|
-
}
|
1274
|
+
skipToNextLine() {
|
1275
|
+
let ch = this.currentChar;
|
1268
1276
|
|
1269
|
-
|
1270
|
-
|
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
|
-
|
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
|
-
|
1281
|
-
}();
|
1295
|
+
}
|
1282
1296
|
|
1283
1297
|
exports.Lexer = Lexer;
|
1284
1298
|
|
1285
|
-
|
1286
|
-
|
1287
|
-
function () {
|
1288
|
-
|
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
|
-
|
1304
|
+
if (Number.isInteger(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
|
1305
|
+
return obj;
|
1304
1306
|
}
|
1305
1307
|
|
1306
|
-
|
1307
|
-
|
1308
|
-
var hintsLength;
|
1308
|
+
throw new Error(`The "${name}" parameter in the linearization ` + "dictionary is invalid.");
|
1309
|
+
}
|
1309
1310
|
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1311
|
+
function getHints(linDict) {
|
1312
|
+
const hints = linDict.get("H");
|
1313
|
+
let hintsLength;
|
1313
1314
|
|
1314
|
-
|
1315
|
-
|
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
|
-
|
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
|
-
|
1324
|
+
return hints;
|
1323
1325
|
}
|
1324
1326
|
|
1325
|
-
|
1326
|
-
|
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
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
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
|
-
|
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;
|