pdfjs-dist 2.6.347 → 2.7.570
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 +3 -3
- package/bower.json +1 -1
- package/build/pdf.js +2050 -1087
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +18219 -10436
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/es5/build/pdf.d.ts +1 -0
- package/es5/build/pdf.js +6623 -6654
- package/es5/build/pdf.js.map +1 -1
- package/es5/build/pdf.min.js +1 -1
- package/es5/build/pdf.worker.js +20815 -13888
- package/es5/build/pdf.worker.js.map +1 -1
- package/es5/build/pdf.worker.min.js +1 -1
- package/es5/image_decoders/pdf.image_decoders.js +3817 -4946
- package/es5/image_decoders/pdf.image_decoders.js.map +1 -1
- package/es5/image_decoders/pdf.image_decoders.min.js +1 -1
- package/es5/web/pdf_viewer.css +18 -15
- package/es5/web/pdf_viewer.js +1094 -514
- package/es5/web/pdf_viewer.js.map +1 -1
- package/image_decoders/pdf.image_decoders.js +774 -168
- 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 +556 -108
- package/lib/core/cff_parser.js +7 -1
- package/lib/core/charsets.js +1 -1
- package/lib/core/cmap.js +20 -1
- package/lib/core/core_utils.js +162 -3
- package/lib/core/crypto.js +1 -1
- package/lib/core/default_appearance.js +132 -0
- package/lib/core/document.js +115 -9
- package/lib/core/encodings.js +1 -1
- package/lib/core/evaluator.js +168 -74
- package/lib/core/fonts.js +97 -11
- package/lib/core/function.js +5 -10
- package/lib/core/glyphlist.js +11 -4529
- package/lib/core/image_utils.js +30 -1
- package/lib/core/jpg.js +1 -1
- package/lib/core/jpx.js +5 -5
- package/lib/core/murmurhash3.js +1 -1
- package/lib/core/obj.js +123 -39
- package/lib/core/pattern.js +4 -4
- package/lib/core/primitives.js +24 -5
- package/lib/core/standard_fonts.js +1 -1
- package/lib/core/stream.js +5 -1
- package/lib/core/unicode.js +15 -1387
- package/lib/core/worker.js +58 -17
- package/lib/core/writer.js +68 -4
- package/lib/display/annotation_layer.js +712 -119
- package/lib/display/annotation_storage.js +21 -4
- package/lib/display/api.js +88 -18
- package/lib/display/canvas.js +414 -375
- package/lib/display/display_utils.js +11 -4
- package/lib/display/fetch_stream.js +3 -3
- package/lib/display/font_loader.js +2 -3
- package/lib/display/metadata.js +54 -20
- package/lib/display/node_stream.js +1 -1
- package/lib/display/optional_content_config.js +1 -1
- package/lib/display/pattern_helper.js +109 -113
- package/lib/display/svg.js +5 -5
- package/lib/display/text_layer.js +54 -54
- package/lib/display/transport_stream.js +4 -4
- package/lib/display/webgl.js +65 -68
- package/lib/examples/node/domstubs.js +9 -4
- package/lib/pdf.js +2 -2
- package/lib/pdf.sandbox.js +311 -0
- package/lib/pdf.worker.js +2 -2
- package/lib/shared/scripting_utils.js +84 -0
- package/lib/shared/util.js +129 -14
- package/lib/{display → shared}/xml_parser.js +112 -4
- package/lib/test/unit/annotation_spec.js +831 -109
- package/lib/test/unit/annotation_storage_spec.js +28 -10
- package/lib/test/unit/api_spec.js +190 -160
- package/lib/test/unit/bidi_spec.js +6 -6
- package/lib/test/unit/cff_parser_spec.js +73 -73
- package/lib/test/unit/clitests_helper.js +2 -0
- package/lib/test/unit/cmap_spec.js +48 -74
- package/lib/test/unit/core_utils_spec.js +34 -0
- package/lib/test/unit/crypto_spec.js +162 -199
- package/lib/test/unit/custom_spec.js +7 -18
- package/lib/test/unit/default_appearance_spec.js +54 -0
- package/lib/test/unit/display_svg_spec.js +24 -19
- package/lib/test/unit/display_utils_spec.js +1 -1
- package/lib/test/unit/document_spec.js +187 -20
- package/lib/test/unit/evaluator_spec.js +30 -30
- package/lib/test/unit/function_spec.js +165 -165
- package/lib/test/unit/jasmine-boot.js +52 -53
- package/lib/test/unit/metadata_spec.js +2 -2
- package/lib/test/unit/murmurhash3_spec.js +29 -16
- package/lib/test/unit/network_spec.js +21 -21
- package/lib/test/unit/pdf_find_controller_spec.js +131 -69
- package/lib/test/unit/pdf_find_utils_spec.js +10 -10
- package/lib/test/unit/scripting_spec.js +1104 -0
- package/lib/test/unit/stream_spec.js +8 -8
- package/lib/test/unit/test_utils.js +16 -19
- package/lib/test/unit/testreporter.js +11 -4
- package/lib/test/unit/type1_parser_spec.js +23 -23
- package/lib/test/unit/ui_utils_spec.js +78 -35
- package/lib/test/unit/unicode_spec.js +7 -7
- package/lib/test/unit/util_spec.js +26 -3
- package/lib/test/unit/writer_spec.js +16 -1
- package/lib/test/unit/xml_spec.js +117 -0
- package/lib/web/annotation_layer_builder.js +18 -6
- package/lib/web/app.js +579 -161
- package/lib/web/app_options.js +14 -0
- package/lib/web/base_tree_viewer.js +50 -0
- package/lib/web/base_viewer.js +350 -14
- package/lib/web/chromecom.js +9 -1
- package/lib/web/debugger.js +1 -2
- package/lib/web/download_manager.js +0 -15
- package/lib/web/firefox_print_service.js +6 -4
- package/lib/web/firefoxcom.js +84 -69
- package/lib/web/generic_scripting.js +55 -0
- package/lib/web/genericcom.js +9 -1
- package/lib/web/grab_to_pan.js +1 -1
- package/lib/web/interfaces.js +9 -3
- package/lib/web/pdf_attachment_viewer.js +1 -3
- package/lib/web/pdf_cursor_tools.js +20 -13
- package/lib/web/pdf_document_properties.js +48 -61
- package/lib/web/pdf_find_bar.js +1 -3
- package/lib/web/pdf_find_controller.js +58 -12
- package/lib/web/pdf_history.js +43 -21
- package/lib/web/pdf_layer_viewer.js +1 -9
- package/lib/web/pdf_link_service.js +108 -78
- package/lib/web/pdf_outline_viewer.js +166 -10
- package/lib/web/pdf_page_view.js +14 -14
- package/lib/web/pdf_presentation_mode.js +21 -31
- package/lib/web/pdf_rendering_queue.js +8 -1
- package/lib/web/pdf_sidebar.js +62 -107
- package/lib/web/pdf_sidebar_resizer.js +11 -21
- package/lib/web/pdf_single_page_viewer.js +8 -0
- package/lib/web/pdf_thumbnail_view.js +26 -26
- package/lib/web/pdf_thumbnail_viewer.js +13 -2
- package/lib/web/pdf_viewer.component.js +2 -2
- package/lib/web/pdf_viewer.js +3 -1
- package/lib/web/preferences.js +33 -44
- package/lib/web/text_layer_builder.js +2 -9
- package/lib/web/ui_utils.js +78 -46
- package/lib/web/viewer_compatibility.js +1 -2
- package/package.json +4 -1
- package/types/display/annotation_layer.d.ts +18 -3
- package/types/display/api.d.ts +110 -54
- package/types/display/canvas.d.ts +1 -1
- package/types/display/display_utils.d.ts +96 -95
- package/types/display/fetch_stream.d.ts +2 -2
- package/types/display/metadata.d.ts +4 -0
- package/types/display/pattern_helper.d.ts +1 -1
- package/types/display/text_layer.d.ts +7 -7
- package/types/display/transport_stream.d.ts +1 -1
- package/types/shared/scripting_utils.d.ts +12 -0
- package/types/shared/util.d.ts +281 -250
- package/types/shared/xml_parser.d.ts +64 -0
- package/web/pdf_viewer.css +18 -15
- package/web/pdf_viewer.js +809 -408
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +1 -1
- package/types/display/xml_parser.d.ts +0 -35
@@ -0,0 +1,54 @@
|
|
1
|
+
/**
|
2
|
+
* @licstart The following is the entire license notice for the
|
3
|
+
* Javascript code in this page
|
4
|
+
*
|
5
|
+
* Copyright 2020 Mozilla Foundation
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*
|
19
|
+
* @licend The above is the entire license notice for the
|
20
|
+
* Javascript code in this page
|
21
|
+
*/
|
22
|
+
"use strict";
|
23
|
+
|
24
|
+
var _default_appearance = require("../../core/default_appearance.js");
|
25
|
+
|
26
|
+
var _primitives = require("../../core/primitives.js");
|
27
|
+
|
28
|
+
describe("Default appearance", function () {
|
29
|
+
describe("parseDefaultAppearance and createDefaultAppearance", function () {
|
30
|
+
it("should parse and create default appearance", function () {
|
31
|
+
const da = "/F1 12 Tf 0.10 0.20 0.30 rg";
|
32
|
+
const result = {
|
33
|
+
fontSize: 12,
|
34
|
+
fontName: _primitives.Name.get("F1"),
|
35
|
+
fontColor: new Uint8ClampedArray([26, 51, 76])
|
36
|
+
};
|
37
|
+
expect((0, _default_appearance.parseDefaultAppearance)(da)).toEqual(result);
|
38
|
+
expect((0, _default_appearance.createDefaultAppearance)(result)).toEqual(da);
|
39
|
+
expect((0, _default_appearance.parseDefaultAppearance)("0.1 0.2 0.3 rg /F1 12 Tf 0.3 0.2 0.1 rg /F2 13 Tf")).toEqual({
|
40
|
+
fontSize: 13,
|
41
|
+
fontName: _primitives.Name.get("F2"),
|
42
|
+
fontColor: new Uint8ClampedArray([76, 51, 26])
|
43
|
+
});
|
44
|
+
});
|
45
|
+
it("should parse default appearance with save/restore", function () {
|
46
|
+
const da = "q Q 0.10 0.20 0.30 rg /F1 12 Tf q 0.30 0.20 0.10 rg /F2 13 Tf Q";
|
47
|
+
expect((0, _default_appearance.parseDefaultAppearance)(da)).toEqual({
|
48
|
+
fontSize: 12,
|
49
|
+
fontName: _primitives.Name.get("F1"),
|
50
|
+
fontColor: new Uint8ClampedArray([26, 51, 76])
|
51
|
+
});
|
52
|
+
});
|
53
|
+
});
|
54
|
+
});
|
@@ -21,8 +21,6 @@
|
|
21
21
|
*/
|
22
22
|
"use strict";
|
23
23
|
|
24
|
-
var _domstubs = require("../../examples/node/domstubs.js");
|
25
|
-
|
26
24
|
var _test_utils = require("./test_utils.js");
|
27
25
|
|
28
26
|
var _api = require("../../display/api.js");
|
@@ -46,9 +44,9 @@ function withZlib(isZlibRequired, callback) {
|
|
46
44
|
return callback();
|
47
45
|
}
|
48
46
|
|
49
|
-
|
47
|
+
const zlib = require("zlib");
|
50
48
|
|
51
|
-
|
49
|
+
const deflateSync = zlib.deflateSync;
|
52
50
|
zlib.deflateSync = disabledDeflateSync;
|
53
51
|
|
54
52
|
function disabledDeflateSync() {
|
@@ -61,14 +59,14 @@ function withZlib(isZlibRequired, callback) {
|
|
61
59
|
}
|
62
60
|
}
|
63
61
|
|
64
|
-
|
62
|
+
const promise = callback();
|
65
63
|
promise.then(restoreDeflateSync, restoreDeflateSync);
|
66
64
|
return promise;
|
67
65
|
}
|
68
66
|
|
69
67
|
describe("SVGGraphics", function () {
|
70
|
-
|
71
|
-
|
68
|
+
let loadingTask;
|
69
|
+
let page;
|
72
70
|
beforeAll(function (done) {
|
73
71
|
loadingTask = (0, _api.getDocument)((0, _test_utils.buildGetDocumentParams)("xobject-image.pdf"));
|
74
72
|
loadingTask.promise.then(function (doc) {
|
@@ -83,31 +81,39 @@ describe("SVGGraphics", function () {
|
|
83
81
|
});
|
84
82
|
describe("paintImageXObject", function () {
|
85
83
|
function getSVGImage() {
|
86
|
-
|
84
|
+
let svgGfx;
|
87
85
|
return page.getOperatorList().then(function (opList) {
|
88
|
-
|
86
|
+
const forceDataSchema = true;
|
89
87
|
svgGfx = new _svg.SVGGraphics(page.commonObjs, page.objs, forceDataSchema);
|
90
88
|
return svgGfx.loadDependencies(opList);
|
91
89
|
}).then(function () {
|
92
|
-
|
93
|
-
|
90
|
+
let svgImg;
|
91
|
+
const elementContainer = {
|
94
92
|
appendChild(element) {
|
95
93
|
svgImg = element;
|
96
94
|
}
|
97
95
|
|
98
96
|
};
|
99
|
-
|
97
|
+
const xobjectObjId = "img_p0_1";
|
100
98
|
|
101
99
|
if (_is_node.isNodeJS) {
|
102
|
-
|
100
|
+
const {
|
101
|
+
setStubs
|
102
|
+
} = require("../../examples/node/domstubs.js");
|
103
|
+
|
104
|
+
setStubs(global);
|
103
105
|
}
|
104
106
|
|
105
107
|
try {
|
106
|
-
|
108
|
+
const imgData = svgGfx.objs.get(xobjectObjId);
|
107
109
|
svgGfx.paintInlineImageXObject(imgData, elementContainer);
|
108
110
|
} finally {
|
109
111
|
if (_is_node.isNodeJS) {
|
110
|
-
|
112
|
+
const {
|
113
|
+
unsetStubs
|
114
|
+
} = require("../../examples/node/domstubs.js");
|
115
|
+
|
116
|
+
unsetStubs(global);
|
111
117
|
}
|
112
118
|
}
|
113
119
|
|
@@ -120,9 +126,8 @@ describe("SVGGraphics", function () {
|
|
120
126
|
require("zlib");
|
121
127
|
}
|
122
128
|
|
123
|
-
expect(testFunc.toString()).toMatch(/\srequire\(["']zlib["']\)/);
|
124
|
-
|
125
129
|
if (_is_node.isNodeJS) {
|
130
|
+
expect(testFunc.toString()).toMatch(/\srequire\(["']zlib["']\)/);
|
126
131
|
expect(testFunc).not.toThrow();
|
127
132
|
} else {
|
128
133
|
expect(testFunc).toThrow();
|
@@ -137,7 +142,7 @@ describe("SVGGraphics", function () {
|
|
137
142
|
expect(svgImg.nodeName).toBe("svg:image");
|
138
143
|
expect(svgImg.getAttributeNS(null, "width")).toBe("200px");
|
139
144
|
expect(svgImg.getAttributeNS(null, "height")).toBe("100px");
|
140
|
-
|
145
|
+
const imgUrl = svgImg.getAttributeNS(XLINK_NS, "href");
|
141
146
|
expect(imgUrl).toMatch(/^data:image\/png;base64,/);
|
142
147
|
expect(imgUrl.length).toBeLessThan(367);
|
143
148
|
}).then(done, done.fail);
|
@@ -147,7 +152,7 @@ describe("SVGGraphics", function () {
|
|
147
152
|
expect(svgImg.nodeName).toBe("svg:image");
|
148
153
|
expect(svgImg.getAttributeNS(null, "width")).toBe("200px");
|
149
154
|
expect(svgImg.getAttributeNS(null, "height")).toBe("100px");
|
150
|
-
|
155
|
+
const imgUrl = svgImg.getAttributeNS(XLINK_NS, "href");
|
151
156
|
expect(imgUrl).toMatch(/^data:image\/png;base64,/);
|
152
157
|
expect(imgUrl.length).toBe(80246);
|
153
158
|
}).then(done, done.fail);
|
@@ -52,19 +52,37 @@ describe("document", function () {
|
|
52
52
|
});
|
53
53
|
});
|
54
54
|
describe("PDFDocument", function () {
|
55
|
-
const pdfManager = {
|
56
|
-
get docId() {
|
57
|
-
return "d0";
|
58
|
-
}
|
59
|
-
|
60
|
-
};
|
61
55
|
const stream = new _stream.StringStream("Dummy_PDF_data");
|
62
56
|
|
63
|
-
function getDocument(acroForm) {
|
64
|
-
const
|
65
|
-
pdfDocument.catalog = {
|
57
|
+
function getDocument(acroForm, xref = new _test_utils.XRefMock()) {
|
58
|
+
const catalog = {
|
66
59
|
acroForm
|
67
60
|
};
|
61
|
+
const pdfManager = {
|
62
|
+
get docId() {
|
63
|
+
return "d0";
|
64
|
+
},
|
65
|
+
|
66
|
+
ensureCatalog(prop, args) {
|
67
|
+
return pdfManager.ensure(catalog, prop, args);
|
68
|
+
},
|
69
|
+
|
70
|
+
ensure(obj, prop, args) {
|
71
|
+
return new Promise(function (resolve) {
|
72
|
+
const value = obj[prop];
|
73
|
+
|
74
|
+
if (typeof value === "function") {
|
75
|
+
resolve(value.apply(obj, args));
|
76
|
+
} else {
|
77
|
+
resolve(value);
|
78
|
+
}
|
79
|
+
});
|
80
|
+
}
|
81
|
+
|
82
|
+
};
|
83
|
+
const pdfDocument = new _document.PDFDocument(pdfManager, stream);
|
84
|
+
pdfDocument.xref = xref;
|
85
|
+
pdfDocument.catalog = catalog;
|
68
86
|
return pdfDocument;
|
69
87
|
}
|
70
88
|
|
@@ -72,7 +90,8 @@ describe("document", function () {
|
|
72
90
|
const pdfDocument = getDocument(null);
|
73
91
|
expect(pdfDocument.formInfo).toEqual({
|
74
92
|
hasAcroForm: false,
|
75
|
-
hasXfa: false
|
93
|
+
hasXfa: false,
|
94
|
+
hasFields: false
|
76
95
|
});
|
77
96
|
});
|
78
97
|
it("should get form info when XFA is present", function () {
|
@@ -81,25 +100,29 @@ describe("document", function () {
|
|
81
100
|
let pdfDocument = getDocument(acroForm);
|
82
101
|
expect(pdfDocument.formInfo).toEqual({
|
83
102
|
hasAcroForm: false,
|
84
|
-
hasXfa: false
|
103
|
+
hasXfa: false,
|
104
|
+
hasFields: false
|
85
105
|
});
|
86
106
|
acroForm.set("XFA", ["foo", "bar"]);
|
87
107
|
pdfDocument = getDocument(acroForm);
|
88
108
|
expect(pdfDocument.formInfo).toEqual({
|
89
109
|
hasAcroForm: false,
|
90
|
-
hasXfa: true
|
110
|
+
hasXfa: true,
|
111
|
+
hasFields: false
|
91
112
|
});
|
92
113
|
acroForm.set("XFA", new _stream.StringStream(""));
|
93
114
|
pdfDocument = getDocument(acroForm);
|
94
115
|
expect(pdfDocument.formInfo).toEqual({
|
95
116
|
hasAcroForm: false,
|
96
|
-
hasXfa: false
|
117
|
+
hasXfa: false,
|
118
|
+
hasFields: false
|
97
119
|
});
|
98
120
|
acroForm.set("XFA", new _stream.StringStream("non-empty"));
|
99
121
|
pdfDocument = getDocument(acroForm);
|
100
122
|
expect(pdfDocument.formInfo).toEqual({
|
101
123
|
hasAcroForm: false,
|
102
|
-
hasXfa: true
|
124
|
+
hasXfa: true,
|
125
|
+
hasFields: false
|
103
126
|
});
|
104
127
|
});
|
105
128
|
it("should get form info when AcroForm is present", function () {
|
@@ -108,20 +131,23 @@ describe("document", function () {
|
|
108
131
|
let pdfDocument = getDocument(acroForm);
|
109
132
|
expect(pdfDocument.formInfo).toEqual({
|
110
133
|
hasAcroForm: false,
|
111
|
-
hasXfa: false
|
134
|
+
hasXfa: false,
|
135
|
+
hasFields: false
|
112
136
|
});
|
113
137
|
acroForm.set("Fields", ["foo", "bar"]);
|
114
138
|
pdfDocument = getDocument(acroForm);
|
115
139
|
expect(pdfDocument.formInfo).toEqual({
|
116
140
|
hasAcroForm: true,
|
117
|
-
hasXfa: false
|
141
|
+
hasXfa: false,
|
142
|
+
hasFields: true
|
118
143
|
});
|
119
144
|
acroForm.set("Fields", ["foo", "bar"]);
|
120
145
|
acroForm.set("SigFlags", 2);
|
121
146
|
pdfDocument = getDocument(acroForm);
|
122
147
|
expect(pdfDocument.formInfo).toEqual({
|
123
148
|
hasAcroForm: true,
|
124
|
-
hasXfa: false
|
149
|
+
hasXfa: false,
|
150
|
+
hasFields: true
|
125
151
|
});
|
126
152
|
const annotationDict = new _primitives.Dict();
|
127
153
|
annotationDict.set("FT", _primitives.Name.get("Sig"));
|
@@ -134,7 +160,7 @@ describe("document", function () {
|
|
134
160
|
|
135
161
|
const kidsRef = _primitives.Ref.get(10, 0);
|
136
162
|
|
137
|
-
|
163
|
+
const xref = new _test_utils.XRefMock([{
|
138
164
|
ref: annotationRef,
|
139
165
|
data: annotationDict
|
140
166
|
}, {
|
@@ -143,11 +169,152 @@ describe("document", function () {
|
|
143
169
|
}]);
|
144
170
|
acroForm.set("Fields", [kidsRef]);
|
145
171
|
acroForm.set("SigFlags", 3);
|
146
|
-
pdfDocument = getDocument(acroForm);
|
172
|
+
pdfDocument = getDocument(acroForm, xref);
|
147
173
|
expect(pdfDocument.formInfo).toEqual({
|
148
174
|
hasAcroForm: false,
|
149
|
-
hasXfa: false
|
175
|
+
hasXfa: false,
|
176
|
+
hasFields: true
|
150
177
|
});
|
151
178
|
});
|
179
|
+
it("should get calculation order array or null", function () {
|
180
|
+
const acroForm = new _primitives.Dict();
|
181
|
+
let pdfDocument = getDocument(acroForm);
|
182
|
+
expect(pdfDocument.calculationOrderIds).toEqual(null);
|
183
|
+
acroForm.set("CO", [_primitives.Ref.get(1, 0), _primitives.Ref.get(2, 0), _primitives.Ref.get(3, 0)]);
|
184
|
+
pdfDocument = getDocument(acroForm);
|
185
|
+
expect(pdfDocument.calculationOrderIds).toEqual(["1R", "2R", "3R"]);
|
186
|
+
acroForm.set("CO", []);
|
187
|
+
pdfDocument = getDocument(acroForm);
|
188
|
+
expect(pdfDocument.calculationOrderIds).toEqual(null);
|
189
|
+
acroForm.set("CO", ["1", "2"]);
|
190
|
+
pdfDocument = getDocument(acroForm);
|
191
|
+
expect(pdfDocument.calculationOrderIds).toEqual(null);
|
192
|
+
acroForm.set("CO", ["1", _primitives.Ref.get(1, 0), "2"]);
|
193
|
+
pdfDocument = getDocument(acroForm);
|
194
|
+
expect(pdfDocument.calculationOrderIds).toEqual(["1R"]);
|
195
|
+
});
|
196
|
+
it("should get field objects array or null", async function () {
|
197
|
+
const acroForm = new _primitives.Dict();
|
198
|
+
let pdfDocument = getDocument(acroForm);
|
199
|
+
let fields = await pdfDocument.fieldObjects;
|
200
|
+
expect(fields).toEqual(null);
|
201
|
+
acroForm.set("Fields", []);
|
202
|
+
pdfDocument = getDocument(acroForm);
|
203
|
+
fields = await pdfDocument.fieldObjects;
|
204
|
+
expect(fields).toEqual(null);
|
205
|
+
|
206
|
+
const kid1Ref = _primitives.Ref.get(314, 0);
|
207
|
+
|
208
|
+
const kid11Ref = _primitives.Ref.get(159, 0);
|
209
|
+
|
210
|
+
const kid2Ref = _primitives.Ref.get(265, 0);
|
211
|
+
|
212
|
+
const kid2BisRef = _primitives.Ref.get(266, 0);
|
213
|
+
|
214
|
+
const parentRef = _primitives.Ref.get(358, 0);
|
215
|
+
|
216
|
+
const allFields = Object.create(null);
|
217
|
+
|
218
|
+
for (const name of ["parent", "kid1", "kid2", "kid11"]) {
|
219
|
+
const buttonWidgetDict = new _primitives.Dict();
|
220
|
+
buttonWidgetDict.set("Type", _primitives.Name.get("Annot"));
|
221
|
+
buttonWidgetDict.set("Subtype", _primitives.Name.get("Widget"));
|
222
|
+
buttonWidgetDict.set("FT", _primitives.Name.get("Btn"));
|
223
|
+
buttonWidgetDict.set("T", name);
|
224
|
+
allFields[name] = buttonWidgetDict;
|
225
|
+
}
|
226
|
+
|
227
|
+
allFields.kid1.set("Kids", [kid11Ref]);
|
228
|
+
allFields.parent.set("Kids", [kid1Ref, kid2Ref, kid2BisRef]);
|
229
|
+
const xref = new _test_utils.XRefMock([{
|
230
|
+
ref: parentRef,
|
231
|
+
data: allFields.parent
|
232
|
+
}, {
|
233
|
+
ref: kid1Ref,
|
234
|
+
data: allFields.kid1
|
235
|
+
}, {
|
236
|
+
ref: kid11Ref,
|
237
|
+
data: allFields.kid11
|
238
|
+
}, {
|
239
|
+
ref: kid2Ref,
|
240
|
+
data: allFields.kid2
|
241
|
+
}, {
|
242
|
+
ref: kid2BisRef,
|
243
|
+
data: allFields.kid2
|
244
|
+
}]);
|
245
|
+
acroForm.set("Fields", [parentRef]);
|
246
|
+
pdfDocument = getDocument(acroForm, xref);
|
247
|
+
fields = await pdfDocument.fieldObjects;
|
248
|
+
|
249
|
+
for (const [name, objs] of Object.entries(fields)) {
|
250
|
+
fields[name] = objs.map(obj => obj.id);
|
251
|
+
}
|
252
|
+
|
253
|
+
expect(fields["parent.kid1"]).toEqual(["314R"]);
|
254
|
+
expect(fields["parent.kid1.kid11"]).toEqual(["159R"]);
|
255
|
+
expect(fields["parent.kid2"]).toEqual(["265R", "266R"]);
|
256
|
+
expect(fields.parent).toEqual(["358R"]);
|
257
|
+
});
|
258
|
+
it("should check if fields have any actions", async function () {
|
259
|
+
const acroForm = new _primitives.Dict();
|
260
|
+
let pdfDocument = getDocument(acroForm);
|
261
|
+
let hasJSActions = await pdfDocument.hasJSActions;
|
262
|
+
expect(hasJSActions).toEqual(false);
|
263
|
+
acroForm.set("Fields", []);
|
264
|
+
pdfDocument = getDocument(acroForm);
|
265
|
+
hasJSActions = await pdfDocument.hasJSActions;
|
266
|
+
expect(hasJSActions).toEqual(false);
|
267
|
+
|
268
|
+
const kid1Ref = _primitives.Ref.get(314, 0);
|
269
|
+
|
270
|
+
const kid11Ref = _primitives.Ref.get(159, 0);
|
271
|
+
|
272
|
+
const kid2Ref = _primitives.Ref.get(265, 0);
|
273
|
+
|
274
|
+
const parentRef = _primitives.Ref.get(358, 0);
|
275
|
+
|
276
|
+
const allFields = Object.create(null);
|
277
|
+
|
278
|
+
for (const name of ["parent", "kid1", "kid2", "kid11"]) {
|
279
|
+
const buttonWidgetDict = new _primitives.Dict();
|
280
|
+
buttonWidgetDict.set("Type", _primitives.Name.get("Annot"));
|
281
|
+
buttonWidgetDict.set("Subtype", _primitives.Name.get("Widget"));
|
282
|
+
buttonWidgetDict.set("FT", _primitives.Name.get("Btn"));
|
283
|
+
buttonWidgetDict.set("T", name);
|
284
|
+
allFields[name] = buttonWidgetDict;
|
285
|
+
}
|
286
|
+
|
287
|
+
allFields.kid1.set("Kids", [kid11Ref]);
|
288
|
+
allFields.parent.set("Kids", [kid1Ref, kid2Ref]);
|
289
|
+
const xref = new _test_utils.XRefMock([{
|
290
|
+
ref: parentRef,
|
291
|
+
data: allFields.parent
|
292
|
+
}, {
|
293
|
+
ref: kid1Ref,
|
294
|
+
data: allFields.kid1
|
295
|
+
}, {
|
296
|
+
ref: kid11Ref,
|
297
|
+
data: allFields.kid11
|
298
|
+
}, {
|
299
|
+
ref: kid2Ref,
|
300
|
+
data: allFields.kid2
|
301
|
+
}]);
|
302
|
+
acroForm.set("Fields", [parentRef]);
|
303
|
+
pdfDocument = getDocument(acroForm, xref);
|
304
|
+
hasJSActions = await pdfDocument.hasJSActions;
|
305
|
+
expect(hasJSActions).toEqual(false);
|
306
|
+
|
307
|
+
const JS = _primitives.Name.get("JavaScript");
|
308
|
+
|
309
|
+
const additionalActionsDict = new _primitives.Dict();
|
310
|
+
const eDict = new _primitives.Dict();
|
311
|
+
eDict.set("JS", "hello()");
|
312
|
+
eDict.set("S", JS);
|
313
|
+
additionalActionsDict.set("E", eDict);
|
314
|
+
allFields.kid2.set("AA", additionalActionsDict);
|
315
|
+
pdfDocument = getDocument(acroForm, xref);
|
316
|
+
hasJSActions = await pdfDocument.hasJSActions;
|
317
|
+
expect(hasJSActions).toEqual(true);
|
318
|
+
});
|
152
319
|
});
|
153
320
|
});
|
@@ -60,8 +60,8 @@ describe("evaluator", function () {
|
|
60
60
|
};
|
61
61
|
|
62
62
|
function runOperatorListCheck(evaluator, stream, resources, callback) {
|
63
|
-
|
64
|
-
|
63
|
+
const result = new _operator_list.OperatorList();
|
64
|
+
const task = new _worker.WorkerTask("OperatorListCheck");
|
65
65
|
evaluator.getOperatorList({
|
66
66
|
stream,
|
67
67
|
task,
|
@@ -74,7 +74,7 @@ describe("evaluator", function () {
|
|
74
74
|
});
|
75
75
|
}
|
76
76
|
|
77
|
-
|
77
|
+
let partialEvaluator;
|
78
78
|
beforeAll(function (done) {
|
79
79
|
partialEvaluator = new _evaluator.PartialEvaluator({
|
80
80
|
xref: new _test_utils.XRefMock(),
|
@@ -89,7 +89,7 @@ describe("evaluator", function () {
|
|
89
89
|
});
|
90
90
|
describe("splitCombinedOperations", function () {
|
91
91
|
it("should reject unknown operations", function (done) {
|
92
|
-
|
92
|
+
const stream = new _stream.StringStream("fTT");
|
93
93
|
runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
|
94
94
|
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
95
95
|
expect(result.fnArray.length).toEqual(1);
|
@@ -99,7 +99,7 @@ describe("evaluator", function () {
|
|
99
99
|
});
|
100
100
|
});
|
101
101
|
it("should handle one operation", function (done) {
|
102
|
-
|
102
|
+
const stream = new _stream.StringStream("Q");
|
103
103
|
runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
|
104
104
|
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
105
105
|
expect(result.fnArray.length).toEqual(1);
|
@@ -118,7 +118,7 @@ describe("evaluator", function () {
|
|
118
118
|
xObject.set("Res1", imgStream);
|
119
119
|
const resources = new ResourcesMock();
|
120
120
|
resources.XObject = xObject;
|
121
|
-
|
121
|
+
const stream = new _stream.StringStream("/Res1 DoQ");
|
122
122
|
runOperatorListCheck(partialEvaluator, stream, resources, function (result) {
|
123
123
|
expect(result.fnArray.length).toEqual(3);
|
124
124
|
expect(result.fnArray[0]).toEqual(_util.OPS.dependency);
|
@@ -132,7 +132,7 @@ describe("evaluator", function () {
|
|
132
132
|
});
|
133
133
|
});
|
134
134
|
it("should handle three glued operations", function (done) {
|
135
|
-
|
135
|
+
const stream = new _stream.StringStream("fff");
|
136
136
|
runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
|
137
137
|
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
138
138
|
expect(result.fnArray.length).toEqual(3);
|
@@ -143,9 +143,9 @@ describe("evaluator", function () {
|
|
143
143
|
});
|
144
144
|
});
|
145
145
|
it("should handle three glued operations #2", function (done) {
|
146
|
-
|
146
|
+
const resources = new ResourcesMock();
|
147
147
|
resources.Res1 = {};
|
148
|
-
|
148
|
+
const stream = new _stream.StringStream("B*Bf*");
|
149
149
|
runOperatorListCheck(partialEvaluator, stream, resources, function (result) {
|
150
150
|
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
151
151
|
expect(result.fnArray.length).toEqual(3);
|
@@ -156,7 +156,7 @@ describe("evaluator", function () {
|
|
156
156
|
});
|
157
157
|
});
|
158
158
|
it("should handle glued operations and operands", function (done) {
|
159
|
-
|
159
|
+
const stream = new _stream.StringStream("f5 Ts");
|
160
160
|
runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
|
161
161
|
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
162
162
|
expect(result.fnArray.length).toEqual(2);
|
@@ -169,7 +169,7 @@ describe("evaluator", function () {
|
|
169
169
|
});
|
170
170
|
});
|
171
171
|
it("should handle glued operations and literals", function (done) {
|
172
|
-
|
172
|
+
const stream = new _stream.StringStream("trueifalserinulln");
|
173
173
|
runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
|
174
174
|
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
175
175
|
expect(result.fnArray.length).toEqual(3);
|
@@ -188,7 +188,7 @@ describe("evaluator", function () {
|
|
188
188
|
});
|
189
189
|
describe("validateNumberOfArgs", function () {
|
190
190
|
it("should execute if correct number of arguments", function (done) {
|
191
|
-
|
191
|
+
const stream = new _stream.StringStream("5 1 d0");
|
192
192
|
runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
|
193
193
|
expect(result.argsArray[0][0]).toEqual(5);
|
194
194
|
expect(result.argsArray[0][1]).toEqual(1);
|
@@ -197,7 +197,7 @@ describe("evaluator", function () {
|
|
197
197
|
});
|
198
198
|
});
|
199
199
|
it("should execute if too many arguments", function (done) {
|
200
|
-
|
200
|
+
const stream = new _stream.StringStream("5 1 4 d0");
|
201
201
|
runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
|
202
202
|
expect(result.argsArray[0][0]).toEqual(1);
|
203
203
|
expect(result.argsArray[0][1]).toEqual(4);
|
@@ -213,7 +213,7 @@ describe("evaluator", function () {
|
|
213
213
|
extGState.set("GS2", gState);
|
214
214
|
const resources = new ResourcesMock();
|
215
215
|
resources.ExtGState = extGState;
|
216
|
-
|
216
|
+
const stream = new _stream.StringStream("/F2 /GS2 gs 5.711 Tf");
|
217
217
|
runOperatorListCheck(partialEvaluator, stream, resources, function (result) {
|
218
218
|
expect(result.fnArray.length).toEqual(3);
|
219
219
|
expect(result.fnArray[0]).toEqual(_util.OPS.setGState);
|
@@ -227,7 +227,7 @@ describe("evaluator", function () {
|
|
227
227
|
});
|
228
228
|
});
|
229
229
|
it("should skip if too few arguments", function (done) {
|
230
|
-
|
230
|
+
const stream = new _stream.StringStream("5 d0");
|
231
231
|
runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
|
232
232
|
expect(result.argsArray).toEqual([]);
|
233
233
|
expect(result.fnArray).toEqual([]);
|
@@ -253,7 +253,7 @@ describe("evaluator", function () {
|
|
253
253
|
});
|
254
254
|
});
|
255
255
|
it("should close opened saves", function (done) {
|
256
|
-
|
256
|
+
const stream = new _stream.StringStream("qq");
|
257
257
|
runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
|
258
258
|
expect(!!result.fnArray && !!result.argsArray).toEqual(true);
|
259
259
|
expect(result.fnArray.length).toEqual(4);
|
@@ -265,7 +265,7 @@ describe("evaluator", function () {
|
|
265
265
|
});
|
266
266
|
});
|
267
267
|
it("should error on paintXObject if name is missing", function (done) {
|
268
|
-
|
268
|
+
const stream = new _stream.StringStream("/ Do");
|
269
269
|
runOperatorListCheck(partialEvaluator, stream, new ResourcesMock(), function (result) {
|
270
270
|
expect(result instanceof _util.FormatError).toEqual(true);
|
271
271
|
expect(result.message).toEqual("XObject must be referred to by name.");
|
@@ -273,14 +273,14 @@ describe("evaluator", function () {
|
|
273
273
|
});
|
274
274
|
});
|
275
275
|
it("should skip paintXObject if subtype is PS", function (done) {
|
276
|
-
|
276
|
+
const xobjStreamDict = new _primitives.Dict();
|
277
277
|
xobjStreamDict.set("Subtype", _primitives.Name.get("PS"));
|
278
|
-
|
279
|
-
|
278
|
+
const xobjStream = new _stream.Stream([], 0, 0, xobjStreamDict);
|
279
|
+
const xobjs = new _primitives.Dict();
|
280
280
|
xobjs.set("Res1", xobjStream);
|
281
|
-
|
281
|
+
const resources = new _primitives.Dict();
|
282
282
|
resources.set("XObject", xobjs);
|
283
|
-
|
283
|
+
const stream = new _stream.StringStream("/Res1 Do");
|
284
284
|
runOperatorListCheck(partialEvaluator, stream, resources, function (result) {
|
285
285
|
expect(result.argsArray).toEqual([]);
|
286
286
|
expect(result.fnArray).toEqual([]);
|
@@ -290,10 +290,10 @@ describe("evaluator", function () {
|
|
290
290
|
});
|
291
291
|
describe("thread control", function () {
|
292
292
|
it("should abort operator list parsing", function (done) {
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
293
|
+
const stream = new _stream.StringStream("qqQQ");
|
294
|
+
const resources = new ResourcesMock();
|
295
|
+
const result = new _operator_list.OperatorList();
|
296
|
+
const task = new _worker.WorkerTask("OperatorListAbort");
|
297
297
|
task.terminate();
|
298
298
|
partialEvaluator.getOperatorList({
|
299
299
|
stream,
|
@@ -307,9 +307,9 @@ describe("evaluator", function () {
|
|
307
307
|
});
|
308
308
|
});
|
309
309
|
it("should abort text parsing parsing", function (done) {
|
310
|
-
|
311
|
-
|
312
|
-
|
310
|
+
const resources = new ResourcesMock();
|
311
|
+
const stream = new _stream.StringStream("qqQQ");
|
312
|
+
const task = new _worker.WorkerTask("TextContentAbort");
|
313
313
|
task.terminate();
|
314
314
|
partialEvaluator.getTextContent({
|
315
315
|
stream,
|
@@ -328,7 +328,7 @@ describe("evaluator", function () {
|
|
328
328
|
}
|
329
329
|
|
330
330
|
it("should get correct total length after flushing", function () {
|
331
|
-
|
331
|
+
const operatorList = new _operator_list.OperatorList(null, new StreamSinkMock());
|
332
332
|
operatorList.addOp(_util.OPS.save, null);
|
333
333
|
operatorList.addOp(_util.OPS.restore, null);
|
334
334
|
expect(operatorList.totalLength).toEqual(2);
|