pdfjs-dist 2.1.266 → 2.2.228
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/CODE_OF_CONDUCT.md +15 -0
- package/bower.json +1 -1
- package/build/pdf.js +3349 -2324
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +2804 -1975
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/image_decoders/pdf.image_decoders.js +431 -511
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +1 -1
- package/lib/core/annotation.js +294 -224
- package/lib/core/arithmetic_decoder.js +1 -1
- package/lib/core/bidi.js +1 -1
- package/lib/core/ccitt.js +1 -1
- package/lib/core/ccitt_stream.js +1 -1
- package/lib/core/cff_parser.js +61 -12
- package/lib/core/charsets.js +1 -1
- package/lib/core/chunked_stream.js +24 -14
- package/lib/core/cmap.js +17 -13
- package/lib/core/colorspace.js +1 -1
- package/lib/core/core_utils.js +147 -0
- package/lib/core/crypto.js +1 -1
- package/lib/core/document.js +47 -40
- package/lib/core/encodings.js +1 -1
- package/lib/core/evaluator.js +346 -279
- package/lib/core/font_renderer.js +1 -1
- package/lib/core/fonts.js +23 -11
- package/lib/core/function.js +1 -1
- package/lib/core/glyphlist.js +2 -2
- package/lib/core/image.js +2 -2
- package/lib/core/image_utils.js +111 -0
- package/lib/core/jbig2.js +1 -1
- package/lib/core/jbig2_stream.js +1 -1
- package/lib/core/jpeg_stream.js +1 -1
- package/lib/core/jpg.js +2 -1
- package/lib/core/jpx.js +1 -1
- package/lib/core/jpx_stream.js +1 -1
- package/lib/core/metrics.js +13 -13
- package/lib/core/murmurhash3.js +37 -33
- package/lib/core/obj.js +245 -41
- package/lib/core/operator_list.js +43 -32
- package/lib/core/parser.js +228 -133
- package/lib/core/pattern.js +4 -2
- package/lib/core/pdf_manager.js +17 -15
- package/lib/core/primitives.js +40 -6
- package/lib/core/ps_parser.js +1 -1
- package/lib/core/standard_fonts.js +9 -9
- package/lib/core/stream.js +1 -1
- package/lib/core/type1_parser.js +1 -1
- package/lib/core/unicode.js +2 -2
- package/lib/core/worker.js +54 -171
- package/lib/core/worker_stream.js +277 -0
- package/lib/display/annotation_layer.js +112 -33
- package/lib/display/api.js +211 -123
- package/lib/display/api_compatibility.js +1 -1
- package/lib/display/canvas.js +40 -19
- package/lib/display/content_disposition.js +1 -1
- package/lib/display/display_utils.js +747 -0
- package/lib/display/fetch_stream.js +19 -12
- package/lib/display/font_loader.js +11 -8
- package/lib/display/metadata.js +1 -1
- package/lib/display/network.js +563 -521
- package/lib/display/network_utils.js +1 -1
- package/lib/display/node_stream.js +21 -12
- package/lib/display/pattern_helper.js +24 -25
- package/lib/display/svg.js +1068 -565
- package/lib/display/text_layer.js +24 -14
- package/lib/display/transport_stream.js +192 -70
- package/lib/display/webgl.js +1 -1
- package/lib/display/worker_options.js +1 -1
- package/lib/display/xml_parser.js +1 -1
- package/lib/examples/node/domstubs.js +4 -1
- package/lib/pdf.js +20 -15
- package/lib/pdf.worker.js +3 -3
- package/lib/shared/compatibility.js +6 -6
- package/lib/shared/global_scope.js +1 -1
- package/lib/shared/is_node.js +2 -2
- package/lib/shared/message_handler.js +7 -7
- package/lib/shared/streams_polyfill.js +1 -1
- package/lib/shared/url_polyfill.js +1 -1
- package/lib/shared/util.js +13 -125
- package/lib/test/unit/annotation_spec.js +278 -93
- package/lib/test/unit/api_spec.js +198 -188
- package/lib/test/unit/bidi_spec.js +1 -1
- package/lib/test/unit/cff_parser_spec.js +15 -1
- package/lib/test/unit/clitests_helper.js +3 -3
- package/lib/test/unit/cmap_spec.js +20 -20
- package/lib/test/unit/colorspace_spec.js +17 -12
- package/lib/test/unit/core_utils_spec.js +191 -0
- package/lib/test/unit/crypto_spec.js +1 -1
- package/lib/test/unit/custom_spec.js +8 -8
- package/lib/test/unit/display_svg_spec.js +8 -8
- package/lib/test/unit/display_utils_spec.js +273 -0
- package/lib/test/unit/document_spec.js +7 -12
- package/lib/test/unit/encodings_spec.js +5 -5
- package/lib/test/unit/evaluator_spec.js +8 -10
- package/lib/test/unit/fetch_stream_spec.js +109 -0
- package/lib/test/unit/function_spec.js +1 -1
- package/lib/test/unit/jasmine-boot.js +4 -4
- package/lib/test/unit/message_handler_spec.js +1 -1
- package/lib/test/unit/metadata_spec.js +1 -1
- package/lib/test/unit/murmurhash3_spec.js +1 -1
- package/lib/test/unit/network_spec.js +5 -55
- package/lib/test/unit/network_utils_spec.js +51 -1
- package/lib/test/unit/node_stream_spec.js +8 -8
- package/lib/test/unit/parser_spec.js +150 -86
- package/lib/test/unit/pdf_find_controller_spec.js +1 -1
- package/lib/test/unit/pdf_find_utils_spec.js +1 -1
- package/lib/test/unit/pdf_history_spec.js +1 -1
- package/lib/test/unit/primitives_spec.js +30 -17
- package/lib/test/unit/stream_spec.js +1 -1
- package/lib/test/unit/test_utils.js +197 -43
- package/lib/test/unit/testreporter.js +1 -1
- package/lib/test/unit/type1_parser_spec.js +1 -1
- package/lib/test/unit/ui_utils_spec.js +20 -20
- package/lib/test/unit/unicode_spec.js +5 -5
- package/lib/test/unit/util_spec.js +1 -164
- package/lib/web/annotation_layer_builder.js +1 -1
- package/lib/web/app.js +104 -60
- package/lib/web/app_options.js +45 -37
- package/lib/web/base_viewer.js +7 -7
- package/lib/web/chromecom.js +8 -8
- package/lib/web/debugger.js +7 -7
- package/lib/web/download_manager.js +3 -2
- package/lib/web/firefox_print_service.js +4 -2
- package/lib/web/firefoxcom.js +50 -19
- package/lib/web/genericcom.js +8 -8
- package/lib/web/genericl10n.js +10 -10
- package/lib/web/grab_to_pan.js +3 -1
- package/lib/web/interfaces.js +13 -13
- package/lib/web/overlay_manager.js +10 -10
- package/lib/web/password_prompt.js +2 -2
- package/lib/web/pdf_attachment_viewer.js +1 -1
- package/lib/web/pdf_cursor_tools.js +1 -1
- package/lib/web/pdf_document_properties.js +188 -119
- package/lib/web/pdf_find_bar.js +1 -1
- package/lib/web/pdf_find_controller.js +3 -3
- package/lib/web/pdf_find_utils.js +1 -1
- package/lib/web/pdf_history.js +1 -1
- package/lib/web/pdf_link_service.js +2 -2
- package/lib/web/pdf_outline_viewer.js +53 -28
- package/lib/web/pdf_page_view.js +9 -18
- package/lib/web/pdf_presentation_mode.js +1 -1
- package/lib/web/pdf_print_service.js +5 -3
- package/lib/web/pdf_rendering_queue.js +4 -7
- package/lib/web/pdf_sidebar.js +24 -17
- package/lib/web/pdf_sidebar_resizer.js +1 -1
- package/lib/web/pdf_single_page_viewer.js +1 -1
- package/lib/web/pdf_thumbnail_view.js +2 -2
- package/lib/web/pdf_thumbnail_viewer.js +3 -3
- package/lib/web/pdf_viewer.component.js +3 -3
- package/lib/web/pdf_viewer.js +3 -3
- package/lib/web/preferences.js +30 -30
- package/lib/web/secondary_toolbar.js +1 -1
- package/lib/web/text_layer_builder.js +23 -45
- package/lib/web/toolbar.js +1 -1
- package/lib/web/ui_utils.js +14 -14
- package/lib/web/view_history.js +15 -15
- package/lib/web/viewer_compatibility.js +1 -1
- package/package.json +1 -1
- package/web/pdf_viewer.css +21 -10
- package/web/pdf_viewer.js +126 -194
- package/web/pdf_viewer.js.map +1 -1
- package/lib/display/dom_utils.js +0 -494
- package/lib/test/unit/dom_utils_spec.js +0 -89
@@ -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 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -26,8 +26,6 @@ var _network = require("../../display/network");
|
|
26
26
|
describe('network', function () {
|
27
27
|
var pdf1 = new URL('../pdfs/tracemonkey.pdf', window.location).href;
|
28
28
|
var pdf1Length = 1016315;
|
29
|
-
var pdf2 = new URL('../pdfs/pdf.pdf', window.location).href;
|
30
|
-
var pdf2Length = 32472771;
|
31
29
|
it('read without stream and range', function (done) {
|
32
30
|
var stream = new _network.PDFNetworkStream({
|
33
31
|
url: pdf1,
|
@@ -47,7 +45,7 @@ describe('network', function () {
|
|
47
45
|
var read = function read() {
|
48
46
|
return fullReader.read().then(function (result) {
|
49
47
|
if (result.done) {
|
50
|
-
return;
|
48
|
+
return undefined;
|
51
49
|
}
|
52
50
|
|
53
51
|
count++;
|
@@ -63,55 +61,7 @@ describe('network', function () {
|
|
63
61
|
expect(isStreamingSupported).toEqual(false);
|
64
62
|
expect(isRangeSupported).toEqual(false);
|
65
63
|
done();
|
66
|
-
})
|
67
|
-
done.fail(reason);
|
68
|
-
});
|
69
|
-
});
|
70
|
-
it('read with streaming', function (done) {
|
71
|
-
var userAgent = window.navigator.userAgent;
|
72
|
-
var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
|
73
|
-
|
74
|
-
if (!m || m[1] < 9) {
|
75
|
-
expect(true).toEqual(true);
|
76
|
-
done();
|
77
|
-
return;
|
78
|
-
}
|
79
|
-
|
80
|
-
var stream = new _network.PDFNetworkStream({
|
81
|
-
url: pdf2,
|
82
|
-
rangeChunkSize: 65536,
|
83
|
-
disableStream: false,
|
84
|
-
disableRange: false
|
85
|
-
});
|
86
|
-
var fullReader = stream.getFullReader();
|
87
|
-
var isStreamingSupported, isRangeSupported;
|
88
|
-
var promise = fullReader.headersReady.then(function () {
|
89
|
-
isStreamingSupported = fullReader.isStreamingSupported;
|
90
|
-
isRangeSupported = fullReader.isRangeSupported;
|
91
|
-
});
|
92
|
-
var len = 0,
|
93
|
-
count = 0;
|
94
|
-
|
95
|
-
var read = function read() {
|
96
|
-
return fullReader.read().then(function (result) {
|
97
|
-
if (result.done) {
|
98
|
-
return;
|
99
|
-
}
|
100
|
-
|
101
|
-
count++;
|
102
|
-
len += result.value.byteLength;
|
103
|
-
return read();
|
104
|
-
});
|
105
|
-
};
|
106
|
-
|
107
|
-
var readPromise = Promise.all([read(), promise]);
|
108
|
-
readPromise.then(function () {
|
109
|
-
expect(len).toEqual(pdf2Length);
|
110
|
-
expect(count).toBeGreaterThan(1);
|
111
|
-
expect(isStreamingSupported).toEqual(true);
|
112
|
-
expect(isRangeSupported).toEqual(true);
|
113
|
-
done();
|
114
|
-
}).catch(function (reason) {
|
64
|
+
})["catch"](function (reason) {
|
115
65
|
done.fail(reason);
|
116
66
|
});
|
117
67
|
});
|
@@ -145,7 +95,7 @@ describe('network', function () {
|
|
145
95
|
var read = function read(reader, lenResult) {
|
146
96
|
return reader.read().then(function (result) {
|
147
97
|
if (result.done) {
|
148
|
-
return;
|
98
|
+
return undefined;
|
149
99
|
}
|
150
100
|
|
151
101
|
lenResult.value += result.value.byteLength;
|
@@ -161,7 +111,7 @@ describe('network', function () {
|
|
161
111
|
expect(isRangeSupported).toEqual(true);
|
162
112
|
expect(fullReaderCancelled).toEqual(true);
|
163
113
|
done();
|
164
|
-
})
|
114
|
+
})["catch"](function (reason) {
|
165
115
|
done.fail(reason);
|
166
116
|
});
|
167
117
|
});
|
@@ -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 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -42,6 +42,8 @@ describe('network_utils', function () {
|
|
42
42
|
if (headerName === 'Content-Length') {
|
43
43
|
return 8;
|
44
44
|
}
|
45
|
+
|
46
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
45
47
|
},
|
46
48
|
rangeChunkSize: 64
|
47
49
|
})).toEqual({
|
@@ -55,6 +57,8 @@ describe('network_utils', function () {
|
|
55
57
|
if (headerName === 'Content-Length') {
|
56
58
|
return 8;
|
57
59
|
}
|
60
|
+
|
61
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
58
62
|
},
|
59
63
|
rangeChunkSize: 64
|
60
64
|
})).toEqual({
|
@@ -72,6 +76,8 @@ describe('network_utils', function () {
|
|
72
76
|
} else if (headerName === 'Content-Length') {
|
73
77
|
return 8;
|
74
78
|
}
|
79
|
+
|
80
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
75
81
|
},
|
76
82
|
rangeChunkSize: 64
|
77
83
|
})).toEqual({
|
@@ -91,6 +97,8 @@ describe('network_utils', function () {
|
|
91
97
|
} else if (headerName === 'Content-Length') {
|
92
98
|
return 8;
|
93
99
|
}
|
100
|
+
|
101
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
94
102
|
},
|
95
103
|
rangeChunkSize: 64
|
96
104
|
})).toEqual({
|
@@ -110,6 +118,8 @@ describe('network_utils', function () {
|
|
110
118
|
} else if (headerName === 'Content-Length') {
|
111
119
|
return 'eight';
|
112
120
|
}
|
121
|
+
|
122
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
113
123
|
},
|
114
124
|
rangeChunkSize: 64
|
115
125
|
})).toEqual({
|
@@ -129,6 +139,8 @@ describe('network_utils', function () {
|
|
129
139
|
} else if (headerName === 'Content-Length') {
|
130
140
|
return 8;
|
131
141
|
}
|
142
|
+
|
143
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
132
144
|
},
|
133
145
|
rangeChunkSize: 64
|
134
146
|
})).toEqual({
|
@@ -148,6 +160,8 @@ describe('network_utils', function () {
|
|
148
160
|
} else if (headerName === 'Content-Length') {
|
149
161
|
return 8192;
|
150
162
|
}
|
163
|
+
|
164
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
151
165
|
},
|
152
166
|
rangeChunkSize: 64
|
153
167
|
})).toEqual({
|
@@ -162,16 +176,22 @@ describe('network_utils', function () {
|
|
162
176
|
if (headerName === 'Content-Disposition') {
|
163
177
|
return null;
|
164
178
|
}
|
179
|
+
|
180
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
165
181
|
})).toBeNull();
|
166
182
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
167
183
|
if (headerName === 'Content-Disposition') {
|
168
184
|
return undefined;
|
169
185
|
}
|
186
|
+
|
187
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
170
188
|
})).toBeNull();
|
171
189
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
172
190
|
if (headerName === 'Content-Disposition') {
|
173
191
|
return '';
|
174
192
|
}
|
193
|
+
|
194
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
175
195
|
})).toBeNull();
|
176
196
|
});
|
177
197
|
it('gets the filename from the response header', function () {
|
@@ -179,36 +199,50 @@ describe('network_utils', function () {
|
|
179
199
|
if (headerName === 'Content-Disposition') {
|
180
200
|
return 'inline';
|
181
201
|
}
|
202
|
+
|
203
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
182
204
|
})).toBeNull();
|
183
205
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
184
206
|
if (headerName === 'Content-Disposition') {
|
185
207
|
return 'attachment';
|
186
208
|
}
|
209
|
+
|
210
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
187
211
|
})).toBeNull();
|
188
212
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
189
213
|
if (headerName === 'Content-Disposition') {
|
190
214
|
return 'attachment; filename="filename.pdf"';
|
191
215
|
}
|
216
|
+
|
217
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
192
218
|
})).toEqual('filename.pdf');
|
193
219
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
194
220
|
if (headerName === 'Content-Disposition') {
|
195
221
|
return 'attachment; filename="filename.pdf and spaces.pdf"';
|
196
222
|
}
|
223
|
+
|
224
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
197
225
|
})).toEqual('filename.pdf and spaces.pdf');
|
198
226
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
199
227
|
if (headerName === 'Content-Disposition') {
|
200
228
|
return 'attachment; filename="tl;dr.pdf"';
|
201
229
|
}
|
230
|
+
|
231
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
202
232
|
})).toEqual('tl;dr.pdf');
|
203
233
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
204
234
|
if (headerName === 'Content-Disposition') {
|
205
235
|
return 'attachment; filename=filename.pdf';
|
206
236
|
}
|
237
|
+
|
238
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
207
239
|
})).toEqual('filename.pdf');
|
208
240
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
209
241
|
if (headerName === 'Content-Disposition') {
|
210
242
|
return 'attachment; filename=filename.pdf someotherparam';
|
211
243
|
}
|
244
|
+
|
245
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
212
246
|
})).toEqual('filename.pdf');
|
213
247
|
});
|
214
248
|
it('gets the filename from the response header (RFC 6266)', function () {
|
@@ -216,26 +250,36 @@ describe('network_utils', function () {
|
|
216
250
|
if (headerName === 'Content-Disposition') {
|
217
251
|
return 'attachment; filename*=filename.pdf';
|
218
252
|
}
|
253
|
+
|
254
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
219
255
|
})).toEqual('filename.pdf');
|
220
256
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
221
257
|
if (headerName === 'Content-Disposition') {
|
222
258
|
return 'attachment; filename*=\'\'filename.pdf';
|
223
259
|
}
|
260
|
+
|
261
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
224
262
|
})).toEqual('filename.pdf');
|
225
263
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
226
264
|
if (headerName === 'Content-Disposition') {
|
227
265
|
return 'attachment; filename*=utf-8\'\'filename.pdf';
|
228
266
|
}
|
267
|
+
|
268
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
229
269
|
})).toEqual('filename.pdf');
|
230
270
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
231
271
|
if (headerName === 'Content-Disposition') {
|
232
272
|
return 'attachment; filename=no.pdf; filename*=utf-8\'\'filename.pdf';
|
233
273
|
}
|
274
|
+
|
275
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
234
276
|
})).toEqual('filename.pdf');
|
235
277
|
expect((0, _network_utils.extractFilenameFromHeader)(function (headerName) {
|
236
278
|
if (headerName === 'Content-Disposition') {
|
237
279
|
return 'attachment; filename*=utf-8\'\'filename.pdf; filename=no.pdf';
|
238
280
|
}
|
281
|
+
|
282
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
239
283
|
})).toEqual('filename.pdf');
|
240
284
|
});
|
241
285
|
it('gets the filename from the response header (RFC 2231)', function () {
|
@@ -243,6 +287,8 @@ describe('network_utils', function () {
|
|
243
287
|
if (headerName === 'Content-Disposition') {
|
244
288
|
return 'attachment; filename*0=filename; filename*1=.pdf';
|
245
289
|
}
|
290
|
+
|
291
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
246
292
|
})).toEqual('filename.pdf');
|
247
293
|
});
|
248
294
|
it('only extracts filename with pdf extension', function () {
|
@@ -250,6 +296,8 @@ describe('network_utils', function () {
|
|
250
296
|
if (headerName === 'Content-Disposition') {
|
251
297
|
return 'attachment; filename="filename.png"';
|
252
298
|
}
|
299
|
+
|
300
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
253
301
|
})).toBeNull();
|
254
302
|
});
|
255
303
|
it('extension validation is case insensitive', function () {
|
@@ -257,6 +305,8 @@ describe('network_utils', function () {
|
|
257
305
|
if (headerName === 'Content-Disposition') {
|
258
306
|
return 'form-data; name="fieldName"; filename="file.PdF"';
|
259
307
|
}
|
308
|
+
|
309
|
+
throw new Error("Unexpected headerName: ".concat(headerName));
|
260
310
|
})).toEqual('file.PdF');
|
261
311
|
});
|
262
312
|
});
|
@@ -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 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -27,7 +27,7 @@ var _is_node = _interopRequireDefault(require("../../shared/is_node"));
|
|
27
27
|
|
28
28
|
var _node_stream = require("../../display/node_stream");
|
29
29
|
|
30
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
31
31
|
|
32
32
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
33
33
|
|
@@ -37,7 +37,7 @@ function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d =
|
|
37
37
|
|
38
38
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
39
39
|
|
40
|
-
(0, _util.assert)((0, _is_node
|
40
|
+
(0, _util.assert)((0, _is_node["default"])());
|
41
41
|
|
42
42
|
var path = require('path');
|
43
43
|
|
@@ -130,7 +130,7 @@ describe('node_stream', function () {
|
|
130
130
|
var read1 = function read1() {
|
131
131
|
return fullReader1.read().then(function (result) {
|
132
132
|
if (result.done) {
|
133
|
-
return;
|
133
|
+
return undefined;
|
134
134
|
}
|
135
135
|
|
136
136
|
len1 += result.value.byteLength;
|
@@ -141,7 +141,7 @@ describe('node_stream', function () {
|
|
141
141
|
var read2 = function read2() {
|
142
142
|
return fullReader2.read().then(function (result) {
|
143
143
|
if (result.done) {
|
144
|
-
return;
|
144
|
+
return undefined;
|
145
145
|
}
|
146
146
|
|
147
147
|
len2 += result.value.byteLength;
|
@@ -158,7 +158,7 @@ describe('node_stream', function () {
|
|
158
158
|
expect(len1).toEqual(pdfLength);
|
159
159
|
expect(len1).toEqual(len2);
|
160
160
|
done();
|
161
|
-
})
|
161
|
+
})["catch"](function (reason) {
|
162
162
|
done.fail(reason);
|
163
163
|
});
|
164
164
|
});
|
@@ -215,7 +215,7 @@ describe('node_stream', function () {
|
|
215
215
|
var read = function read(reader, lenResult) {
|
216
216
|
return reader.read().then(function (result) {
|
217
217
|
if (result.done) {
|
218
|
-
return;
|
218
|
+
return undefined;
|
219
219
|
}
|
220
220
|
|
221
221
|
lenResult.value += result.value.byteLength;
|
@@ -236,7 +236,7 @@ describe('node_stream', function () {
|
|
236
236
|
expect(isRangeSupported2).toEqual(true);
|
237
237
|
expect(fullReaderCancelled2).toEqual(true);
|
238
238
|
done();
|
239
|
-
})
|
239
|
+
})["catch"](function (reason) {
|
240
240
|
done.fail(reason);
|
241
241
|
});
|
242
242
|
});
|
@@ -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 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -30,104 +30,168 @@ var _primitives = require("../../core/primitives");
|
|
30
30
|
var _stream = require("../../core/stream");
|
31
31
|
|
32
32
|
describe('parser', function () {
|
33
|
-
describe('
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
describe('Parser', function () {
|
34
|
+
describe('inlineStreamSkipEI', function () {
|
35
|
+
it('should skip over the EI marker if it is found', function () {
|
36
|
+
var string = 'q 1 0 0 1 0 0 cm BI /W 10 /H 10 /BPC 1 ' + '/F /A85 ID abc123~> EI Q';
|
37
|
+
var input = new _stream.StringStream(string);
|
38
|
+
var parser = new _parser.Parser({
|
39
|
+
lexer: new _parser.Lexer(input),
|
40
|
+
xref: null,
|
41
|
+
allowStreams: true
|
42
|
+
});
|
43
|
+
parser.inlineStreamSkipEI(input);
|
44
|
+
expect(input.pos).toEqual(string.indexOf('Q'));
|
45
|
+
expect(input.peekByte()).toEqual(0x51);
|
46
|
+
});
|
47
|
+
it('should skip to the end of stream if the EI marker is not found', function () {
|
48
|
+
var string = 'q 1 0 0 1 0 0 cm BI /W 10 /H 10 /BPC 1 ' + '/F /A85 ID abc123~> Q';
|
49
|
+
var input = new _stream.StringStream(string);
|
50
|
+
var parser = new _parser.Parser({
|
51
|
+
lexer: new _parser.Lexer(input),
|
52
|
+
xref: null,
|
53
|
+
allowStreams: true
|
54
|
+
});
|
55
|
+
parser.inlineStreamSkipEI(input);
|
56
|
+
expect(input.pos).toEqual(string.length);
|
57
|
+
expect(input.peekByte()).toEqual(-1);
|
58
|
+
});
|
39
59
|
});
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
var
|
45
|
-
var input = new _stream.StringStream(num);
|
60
|
+
});
|
61
|
+
describe('Lexer', function () {
|
62
|
+
describe('nextChar', function () {
|
63
|
+
it('should return and set -1 when the end of the stream is reached', function () {
|
64
|
+
var input = new _stream.StringStream('');
|
46
65
|
var lexer = new _parser.Lexer(input);
|
47
|
-
|
48
|
-
expect(
|
49
|
-
}
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
});
|
57
|
-
it('should ignore minus signs in the middle of number', function () {
|
58
|
-
var input = new _stream.StringStream('205--.88');
|
59
|
-
var lexer = new _parser.Lexer(input);
|
60
|
-
var result = lexer.getNumber();
|
61
|
-
expect(result).toEqual(205.88);
|
66
|
+
expect(lexer.nextChar()).toEqual(-1);
|
67
|
+
expect(lexer.currentChar).toEqual(-1);
|
68
|
+
});
|
69
|
+
it('should return and set the character after the current position', function () {
|
70
|
+
var input = new _stream.StringStream('123');
|
71
|
+
var lexer = new _parser.Lexer(input);
|
72
|
+
expect(lexer.nextChar()).toEqual(0x32);
|
73
|
+
expect(lexer.currentChar).toEqual(0x32);
|
74
|
+
});
|
62
75
|
});
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
76
|
+
describe('peekChar', function () {
|
77
|
+
it('should only return -1 when the end of the stream is reached', function () {
|
78
|
+
var input = new _stream.StringStream('');
|
79
|
+
var lexer = new _parser.Lexer(input);
|
80
|
+
expect(lexer.peekChar()).toEqual(-1);
|
81
|
+
expect(lexer.currentChar).toEqual(-1);
|
82
|
+
});
|
83
|
+
it('should only return the character after the current position', function () {
|
84
|
+
var input = new _stream.StringStream('123');
|
85
|
+
var lexer = new _parser.Lexer(input);
|
86
|
+
expect(lexer.peekChar()).toEqual(0x32);
|
87
|
+
expect(lexer.currentChar).toEqual(0x31);
|
88
|
+
});
|
70
89
|
});
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
90
|
+
describe('getNumber', function () {
|
91
|
+
it('should stop parsing numbers at the end of stream', function () {
|
92
|
+
var input = new _stream.StringStream('11.234');
|
93
|
+
var lexer = new _parser.Lexer(input);
|
94
|
+
expect(lexer.getNumber()).toEqual(11.234);
|
95
|
+
});
|
96
|
+
it('should parse PostScript numbers', function () {
|
97
|
+
var numbers = ['-.002', '34.5', '-3.62', '123.6e10', '1E-5', '-1.', '0.0', '123', '-98', '43445', '0', '+17'];
|
98
|
+
|
99
|
+
for (var _i = 0, _numbers = numbers; _i < _numbers.length; _i++) {
|
100
|
+
var number = _numbers[_i];
|
101
|
+
var input = new _stream.StringStream(number);
|
102
|
+
var lexer = new _parser.Lexer(input);
|
103
|
+
var result = lexer.getNumber(),
|
104
|
+
expected = parseFloat(number);
|
105
|
+
|
106
|
+
if (result !== expected && Math.abs(result - expected) < 1e-15) {
|
107
|
+
console.error("Fuzzy matching \"".concat(result, "\" with \"").concat(expected, "\" to ") + 'work-around rounding bugs in Chromium browsers.');
|
108
|
+
expect(true).toEqual(true);
|
109
|
+
continue;
|
110
|
+
}
|
76
111
|
|
77
|
-
|
78
|
-
|
79
|
-
|
112
|
+
expect(result).toEqual(expected);
|
113
|
+
}
|
114
|
+
});
|
115
|
+
it('should ignore double negative before number', function () {
|
116
|
+
var input = new _stream.StringStream('--205.88');
|
80
117
|
var lexer = new _parser.Lexer(input);
|
81
|
-
expect(
|
82
|
-
|
83
|
-
|
84
|
-
|
118
|
+
expect(lexer.getNumber()).toEqual(-205.88);
|
119
|
+
});
|
120
|
+
it('should ignore minus signs in the middle of number', function () {
|
121
|
+
var input = new _stream.StringStream('205--.88');
|
122
|
+
var lexer = new _parser.Lexer(input);
|
123
|
+
expect(lexer.getNumber()).toEqual(205.88);
|
124
|
+
});
|
125
|
+
it('should ignore line-breaks between operator and digit in number', function () {
|
126
|
+
var minusInput = new _stream.StringStream('-\r\n205.88');
|
127
|
+
var minusLexer = new _parser.Lexer(minusInput);
|
128
|
+
expect(minusLexer.getNumber()).toEqual(-205.88);
|
129
|
+
var plusInput = new _stream.StringStream('+\r\n205.88');
|
130
|
+
var plusLexer = new _parser.Lexer(plusInput);
|
131
|
+
expect(plusLexer.getNumber()).toEqual(205.88);
|
132
|
+
});
|
133
|
+
it('should treat a single decimal point as zero', function () {
|
134
|
+
var input = new _stream.StringStream('.');
|
135
|
+
var lexer = new _parser.Lexer(input);
|
136
|
+
expect(lexer.getNumber()).toEqual(0);
|
137
|
+
var numbers = ['..', '-.', '+.', '-\r\n.', '+\r\n.'];
|
85
138
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
139
|
+
var _loop = function _loop() {
|
140
|
+
var number = _numbers2[_i2];
|
141
|
+
var input = new _stream.StringStream(number);
|
142
|
+
var lexer = new _parser.Lexer(input);
|
143
|
+
expect(function () {
|
144
|
+
return lexer.getNumber();
|
145
|
+
}).toThrowError(_util.FormatError, /^Invalid number:\s/);
|
146
|
+
};
|
147
|
+
|
148
|
+
for (var _i2 = 0, _numbers2 = numbers; _i2 < _numbers2.length; _i2++) {
|
149
|
+
_loop();
|
150
|
+
}
|
151
|
+
});
|
152
|
+
it('should handle glued numbers and operators', function () {
|
153
|
+
var input = new _stream.StringStream('123ET');
|
154
|
+
var lexer = new _parser.Lexer(input);
|
155
|
+
expect(lexer.getNumber()).toEqual(123);
|
156
|
+
expect(lexer.currentChar).toEqual(0x45);
|
157
|
+
});
|
96
158
|
});
|
97
|
-
|
98
|
-
|
159
|
+
describe('getString', function () {
|
160
|
+
it('should stop parsing strings at the end of stream', function () {
|
161
|
+
var input = new _stream.StringStream('(1$4)');
|
99
162
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
163
|
+
input.getByte = function (super_getByte) {
|
164
|
+
var ch = super_getByte.call(input);
|
165
|
+
return ch === 0x24 ? -1 : ch;
|
166
|
+
}.bind(input, input.getByte);
|
104
167
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
expect(result).toEqual('p!U"$2');
|
168
|
+
var lexer = new _parser.Lexer(input);
|
169
|
+
expect(lexer.getString()).toEqual('1');
|
170
|
+
});
|
171
|
+
it('should ignore escaped CR and LF', function () {
|
172
|
+
var input = new _stream.StringStream('(\\101\\\r\n\\102\\\r\\103\\\n\\104)');
|
173
|
+
var lexer = new _parser.Lexer(input);
|
174
|
+
expect(lexer.getString()).toEqual('ABCD');
|
175
|
+
});
|
114
176
|
});
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
177
|
+
describe('getHexString', function () {
|
178
|
+
it('should not throw exception on bad input', function () {
|
179
|
+
var input = new _stream.StringStream('<7 0 2 15 5 2 2 2 4 3 2 4>');
|
180
|
+
var lexer = new _parser.Lexer(input);
|
181
|
+
expect(lexer.getHexString()).toEqual('p!U"$2');
|
182
|
+
});
|
120
183
|
});
|
121
|
-
|
122
|
-
|
123
|
-
|
184
|
+
describe('getName', function () {
|
185
|
+
it('should handle Names with invalid usage of NUMBER SIGN (#)', function () {
|
186
|
+
var inputNames = ['/# 680 0 R', '/#AQwerty', '/#A<</B'];
|
187
|
+
var expectedNames = ['#', '#AQwerty', '#A'];
|
124
188
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
}
|
189
|
+
for (var i = 0, ii = inputNames.length; i < ii; i++) {
|
190
|
+
var input = new _stream.StringStream(inputNames[i]);
|
191
|
+
var lexer = new _parser.Lexer(input);
|
192
|
+
expect(lexer.getName()).toEqual(_primitives.Name.get(expectedNames[i]));
|
193
|
+
}
|
194
|
+
});
|
131
195
|
});
|
132
196
|
});
|
133
197
|
describe('Linearization', function () {
|
@@ -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 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -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 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|