pdfjs-dist 2.0.943 → 2.4.456
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/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +8286 -14230
- 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 +25500 -26628
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -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/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +2887 -4094
- 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 +855 -778
- package/lib/core/arithmetic_decoder.js +325 -311
- package/lib/core/bidi.js +117 -50
- package/lib/core/ccitt.js +251 -89
- package/lib/core/ccitt_stream.js +26 -16
- package/lib/core/cff_parser.js +525 -197
- package/lib/core/charsets.js +6 -5
- package/lib/core/chunked_stream.js +541 -406
- package/lib/core/cmap.js +368 -253
- package/lib/core/colorspace.js +781 -800
- package/lib/core/core_utils.js +152 -0
- package/lib/core/crypto.js +609 -422
- package/lib/core/document.js +649 -481
- package/lib/core/encodings.js +33 -24
- package/lib/core/evaluator.js +1471 -736
- package/lib/core/font_renderer.js +289 -149
- package/lib/core/fonts.js +1067 -413
- package/lib/core/function.js +517 -287
- package/lib/core/glyphlist.js +4529 -4527
- package/lib/core/image.js +232 -114
- package/lib/core/image_utils.js +94 -0
- package/lib/core/jbig2.js +711 -342
- package/lib/core/jbig2_stream.js +31 -19
- package/lib/core/jpeg_stream.js +151 -26
- package/lib/core/jpg.js +433 -181
- package/lib/core/jpx.js +551 -143
- package/lib/core/jpx_stream.js +40 -28
- package/lib/core/metrics.js +2931 -2931
- package/lib/core/murmurhash3.js +104 -97
- package/lib/core/obj.js +1561 -1053
- package/lib/core/operator_list.js +192 -64
- package/lib/core/parser.js +1162 -864
- package/lib/core/pattern.js +224 -75
- package/lib/core/pdf_manager.js +154 -285
- package/lib/core/primitives.js +145 -69
- package/lib/core/ps_parser.js +212 -162
- package/lib/core/standard_fonts.js +245 -244
- package/lib/core/stream.js +353 -81
- package/lib/core/type1_parser.js +218 -68
- package/lib/core/unicode.js +1682 -1655
- package/lib/core/worker.js +233 -302
- package/lib/core/worker_stream.js +168 -0
- package/lib/display/annotation_layer.js +808 -862
- package/lib/display/api.js +1778 -1462
- package/lib/display/api_compatibility.js +14 -9
- package/lib/display/canvas.js +463 -140
- package/lib/display/content_disposition.js +86 -58
- package/lib/display/display_utils.js +524 -0
- package/lib/display/fetch_stream.js +202 -274
- package/lib/display/font_loader.js +311 -333
- package/lib/display/metadata.js +98 -88
- package/lib/display/network.js +343 -347
- package/lib/display/network_utils.js +46 -26
- package/lib/display/node_stream.js +326 -404
- package/lib/display/pattern_helper.js +168 -69
- package/lib/display/svg.js +1296 -885
- package/lib/display/text_layer.js +229 -103
- package/lib/display/transport_stream.js +290 -250
- package/lib/display/webgl.js +116 -83
- package/lib/display/worker_options.js +6 -5
- package/lib/display/xml_parser.js +358 -337
- package/lib/examples/node/domstubs.js +95 -39
- package/lib/pdf.js +49 -31
- package/lib/pdf.worker.js +7 -5
- package/lib/shared/compatibility.js +3 -145
- package/lib/shared/is_node.js +8 -7
- package/lib/shared/message_handler.js +367 -314
- package/lib/shared/util.js +421 -415
- package/lib/test/unit/annotation_spec.js +1570 -690
- package/lib/test/unit/api_spec.js +855 -493
- package/lib/test/unit/bidi_spec.js +12 -12
- package/lib/test/unit/cff_parser_spec.js +88 -61
- package/lib/test/unit/clitests_helper.js +9 -12
- package/lib/test/unit/cmap_spec.js +140 -88
- package/lib/test/unit/colorspace_spec.js +204 -152
- package/lib/test/unit/core_utils_spec.js +211 -0
- package/lib/test/unit/crypto_spec.js +194 -182
- package/lib/test/unit/custom_spec.js +50 -64
- package/lib/test/unit/display_svg_spec.js +53 -38
- package/lib/test/unit/display_utils_spec.js +263 -0
- package/lib/test/unit/document_spec.js +17 -22
- package/lib/test/unit/encodings_spec.js +15 -57
- package/lib/test/unit/evaluator_spec.js +90 -83
- package/lib/test/unit/fetch_stream_spec.js +111 -0
- package/lib/test/unit/function_spec.js +219 -205
- package/lib/test/unit/jasmine-boot.js +68 -39
- package/lib/test/unit/message_handler_spec.js +187 -160
- package/lib/test/unit/metadata_spec.js +87 -34
- package/lib/test/unit/murmurhash3_spec.js +13 -13
- package/lib/test/unit/network_spec.js +26 -59
- package/lib/test/unit/network_utils_spec.js +187 -121
- package/lib/test/unit/node_stream_spec.js +98 -90
- package/lib/test/unit/parser_spec.js +173 -131
- package/lib/test/unit/pdf_find_controller_spec.js +148 -67
- package/lib/test/unit/pdf_find_utils_spec.js +35 -34
- package/lib/test/unit/pdf_history_spec.js +45 -33
- package/lib/test/unit/primitives_spec.js +161 -126
- package/lib/test/unit/stream_spec.js +22 -15
- package/lib/test/unit/test_utils.js +149 -98
- package/lib/test/unit/testreporter.js +36 -18
- package/lib/test/unit/type1_parser_spec.js +46 -44
- package/lib/test/unit/ui_utils_spec.js +388 -372
- package/lib/test/unit/unicode_spec.js +49 -46
- package/lib/test/unit/util_spec.js +144 -248
- package/lib/web/annotation_layer_builder.js +75 -95
- package/lib/web/app.js +1538 -1147
- package/lib/web/app_options.js +116 -104
- package/lib/web/base_viewer.js +950 -775
- package/lib/web/chromecom.js +217 -225
- package/lib/web/debugger.js +236 -148
- package/lib/web/download_manager.js +50 -50
- package/lib/web/firefox_print_service.js +51 -33
- package/lib/web/firefoxcom.js +225 -352
- package/lib/web/genericcom.js +30 -93
- package/lib/web/genericl10n.js +26 -143
- package/lib/web/grab_to_pan.js +57 -33
- package/lib/web/interfaces.js +105 -232
- package/lib/web/overlay_manager.js +73 -227
- package/lib/web/password_prompt.js +44 -62
- package/lib/web/pdf_attachment_viewer.js +118 -123
- package/lib/web/pdf_cursor_tools.js +89 -93
- package/lib/web/pdf_document_properties.js +242 -281
- package/lib/web/pdf_find_bar.js +157 -163
- package/lib/web/pdf_find_controller.js +598 -454
- package/lib/web/pdf_find_utils.js +32 -16
- package/lib/web/pdf_history.js +481 -355
- package/lib/web/pdf_link_service.js +355 -323
- package/lib/web/pdf_outline_viewer.js +167 -152
- package/lib/web/pdf_page_view.js +511 -457
- package/lib/web/pdf_presentation_mode.js +347 -335
- package/lib/web/pdf_print_service.js +133 -103
- package/lib/web/pdf_rendering_queue.js +98 -100
- package/lib/web/pdf_sidebar.js +323 -299
- package/lib/web/pdf_sidebar_resizer.js +107 -108
- package/lib/web/pdf_single_page_viewer.js +94 -146
- package/lib/web/pdf_thumbnail_view.js +319 -269
- package/lib/web/pdf_thumbnail_viewer.js +219 -199
- package/lib/web/pdf_viewer.component.js +111 -32
- package/lib/web/pdf_viewer.js +61 -101
- package/lib/web/preferences.js +87 -272
- package/lib/web/secondary_toolbar.js +207 -220
- package/lib/web/text_layer_builder.js +322 -322
- package/lib/web/toolbar.js +227 -180
- package/lib/web/ui_utils.js +476 -421
- package/lib/web/view_history.js +59 -208
- package/lib/web/viewer_compatibility.js +9 -6
- package/package.json +2 -9
- package/web/pdf_viewer.css +36 -22
- package/web/pdf_viewer.js +4407 -4516
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/external/streams/streams-lib.js +0 -3962
- package/external/url/url-lib.js +0 -627
- package/lib/display/dom_utils.js +0 -441
- package/lib/shared/streams_polyfill.js +0 -39
- package/lib/shared/url_polyfill.js +0 -50
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/web/dom_events.js +0 -140
@@ -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.
|
@@ -19,150 +19,222 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
|
-
var
|
24
|
+
var _annotation = require("../../core/annotation.js");
|
25
25
|
|
26
|
-
var
|
26
|
+
var _util = require("../../shared/util.js");
|
27
27
|
|
28
|
-
var
|
28
|
+
var _test_utils = require("./test_utils.js");
|
29
29
|
|
30
|
-
var _primitives = require(
|
30
|
+
var _primitives = require("../../core/primitives.js");
|
31
31
|
|
32
|
-
var _parser = require(
|
32
|
+
var _parser = require("../../core/parser.js");
|
33
33
|
|
34
|
-
var _stream = require(
|
35
|
-
|
36
|
-
var _test_utils = require('./test_utils');
|
37
|
-
|
38
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
39
|
-
|
40
|
-
describe('annotation', function () {
|
41
|
-
var PDFManagerMock = function () {
|
42
|
-
function PDFManagerMock(params) {
|
43
|
-
_classCallCheck(this, PDFManagerMock);
|
34
|
+
var _stream = require("../../core/stream.js");
|
44
35
|
|
36
|
+
describe("annotation", function () {
|
37
|
+
class PDFManagerMock {
|
38
|
+
constructor(params) {
|
45
39
|
this.docBaseUrl = params.docBaseUrl || null;
|
46
40
|
}
|
47
41
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
return new Promise(function (resolve) {
|
52
|
-
var value = obj[prop];
|
53
|
-
if (typeof value === 'function') {
|
54
|
-
resolve(value.apply(obj, args));
|
55
|
-
} else {
|
56
|
-
resolve(value);
|
57
|
-
}
|
58
|
-
});
|
59
|
-
}
|
60
|
-
}]);
|
61
|
-
|
62
|
-
return PDFManagerMock;
|
63
|
-
}();
|
42
|
+
ensure(obj, prop, args) {
|
43
|
+
return new Promise(function (resolve) {
|
44
|
+
const value = obj[prop];
|
64
45
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
46
|
+
if (typeof value === "function") {
|
47
|
+
resolve(value.apply(obj, args));
|
48
|
+
} else {
|
49
|
+
resolve(value);
|
50
|
+
}
|
51
|
+
});
|
71
52
|
}
|
72
53
|
|
73
|
-
|
74
|
-
key: 'createObjId',
|
75
|
-
value: function createObjId() {
|
76
|
-
return this.uniquePrefix + ++this.idCounters.obj;
|
77
|
-
}
|
78
|
-
}]);
|
54
|
+
}
|
79
55
|
|
80
|
-
|
81
|
-
}();
|
82
|
-
|
83
|
-
var pdfManagerMock = void 0,
|
84
|
-
idFactoryMock = void 0;
|
56
|
+
let pdfManagerMock, idFactoryMock;
|
85
57
|
beforeAll(function (done) {
|
86
|
-
pdfManagerMock = new PDFManagerMock({
|
87
|
-
|
58
|
+
pdfManagerMock = new PDFManagerMock({
|
59
|
+
docBaseUrl: null
|
60
|
+
});
|
61
|
+
idFactoryMock = (0, _test_utils.createIdFactory)(0);
|
88
62
|
done();
|
89
63
|
});
|
90
64
|
afterAll(function () {
|
91
65
|
pdfManagerMock = null;
|
92
66
|
idFactoryMock = null;
|
93
67
|
});
|
94
|
-
describe(
|
95
|
-
it(
|
96
|
-
|
97
|
-
annotationDict.set(
|
98
|
-
annotationDict.set(
|
99
|
-
|
100
|
-
|
68
|
+
describe("AnnotationFactory", function () {
|
69
|
+
it("should get id for annotation", function (done) {
|
70
|
+
const annotationDict = new _primitives.Dict();
|
71
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
72
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
73
|
+
|
74
|
+
const annotationRef = _primitives.Ref.get(10, 0);
|
75
|
+
|
76
|
+
const xref = new _test_utils.XRefMock([{
|
101
77
|
ref: annotationRef,
|
102
78
|
data: annotationDict
|
103
79
|
}]);
|
104
|
-
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref) {
|
105
|
-
var data = _ref.data;
|
106
80
|
|
81
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
82
|
+
data
|
83
|
+
}) => {
|
107
84
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
108
|
-
expect(data.id).toEqual(
|
85
|
+
expect(data.id).toEqual("10R");
|
109
86
|
done();
|
110
87
|
}, done.fail);
|
111
88
|
});
|
112
|
-
it(
|
113
|
-
|
114
|
-
annotationDict.set(
|
115
|
-
annotationDict.set(
|
116
|
-
|
117
|
-
|
118
|
-
prefix: 'p0_',
|
119
|
-
startObjId: 0
|
120
|
-
});
|
121
|
-
var annotation1 = _annotation.AnnotationFactory.create(xref, annotationDict, pdfManagerMock, idFactory).then(function (_ref2) {
|
122
|
-
var data = _ref2.data;
|
89
|
+
it("should handle, and get fallback IDs for, annotations that are not " + "indirect objects (issue 7569)", function (done) {
|
90
|
+
const annotationDict = new _primitives.Dict();
|
91
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
92
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
93
|
+
const xref = new _test_utils.XRefMock();
|
94
|
+
const idFactory = (0, _test_utils.createIdFactory)(0);
|
123
95
|
|
96
|
+
const annotation1 = _annotation.AnnotationFactory.create(xref, annotationDict, pdfManagerMock, idFactory).then(({
|
97
|
+
data
|
98
|
+
}) => {
|
124
99
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
125
|
-
expect(data.id).toEqual(
|
100
|
+
expect(data.id).toEqual("annot_p0_1");
|
126
101
|
});
|
127
|
-
var annotation2 = _annotation.AnnotationFactory.create(xref, annotationDict, pdfManagerMock, idFactory).then(function (_ref3) {
|
128
|
-
var data = _ref3.data;
|
129
102
|
|
103
|
+
const annotation2 = _annotation.AnnotationFactory.create(xref, annotationDict, pdfManagerMock, idFactory).then(({
|
104
|
+
data
|
105
|
+
}) => {
|
130
106
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
131
|
-
expect(data.id).toEqual(
|
107
|
+
expect(data.id).toEqual("annot_p0_2");
|
132
108
|
});
|
109
|
+
|
133
110
|
Promise.all([annotation1, annotation2]).then(done, done.fail);
|
134
111
|
});
|
135
|
-
it(
|
136
|
-
|
137
|
-
annotationDict.set(
|
138
|
-
|
139
|
-
|
112
|
+
it("should handle missing /Subtype", function (done) {
|
113
|
+
const annotationDict = new _primitives.Dict();
|
114
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
115
|
+
|
116
|
+
const annotationRef = _primitives.Ref.get(1, 0);
|
117
|
+
|
118
|
+
const xref = new _test_utils.XRefMock([{
|
140
119
|
ref: annotationRef,
|
141
120
|
data: annotationDict
|
142
121
|
}]);
|
143
|
-
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref4) {
|
144
|
-
var data = _ref4.data;
|
145
122
|
|
123
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
124
|
+
data
|
125
|
+
}) => {
|
146
126
|
expect(data.annotationType).toBeUndefined();
|
147
127
|
done();
|
148
128
|
}, done.fail);
|
149
129
|
});
|
150
130
|
});
|
151
|
-
describe(
|
152
|
-
|
153
|
-
|
131
|
+
describe("getQuadPoints", function () {
|
132
|
+
let dict, rect;
|
133
|
+
beforeEach(function (done) {
|
134
|
+
dict = new _primitives.Dict();
|
135
|
+
rect = [];
|
136
|
+
done();
|
137
|
+
});
|
138
|
+
afterEach(function () {
|
139
|
+
dict = null;
|
140
|
+
rect = null;
|
141
|
+
});
|
142
|
+
it("should ignore missing quadpoints", function () {
|
143
|
+
expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual(null);
|
144
|
+
});
|
145
|
+
it("should ignore non-array values", function () {
|
146
|
+
dict.set("QuadPoints", "foo");
|
147
|
+
expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual(null);
|
148
|
+
});
|
149
|
+
it("should ignore arrays where the length is not a multiple of eight", function () {
|
150
|
+
dict.set("QuadPoints", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
151
|
+
expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual(null);
|
152
|
+
});
|
153
|
+
it("should ignore quadpoints if one coordinate lies outside the rectangle", function () {
|
154
|
+
rect = [10, 10, 20, 20];
|
155
|
+
const inputs = [[11, 11, 12, 12, 9, 13, 14, 14], [11, 11, 12, 12, 13, 9, 14, 14], [11, 11, 12, 12, 21, 13, 14, 14], [11, 11, 12, 12, 13, 21, 14, 14]];
|
156
|
+
|
157
|
+
for (const input of inputs) {
|
158
|
+
dict.set("QuadPoints", input);
|
159
|
+
expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual(null);
|
160
|
+
}
|
161
|
+
});
|
162
|
+
it("should process valid quadpoints arrays", function () {
|
163
|
+
rect = [10, 10, 20, 20];
|
164
|
+
dict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18]);
|
165
|
+
expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual([[{
|
166
|
+
x: 11,
|
167
|
+
y: 11
|
168
|
+
}, {
|
169
|
+
x: 12,
|
170
|
+
y: 12
|
171
|
+
}, {
|
172
|
+
x: 13,
|
173
|
+
y: 13
|
174
|
+
}, {
|
175
|
+
x: 14,
|
176
|
+
y: 14
|
177
|
+
}], [{
|
178
|
+
x: 15,
|
179
|
+
y: 15
|
180
|
+
}, {
|
181
|
+
x: 16,
|
182
|
+
y: 16
|
183
|
+
}, {
|
184
|
+
x: 17,
|
185
|
+
y: 17
|
186
|
+
}, {
|
187
|
+
x: 18,
|
188
|
+
y: 18
|
189
|
+
}]]);
|
190
|
+
});
|
191
|
+
});
|
192
|
+
describe("Annotation", function () {
|
193
|
+
let dict, ref;
|
154
194
|
beforeAll(function (done) {
|
155
195
|
dict = new _primitives.Dict();
|
156
|
-
ref =
|
196
|
+
ref = _primitives.Ref.get(1, 0);
|
157
197
|
done();
|
158
198
|
});
|
159
199
|
afterAll(function () {
|
160
200
|
dict = ref = null;
|
161
201
|
});
|
162
|
-
it(
|
163
|
-
|
164
|
-
dict
|
165
|
-
ref
|
202
|
+
it("should set and get valid contents", function () {
|
203
|
+
const annotation = new _annotation.Annotation({
|
204
|
+
dict,
|
205
|
+
ref
|
206
|
+
});
|
207
|
+
annotation.setContents("Foo bar baz");
|
208
|
+
expect(annotation.contents).toEqual("Foo bar baz");
|
209
|
+
});
|
210
|
+
it("should not set and get invalid contents", function () {
|
211
|
+
const annotation = new _annotation.Annotation({
|
212
|
+
dict,
|
213
|
+
ref
|
214
|
+
});
|
215
|
+
annotation.setContents(undefined);
|
216
|
+
expect(annotation.contents).toEqual("");
|
217
|
+
});
|
218
|
+
it("should set and get a valid modification date", function () {
|
219
|
+
const annotation = new _annotation.Annotation({
|
220
|
+
dict,
|
221
|
+
ref
|
222
|
+
});
|
223
|
+
annotation.setModificationDate("D:20190422");
|
224
|
+
expect(annotation.modificationDate).toEqual("D:20190422");
|
225
|
+
});
|
226
|
+
it("should not set and get an invalid modification date", function () {
|
227
|
+
const annotation = new _annotation.Annotation({
|
228
|
+
dict,
|
229
|
+
ref
|
230
|
+
});
|
231
|
+
annotation.setModificationDate(undefined);
|
232
|
+
expect(annotation.modificationDate).toEqual(null);
|
233
|
+
});
|
234
|
+
it("should set and get flags", function () {
|
235
|
+
const annotation = new _annotation.Annotation({
|
236
|
+
dict,
|
237
|
+
ref
|
166
238
|
});
|
167
239
|
annotation.setFlags(13);
|
168
240
|
expect(annotation.hasFlag(_util.AnnotationFlag.INVISIBLE)).toEqual(true);
|
@@ -170,386 +242,693 @@ describe('annotation', function () {
|
|
170
242
|
expect(annotation.hasFlag(_util.AnnotationFlag.PRINT)).toEqual(true);
|
171
243
|
expect(annotation.hasFlag(_util.AnnotationFlag.READONLY)).toEqual(false);
|
172
244
|
});
|
173
|
-
it(
|
174
|
-
|
175
|
-
dict
|
176
|
-
ref
|
245
|
+
it("should be viewable and not printable by default", function () {
|
246
|
+
const annotation = new _annotation.Annotation({
|
247
|
+
dict,
|
248
|
+
ref
|
177
249
|
});
|
178
250
|
expect(annotation.viewable).toEqual(true);
|
179
251
|
expect(annotation.printable).toEqual(false);
|
180
252
|
});
|
181
|
-
it(
|
182
|
-
|
183
|
-
dict
|
184
|
-
ref
|
253
|
+
it("should set and get a valid rectangle", function () {
|
254
|
+
const annotation = new _annotation.Annotation({
|
255
|
+
dict,
|
256
|
+
ref
|
185
257
|
});
|
186
258
|
annotation.setRectangle([117, 694, 164.298, 720]);
|
187
259
|
expect(annotation.rectangle).toEqual([117, 694, 164.298, 720]);
|
188
260
|
});
|
189
|
-
it(
|
190
|
-
|
191
|
-
dict
|
192
|
-
ref
|
261
|
+
it("should not set and get an invalid rectangle", function () {
|
262
|
+
const annotation = new _annotation.Annotation({
|
263
|
+
dict,
|
264
|
+
ref
|
193
265
|
});
|
194
266
|
annotation.setRectangle([117, 694, 164.298]);
|
195
267
|
expect(annotation.rectangle).toEqual([0, 0, 0, 0]);
|
196
268
|
});
|
197
|
-
it(
|
198
|
-
|
199
|
-
dict
|
200
|
-
ref
|
269
|
+
it("should reject a color if it is not an array", function () {
|
270
|
+
const annotation = new _annotation.Annotation({
|
271
|
+
dict,
|
272
|
+
ref
|
201
273
|
});
|
202
|
-
annotation.setColor(
|
274
|
+
annotation.setColor("red");
|
203
275
|
expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
|
204
276
|
});
|
205
|
-
it(
|
206
|
-
|
207
|
-
dict
|
208
|
-
ref
|
277
|
+
it("should set and get a transparent color", function () {
|
278
|
+
const annotation = new _annotation.Annotation({
|
279
|
+
dict,
|
280
|
+
ref
|
209
281
|
});
|
210
282
|
annotation.setColor([]);
|
211
283
|
expect(annotation.color).toEqual(null);
|
212
284
|
});
|
213
|
-
it(
|
214
|
-
|
215
|
-
dict
|
216
|
-
ref
|
285
|
+
it("should set and get a grayscale color", function () {
|
286
|
+
const annotation = new _annotation.Annotation({
|
287
|
+
dict,
|
288
|
+
ref
|
217
289
|
});
|
218
290
|
annotation.setColor([0.4]);
|
219
291
|
expect(annotation.color).toEqual(new Uint8ClampedArray([102, 102, 102]));
|
220
292
|
});
|
221
|
-
it(
|
222
|
-
|
223
|
-
dict
|
224
|
-
ref
|
293
|
+
it("should set and get an RGB color", function () {
|
294
|
+
const annotation = new _annotation.Annotation({
|
295
|
+
dict,
|
296
|
+
ref
|
225
297
|
});
|
226
298
|
annotation.setColor([0, 0, 1]);
|
227
299
|
expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
|
228
300
|
});
|
229
|
-
it(
|
230
|
-
|
231
|
-
dict
|
232
|
-
ref
|
301
|
+
it("should set and get a CMYK color", function () {
|
302
|
+
const annotation = new _annotation.Annotation({
|
303
|
+
dict,
|
304
|
+
ref
|
233
305
|
});
|
234
306
|
annotation.setColor([0.1, 0.92, 0.84, 0.02]);
|
235
307
|
expect(annotation.color).toEqual(new Uint8ClampedArray([234, 59, 48]));
|
236
308
|
});
|
237
|
-
it(
|
238
|
-
|
239
|
-
dict
|
240
|
-
ref
|
309
|
+
it("should not set and get an invalid color", function () {
|
310
|
+
const annotation = new _annotation.Annotation({
|
311
|
+
dict,
|
312
|
+
ref
|
241
313
|
});
|
242
314
|
annotation.setColor([0.4, 0.6]);
|
243
315
|
expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
|
244
316
|
});
|
245
317
|
});
|
246
|
-
describe(
|
247
|
-
it(
|
248
|
-
|
318
|
+
describe("AnnotationBorderStyle", function () {
|
319
|
+
it("should set and get a valid width", function () {
|
320
|
+
const borderStyle = new _annotation.AnnotationBorderStyle();
|
249
321
|
borderStyle.setWidth(3);
|
250
322
|
expect(borderStyle.width).toEqual(3);
|
251
323
|
});
|
252
|
-
it(
|
253
|
-
|
254
|
-
borderStyle.setWidth(
|
324
|
+
it("should not set and get an invalid width", function () {
|
325
|
+
const borderStyle = new _annotation.AnnotationBorderStyle();
|
326
|
+
borderStyle.setWidth("three");
|
255
327
|
expect(borderStyle.width).toEqual(1);
|
256
328
|
});
|
257
|
-
it(
|
258
|
-
|
259
|
-
|
329
|
+
it("should set the width to zero, when the input is a `Name` (issue 10385)", function () {
|
330
|
+
const borderStyleZero = new _annotation.AnnotationBorderStyle();
|
331
|
+
borderStyleZero.setWidth(_primitives.Name.get("0"));
|
332
|
+
const borderStyleFive = new _annotation.AnnotationBorderStyle();
|
333
|
+
borderStyleFive.setWidth(_primitives.Name.get("5"));
|
334
|
+
expect(borderStyleZero.width).toEqual(0);
|
335
|
+
expect(borderStyleFive.width).toEqual(0);
|
336
|
+
});
|
337
|
+
it("should set and get a valid style", function () {
|
338
|
+
const borderStyle = new _annotation.AnnotationBorderStyle();
|
339
|
+
borderStyle.setStyle(_primitives.Name.get("D"));
|
260
340
|
expect(borderStyle.style).toEqual(_util.AnnotationBorderStyleType.DASHED);
|
261
341
|
});
|
262
|
-
it(
|
263
|
-
|
264
|
-
borderStyle.setStyle(
|
342
|
+
it("should not set and get an invalid style", function () {
|
343
|
+
const borderStyle = new _annotation.AnnotationBorderStyle();
|
344
|
+
borderStyle.setStyle("Dashed");
|
265
345
|
expect(borderStyle.style).toEqual(_util.AnnotationBorderStyleType.SOLID);
|
266
346
|
});
|
267
|
-
it(
|
268
|
-
|
347
|
+
it("should set and get a valid dash array", function () {
|
348
|
+
const borderStyle = new _annotation.AnnotationBorderStyle();
|
269
349
|
borderStyle.setDashArray([1, 2, 3]);
|
270
350
|
expect(borderStyle.dashArray).toEqual([1, 2, 3]);
|
271
351
|
});
|
272
|
-
it(
|
273
|
-
|
352
|
+
it("should not set and get an invalid dash array", function () {
|
353
|
+
const borderStyle = new _annotation.AnnotationBorderStyle();
|
274
354
|
borderStyle.setDashArray([0, 0]);
|
275
355
|
expect(borderStyle.dashArray).toEqual([3]);
|
276
356
|
});
|
277
|
-
it(
|
278
|
-
|
357
|
+
it("should set and get a valid horizontal corner radius", function () {
|
358
|
+
const borderStyle = new _annotation.AnnotationBorderStyle();
|
279
359
|
borderStyle.setHorizontalCornerRadius(3);
|
280
360
|
expect(borderStyle.horizontalCornerRadius).toEqual(3);
|
281
361
|
});
|
282
|
-
it(
|
283
|
-
|
284
|
-
borderStyle.setHorizontalCornerRadius(
|
362
|
+
it("should not set and get an invalid horizontal corner radius", function () {
|
363
|
+
const borderStyle = new _annotation.AnnotationBorderStyle();
|
364
|
+
borderStyle.setHorizontalCornerRadius("three");
|
285
365
|
expect(borderStyle.horizontalCornerRadius).toEqual(0);
|
286
366
|
});
|
287
|
-
it(
|
288
|
-
|
367
|
+
it("should set and get a valid vertical corner radius", function () {
|
368
|
+
const borderStyle = new _annotation.AnnotationBorderStyle();
|
289
369
|
borderStyle.setVerticalCornerRadius(3);
|
290
370
|
expect(borderStyle.verticalCornerRadius).toEqual(3);
|
291
371
|
});
|
292
|
-
it(
|
293
|
-
|
294
|
-
borderStyle.setVerticalCornerRadius(
|
372
|
+
it("should not set and get an invalid vertical corner radius", function () {
|
373
|
+
const borderStyle = new _annotation.AnnotationBorderStyle();
|
374
|
+
borderStyle.setVerticalCornerRadius("three");
|
295
375
|
expect(borderStyle.verticalCornerRadius).toEqual(0);
|
296
376
|
});
|
297
377
|
});
|
298
|
-
describe(
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
378
|
+
describe("MarkupAnnotation", function () {
|
379
|
+
let dict, ref;
|
380
|
+
beforeAll(function (done) {
|
381
|
+
dict = new _primitives.Dict();
|
382
|
+
ref = _primitives.Ref.get(1, 0);
|
383
|
+
done();
|
384
|
+
});
|
385
|
+
afterAll(function () {
|
386
|
+
dict = ref = null;
|
387
|
+
});
|
388
|
+
it("should set and get a valid creation date", function () {
|
389
|
+
const markupAnnotation = new _annotation.MarkupAnnotation({
|
390
|
+
dict,
|
391
|
+
ref
|
392
|
+
});
|
393
|
+
markupAnnotation.setCreationDate("D:20190422");
|
394
|
+
expect(markupAnnotation.creationDate).toEqual("D:20190422");
|
395
|
+
});
|
396
|
+
it("should not set and get an invalid creation date", function () {
|
397
|
+
const markupAnnotation = new _annotation.MarkupAnnotation({
|
398
|
+
dict,
|
399
|
+
ref
|
400
|
+
});
|
401
|
+
markupAnnotation.setCreationDate(undefined);
|
402
|
+
expect(markupAnnotation.creationDate).toEqual(null);
|
403
|
+
});
|
404
|
+
it("should not parse IRT/RT when not defined", function (done) {
|
405
|
+
dict.set("Type", _primitives.Name.get("Annot"));
|
406
|
+
dict.set("Subtype", _primitives.Name.get("Text"));
|
407
|
+
const xref = new _test_utils.XRefMock([{
|
408
|
+
ref,
|
409
|
+
data: dict
|
410
|
+
}]);
|
411
|
+
|
412
|
+
_annotation.AnnotationFactory.create(xref, ref, pdfManagerMock, idFactoryMock).then(({
|
413
|
+
data
|
414
|
+
}) => {
|
415
|
+
expect(data.inReplyTo).toBeUndefined();
|
416
|
+
expect(data.replyType).toBeUndefined();
|
417
|
+
done();
|
418
|
+
}, done.fail);
|
419
|
+
});
|
420
|
+
it("should parse IRT and set default RT when not defined.", function (done) {
|
421
|
+
const annotationRef = _primitives.Ref.get(819, 0);
|
422
|
+
|
423
|
+
const annotationDict = new _primitives.Dict();
|
424
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
425
|
+
annotationDict.set("Subtype", _primitives.Name.get("Text"));
|
426
|
+
|
427
|
+
const replyRef = _primitives.Ref.get(820, 0);
|
428
|
+
|
429
|
+
const replyDict = new _primitives.Dict();
|
430
|
+
replyDict.set("Type", _primitives.Name.get("Annot"));
|
431
|
+
replyDict.set("Subtype", _primitives.Name.get("Text"));
|
432
|
+
replyDict.set("IRT", annotationRef);
|
433
|
+
const xref = new _test_utils.XRefMock([{
|
434
|
+
ref: annotationRef,
|
435
|
+
data: annotationDict
|
436
|
+
}, {
|
437
|
+
ref: replyRef,
|
438
|
+
data: replyDict
|
439
|
+
}]);
|
440
|
+
annotationDict.assignXref(xref);
|
441
|
+
replyDict.assignXref(xref);
|
442
|
+
|
443
|
+
_annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({
|
444
|
+
data
|
445
|
+
}) => {
|
446
|
+
expect(data.inReplyTo).toEqual(annotationRef.toString());
|
447
|
+
expect(data.replyType).toEqual("R");
|
448
|
+
done();
|
449
|
+
}, done.fail);
|
450
|
+
});
|
451
|
+
it("should parse IRT/RT for a group type", function (done) {
|
452
|
+
const annotationRef = _primitives.Ref.get(819, 0);
|
453
|
+
|
454
|
+
const annotationDict = new _primitives.Dict();
|
455
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
456
|
+
annotationDict.set("Subtype", _primitives.Name.get("Text"));
|
457
|
+
annotationDict.set("T", "ParentTitle");
|
458
|
+
annotationDict.set("Contents", "ParentText");
|
459
|
+
annotationDict.set("CreationDate", "D:20180423");
|
460
|
+
annotationDict.set("M", "D:20190423");
|
461
|
+
annotationDict.set("C", [0, 0, 1]);
|
462
|
+
|
463
|
+
const popupRef = _primitives.Ref.get(820, 0);
|
464
|
+
|
465
|
+
const popupDict = new _primitives.Dict();
|
466
|
+
popupDict.set("Type", _primitives.Name.get("Annot"));
|
467
|
+
popupDict.set("Subtype", _primitives.Name.get("Popup"));
|
468
|
+
popupDict.set("Parent", annotationRef);
|
469
|
+
annotationDict.set("Popup", popupRef);
|
470
|
+
|
471
|
+
const replyRef = _primitives.Ref.get(821, 0);
|
472
|
+
|
473
|
+
const replyDict = new _primitives.Dict();
|
474
|
+
replyDict.set("Type", _primitives.Name.get("Annot"));
|
475
|
+
replyDict.set("Subtype", _primitives.Name.get("Text"));
|
476
|
+
replyDict.set("IRT", annotationRef);
|
477
|
+
replyDict.set("RT", _primitives.Name.get("Group"));
|
478
|
+
replyDict.set("T", "ReplyTitle");
|
479
|
+
replyDict.set("Contents", "ReplyText");
|
480
|
+
replyDict.set("CreationDate", "D:20180523");
|
481
|
+
replyDict.set("M", "D:20190523");
|
482
|
+
replyDict.set("C", [0.4]);
|
483
|
+
const xref = new _test_utils.XRefMock([{
|
310
484
|
ref: annotationRef,
|
311
485
|
data: annotationDict
|
486
|
+
}, {
|
487
|
+
ref: popupRef,
|
488
|
+
data: popupDict
|
489
|
+
}, {
|
490
|
+
ref: replyRef,
|
491
|
+
data: replyDict
|
312
492
|
}]);
|
313
|
-
|
314
|
-
|
493
|
+
annotationDict.assignXref(xref);
|
494
|
+
popupDict.assignXref(xref);
|
495
|
+
replyDict.assignXref(xref);
|
496
|
+
|
497
|
+
_annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({
|
498
|
+
data
|
499
|
+
}) => {
|
500
|
+
expect(data.inReplyTo).toEqual(annotationRef.toString());
|
501
|
+
expect(data.replyType).toEqual("Group");
|
502
|
+
expect(data.title).toEqual("ParentTitle");
|
503
|
+
expect(data.contents).toEqual("ParentText");
|
504
|
+
expect(data.creationDate).toEqual("D:20180423");
|
505
|
+
expect(data.modificationDate).toEqual("D:20190423");
|
506
|
+
expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
|
507
|
+
expect(data.hasPopup).toEqual(true);
|
508
|
+
done();
|
509
|
+
}, done.fail);
|
510
|
+
});
|
511
|
+
it("should parse IRT/RT for a reply type", function (done) {
|
512
|
+
const annotationRef = _primitives.Ref.get(819, 0);
|
513
|
+
|
514
|
+
const annotationDict = new _primitives.Dict();
|
515
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
516
|
+
annotationDict.set("Subtype", _primitives.Name.get("Text"));
|
517
|
+
annotationDict.set("T", "ParentTitle");
|
518
|
+
annotationDict.set("Contents", "ParentText");
|
519
|
+
annotationDict.set("CreationDate", "D:20180423");
|
520
|
+
annotationDict.set("M", "D:20190423");
|
521
|
+
annotationDict.set("C", [0, 0, 1]);
|
522
|
+
|
523
|
+
const popupRef = _primitives.Ref.get(820, 0);
|
524
|
+
|
525
|
+
const popupDict = new _primitives.Dict();
|
526
|
+
popupDict.set("Type", _primitives.Name.get("Annot"));
|
527
|
+
popupDict.set("Subtype", _primitives.Name.get("Popup"));
|
528
|
+
popupDict.set("Parent", annotationRef);
|
529
|
+
annotationDict.set("Popup", popupRef);
|
530
|
+
|
531
|
+
const replyRef = _primitives.Ref.get(821, 0);
|
532
|
+
|
533
|
+
const replyDict = new _primitives.Dict();
|
534
|
+
replyDict.set("Type", _primitives.Name.get("Annot"));
|
535
|
+
replyDict.set("Subtype", _primitives.Name.get("Text"));
|
536
|
+
replyDict.set("IRT", annotationRef);
|
537
|
+
replyDict.set("RT", _primitives.Name.get("R"));
|
538
|
+
replyDict.set("T", "ReplyTitle");
|
539
|
+
replyDict.set("Contents", "ReplyText");
|
540
|
+
replyDict.set("CreationDate", "D:20180523");
|
541
|
+
replyDict.set("M", "D:20190523");
|
542
|
+
replyDict.set("C", [0.4]);
|
543
|
+
const xref = new _test_utils.XRefMock([{
|
544
|
+
ref: annotationRef,
|
545
|
+
data: annotationDict
|
546
|
+
}, {
|
547
|
+
ref: popupRef,
|
548
|
+
data: popupDict
|
549
|
+
}, {
|
550
|
+
ref: replyRef,
|
551
|
+
data: replyDict
|
552
|
+
}]);
|
553
|
+
annotationDict.assignXref(xref);
|
554
|
+
popupDict.assignXref(xref);
|
555
|
+
replyDict.assignXref(xref);
|
556
|
+
|
557
|
+
_annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({
|
558
|
+
data
|
559
|
+
}) => {
|
560
|
+
expect(data.inReplyTo).toEqual(annotationRef.toString());
|
561
|
+
expect(data.replyType).toEqual("R");
|
562
|
+
expect(data.title).toEqual("ReplyTitle");
|
563
|
+
expect(data.contents).toEqual("ReplyText");
|
564
|
+
expect(data.creationDate).toEqual("D:20180523");
|
565
|
+
expect(data.modificationDate).toEqual("D:20190523");
|
566
|
+
expect(data.color).toEqual(new Uint8ClampedArray([102, 102, 102]));
|
567
|
+
expect(data.hasPopup).toEqual(false);
|
568
|
+
done();
|
569
|
+
}, done.fail);
|
570
|
+
});
|
571
|
+
});
|
572
|
+
describe("TextAnnotation", function () {
|
573
|
+
it("should not parse state model and state when not defined", function (done) {
|
574
|
+
const annotationRef = _primitives.Ref.get(819, 0);
|
575
|
+
|
576
|
+
const annotationDict = new _primitives.Dict();
|
577
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
578
|
+
annotationDict.set("Subtype", _primitives.Name.get("Text"));
|
579
|
+
annotationDict.set("Contents", "TestText");
|
580
|
+
|
581
|
+
const replyRef = _primitives.Ref.get(820, 0);
|
582
|
+
|
583
|
+
const replyDict = new _primitives.Dict();
|
584
|
+
replyDict.set("Type", _primitives.Name.get("Annot"));
|
585
|
+
replyDict.set("Subtype", _primitives.Name.get("Text"));
|
586
|
+
replyDict.set("IRT", annotationRef);
|
587
|
+
replyDict.set("RT", _primitives.Name.get("R"));
|
588
|
+
replyDict.set("Contents", "ReplyText");
|
589
|
+
const xref = new _test_utils.XRefMock([{
|
590
|
+
ref: annotationRef,
|
591
|
+
data: annotationDict
|
592
|
+
}, {
|
593
|
+
ref: replyRef,
|
594
|
+
data: replyDict
|
595
|
+
}]);
|
596
|
+
annotationDict.assignXref(xref);
|
597
|
+
replyDict.assignXref(xref);
|
598
|
+
|
599
|
+
_annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({
|
600
|
+
data
|
601
|
+
}) => {
|
602
|
+
expect(data.stateModel).toBeNull();
|
603
|
+
expect(data.state).toBeNull();
|
604
|
+
done();
|
605
|
+
}, done.fail);
|
606
|
+
});
|
607
|
+
it("should correctly parse state model and state when defined", function (done) {
|
608
|
+
const annotationRef = _primitives.Ref.get(819, 0);
|
609
|
+
|
610
|
+
const annotationDict = new _primitives.Dict();
|
611
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
612
|
+
annotationDict.set("Subtype", _primitives.Name.get("Text"));
|
315
613
|
|
614
|
+
const replyRef = _primitives.Ref.get(820, 0);
|
615
|
+
|
616
|
+
const replyDict = new _primitives.Dict();
|
617
|
+
replyDict.set("Type", _primitives.Name.get("Annot"));
|
618
|
+
replyDict.set("Subtype", _primitives.Name.get("Text"));
|
619
|
+
replyDict.set("IRT", annotationRef);
|
620
|
+
replyDict.set("RT", _primitives.Name.get("R"));
|
621
|
+
replyDict.set("StateModel", "Review");
|
622
|
+
replyDict.set("State", "Rejected");
|
623
|
+
const xref = new _test_utils.XRefMock([{
|
624
|
+
ref: annotationRef,
|
625
|
+
data: annotationDict
|
626
|
+
}, {
|
627
|
+
ref: replyRef,
|
628
|
+
data: replyDict
|
629
|
+
}]);
|
630
|
+
annotationDict.assignXref(xref);
|
631
|
+
replyDict.assignXref(xref);
|
632
|
+
|
633
|
+
_annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({
|
634
|
+
data
|
635
|
+
}) => {
|
636
|
+
expect(data.stateModel).toEqual("Review");
|
637
|
+
expect(data.state).toEqual("Rejected");
|
638
|
+
done();
|
639
|
+
}, done.fail);
|
640
|
+
});
|
641
|
+
});
|
642
|
+
describe("LinkAnnotation", function () {
|
643
|
+
it("should correctly parse a URI action", function (done) {
|
644
|
+
const actionDict = new _primitives.Dict();
|
645
|
+
actionDict.set("Type", _primitives.Name.get("Action"));
|
646
|
+
actionDict.set("S", _primitives.Name.get("URI"));
|
647
|
+
actionDict.set("URI", "http://www.ctan.org/tex-archive/info/lshort");
|
648
|
+
const annotationDict = new _primitives.Dict();
|
649
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
650
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
651
|
+
annotationDict.set("A", actionDict);
|
652
|
+
|
653
|
+
const annotationRef = _primitives.Ref.get(820, 0);
|
654
|
+
|
655
|
+
const xref = new _test_utils.XRefMock([{
|
656
|
+
ref: annotationRef,
|
657
|
+
data: annotationDict
|
658
|
+
}]);
|
659
|
+
|
660
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
661
|
+
data
|
662
|
+
}) => {
|
316
663
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
317
|
-
expect(data.url).toEqual(
|
318
|
-
expect(data.unsafeUrl).toEqual(
|
664
|
+
expect(data.url).toEqual("http://www.ctan.org/tex-archive/info/lshort");
|
665
|
+
expect(data.unsafeUrl).toEqual("http://www.ctan.org/tex-archive/info/lshort");
|
319
666
|
expect(data.dest).toBeUndefined();
|
320
667
|
done();
|
321
668
|
}, done.fail);
|
322
669
|
});
|
323
|
-
it(
|
324
|
-
|
325
|
-
actionDict.set(
|
326
|
-
actionDict.set(
|
327
|
-
actionDict.set(
|
328
|
-
|
329
|
-
annotationDict.set(
|
330
|
-
annotationDict.set(
|
331
|
-
annotationDict.set(
|
332
|
-
|
333
|
-
|
670
|
+
it("should correctly parse a URI action, where the URI entry " + "is missing a protocol", function (done) {
|
671
|
+
const actionDict = new _primitives.Dict();
|
672
|
+
actionDict.set("Type", _primitives.Name.get("Action"));
|
673
|
+
actionDict.set("S", _primitives.Name.get("URI"));
|
674
|
+
actionDict.set("URI", "www.hmrc.gov.uk");
|
675
|
+
const annotationDict = new _primitives.Dict();
|
676
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
677
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
678
|
+
annotationDict.set("A", actionDict);
|
679
|
+
|
680
|
+
const annotationRef = _primitives.Ref.get(353, 0);
|
681
|
+
|
682
|
+
const xref = new _test_utils.XRefMock([{
|
334
683
|
ref: annotationRef,
|
335
684
|
data: annotationDict
|
336
685
|
}]);
|
337
|
-
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref6) {
|
338
|
-
var data = _ref6.data;
|
339
686
|
|
687
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
688
|
+
data
|
689
|
+
}) => {
|
340
690
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
341
|
-
expect(data.url).toEqual(
|
342
|
-
expect(data.unsafeUrl).toEqual(
|
691
|
+
expect(data.url).toEqual("http://www.hmrc.gov.uk/");
|
692
|
+
expect(data.unsafeUrl).toEqual("http://www.hmrc.gov.uk");
|
343
693
|
expect(data.dest).toBeUndefined();
|
344
694
|
done();
|
345
695
|
}, done.fail);
|
346
696
|
});
|
347
|
-
it(
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
annotationDict
|
355
|
-
annotationDict.set(
|
356
|
-
|
357
|
-
|
697
|
+
it("should correctly parse a URI action, where the URI entry " + "has an incorrect encoding (bug 1122280)", function (done) {
|
698
|
+
const actionStream = new _stream.StringStream("<<\n" + "/Type /Action\n" + "/S /URI\n" + "/URI (http://www.example.com/\\303\\274\\303\\266\\303\\244)\n" + ">>\n");
|
699
|
+
const parser = new _parser.Parser({
|
700
|
+
lexer: new _parser.Lexer(actionStream),
|
701
|
+
xref: null
|
702
|
+
});
|
703
|
+
const actionDict = parser.getObj();
|
704
|
+
const annotationDict = new _primitives.Dict();
|
705
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
706
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
707
|
+
annotationDict.set("A", actionDict);
|
708
|
+
|
709
|
+
const annotationRef = _primitives.Ref.get(8, 0);
|
710
|
+
|
711
|
+
const xref = new _test_utils.XRefMock([{
|
358
712
|
ref: annotationRef,
|
359
713
|
data: annotationDict
|
360
714
|
}]);
|
361
|
-
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref7) {
|
362
|
-
var data = _ref7.data;
|
363
715
|
|
716
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
717
|
+
data
|
718
|
+
}) => {
|
364
719
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
365
|
-
expect(data.url).toEqual(new URL((0, _util.stringToUTF8String)(
|
366
|
-
expect(data.unsafeUrl).toEqual((0, _util.stringToUTF8String)(
|
720
|
+
expect(data.url).toEqual(new URL((0, _util.stringToUTF8String)("http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4")).href);
|
721
|
+
expect(data.unsafeUrl).toEqual((0, _util.stringToUTF8String)("http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4"));
|
367
722
|
expect(data.dest).toBeUndefined();
|
368
723
|
done();
|
369
724
|
}, done.fail);
|
370
725
|
});
|
371
|
-
it(
|
372
|
-
|
373
|
-
actionDict.set(
|
374
|
-
actionDict.set(
|
375
|
-
actionDict.set(
|
376
|
-
|
377
|
-
annotationDict.set(
|
378
|
-
annotationDict.set(
|
379
|
-
annotationDict.set(
|
380
|
-
|
381
|
-
|
726
|
+
it("should correctly parse a GoTo action", function (done) {
|
727
|
+
const actionDict = new _primitives.Dict();
|
728
|
+
actionDict.set("Type", _primitives.Name.get("Action"));
|
729
|
+
actionDict.set("S", _primitives.Name.get("GoTo"));
|
730
|
+
actionDict.set("D", "page.157");
|
731
|
+
const annotationDict = new _primitives.Dict();
|
732
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
733
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
734
|
+
annotationDict.set("A", actionDict);
|
735
|
+
|
736
|
+
const annotationRef = _primitives.Ref.get(798, 0);
|
737
|
+
|
738
|
+
const xref = new _test_utils.XRefMock([{
|
382
739
|
ref: annotationRef,
|
383
740
|
data: annotationDict
|
384
741
|
}]);
|
385
|
-
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref8) {
|
386
|
-
var data = _ref8.data;
|
387
742
|
|
743
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
744
|
+
data
|
745
|
+
}) => {
|
388
746
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
389
747
|
expect(data.url).toBeUndefined();
|
390
748
|
expect(data.unsafeUrl).toBeUndefined();
|
391
|
-
expect(data.dest).toEqual(
|
749
|
+
expect(data.dest).toEqual("page.157");
|
392
750
|
done();
|
393
751
|
}, done.fail);
|
394
752
|
});
|
395
|
-
it(
|
396
|
-
|
397
|
-
actionDict.set(
|
398
|
-
actionDict.set(
|
399
|
-
actionDict.set(
|
400
|
-
actionDict.set(
|
401
|
-
actionDict.set(
|
402
|
-
|
403
|
-
annotationDict.set(
|
404
|
-
annotationDict.set(
|
405
|
-
annotationDict.set(
|
406
|
-
|
407
|
-
|
753
|
+
it("should correctly parse a GoToR action, where the FileSpec entry " + "is a string containing a relative URL", function (done) {
|
754
|
+
const actionDict = new _primitives.Dict();
|
755
|
+
actionDict.set("Type", _primitives.Name.get("Action"));
|
756
|
+
actionDict.set("S", _primitives.Name.get("GoToR"));
|
757
|
+
actionDict.set("F", "../../0013/001346/134685E.pdf");
|
758
|
+
actionDict.set("D", "4.3");
|
759
|
+
actionDict.set("NewWindow", true);
|
760
|
+
const annotationDict = new _primitives.Dict();
|
761
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
762
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
763
|
+
annotationDict.set("A", actionDict);
|
764
|
+
|
765
|
+
const annotationRef = _primitives.Ref.get(489, 0);
|
766
|
+
|
767
|
+
const xref = new _test_utils.XRefMock([{
|
408
768
|
ref: annotationRef,
|
409
769
|
data: annotationDict
|
410
770
|
}]);
|
411
|
-
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref9) {
|
412
|
-
var data = _ref9.data;
|
413
771
|
|
772
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
773
|
+
data
|
774
|
+
}) => {
|
414
775
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
415
776
|
expect(data.url).toBeUndefined();
|
416
|
-
expect(data.unsafeUrl).toEqual(
|
777
|
+
expect(data.unsafeUrl).toEqual("../../0013/001346/134685E.pdf#4.3");
|
417
778
|
expect(data.dest).toBeUndefined();
|
418
779
|
expect(data.newWindow).toEqual(true);
|
419
780
|
done();
|
420
781
|
}, done.fail);
|
421
782
|
});
|
422
|
-
it(
|
423
|
-
|
424
|
-
actionDict.set(
|
425
|
-
actionDict.set(
|
426
|
-
actionDict.set(
|
427
|
-
actionDict.set(
|
428
|
-
|
429
|
-
annotationDict.set(
|
430
|
-
annotationDict.set(
|
431
|
-
annotationDict.set(
|
432
|
-
|
433
|
-
|
783
|
+
it("should correctly parse a GoToR action, containing a relative URL, " + 'with the "docBaseUrl" parameter specified', function (done) {
|
784
|
+
const actionDict = new _primitives.Dict();
|
785
|
+
actionDict.set("Type", _primitives.Name.get("Action"));
|
786
|
+
actionDict.set("S", _primitives.Name.get("GoToR"));
|
787
|
+
actionDict.set("F", "../../0013/001346/134685E.pdf");
|
788
|
+
actionDict.set("D", "4.3");
|
789
|
+
const annotationDict = new _primitives.Dict();
|
790
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
791
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
792
|
+
annotationDict.set("A", actionDict);
|
793
|
+
|
794
|
+
const annotationRef = _primitives.Ref.get(489, 0);
|
795
|
+
|
796
|
+
const xref = new _test_utils.XRefMock([{
|
434
797
|
ref: annotationRef,
|
435
798
|
data: annotationDict
|
436
799
|
}]);
|
437
|
-
|
438
|
-
|
439
|
-
|
800
|
+
const pdfManager = new PDFManagerMock({
|
801
|
+
docBaseUrl: "http://www.example.com/test/pdfs/qwerty.pdf"
|
802
|
+
});
|
440
803
|
|
804
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManager, idFactoryMock).then(({
|
805
|
+
data
|
806
|
+
}) => {
|
441
807
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
442
|
-
expect(data.url).toEqual(
|
443
|
-
expect(data.unsafeUrl).toEqual(
|
808
|
+
expect(data.url).toEqual("http://www.example.com/0013/001346/134685E.pdf#4.3");
|
809
|
+
expect(data.unsafeUrl).toEqual("../../0013/001346/134685E.pdf#4.3");
|
444
810
|
expect(data.dest).toBeUndefined();
|
445
811
|
done();
|
446
812
|
}, done.fail);
|
447
813
|
});
|
448
|
-
it(
|
449
|
-
|
450
|
-
actionDict.set(
|
451
|
-
actionDict.set(
|
452
|
-
actionDict.set(
|
453
|
-
actionDict.set(
|
454
|
-
|
455
|
-
annotationDict.set(
|
456
|
-
annotationDict.set(
|
457
|
-
annotationDict.set(
|
458
|
-
|
459
|
-
|
814
|
+
it("should correctly parse a GoToR action, with named destination", function (done) {
|
815
|
+
const actionDict = new _primitives.Dict();
|
816
|
+
actionDict.set("Type", _primitives.Name.get("Action"));
|
817
|
+
actionDict.set("S", _primitives.Name.get("GoToR"));
|
818
|
+
actionDict.set("F", "http://www.example.com/test.pdf");
|
819
|
+
actionDict.set("D", "15");
|
820
|
+
const annotationDict = new _primitives.Dict();
|
821
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
822
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
823
|
+
annotationDict.set("A", actionDict);
|
824
|
+
|
825
|
+
const annotationRef = _primitives.Ref.get(495, 0);
|
826
|
+
|
827
|
+
const xref = new _test_utils.XRefMock([{
|
460
828
|
ref: annotationRef,
|
461
829
|
data: annotationDict
|
462
830
|
}]);
|
463
|
-
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref11) {
|
464
|
-
var data = _ref11.data;
|
465
831
|
|
832
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
833
|
+
data
|
834
|
+
}) => {
|
466
835
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
467
|
-
expect(data.url).toEqual(
|
468
|
-
expect(data.unsafeUrl).toEqual(
|
836
|
+
expect(data.url).toEqual("http://www.example.com/test.pdf#15");
|
837
|
+
expect(data.unsafeUrl).toEqual("http://www.example.com/test.pdf#15");
|
469
838
|
expect(data.dest).toBeUndefined();
|
470
839
|
expect(data.newWindow).toBeFalsy();
|
471
840
|
done();
|
472
841
|
}, done.fail);
|
473
842
|
});
|
474
|
-
it(
|
475
|
-
|
476
|
-
actionDict.set(
|
477
|
-
actionDict.set(
|
478
|
-
actionDict.set(
|
479
|
-
actionDict.set(
|
480
|
-
|
481
|
-
annotationDict.set(
|
482
|
-
annotationDict.set(
|
483
|
-
annotationDict.set(
|
484
|
-
|
485
|
-
|
843
|
+
it("should correctly parse a GoToR action, with explicit destination array", function (done) {
|
844
|
+
const actionDict = new _primitives.Dict();
|
845
|
+
actionDict.set("Type", _primitives.Name.get("Action"));
|
846
|
+
actionDict.set("S", _primitives.Name.get("GoToR"));
|
847
|
+
actionDict.set("F", "http://www.example.com/test.pdf");
|
848
|
+
actionDict.set("D", [14, _primitives.Name.get("XYZ"), null, 298.043, null]);
|
849
|
+
const annotationDict = new _primitives.Dict();
|
850
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
851
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
852
|
+
annotationDict.set("A", actionDict);
|
853
|
+
|
854
|
+
const annotationRef = _primitives.Ref.get(489, 0);
|
855
|
+
|
856
|
+
const xref = new _test_utils.XRefMock([{
|
486
857
|
ref: annotationRef,
|
487
858
|
data: annotationDict
|
488
859
|
}]);
|
489
|
-
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref12) {
|
490
|
-
var data = _ref12.data;
|
491
860
|
|
861
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
862
|
+
data
|
863
|
+
}) => {
|
492
864
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
493
|
-
expect(data.url).toEqual(new URL(
|
494
|
-
expect(data.unsafeUrl).toEqual(
|
865
|
+
expect(data.url).toEqual(new URL("http://www.example.com/test.pdf#" + '[14,{"name":"XYZ"},null,298.043,null]').href);
|
866
|
+
expect(data.unsafeUrl).toEqual("http://www.example.com/test.pdf#" + '[14,{"name":"XYZ"},null,298.043,null]');
|
495
867
|
expect(data.dest).toBeUndefined();
|
496
868
|
expect(data.newWindow).toBeFalsy();
|
497
869
|
done();
|
498
870
|
}, done.fail);
|
499
871
|
});
|
500
|
-
it(
|
501
|
-
|
502
|
-
fileSpecDict.set(
|
503
|
-
fileSpecDict.set(
|
504
|
-
fileSpecDict.set(
|
505
|
-
|
506
|
-
actionDict.set(
|
507
|
-
actionDict.set(
|
508
|
-
actionDict.set(
|
509
|
-
actionDict.set(
|
510
|
-
|
511
|
-
annotationDict.set(
|
512
|
-
annotationDict.set(
|
513
|
-
annotationDict.set(
|
514
|
-
|
515
|
-
|
872
|
+
it("should correctly parse a Launch action, where the FileSpec dict " + 'contains a relative URL, with the "docBaseUrl" parameter specified', function (done) {
|
873
|
+
const fileSpecDict = new _primitives.Dict();
|
874
|
+
fileSpecDict.set("Type", _primitives.Name.get("FileSpec"));
|
875
|
+
fileSpecDict.set("F", "Part II/Part II.pdf");
|
876
|
+
fileSpecDict.set("UF", "Part II/Part II.pdf");
|
877
|
+
const actionDict = new _primitives.Dict();
|
878
|
+
actionDict.set("Type", _primitives.Name.get("Action"));
|
879
|
+
actionDict.set("S", _primitives.Name.get("Launch"));
|
880
|
+
actionDict.set("F", fileSpecDict);
|
881
|
+
actionDict.set("NewWindow", true);
|
882
|
+
const annotationDict = new _primitives.Dict();
|
883
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
884
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
885
|
+
annotationDict.set("A", actionDict);
|
886
|
+
|
887
|
+
const annotationRef = _primitives.Ref.get(88, 0);
|
888
|
+
|
889
|
+
const xref = new _test_utils.XRefMock([{
|
516
890
|
ref: annotationRef,
|
517
891
|
data: annotationDict
|
518
892
|
}]);
|
519
|
-
|
520
|
-
|
521
|
-
|
893
|
+
const pdfManager = new PDFManagerMock({
|
894
|
+
docBaseUrl: "http://www.example.com/test/pdfs/qwerty.pdf"
|
895
|
+
});
|
522
896
|
|
897
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManager, idFactoryMock).then(({
|
898
|
+
data
|
899
|
+
}) => {
|
523
900
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
524
|
-
expect(data.url).toEqual(new URL(
|
525
|
-
expect(data.unsafeUrl).toEqual(
|
901
|
+
expect(data.url).toEqual(new URL("http://www.example.com/test/pdfs/Part II/Part II.pdf").href);
|
902
|
+
expect(data.unsafeUrl).toEqual("Part II/Part II.pdf");
|
526
903
|
expect(data.dest).toBeUndefined();
|
527
904
|
expect(data.newWindow).toEqual(true);
|
528
905
|
done();
|
529
906
|
}, done.fail);
|
530
907
|
});
|
531
|
-
it(
|
908
|
+
it("should recover valid URLs from JavaScript actions having certain " + "white-listed formats", function (done) {
|
532
909
|
function checkJsAction(params) {
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
actionDict.set(
|
539
|
-
actionDict.set(
|
540
|
-
actionDict.set(
|
541
|
-
|
542
|
-
annotationDict.set(
|
543
|
-
annotationDict.set(
|
544
|
-
annotationDict.set(
|
545
|
-
|
546
|
-
|
910
|
+
const jsEntry = params.jsEntry;
|
911
|
+
const expectedUrl = params.expectedUrl;
|
912
|
+
const expectedUnsafeUrl = params.expectedUnsafeUrl;
|
913
|
+
const expectedNewWindow = params.expectedNewWindow;
|
914
|
+
const actionDict = new _primitives.Dict();
|
915
|
+
actionDict.set("Type", _primitives.Name.get("Action"));
|
916
|
+
actionDict.set("S", _primitives.Name.get("JavaScript"));
|
917
|
+
actionDict.set("JS", jsEntry);
|
918
|
+
const annotationDict = new _primitives.Dict();
|
919
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
920
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
921
|
+
annotationDict.set("A", actionDict);
|
922
|
+
|
923
|
+
const annotationRef = _primitives.Ref.get(46, 0);
|
924
|
+
|
925
|
+
const xref = new _test_utils.XRefMock([{
|
547
926
|
ref: annotationRef,
|
548
927
|
data: annotationDict
|
549
928
|
}]);
|
550
|
-
return _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(
|
551
|
-
|
552
|
-
|
929
|
+
return _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
930
|
+
data
|
931
|
+
}) => {
|
553
932
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
554
933
|
expect(data.url).toEqual(expectedUrl);
|
555
934
|
expect(data.unsafeUrl).toEqual(expectedUnsafeUrl);
|
@@ -557,220 +936,302 @@ describe('annotation', function () {
|
|
557
936
|
expect(data.newWindow).toEqual(expectedNewWindow);
|
558
937
|
});
|
559
938
|
}
|
560
|
-
|
939
|
+
|
940
|
+
const annotation1 = checkJsAction({
|
561
941
|
jsEntry: 'function someFun() { return "qwerty"; } someFun();',
|
562
942
|
expectedUrl: undefined,
|
563
943
|
expectedUnsafeUrl: undefined,
|
564
944
|
expectedNewWindow: undefined
|
565
945
|
});
|
566
|
-
|
567
|
-
jsEntry:
|
568
|
-
expectedUrl: new URL(
|
569
|
-
expectedUnsafeUrl:
|
946
|
+
const annotation2 = checkJsAction({
|
947
|
+
jsEntry: "window.open('http://www.example.com/test.pdf')",
|
948
|
+
expectedUrl: new URL("http://www.example.com/test.pdf").href,
|
949
|
+
expectedUnsafeUrl: "http://www.example.com/test.pdf",
|
570
950
|
expectedNewWindow: undefined
|
571
951
|
});
|
572
|
-
|
952
|
+
const annotation3 = checkJsAction({
|
573
953
|
jsEntry: new _stream.StringStream('app.launchURL("http://www.example.com/test.pdf", true)'),
|
574
|
-
expectedUrl: new URL(
|
575
|
-
expectedUnsafeUrl:
|
954
|
+
expectedUrl: new URL("http://www.example.com/test.pdf").href,
|
955
|
+
expectedUnsafeUrl: "http://www.example.com/test.pdf",
|
576
956
|
expectedNewWindow: true
|
577
957
|
});
|
578
958
|
Promise.all([annotation1, annotation2, annotation3]).then(done, done.fail);
|
579
959
|
});
|
580
|
-
it(
|
581
|
-
|
582
|
-
actionDict.set(
|
583
|
-
actionDict.set(
|
584
|
-
actionDict.set(
|
585
|
-
|
586
|
-
annotationDict.set(
|
587
|
-
annotationDict.set(
|
588
|
-
annotationDict.set(
|
589
|
-
|
590
|
-
|
960
|
+
it("should correctly parse a Named action", function (done) {
|
961
|
+
const actionDict = new _primitives.Dict();
|
962
|
+
actionDict.set("Type", _primitives.Name.get("Action"));
|
963
|
+
actionDict.set("S", _primitives.Name.get("Named"));
|
964
|
+
actionDict.set("N", _primitives.Name.get("GoToPage"));
|
965
|
+
const annotationDict = new _primitives.Dict();
|
966
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
967
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
968
|
+
annotationDict.set("A", actionDict);
|
969
|
+
|
970
|
+
const annotationRef = _primitives.Ref.get(12, 0);
|
971
|
+
|
972
|
+
const xref = new _test_utils.XRefMock([{
|
591
973
|
ref: annotationRef,
|
592
974
|
data: annotationDict
|
593
975
|
}]);
|
594
|
-
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref15) {
|
595
|
-
var data = _ref15.data;
|
596
976
|
|
977
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
978
|
+
data
|
979
|
+
}) => {
|
597
980
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
598
981
|
expect(data.url).toBeUndefined();
|
599
982
|
expect(data.unsafeUrl).toBeUndefined();
|
600
|
-
expect(data.action).toEqual(
|
983
|
+
expect(data.action).toEqual("GoToPage");
|
601
984
|
done();
|
602
985
|
}, done.fail);
|
603
986
|
});
|
604
|
-
it(
|
605
|
-
|
606
|
-
annotationDict.set(
|
607
|
-
annotationDict.set(
|
608
|
-
annotationDict.set(
|
609
|
-
|
610
|
-
|
987
|
+
it("should correctly parse a simple Dest", function (done) {
|
988
|
+
const annotationDict = new _primitives.Dict();
|
989
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
990
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
991
|
+
annotationDict.set("Dest", _primitives.Name.get("LI0"));
|
992
|
+
|
993
|
+
const annotationRef = _primitives.Ref.get(583, 0);
|
994
|
+
|
995
|
+
const xref = new _test_utils.XRefMock([{
|
611
996
|
ref: annotationRef,
|
612
997
|
data: annotationDict
|
613
998
|
}]);
|
614
|
-
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref16) {
|
615
|
-
var data = _ref16.data;
|
616
999
|
|
1000
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
1001
|
+
data
|
1002
|
+
}) => {
|
617
1003
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
618
1004
|
expect(data.url).toBeUndefined();
|
619
1005
|
expect(data.unsafeUrl).toBeUndefined();
|
620
|
-
expect(data.dest).toEqual(
|
1006
|
+
expect(data.dest).toEqual("LI0");
|
621
1007
|
done();
|
622
1008
|
}, done.fail);
|
623
1009
|
});
|
624
|
-
it(
|
625
|
-
|
626
|
-
annotationDict.set(
|
627
|
-
annotationDict.set(
|
628
|
-
annotationDict.set(
|
629
|
-
|
630
|
-
|
1010
|
+
it("should correctly parse a simple Dest, with explicit destination array", function (done) {
|
1011
|
+
const annotationDict = new _primitives.Dict();
|
1012
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
1013
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
1014
|
+
annotationDict.set("Dest", [_primitives.Ref.get(17, 0), _primitives.Name.get("XYZ"), 0, 841.89, null]);
|
1015
|
+
|
1016
|
+
const annotationRef = _primitives.Ref.get(10, 0);
|
1017
|
+
|
1018
|
+
const xref = new _test_utils.XRefMock([{
|
631
1019
|
ref: annotationRef,
|
632
1020
|
data: annotationDict
|
633
1021
|
}]);
|
634
|
-
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref17) {
|
635
|
-
var data = _ref17.data;
|
636
1022
|
|
1023
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
1024
|
+
data
|
1025
|
+
}) => {
|
637
1026
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
638
1027
|
expect(data.url).toBeUndefined();
|
639
1028
|
expect(data.unsafeUrl).toBeUndefined();
|
640
1029
|
expect(data.dest).toEqual([{
|
641
1030
|
num: 17,
|
642
1031
|
gen: 0
|
643
|
-
}, {
|
1032
|
+
}, {
|
1033
|
+
name: "XYZ"
|
1034
|
+
}, 0, 841.89, null]);
|
644
1035
|
done();
|
645
1036
|
}, done.fail);
|
646
1037
|
});
|
647
|
-
it(
|
648
|
-
|
649
|
-
destDict.set(
|
650
|
-
destDict.set(
|
651
|
-
destDict.set(
|
652
|
-
|
653
|
-
annotationDict.set(
|
654
|
-
annotationDict.set(
|
655
|
-
annotationDict.set(
|
656
|
-
|
657
|
-
|
1038
|
+
it("should correctly parse a Dest, which violates the specification " + "by containing a dictionary", function (done) {
|
1039
|
+
const destDict = new _primitives.Dict();
|
1040
|
+
destDict.set("Type", _primitives.Name.get("Action"));
|
1041
|
+
destDict.set("S", _primitives.Name.get("GoTo"));
|
1042
|
+
destDict.set("D", "page.157");
|
1043
|
+
const annotationDict = new _primitives.Dict();
|
1044
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
1045
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
1046
|
+
annotationDict.set("Dest", destDict);
|
1047
|
+
|
1048
|
+
const annotationRef = _primitives.Ref.get(798, 0);
|
1049
|
+
|
1050
|
+
const xref = new _test_utils.XRefMock([{
|
658
1051
|
ref: annotationRef,
|
659
1052
|
data: annotationDict
|
660
1053
|
}]);
|
661
|
-
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(function (_ref18) {
|
662
|
-
var data = _ref18.data;
|
663
1054
|
|
1055
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
1056
|
+
data
|
1057
|
+
}) => {
|
664
1058
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
665
1059
|
expect(data.url).toBeUndefined();
|
666
1060
|
expect(data.unsafeUrl).toBeUndefined();
|
667
|
-
expect(data.dest).toEqual(
|
1061
|
+
expect(data.dest).toEqual("page.157");
|
1062
|
+
done();
|
1063
|
+
}, done.fail);
|
1064
|
+
});
|
1065
|
+
it("should not set quadpoints if not defined", function (done) {
|
1066
|
+
const annotationDict = new _primitives.Dict();
|
1067
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
1068
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
1069
|
+
|
1070
|
+
const annotationRef = _primitives.Ref.get(121, 0);
|
1071
|
+
|
1072
|
+
const xref = new _test_utils.XRefMock([{
|
1073
|
+
ref: annotationRef,
|
1074
|
+
data: annotationDict
|
1075
|
+
}]);
|
1076
|
+
|
1077
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
1078
|
+
data
|
1079
|
+
}) => {
|
1080
|
+
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
1081
|
+
expect(data.quadPoints).toBeUndefined();
|
1082
|
+
done();
|
1083
|
+
}, done.fail);
|
1084
|
+
});
|
1085
|
+
it("should set quadpoints if defined", function (done) {
|
1086
|
+
const annotationDict = new _primitives.Dict();
|
1087
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
1088
|
+
annotationDict.set("Subtype", _primitives.Name.get("Link"));
|
1089
|
+
annotationDict.set("Rect", [10, 10, 20, 20]);
|
1090
|
+
annotationDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
|
1091
|
+
|
1092
|
+
const annotationRef = _primitives.Ref.get(121, 0);
|
1093
|
+
|
1094
|
+
const xref = new _test_utils.XRefMock([{
|
1095
|
+
ref: annotationRef,
|
1096
|
+
data: annotationDict
|
1097
|
+
}]);
|
1098
|
+
|
1099
|
+
_annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
|
1100
|
+
data
|
1101
|
+
}) => {
|
1102
|
+
expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
1103
|
+
expect(data.quadPoints).toEqual([[{
|
1104
|
+
x: 11,
|
1105
|
+
y: 11
|
1106
|
+
}, {
|
1107
|
+
x: 12,
|
1108
|
+
y: 12
|
1109
|
+
}, {
|
1110
|
+
x: 13,
|
1111
|
+
y: 13
|
1112
|
+
}, {
|
1113
|
+
x: 14,
|
1114
|
+
y: 14
|
1115
|
+
}]]);
|
668
1116
|
done();
|
669
1117
|
}, done.fail);
|
670
1118
|
});
|
671
1119
|
});
|
672
|
-
describe(
|
673
|
-
|
1120
|
+
describe("WidgetAnnotation", function () {
|
1121
|
+
let widgetDict;
|
674
1122
|
beforeEach(function (done) {
|
675
1123
|
widgetDict = new _primitives.Dict();
|
676
|
-
widgetDict.set(
|
677
|
-
widgetDict.set(
|
1124
|
+
widgetDict.set("Type", _primitives.Name.get("Annot"));
|
1125
|
+
widgetDict.set("Subtype", _primitives.Name.get("Widget"));
|
678
1126
|
done();
|
679
1127
|
});
|
680
1128
|
afterEach(function () {
|
681
1129
|
widgetDict = null;
|
682
1130
|
});
|
683
|
-
it(
|
684
|
-
|
685
|
-
|
1131
|
+
it("should handle unknown field names", function (done) {
|
1132
|
+
const widgetRef = _primitives.Ref.get(20, 0);
|
1133
|
+
|
1134
|
+
const xref = new _test_utils.XRefMock([{
|
686
1135
|
ref: widgetRef,
|
687
1136
|
data: widgetDict
|
688
1137
|
}]);
|
689
|
-
_annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(function (_ref19) {
|
690
|
-
var data = _ref19.data;
|
691
1138
|
|
1139
|
+
_annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(({
|
1140
|
+
data
|
1141
|
+
}) => {
|
692
1142
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
693
|
-
expect(data.fieldName).toEqual(
|
1143
|
+
expect(data.fieldName).toEqual("");
|
694
1144
|
done();
|
695
1145
|
}, done.fail);
|
696
1146
|
});
|
697
|
-
it(
|
698
|
-
widgetDict.set(
|
699
|
-
|
700
|
-
|
1147
|
+
it("should construct the field name when there are no ancestors", function (done) {
|
1148
|
+
widgetDict.set("T", "foo");
|
1149
|
+
|
1150
|
+
const widgetRef = _primitives.Ref.get(21, 0);
|
1151
|
+
|
1152
|
+
const xref = new _test_utils.XRefMock([{
|
701
1153
|
ref: widgetRef,
|
702
1154
|
data: widgetDict
|
703
1155
|
}]);
|
704
|
-
_annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(function (_ref20) {
|
705
|
-
var data = _ref20.data;
|
706
1156
|
|
1157
|
+
_annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(({
|
1158
|
+
data
|
1159
|
+
}) => {
|
707
1160
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
708
|
-
expect(data.fieldName).toEqual(
|
1161
|
+
expect(data.fieldName).toEqual("foo");
|
709
1162
|
done();
|
710
1163
|
}, done.fail);
|
711
1164
|
});
|
712
|
-
it(
|
713
|
-
|
714
|
-
firstParent.set(
|
715
|
-
|
716
|
-
secondParent.set(
|
717
|
-
secondParent.set(
|
718
|
-
widgetDict.set(
|
719
|
-
widgetDict.set(
|
720
|
-
|
721
|
-
|
1165
|
+
it("should construct the field name when there are ancestors", function (done) {
|
1166
|
+
const firstParent = new _primitives.Dict();
|
1167
|
+
firstParent.set("T", "foo");
|
1168
|
+
const secondParent = new _primitives.Dict();
|
1169
|
+
secondParent.set("Parent", firstParent);
|
1170
|
+
secondParent.set("T", "bar");
|
1171
|
+
widgetDict.set("Parent", secondParent);
|
1172
|
+
widgetDict.set("T", "baz");
|
1173
|
+
|
1174
|
+
const widgetRef = _primitives.Ref.get(22, 0);
|
1175
|
+
|
1176
|
+
const xref = new _test_utils.XRefMock([{
|
722
1177
|
ref: widgetRef,
|
723
1178
|
data: widgetDict
|
724
1179
|
}]);
|
725
|
-
_annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(function (_ref21) {
|
726
|
-
var data = _ref21.data;
|
727
1180
|
|
1181
|
+
_annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(({
|
1182
|
+
data
|
1183
|
+
}) => {
|
728
1184
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
729
|
-
expect(data.fieldName).toEqual(
|
1185
|
+
expect(data.fieldName).toEqual("foo.bar.baz");
|
730
1186
|
done();
|
731
1187
|
}, done.fail);
|
732
1188
|
});
|
733
|
-
it(
|
734
|
-
|
735
|
-
parentDict.set(
|
736
|
-
parentDict.set(
|
737
|
-
widgetDict.set(
|
738
|
-
widgetDict.set(
|
739
|
-
|
740
|
-
|
1189
|
+
it("should construct the field name if a parent is not a dictionary " + "(issue 8143)", function (done) {
|
1190
|
+
const parentDict = new _primitives.Dict();
|
1191
|
+
parentDict.set("Parent", null);
|
1192
|
+
parentDict.set("T", "foo");
|
1193
|
+
widgetDict.set("Parent", parentDict);
|
1194
|
+
widgetDict.set("T", "bar");
|
1195
|
+
|
1196
|
+
const widgetRef = _primitives.Ref.get(22, 0);
|
1197
|
+
|
1198
|
+
const xref = new _test_utils.XRefMock([{
|
741
1199
|
ref: widgetRef,
|
742
1200
|
data: widgetDict
|
743
1201
|
}]);
|
744
|
-
_annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(function (_ref22) {
|
745
|
-
var data = _ref22.data;
|
746
1202
|
|
1203
|
+
_annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(({
|
1204
|
+
data
|
1205
|
+
}) => {
|
747
1206
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
748
|
-
expect(data.fieldName).toEqual(
|
1207
|
+
expect(data.fieldName).toEqual("foo.bar");
|
749
1208
|
done();
|
750
1209
|
}, done.fail);
|
751
1210
|
});
|
752
1211
|
});
|
753
|
-
describe(
|
754
|
-
|
1212
|
+
describe("TextWidgetAnnotation", function () {
|
1213
|
+
let textWidgetDict;
|
755
1214
|
beforeEach(function (done) {
|
756
1215
|
textWidgetDict = new _primitives.Dict();
|
757
|
-
textWidgetDict.set(
|
758
|
-
textWidgetDict.set(
|
759
|
-
textWidgetDict.set(
|
1216
|
+
textWidgetDict.set("Type", _primitives.Name.get("Annot"));
|
1217
|
+
textWidgetDict.set("Subtype", _primitives.Name.get("Widget"));
|
1218
|
+
textWidgetDict.set("FT", _primitives.Name.get("Tx"));
|
760
1219
|
done();
|
761
1220
|
});
|
762
1221
|
afterEach(function () {
|
763
1222
|
textWidgetDict = null;
|
764
1223
|
});
|
765
|
-
it(
|
766
|
-
|
767
|
-
|
1224
|
+
it("should handle unknown text alignment, maximum length and flags", function (done) {
|
1225
|
+
const textWidgetRef = _primitives.Ref.get(124, 0);
|
1226
|
+
|
1227
|
+
const xref = new _test_utils.XRefMock([{
|
768
1228
|
ref: textWidgetRef,
|
769
1229
|
data: textWidgetDict
|
770
1230
|
}]);
|
771
|
-
_annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref23) {
|
772
|
-
var data = _ref23.data;
|
773
1231
|
|
1232
|
+
_annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1233
|
+
data
|
1234
|
+
}) => {
|
774
1235
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
775
1236
|
expect(data.textAlignment).toEqual(null);
|
776
1237
|
expect(data.maxLen).toEqual(null);
|
@@ -780,18 +1241,21 @@ describe('annotation', function () {
|
|
780
1241
|
done();
|
781
1242
|
}, done.fail);
|
782
1243
|
});
|
783
|
-
it(
|
784
|
-
textWidgetDict.set(
|
785
|
-
textWidgetDict.set(
|
786
|
-
textWidgetDict.set(
|
787
|
-
|
788
|
-
|
1244
|
+
it("should not set invalid text alignment, maximum length and flags", function (done) {
|
1245
|
+
textWidgetDict.set("Q", "center");
|
1246
|
+
textWidgetDict.set("MaxLen", "five");
|
1247
|
+
textWidgetDict.set("Ff", "readonly");
|
1248
|
+
|
1249
|
+
const textWidgetRef = _primitives.Ref.get(43, 0);
|
1250
|
+
|
1251
|
+
const xref = new _test_utils.XRefMock([{
|
789
1252
|
ref: textWidgetRef,
|
790
1253
|
data: textWidgetDict
|
791
1254
|
}]);
|
792
|
-
_annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref24) {
|
793
|
-
var data = _ref24.data;
|
794
1255
|
|
1256
|
+
_annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1257
|
+
data
|
1258
|
+
}) => {
|
795
1259
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
796
1260
|
expect(data.textAlignment).toEqual(null);
|
797
1261
|
expect(data.maxLen).toEqual(null);
|
@@ -801,18 +1265,21 @@ describe('annotation', function () {
|
|
801
1265
|
done();
|
802
1266
|
}, done.fail);
|
803
1267
|
});
|
804
|
-
it(
|
805
|
-
textWidgetDict.set(
|
806
|
-
textWidgetDict.set(
|
807
|
-
textWidgetDict.set(
|
808
|
-
|
809
|
-
|
1268
|
+
it("should set valid text alignment, maximum length and flags", function (done) {
|
1269
|
+
textWidgetDict.set("Q", 1);
|
1270
|
+
textWidgetDict.set("MaxLen", 20);
|
1271
|
+
textWidgetDict.set("Ff", _util.AnnotationFieldFlag.READONLY + _util.AnnotationFieldFlag.MULTILINE);
|
1272
|
+
|
1273
|
+
const textWidgetRef = _primitives.Ref.get(84, 0);
|
1274
|
+
|
1275
|
+
const xref = new _test_utils.XRefMock([{
|
810
1276
|
ref: textWidgetRef,
|
811
1277
|
data: textWidgetDict
|
812
1278
|
}]);
|
813
|
-
_annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref25) {
|
814
|
-
var data = _ref25.data;
|
815
1279
|
|
1280
|
+
_annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1281
|
+
data
|
1282
|
+
}) => {
|
816
1283
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
817
1284
|
expect(data.textAlignment).toEqual(1);
|
818
1285
|
expect(data.maxLen).toEqual(20);
|
@@ -821,210 +1288,240 @@ describe('annotation', function () {
|
|
821
1288
|
done();
|
822
1289
|
}, done.fail);
|
823
1290
|
});
|
824
|
-
it(
|
825
|
-
textWidgetDict.set(
|
826
|
-
|
827
|
-
|
1291
|
+
it("should reject comb fields without a maximum length", function (done) {
|
1292
|
+
textWidgetDict.set("Ff", _util.AnnotationFieldFlag.COMB);
|
1293
|
+
|
1294
|
+
const textWidgetRef = _primitives.Ref.get(46, 0);
|
1295
|
+
|
1296
|
+
const xref = new _test_utils.XRefMock([{
|
828
1297
|
ref: textWidgetRef,
|
829
1298
|
data: textWidgetDict
|
830
1299
|
}]);
|
831
|
-
_annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref26) {
|
832
|
-
var data = _ref26.data;
|
833
1300
|
|
1301
|
+
_annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1302
|
+
data
|
1303
|
+
}) => {
|
834
1304
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
835
1305
|
expect(data.comb).toEqual(false);
|
836
1306
|
done();
|
837
1307
|
}, done.fail);
|
838
1308
|
});
|
839
|
-
it(
|
840
|
-
textWidgetDict.set(
|
841
|
-
textWidgetDict.set(
|
842
|
-
|
843
|
-
|
1309
|
+
it("should accept comb fields with a maximum length", function (done) {
|
1310
|
+
textWidgetDict.set("MaxLen", 20);
|
1311
|
+
textWidgetDict.set("Ff", _util.AnnotationFieldFlag.COMB);
|
1312
|
+
|
1313
|
+
const textWidgetRef = _primitives.Ref.get(46, 0);
|
1314
|
+
|
1315
|
+
const xref = new _test_utils.XRefMock([{
|
844
1316
|
ref: textWidgetRef,
|
845
1317
|
data: textWidgetDict
|
846
1318
|
}]);
|
847
|
-
_annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref27) {
|
848
|
-
var data = _ref27.data;
|
849
1319
|
|
1320
|
+
_annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1321
|
+
data
|
1322
|
+
}) => {
|
850
1323
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
851
1324
|
expect(data.comb).toEqual(true);
|
852
1325
|
done();
|
853
1326
|
}, done.fail);
|
854
1327
|
});
|
855
|
-
it(
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
textWidgetDict.set(
|
863
|
-
|
864
|
-
|
1328
|
+
it("should only accept comb fields when the flags are valid", function (done) {
|
1329
|
+
const invalidFieldFlags = [_util.AnnotationFieldFlag.MULTILINE, _util.AnnotationFieldFlag.PASSWORD, _util.AnnotationFieldFlag.FILESELECT];
|
1330
|
+
let flags = _util.AnnotationFieldFlag.COMB + _util.AnnotationFieldFlag.MULTILINE + _util.AnnotationFieldFlag.PASSWORD + _util.AnnotationFieldFlag.FILESELECT;
|
1331
|
+
let promise = Promise.resolve();
|
1332
|
+
|
1333
|
+
for (let i = 0, ii = invalidFieldFlags.length; i <= ii; i++) {
|
1334
|
+
promise = promise.then(() => {
|
1335
|
+
textWidgetDict.set("MaxLen", 20);
|
1336
|
+
textWidgetDict.set("Ff", flags);
|
1337
|
+
|
1338
|
+
const textWidgetRef = _primitives.Ref.get(93, 0);
|
1339
|
+
|
1340
|
+
const xref = new _test_utils.XRefMock([{
|
865
1341
|
ref: textWidgetRef,
|
866
1342
|
data: textWidgetDict
|
867
1343
|
}]);
|
868
|
-
return _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(
|
869
|
-
|
870
|
-
|
1344
|
+
return _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1345
|
+
data
|
1346
|
+
}) => {
|
871
1347
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
872
|
-
|
1348
|
+
const valid = invalidFieldFlags.length === 0;
|
873
1349
|
expect(data.comb).toEqual(valid);
|
1350
|
+
|
874
1351
|
if (!valid) {
|
875
1352
|
flags -= invalidFieldFlags.pop();
|
876
1353
|
}
|
877
1354
|
});
|
878
1355
|
});
|
879
1356
|
}
|
1357
|
+
|
880
1358
|
promise.then(done, done.fail);
|
881
1359
|
});
|
882
1360
|
});
|
883
|
-
describe(
|
884
|
-
|
1361
|
+
describe("ButtonWidgetAnnotation", function () {
|
1362
|
+
let buttonWidgetDict;
|
885
1363
|
beforeEach(function (done) {
|
886
1364
|
buttonWidgetDict = new _primitives.Dict();
|
887
|
-
buttonWidgetDict.set(
|
888
|
-
buttonWidgetDict.set(
|
889
|
-
buttonWidgetDict.set(
|
1365
|
+
buttonWidgetDict.set("Type", _primitives.Name.get("Annot"));
|
1366
|
+
buttonWidgetDict.set("Subtype", _primitives.Name.get("Widget"));
|
1367
|
+
buttonWidgetDict.set("FT", _primitives.Name.get("Btn"));
|
890
1368
|
done();
|
891
1369
|
});
|
892
1370
|
afterEach(function () {
|
893
1371
|
buttonWidgetDict = null;
|
894
1372
|
});
|
895
|
-
it(
|
896
|
-
buttonWidgetDict.set(
|
897
|
-
|
898
|
-
|
899
|
-
exportValueOptionsDict.set(
|
900
|
-
exportValueOptionsDict.set(
|
901
|
-
appearanceStatesDict.set(
|
902
|
-
buttonWidgetDict.set(
|
903
|
-
|
904
|
-
|
1373
|
+
it("should handle checkboxes with export value", function (done) {
|
1374
|
+
buttonWidgetDict.set("V", _primitives.Name.get("1"));
|
1375
|
+
const appearanceStatesDict = new _primitives.Dict();
|
1376
|
+
const exportValueOptionsDict = new _primitives.Dict();
|
1377
|
+
exportValueOptionsDict.set("Off", 0);
|
1378
|
+
exportValueOptionsDict.set("Checked", 1);
|
1379
|
+
appearanceStatesDict.set("D", exportValueOptionsDict);
|
1380
|
+
buttonWidgetDict.set("AP", appearanceStatesDict);
|
1381
|
+
|
1382
|
+
const buttonWidgetRef = _primitives.Ref.get(124, 0);
|
1383
|
+
|
1384
|
+
const xref = new _test_utils.XRefMock([{
|
905
1385
|
ref: buttonWidgetRef,
|
906
1386
|
data: buttonWidgetDict
|
907
1387
|
}]);
|
908
|
-
_annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref29) {
|
909
|
-
var data = _ref29.data;
|
910
1388
|
|
1389
|
+
_annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1390
|
+
data
|
1391
|
+
}) => {
|
911
1392
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
912
1393
|
expect(data.checkBox).toEqual(true);
|
913
|
-
expect(data.fieldValue).toEqual(
|
1394
|
+
expect(data.fieldValue).toEqual("1");
|
914
1395
|
expect(data.radioButton).toEqual(false);
|
915
|
-
expect(data.exportValue).toEqual(
|
1396
|
+
expect(data.exportValue).toEqual("Checked");
|
916
1397
|
done();
|
917
1398
|
}, done.fail);
|
918
1399
|
});
|
919
|
-
it(
|
920
|
-
buttonWidgetDict.set(
|
921
|
-
|
922
|
-
|
1400
|
+
it("should handle checkboxes without export value", function (done) {
|
1401
|
+
buttonWidgetDict.set("V", _primitives.Name.get("1"));
|
1402
|
+
|
1403
|
+
const buttonWidgetRef = _primitives.Ref.get(124, 0);
|
1404
|
+
|
1405
|
+
const xref = new _test_utils.XRefMock([{
|
923
1406
|
ref: buttonWidgetRef,
|
924
1407
|
data: buttonWidgetDict
|
925
1408
|
}]);
|
926
|
-
_annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref30) {
|
927
|
-
var data = _ref30.data;
|
928
1409
|
|
1410
|
+
_annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1411
|
+
data
|
1412
|
+
}) => {
|
929
1413
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
930
1414
|
expect(data.checkBox).toEqual(true);
|
931
|
-
expect(data.fieldValue).toEqual(
|
1415
|
+
expect(data.fieldValue).toEqual("1");
|
932
1416
|
expect(data.radioButton).toEqual(false);
|
933
1417
|
done();
|
934
1418
|
}, done.fail);
|
935
1419
|
});
|
936
|
-
it(
|
937
|
-
|
938
|
-
parentDict.set(
|
939
|
-
|
940
|
-
normalAppearanceStateDict.set(
|
941
|
-
|
942
|
-
appearanceStatesDict.set(
|
943
|
-
buttonWidgetDict.set(
|
944
|
-
buttonWidgetDict.set(
|
945
|
-
buttonWidgetDict.set(
|
946
|
-
|
947
|
-
|
1420
|
+
it("should handle radio buttons with a field value", function (done) {
|
1421
|
+
const parentDict = new _primitives.Dict();
|
1422
|
+
parentDict.set("V", _primitives.Name.get("1"));
|
1423
|
+
const normalAppearanceStateDict = new _primitives.Dict();
|
1424
|
+
normalAppearanceStateDict.set("2", null);
|
1425
|
+
const appearanceStatesDict = new _primitives.Dict();
|
1426
|
+
appearanceStatesDict.set("N", normalAppearanceStateDict);
|
1427
|
+
buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.RADIO);
|
1428
|
+
buttonWidgetDict.set("Parent", parentDict);
|
1429
|
+
buttonWidgetDict.set("AP", appearanceStatesDict);
|
1430
|
+
|
1431
|
+
const buttonWidgetRef = _primitives.Ref.get(124, 0);
|
1432
|
+
|
1433
|
+
const xref = new _test_utils.XRefMock([{
|
948
1434
|
ref: buttonWidgetRef,
|
949
1435
|
data: buttonWidgetDict
|
950
1436
|
}]);
|
951
|
-
_annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref31) {
|
952
|
-
var data = _ref31.data;
|
953
1437
|
|
1438
|
+
_annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1439
|
+
data
|
1440
|
+
}) => {
|
954
1441
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
955
1442
|
expect(data.checkBox).toEqual(false);
|
956
1443
|
expect(data.radioButton).toEqual(true);
|
957
|
-
expect(data.fieldValue).toEqual(
|
958
|
-
expect(data.buttonValue).toEqual(
|
1444
|
+
expect(data.fieldValue).toEqual("1");
|
1445
|
+
expect(data.buttonValue).toEqual("2");
|
959
1446
|
done();
|
960
1447
|
}, done.fail);
|
961
1448
|
});
|
962
|
-
it(
|
963
|
-
|
964
|
-
normalAppearanceStateDict.set(
|
965
|
-
|
966
|
-
appearanceStatesDict.set(
|
967
|
-
buttonWidgetDict.set(
|
968
|
-
buttonWidgetDict.set(
|
969
|
-
|
970
|
-
|
1449
|
+
it("should handle radio buttons without a field value", function (done) {
|
1450
|
+
const normalAppearanceStateDict = new _primitives.Dict();
|
1451
|
+
normalAppearanceStateDict.set("2", null);
|
1452
|
+
const appearanceStatesDict = new _primitives.Dict();
|
1453
|
+
appearanceStatesDict.set("N", normalAppearanceStateDict);
|
1454
|
+
buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.RADIO);
|
1455
|
+
buttonWidgetDict.set("AP", appearanceStatesDict);
|
1456
|
+
|
1457
|
+
const buttonWidgetRef = _primitives.Ref.get(124, 0);
|
1458
|
+
|
1459
|
+
const xref = new _test_utils.XRefMock([{
|
971
1460
|
ref: buttonWidgetRef,
|
972
1461
|
data: buttonWidgetDict
|
973
1462
|
}]);
|
974
|
-
_annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref32) {
|
975
|
-
var data = _ref32.data;
|
976
1463
|
|
1464
|
+
_annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1465
|
+
data
|
1466
|
+
}) => {
|
977
1467
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
978
1468
|
expect(data.checkBox).toEqual(false);
|
979
1469
|
expect(data.radioButton).toEqual(true);
|
980
1470
|
expect(data.fieldValue).toEqual(null);
|
981
|
-
expect(data.buttonValue).toEqual(
|
1471
|
+
expect(data.buttonValue).toEqual("2");
|
982
1472
|
done();
|
983
1473
|
}, done.fail);
|
984
1474
|
});
|
985
1475
|
});
|
986
|
-
describe(
|
987
|
-
|
1476
|
+
describe("ChoiceWidgetAnnotation", function () {
|
1477
|
+
let choiceWidgetDict;
|
988
1478
|
beforeEach(function (done) {
|
989
1479
|
choiceWidgetDict = new _primitives.Dict();
|
990
|
-
choiceWidgetDict.set(
|
991
|
-
choiceWidgetDict.set(
|
992
|
-
choiceWidgetDict.set(
|
1480
|
+
choiceWidgetDict.set("Type", _primitives.Name.get("Annot"));
|
1481
|
+
choiceWidgetDict.set("Subtype", _primitives.Name.get("Widget"));
|
1482
|
+
choiceWidgetDict.set("FT", _primitives.Name.get("Ch"));
|
993
1483
|
done();
|
994
1484
|
});
|
995
1485
|
afterEach(function () {
|
996
1486
|
choiceWidgetDict = null;
|
997
1487
|
});
|
998
|
-
it(
|
999
|
-
|
1000
|
-
|
1488
|
+
it("should handle missing option arrays", function (done) {
|
1489
|
+
const choiceWidgetRef = _primitives.Ref.get(122, 0);
|
1490
|
+
|
1491
|
+
const xref = new _test_utils.XRefMock([{
|
1001
1492
|
ref: choiceWidgetRef,
|
1002
1493
|
data: choiceWidgetDict
|
1003
1494
|
}]);
|
1004
|
-
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref33) {
|
1005
|
-
var data = _ref33.data;
|
1006
1495
|
|
1496
|
+
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1497
|
+
data
|
1498
|
+
}) => {
|
1007
1499
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
1008
1500
|
expect(data.options).toEqual([]);
|
1009
1501
|
done();
|
1010
1502
|
}, done.fail);
|
1011
1503
|
});
|
1012
|
-
it(
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1504
|
+
it("should handle option arrays with array elements", function (done) {
|
1505
|
+
const optionBarRef = _primitives.Ref.get(20, 0);
|
1506
|
+
|
1507
|
+
const optionBarStr = "Bar";
|
1508
|
+
|
1509
|
+
const optionOneRef = _primitives.Ref.get(10, 0);
|
1510
|
+
|
1511
|
+
const optionOneArr = ["bar_export", optionBarRef];
|
1512
|
+
const options = [["foo_export", "Foo"], optionOneRef];
|
1513
|
+
const expected = [{
|
1514
|
+
exportValue: "foo_export",
|
1515
|
+
displayValue: "Foo"
|
1021
1516
|
}, {
|
1022
|
-
exportValue:
|
1023
|
-
displayValue:
|
1517
|
+
exportValue: "bar_export",
|
1518
|
+
displayValue: "Bar"
|
1024
1519
|
}];
|
1025
|
-
choiceWidgetDict.set(
|
1026
|
-
|
1027
|
-
|
1520
|
+
choiceWidgetDict.set("Opt", options);
|
1521
|
+
|
1522
|
+
const choiceWidgetRef = _primitives.Ref.get(123, 0);
|
1523
|
+
|
1524
|
+
const xref = new _test_utils.XRefMock([{
|
1028
1525
|
ref: choiceWidgetRef,
|
1029
1526
|
data: choiceWidgetDict
|
1030
1527
|
}, {
|
@@ -1034,128 +1531,147 @@ describe('annotation', function () {
|
|
1034
1531
|
ref: optionOneRef,
|
1035
1532
|
data: optionOneArr
|
1036
1533
|
}]);
|
1037
|
-
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref34) {
|
1038
|
-
var data = _ref34.data;
|
1039
1534
|
|
1535
|
+
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1536
|
+
data
|
1537
|
+
}) => {
|
1040
1538
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
1041
1539
|
expect(data.options).toEqual(expected);
|
1042
1540
|
done();
|
1043
1541
|
}, done.fail);
|
1044
1542
|
});
|
1045
|
-
it(
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1543
|
+
it("should handle option arrays with string elements", function (done) {
|
1544
|
+
const optionBarRef = _primitives.Ref.get(10, 0);
|
1545
|
+
|
1546
|
+
const optionBarStr = "Bar";
|
1547
|
+
const options = ["Foo", optionBarRef];
|
1548
|
+
const expected = [{
|
1549
|
+
exportValue: "Foo",
|
1550
|
+
displayValue: "Foo"
|
1052
1551
|
}, {
|
1053
|
-
exportValue:
|
1054
|
-
displayValue:
|
1552
|
+
exportValue: "Bar",
|
1553
|
+
displayValue: "Bar"
|
1055
1554
|
}];
|
1056
|
-
choiceWidgetDict.set(
|
1057
|
-
|
1058
|
-
|
1555
|
+
choiceWidgetDict.set("Opt", options);
|
1556
|
+
|
1557
|
+
const choiceWidgetRef = _primitives.Ref.get(981, 0);
|
1558
|
+
|
1559
|
+
const xref = new _test_utils.XRefMock([{
|
1059
1560
|
ref: choiceWidgetRef,
|
1060
1561
|
data: choiceWidgetDict
|
1061
1562
|
}, {
|
1062
1563
|
ref: optionBarRef,
|
1063
1564
|
data: optionBarStr
|
1064
1565
|
}]);
|
1065
|
-
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref35) {
|
1066
|
-
var data = _ref35.data;
|
1067
1566
|
|
1567
|
+
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1568
|
+
data
|
1569
|
+
}) => {
|
1068
1570
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
1069
1571
|
expect(data.options).toEqual(expected);
|
1070
1572
|
done();
|
1071
1573
|
}, done.fail);
|
1072
1574
|
});
|
1073
|
-
it(
|
1074
|
-
|
1075
|
-
|
1076
|
-
exportValue:
|
1077
|
-
displayValue:
|
1575
|
+
it("should handle inherited option arrays (issue 8094)", function (done) {
|
1576
|
+
const options = [["Value1", "Description1"], ["Value2", "Description2"]];
|
1577
|
+
const expected = [{
|
1578
|
+
exportValue: "Value1",
|
1579
|
+
displayValue: "Description1"
|
1078
1580
|
}, {
|
1079
|
-
exportValue:
|
1080
|
-
displayValue:
|
1581
|
+
exportValue: "Value2",
|
1582
|
+
displayValue: "Description2"
|
1081
1583
|
}];
|
1082
|
-
|
1083
|
-
parentDict.set(
|
1084
|
-
choiceWidgetDict.set(
|
1085
|
-
|
1086
|
-
|
1584
|
+
const parentDict = new _primitives.Dict();
|
1585
|
+
parentDict.set("Opt", options);
|
1586
|
+
choiceWidgetDict.set("Parent", parentDict);
|
1587
|
+
|
1588
|
+
const choiceWidgetRef = _primitives.Ref.get(123, 0);
|
1589
|
+
|
1590
|
+
const xref = new _test_utils.XRefMock([{
|
1087
1591
|
ref: choiceWidgetRef,
|
1088
1592
|
data: choiceWidgetDict
|
1089
1593
|
}]);
|
1090
|
-
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref36) {
|
1091
|
-
var data = _ref36.data;
|
1092
1594
|
|
1595
|
+
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1596
|
+
data
|
1597
|
+
}) => {
|
1093
1598
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
1094
1599
|
expect(data.options).toEqual(expected);
|
1095
1600
|
done();
|
1096
1601
|
}, done.fail);
|
1097
1602
|
});
|
1098
|
-
it(
|
1099
|
-
|
1100
|
-
|
1101
|
-
exportValue:
|
1102
|
-
displayValue:
|
1603
|
+
it("should sanitize display values in option arrays (issue 8947)", function (done) {
|
1604
|
+
const options = ["\xFE\xFF\x00F\x00o\x00o"];
|
1605
|
+
const expected = [{
|
1606
|
+
exportValue: "\xFE\xFF\x00F\x00o\x00o",
|
1607
|
+
displayValue: "Foo"
|
1103
1608
|
}];
|
1104
|
-
choiceWidgetDict.set(
|
1105
|
-
|
1106
|
-
|
1609
|
+
choiceWidgetDict.set("Opt", options);
|
1610
|
+
|
1611
|
+
const choiceWidgetRef = _primitives.Ref.get(984, 0);
|
1612
|
+
|
1613
|
+
const xref = new _test_utils.XRefMock([{
|
1107
1614
|
ref: choiceWidgetRef,
|
1108
1615
|
data: choiceWidgetDict
|
1109
1616
|
}]);
|
1110
|
-
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref37) {
|
1111
|
-
var data = _ref37.data;
|
1112
1617
|
|
1618
|
+
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1619
|
+
data
|
1620
|
+
}) => {
|
1113
1621
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
1114
1622
|
expect(data.options).toEqual(expected);
|
1115
1623
|
done();
|
1116
1624
|
}, done.fail);
|
1117
1625
|
});
|
1118
|
-
it(
|
1119
|
-
|
1120
|
-
choiceWidgetDict.set(
|
1121
|
-
|
1122
|
-
|
1626
|
+
it("should handle array field values", function (done) {
|
1627
|
+
const fieldValue = ["Foo", "Bar"];
|
1628
|
+
choiceWidgetDict.set("V", fieldValue);
|
1629
|
+
|
1630
|
+
const choiceWidgetRef = _primitives.Ref.get(968, 0);
|
1631
|
+
|
1632
|
+
const xref = new _test_utils.XRefMock([{
|
1123
1633
|
ref: choiceWidgetRef,
|
1124
1634
|
data: choiceWidgetDict
|
1125
1635
|
}]);
|
1126
|
-
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref38) {
|
1127
|
-
var data = _ref38.data;
|
1128
1636
|
|
1637
|
+
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1638
|
+
data
|
1639
|
+
}) => {
|
1129
1640
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
1130
1641
|
expect(data.fieldValue).toEqual(fieldValue);
|
1131
1642
|
done();
|
1132
1643
|
}, done.fail);
|
1133
1644
|
});
|
1134
|
-
it(
|
1135
|
-
|
1136
|
-
choiceWidgetDict.set(
|
1137
|
-
|
1138
|
-
|
1645
|
+
it("should handle string field values", function (done) {
|
1646
|
+
const fieldValue = "Foo";
|
1647
|
+
choiceWidgetDict.set("V", fieldValue);
|
1648
|
+
|
1649
|
+
const choiceWidgetRef = _primitives.Ref.get(978, 0);
|
1650
|
+
|
1651
|
+
const xref = new _test_utils.XRefMock([{
|
1139
1652
|
ref: choiceWidgetRef,
|
1140
1653
|
data: choiceWidgetDict
|
1141
1654
|
}]);
|
1142
|
-
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref39) {
|
1143
|
-
var data = _ref39.data;
|
1144
1655
|
|
1656
|
+
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1657
|
+
data
|
1658
|
+
}) => {
|
1145
1659
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
1146
1660
|
expect(data.fieldValue).toEqual([fieldValue]);
|
1147
1661
|
done();
|
1148
1662
|
}, done.fail);
|
1149
1663
|
});
|
1150
|
-
it(
|
1151
|
-
|
1152
|
-
|
1664
|
+
it("should handle unknown flags", function (done) {
|
1665
|
+
const choiceWidgetRef = _primitives.Ref.get(166, 0);
|
1666
|
+
|
1667
|
+
const xref = new _test_utils.XRefMock([{
|
1153
1668
|
ref: choiceWidgetRef,
|
1154
1669
|
data: choiceWidgetDict
|
1155
1670
|
}]);
|
1156
|
-
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref40) {
|
1157
|
-
var data = _ref40.data;
|
1158
1671
|
|
1672
|
+
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1673
|
+
data
|
1674
|
+
}) => {
|
1159
1675
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
1160
1676
|
expect(data.readOnly).toEqual(false);
|
1161
1677
|
expect(data.combo).toEqual(false);
|
@@ -1163,16 +1679,19 @@ describe('annotation', function () {
|
|
1163
1679
|
done();
|
1164
1680
|
}, done.fail);
|
1165
1681
|
});
|
1166
|
-
it(
|
1167
|
-
choiceWidgetDict.set(
|
1168
|
-
|
1169
|
-
|
1682
|
+
it("should not set invalid flags", function (done) {
|
1683
|
+
choiceWidgetDict.set("Ff", "readonly");
|
1684
|
+
|
1685
|
+
const choiceWidgetRef = _primitives.Ref.get(165, 0);
|
1686
|
+
|
1687
|
+
const xref = new _test_utils.XRefMock([{
|
1170
1688
|
ref: choiceWidgetRef,
|
1171
1689
|
data: choiceWidgetDict
|
1172
1690
|
}]);
|
1173
|
-
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref41) {
|
1174
|
-
var data = _ref41.data;
|
1175
1691
|
|
1692
|
+
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1693
|
+
data
|
1694
|
+
}) => {
|
1176
1695
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
1177
1696
|
expect(data.readOnly).toEqual(false);
|
1178
1697
|
expect(data.combo).toEqual(false);
|
@@ -1180,16 +1699,19 @@ describe('annotation', function () {
|
|
1180
1699
|
done();
|
1181
1700
|
}, done.fail);
|
1182
1701
|
});
|
1183
|
-
it(
|
1184
|
-
choiceWidgetDict.set(
|
1185
|
-
|
1186
|
-
|
1702
|
+
it("should set valid flags", function (done) {
|
1703
|
+
choiceWidgetDict.set("Ff", _util.AnnotationFieldFlag.READONLY + _util.AnnotationFieldFlag.COMBO + _util.AnnotationFieldFlag.MULTISELECT);
|
1704
|
+
|
1705
|
+
const choiceWidgetRef = _primitives.Ref.get(512, 0);
|
1706
|
+
|
1707
|
+
const xref = new _test_utils.XRefMock([{
|
1187
1708
|
ref: choiceWidgetRef,
|
1188
1709
|
data: choiceWidgetDict
|
1189
1710
|
}]);
|
1190
|
-
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(function (_ref42) {
|
1191
|
-
var data = _ref42.data;
|
1192
1711
|
|
1712
|
+
_annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
|
1713
|
+
data
|
1714
|
+
}) => {
|
1193
1715
|
expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
1194
1716
|
expect(data.readOnly).toEqual(true);
|
1195
1717
|
expect(data.combo).toEqual(true);
|
@@ -1198,49 +1720,61 @@ describe('annotation', function () {
|
|
1198
1720
|
}, done.fail);
|
1199
1721
|
});
|
1200
1722
|
});
|
1201
|
-
describe(
|
1202
|
-
it(
|
1203
|
-
|
1204
|
-
lineDict.set(
|
1205
|
-
lineDict.set(
|
1206
|
-
lineDict.set(
|
1207
|
-
|
1208
|
-
|
1723
|
+
describe("LineAnnotation", function () {
|
1724
|
+
it("should set the line coordinates", function (done) {
|
1725
|
+
const lineDict = new _primitives.Dict();
|
1726
|
+
lineDict.set("Type", _primitives.Name.get("Annot"));
|
1727
|
+
lineDict.set("Subtype", _primitives.Name.get("Line"));
|
1728
|
+
lineDict.set("L", [1, 2, 3, 4]);
|
1729
|
+
|
1730
|
+
const lineRef = _primitives.Ref.get(122, 0);
|
1731
|
+
|
1732
|
+
const xref = new _test_utils.XRefMock([{
|
1209
1733
|
ref: lineRef,
|
1210
1734
|
data: lineDict
|
1211
1735
|
}]);
|
1212
|
-
_annotation.AnnotationFactory.create(xref, lineRef, pdfManagerMock, idFactoryMock).then(function (_ref43) {
|
1213
|
-
var data = _ref43.data;
|
1214
1736
|
|
1737
|
+
_annotation.AnnotationFactory.create(xref, lineRef, pdfManagerMock, idFactoryMock).then(({
|
1738
|
+
data
|
1739
|
+
}) => {
|
1215
1740
|
expect(data.annotationType).toEqual(_util.AnnotationType.LINE);
|
1216
1741
|
expect(data.lineCoordinates).toEqual([1, 2, 3, 4]);
|
1217
1742
|
done();
|
1218
1743
|
}, done.fail);
|
1219
1744
|
});
|
1220
1745
|
});
|
1221
|
-
describe(
|
1222
|
-
it(
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1746
|
+
describe("FileAttachmentAnnotation", function () {
|
1747
|
+
it("should correctly parse a file attachment", function (done) {
|
1748
|
+
const fileStream = new _stream.StringStream("<<\n" + "/Type /EmbeddedFile\n" + "/Subtype /text#2Fplain\n" + ">>\n" + "stream\n" + "Test attachment" + "endstream\n");
|
1749
|
+
const parser = new _parser.Parser({
|
1750
|
+
lexer: new _parser.Lexer(fileStream),
|
1751
|
+
xref: null,
|
1752
|
+
allowStreams: true
|
1753
|
+
});
|
1754
|
+
|
1755
|
+
const fileStreamRef = _primitives.Ref.get(18, 0);
|
1756
|
+
|
1757
|
+
const fileStreamDict = parser.getObj();
|
1758
|
+
const embeddedFileDict = new _primitives.Dict();
|
1759
|
+
embeddedFileDict.set("F", fileStreamRef);
|
1760
|
+
|
1761
|
+
const fileSpecRef = _primitives.Ref.get(19, 0);
|
1762
|
+
|
1763
|
+
const fileSpecDict = new _primitives.Dict();
|
1764
|
+
fileSpecDict.set("Type", _primitives.Name.get("Filespec"));
|
1765
|
+
fileSpecDict.set("Desc", "");
|
1766
|
+
fileSpecDict.set("EF", embeddedFileDict);
|
1767
|
+
fileSpecDict.set("UF", "Test.txt");
|
1768
|
+
|
1769
|
+
const fileAttachmentRef = _primitives.Ref.get(20, 0);
|
1770
|
+
|
1771
|
+
const fileAttachmentDict = new _primitives.Dict();
|
1772
|
+
fileAttachmentDict.set("Type", _primitives.Name.get("Annot"));
|
1773
|
+
fileAttachmentDict.set("Subtype", _primitives.Name.get("FileAttachment"));
|
1774
|
+
fileAttachmentDict.set("FS", fileSpecRef);
|
1775
|
+
fileAttachmentDict.set("T", "Topic");
|
1776
|
+
fileAttachmentDict.set("Contents", "Test.txt");
|
1777
|
+
const xref = new _test_utils.XRefMock([{
|
1244
1778
|
ref: fileStreamRef,
|
1245
1779
|
data: fileStreamDict
|
1246
1780
|
}, {
|
@@ -1253,57 +1787,176 @@ describe('annotation', function () {
|
|
1253
1787
|
embeddedFileDict.assignXref(xref);
|
1254
1788
|
fileSpecDict.assignXref(xref);
|
1255
1789
|
fileAttachmentDict.assignXref(xref);
|
1256
|
-
_annotation.AnnotationFactory.create(xref, fileAttachmentRef, pdfManagerMock, idFactoryMock).then(function (_ref44) {
|
1257
|
-
var data = _ref44.data;
|
1258
1790
|
|
1791
|
+
_annotation.AnnotationFactory.create(xref, fileAttachmentRef, pdfManagerMock, idFactoryMock).then(({
|
1792
|
+
data
|
1793
|
+
}) => {
|
1259
1794
|
expect(data.annotationType).toEqual(_util.AnnotationType.FILEATTACHMENT);
|
1260
|
-
expect(data.file.filename).toEqual(
|
1261
|
-
expect(data.file.content).toEqual((0, _util.stringToBytes)(
|
1795
|
+
expect(data.file.filename).toEqual("Test.txt");
|
1796
|
+
expect(data.file.content).toEqual((0, _util.stringToBytes)("Test attachment"));
|
1262
1797
|
done();
|
1263
1798
|
}, done.fail);
|
1264
1799
|
});
|
1265
1800
|
});
|
1266
|
-
describe(
|
1267
|
-
it(
|
1268
|
-
|
1269
|
-
parentDict.set(
|
1270
|
-
parentDict.set(
|
1271
|
-
parentDict.set(
|
1272
|
-
|
1273
|
-
popupDict
|
1274
|
-
popupDict.set(
|
1275
|
-
popupDict.set(
|
1276
|
-
popupDict.set(
|
1277
|
-
|
1278
|
-
|
1801
|
+
describe("PopupAnnotation", function () {
|
1802
|
+
it("should inherit properties from its parent", function (done) {
|
1803
|
+
const parentDict = new _primitives.Dict();
|
1804
|
+
parentDict.set("Type", _primitives.Name.get("Annot"));
|
1805
|
+
parentDict.set("Subtype", _primitives.Name.get("Text"));
|
1806
|
+
parentDict.set("M", "D:20190423");
|
1807
|
+
parentDict.set("C", [0, 0, 1]);
|
1808
|
+
const popupDict = new _primitives.Dict();
|
1809
|
+
popupDict.set("Type", _primitives.Name.get("Annot"));
|
1810
|
+
popupDict.set("Subtype", _primitives.Name.get("Popup"));
|
1811
|
+
popupDict.set("Parent", parentDict);
|
1812
|
+
|
1813
|
+
const popupRef = _primitives.Ref.get(13, 0);
|
1814
|
+
|
1815
|
+
const xref = new _test_utils.XRefMock([{
|
1816
|
+
ref: popupRef,
|
1817
|
+
data: popupDict
|
1818
|
+
}]);
|
1819
|
+
|
1820
|
+
_annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(({
|
1821
|
+
data,
|
1822
|
+
viewable
|
1823
|
+
}) => {
|
1824
|
+
expect(data.annotationType).toEqual(_util.AnnotationType.POPUP);
|
1825
|
+
expect(data.modificationDate).toEqual("D:20190423");
|
1826
|
+
expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
|
1827
|
+
done();
|
1828
|
+
}, done.fail);
|
1829
|
+
});
|
1830
|
+
it("should handle missing parent properties", function (done) {
|
1831
|
+
const parentDict = new _primitives.Dict();
|
1832
|
+
parentDict.set("Type", _primitives.Name.get("Annot"));
|
1833
|
+
parentDict.set("Subtype", _primitives.Name.get("Text"));
|
1834
|
+
const popupDict = new _primitives.Dict();
|
1835
|
+
popupDict.set("Type", _primitives.Name.get("Annot"));
|
1836
|
+
popupDict.set("Subtype", _primitives.Name.get("Popup"));
|
1837
|
+
popupDict.set("Parent", parentDict);
|
1838
|
+
|
1839
|
+
const popupRef = _primitives.Ref.get(13, 0);
|
1840
|
+
|
1841
|
+
const xref = new _test_utils.XRefMock([{
|
1842
|
+
ref: popupRef,
|
1843
|
+
data: popupDict
|
1844
|
+
}]);
|
1845
|
+
|
1846
|
+
_annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(({
|
1847
|
+
data,
|
1848
|
+
viewable
|
1849
|
+
}) => {
|
1850
|
+
expect(data.annotationType).toEqual(_util.AnnotationType.POPUP);
|
1851
|
+
expect(data.modificationDate).toEqual(null);
|
1852
|
+
expect(data.color).toEqual(null);
|
1853
|
+
done();
|
1854
|
+
}, done.fail);
|
1855
|
+
});
|
1856
|
+
it("should inherit the parent flags when the Popup is not viewable, " + "but the parent is (PR 7352)", function (done) {
|
1857
|
+
const parentDict = new _primitives.Dict();
|
1858
|
+
parentDict.set("Type", _primitives.Name.get("Annot"));
|
1859
|
+
parentDict.set("Subtype", _primitives.Name.get("Text"));
|
1860
|
+
parentDict.set("F", 28);
|
1861
|
+
const popupDict = new _primitives.Dict();
|
1862
|
+
popupDict.set("Type", _primitives.Name.get("Annot"));
|
1863
|
+
popupDict.set("Subtype", _primitives.Name.get("Popup"));
|
1864
|
+
popupDict.set("F", 25);
|
1865
|
+
popupDict.set("Parent", parentDict);
|
1866
|
+
|
1867
|
+
const popupRef = _primitives.Ref.get(13, 0);
|
1868
|
+
|
1869
|
+
const xref = new _test_utils.XRefMock([{
|
1279
1870
|
ref: popupRef,
|
1280
1871
|
data: popupDict
|
1281
1872
|
}]);
|
1282
|
-
_annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(function (_ref45) {
|
1283
|
-
var data = _ref45.data,
|
1284
|
-
viewable = _ref45.viewable;
|
1285
1873
|
|
1874
|
+
_annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(({
|
1875
|
+
data,
|
1876
|
+
viewable
|
1877
|
+
}) => {
|
1286
1878
|
expect(data.annotationType).toEqual(_util.AnnotationType.POPUP);
|
1287
1879
|
expect(data.annotationFlags).toEqual(25);
|
1288
1880
|
expect(viewable).toEqual(true);
|
1289
1881
|
done();
|
1290
1882
|
}, done.fail);
|
1291
1883
|
});
|
1884
|
+
it("should correctly inherit Contents from group-master annotation " + "if parent has ReplyType == Group", function (done) {
|
1885
|
+
const annotationRef = _primitives.Ref.get(819, 0);
|
1886
|
+
|
1887
|
+
const annotationDict = new _primitives.Dict();
|
1888
|
+
annotationDict.set("Type", _primitives.Name.get("Annot"));
|
1889
|
+
annotationDict.set("Subtype", _primitives.Name.get("Text"));
|
1890
|
+
annotationDict.set("T", "Correct Title");
|
1891
|
+
annotationDict.set("Contents", "Correct Text");
|
1892
|
+
annotationDict.set("M", "D:20190423");
|
1893
|
+
annotationDict.set("C", [0, 0, 1]);
|
1894
|
+
|
1895
|
+
const replyRef = _primitives.Ref.get(820, 0);
|
1896
|
+
|
1897
|
+
const replyDict = new _primitives.Dict();
|
1898
|
+
replyDict.set("Type", _primitives.Name.get("Annot"));
|
1899
|
+
replyDict.set("Subtype", _primitives.Name.get("Text"));
|
1900
|
+
replyDict.set("IRT", annotationRef);
|
1901
|
+
replyDict.set("RT", _primitives.Name.get("Group"));
|
1902
|
+
replyDict.set("T", "Reply Title");
|
1903
|
+
replyDict.set("Contents", "Reply Text");
|
1904
|
+
replyDict.set("M", "D:20190523");
|
1905
|
+
replyDict.set("C", [0.4]);
|
1906
|
+
|
1907
|
+
const popupRef = _primitives.Ref.get(821, 0);
|
1908
|
+
|
1909
|
+
const popupDict = new _primitives.Dict();
|
1910
|
+
popupDict.set("Type", _primitives.Name.get("Annot"));
|
1911
|
+
popupDict.set("Subtype", _primitives.Name.get("Popup"));
|
1912
|
+
popupDict.set("T", "Wrong Title");
|
1913
|
+
popupDict.set("Contents", "Wrong Text");
|
1914
|
+
popupDict.set("Parent", replyRef);
|
1915
|
+
popupDict.set("M", "D:20190623");
|
1916
|
+
popupDict.set("C", [0.8]);
|
1917
|
+
replyDict.set("Popup", popupRef);
|
1918
|
+
const xref = new _test_utils.XRefMock([{
|
1919
|
+
ref: annotationRef,
|
1920
|
+
data: annotationDict
|
1921
|
+
}, {
|
1922
|
+
ref: replyRef,
|
1923
|
+
data: replyDict
|
1924
|
+
}, {
|
1925
|
+
ref: popupRef,
|
1926
|
+
data: popupDict
|
1927
|
+
}]);
|
1928
|
+
annotationDict.assignXref(xref);
|
1929
|
+
popupDict.assignXref(xref);
|
1930
|
+
replyDict.assignXref(xref);
|
1931
|
+
|
1932
|
+
_annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(({
|
1933
|
+
data
|
1934
|
+
}) => {
|
1935
|
+
expect(data.title).toEqual("Correct Title");
|
1936
|
+
expect(data.contents).toEqual("Correct Text");
|
1937
|
+
expect(data.modificationDate).toEqual("D:20190423");
|
1938
|
+
expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
|
1939
|
+
done();
|
1940
|
+
}, done.fail);
|
1941
|
+
});
|
1292
1942
|
});
|
1293
|
-
describe(
|
1294
|
-
it(
|
1295
|
-
|
1296
|
-
inkDict.set(
|
1297
|
-
inkDict.set(
|
1298
|
-
inkDict.set(
|
1299
|
-
|
1300
|
-
|
1943
|
+
describe("InkAnnotation", function () {
|
1944
|
+
it("should handle a single ink list", function (done) {
|
1945
|
+
const inkDict = new _primitives.Dict();
|
1946
|
+
inkDict.set("Type", _primitives.Name.get("Annot"));
|
1947
|
+
inkDict.set("Subtype", _primitives.Name.get("Ink"));
|
1948
|
+
inkDict.set("InkList", [[1, 1, 1, 2, 2, 2, 3, 3]]);
|
1949
|
+
|
1950
|
+
const inkRef = _primitives.Ref.get(142, 0);
|
1951
|
+
|
1952
|
+
const xref = new _test_utils.XRefMock([{
|
1301
1953
|
ref: inkRef,
|
1302
1954
|
data: inkDict
|
1303
1955
|
}]);
|
1304
|
-
_annotation.AnnotationFactory.create(xref, inkRef, pdfManagerMock, idFactoryMock).then(function (_ref46) {
|
1305
|
-
var data = _ref46.data;
|
1306
1956
|
|
1957
|
+
_annotation.AnnotationFactory.create(xref, inkRef, pdfManagerMock, idFactoryMock).then(({
|
1958
|
+
data
|
1959
|
+
}) => {
|
1307
1960
|
expect(data.annotationType).toEqual(_util.AnnotationType.INK);
|
1308
1961
|
expect(data.inkLists.length).toEqual(1);
|
1309
1962
|
expect(data.inkLists[0]).toEqual([{
|
@@ -1322,19 +1975,22 @@ describe('annotation', function () {
|
|
1322
1975
|
done();
|
1323
1976
|
}, done.fail);
|
1324
1977
|
});
|
1325
|
-
it(
|
1326
|
-
|
1327
|
-
inkDict.set(
|
1328
|
-
inkDict.set(
|
1329
|
-
inkDict.set(
|
1330
|
-
|
1331
|
-
|
1978
|
+
it("should handle multiple ink lists", function (done) {
|
1979
|
+
const inkDict = new _primitives.Dict();
|
1980
|
+
inkDict.set("Type", _primitives.Name.get("Annot"));
|
1981
|
+
inkDict.set("Subtype", _primitives.Name.get("Ink"));
|
1982
|
+
inkDict.set("InkList", [[1, 1, 1, 2], [3, 3, 4, 5]]);
|
1983
|
+
|
1984
|
+
const inkRef = _primitives.Ref.get(143, 0);
|
1985
|
+
|
1986
|
+
const xref = new _test_utils.XRefMock([{
|
1332
1987
|
ref: inkRef,
|
1333
1988
|
data: inkDict
|
1334
1989
|
}]);
|
1335
|
-
_annotation.AnnotationFactory.create(xref, inkRef, pdfManagerMock, idFactoryMock).then(function (_ref47) {
|
1336
|
-
var data = _ref47.data;
|
1337
1990
|
|
1991
|
+
_annotation.AnnotationFactory.create(xref, inkRef, pdfManagerMock, idFactoryMock).then(({
|
1992
|
+
data
|
1993
|
+
}) => {
|
1338
1994
|
expect(data.annotationType).toEqual(_util.AnnotationType.INK);
|
1339
1995
|
expect(data.inkLists.length).toEqual(2);
|
1340
1996
|
expect(data.inkLists[0]).toEqual([{
|
@@ -1355,4 +2011,228 @@ describe('annotation', function () {
|
|
1355
2011
|
}, done.fail);
|
1356
2012
|
});
|
1357
2013
|
});
|
2014
|
+
describe("HightlightAnnotation", function () {
|
2015
|
+
it("should not set quadpoints if not defined", function (done) {
|
2016
|
+
const highlightDict = new _primitives.Dict();
|
2017
|
+
highlightDict.set("Type", _primitives.Name.get("Annot"));
|
2018
|
+
highlightDict.set("Subtype", _primitives.Name.get("Highlight"));
|
2019
|
+
|
2020
|
+
const highlightRef = _primitives.Ref.get(121, 0);
|
2021
|
+
|
2022
|
+
const xref = new _test_utils.XRefMock([{
|
2023
|
+
ref: highlightRef,
|
2024
|
+
data: highlightDict
|
2025
|
+
}]);
|
2026
|
+
|
2027
|
+
_annotation.AnnotationFactory.create(xref, highlightRef, pdfManagerMock, idFactoryMock).then(({
|
2028
|
+
data
|
2029
|
+
}) => {
|
2030
|
+
expect(data.annotationType).toEqual(_util.AnnotationType.HIGHLIGHT);
|
2031
|
+
expect(data.quadPoints).toBeUndefined();
|
2032
|
+
done();
|
2033
|
+
}, done.fail);
|
2034
|
+
});
|
2035
|
+
it("should set quadpoints if defined", function (done) {
|
2036
|
+
const highlightDict = new _primitives.Dict();
|
2037
|
+
highlightDict.set("Type", _primitives.Name.get("Annot"));
|
2038
|
+
highlightDict.set("Subtype", _primitives.Name.get("Highlight"));
|
2039
|
+
highlightDict.set("Rect", [10, 10, 20, 20]);
|
2040
|
+
highlightDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
|
2041
|
+
|
2042
|
+
const highlightRef = _primitives.Ref.get(121, 0);
|
2043
|
+
|
2044
|
+
const xref = new _test_utils.XRefMock([{
|
2045
|
+
ref: highlightRef,
|
2046
|
+
data: highlightDict
|
2047
|
+
}]);
|
2048
|
+
|
2049
|
+
_annotation.AnnotationFactory.create(xref, highlightRef, pdfManagerMock, idFactoryMock).then(({
|
2050
|
+
data
|
2051
|
+
}) => {
|
2052
|
+
expect(data.annotationType).toEqual(_util.AnnotationType.HIGHLIGHT);
|
2053
|
+
expect(data.quadPoints).toEqual([[{
|
2054
|
+
x: 11,
|
2055
|
+
y: 11
|
2056
|
+
}, {
|
2057
|
+
x: 12,
|
2058
|
+
y: 12
|
2059
|
+
}, {
|
2060
|
+
x: 13,
|
2061
|
+
y: 13
|
2062
|
+
}, {
|
2063
|
+
x: 14,
|
2064
|
+
y: 14
|
2065
|
+
}]]);
|
2066
|
+
done();
|
2067
|
+
}, done.fail);
|
2068
|
+
});
|
2069
|
+
});
|
2070
|
+
describe("UnderlineAnnotation", function () {
|
2071
|
+
it("should not set quadpoints if not defined", function (done) {
|
2072
|
+
const underlineDict = new _primitives.Dict();
|
2073
|
+
underlineDict.set("Type", _primitives.Name.get("Annot"));
|
2074
|
+
underlineDict.set("Subtype", _primitives.Name.get("Underline"));
|
2075
|
+
|
2076
|
+
const underlineRef = _primitives.Ref.get(121, 0);
|
2077
|
+
|
2078
|
+
const xref = new _test_utils.XRefMock([{
|
2079
|
+
ref: underlineRef,
|
2080
|
+
data: underlineDict
|
2081
|
+
}]);
|
2082
|
+
|
2083
|
+
_annotation.AnnotationFactory.create(xref, underlineRef, pdfManagerMock, idFactoryMock).then(({
|
2084
|
+
data
|
2085
|
+
}) => {
|
2086
|
+
expect(data.annotationType).toEqual(_util.AnnotationType.UNDERLINE);
|
2087
|
+
expect(data.quadPoints).toBeUndefined();
|
2088
|
+
done();
|
2089
|
+
}, done.fail);
|
2090
|
+
});
|
2091
|
+
it("should set quadpoints if defined", function (done) {
|
2092
|
+
const underlineDict = new _primitives.Dict();
|
2093
|
+
underlineDict.set("Type", _primitives.Name.get("Annot"));
|
2094
|
+
underlineDict.set("Subtype", _primitives.Name.get("Underline"));
|
2095
|
+
underlineDict.set("Rect", [10, 10, 20, 20]);
|
2096
|
+
underlineDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
|
2097
|
+
|
2098
|
+
const underlineRef = _primitives.Ref.get(121, 0);
|
2099
|
+
|
2100
|
+
const xref = new _test_utils.XRefMock([{
|
2101
|
+
ref: underlineRef,
|
2102
|
+
data: underlineDict
|
2103
|
+
}]);
|
2104
|
+
|
2105
|
+
_annotation.AnnotationFactory.create(xref, underlineRef, pdfManagerMock, idFactoryMock).then(({
|
2106
|
+
data
|
2107
|
+
}) => {
|
2108
|
+
expect(data.annotationType).toEqual(_util.AnnotationType.UNDERLINE);
|
2109
|
+
expect(data.quadPoints).toEqual([[{
|
2110
|
+
x: 11,
|
2111
|
+
y: 11
|
2112
|
+
}, {
|
2113
|
+
x: 12,
|
2114
|
+
y: 12
|
2115
|
+
}, {
|
2116
|
+
x: 13,
|
2117
|
+
y: 13
|
2118
|
+
}, {
|
2119
|
+
x: 14,
|
2120
|
+
y: 14
|
2121
|
+
}]]);
|
2122
|
+
done();
|
2123
|
+
}, done.fail);
|
2124
|
+
});
|
2125
|
+
});
|
2126
|
+
describe("SquigglyAnnotation", function () {
|
2127
|
+
it("should not set quadpoints if not defined", function (done) {
|
2128
|
+
const squigglyDict = new _primitives.Dict();
|
2129
|
+
squigglyDict.set("Type", _primitives.Name.get("Annot"));
|
2130
|
+
squigglyDict.set("Subtype", _primitives.Name.get("Squiggly"));
|
2131
|
+
|
2132
|
+
const squigglyRef = _primitives.Ref.get(121, 0);
|
2133
|
+
|
2134
|
+
const xref = new _test_utils.XRefMock([{
|
2135
|
+
ref: squigglyRef,
|
2136
|
+
data: squigglyDict
|
2137
|
+
}]);
|
2138
|
+
|
2139
|
+
_annotation.AnnotationFactory.create(xref, squigglyRef, pdfManagerMock, idFactoryMock).then(({
|
2140
|
+
data
|
2141
|
+
}) => {
|
2142
|
+
expect(data.annotationType).toEqual(_util.AnnotationType.SQUIGGLY);
|
2143
|
+
expect(data.quadPoints).toBeUndefined();
|
2144
|
+
done();
|
2145
|
+
}, done.fail);
|
2146
|
+
});
|
2147
|
+
it("should set quadpoints if defined", function (done) {
|
2148
|
+
const squigglyDict = new _primitives.Dict();
|
2149
|
+
squigglyDict.set("Type", _primitives.Name.get("Annot"));
|
2150
|
+
squigglyDict.set("Subtype", _primitives.Name.get("Squiggly"));
|
2151
|
+
squigglyDict.set("Rect", [10, 10, 20, 20]);
|
2152
|
+
squigglyDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
|
2153
|
+
|
2154
|
+
const squigglyRef = _primitives.Ref.get(121, 0);
|
2155
|
+
|
2156
|
+
const xref = new _test_utils.XRefMock([{
|
2157
|
+
ref: squigglyRef,
|
2158
|
+
data: squigglyDict
|
2159
|
+
}]);
|
2160
|
+
|
2161
|
+
_annotation.AnnotationFactory.create(xref, squigglyRef, pdfManagerMock, idFactoryMock).then(({
|
2162
|
+
data
|
2163
|
+
}) => {
|
2164
|
+
expect(data.annotationType).toEqual(_util.AnnotationType.SQUIGGLY);
|
2165
|
+
expect(data.quadPoints).toEqual([[{
|
2166
|
+
x: 11,
|
2167
|
+
y: 11
|
2168
|
+
}, {
|
2169
|
+
x: 12,
|
2170
|
+
y: 12
|
2171
|
+
}, {
|
2172
|
+
x: 13,
|
2173
|
+
y: 13
|
2174
|
+
}, {
|
2175
|
+
x: 14,
|
2176
|
+
y: 14
|
2177
|
+
}]]);
|
2178
|
+
done();
|
2179
|
+
}, done.fail);
|
2180
|
+
});
|
2181
|
+
});
|
2182
|
+
describe("StrikeOutAnnotation", function () {
|
2183
|
+
it("should not set quadpoints if not defined", function (done) {
|
2184
|
+
const strikeOutDict = new _primitives.Dict();
|
2185
|
+
strikeOutDict.set("Type", _primitives.Name.get("Annot"));
|
2186
|
+
strikeOutDict.set("Subtype", _primitives.Name.get("StrikeOut"));
|
2187
|
+
|
2188
|
+
const strikeOutRef = _primitives.Ref.get(121, 0);
|
2189
|
+
|
2190
|
+
const xref = new _test_utils.XRefMock([{
|
2191
|
+
ref: strikeOutRef,
|
2192
|
+
data: strikeOutDict
|
2193
|
+
}]);
|
2194
|
+
|
2195
|
+
_annotation.AnnotationFactory.create(xref, strikeOutRef, pdfManagerMock, idFactoryMock).then(({
|
2196
|
+
data
|
2197
|
+
}) => {
|
2198
|
+
expect(data.annotationType).toEqual(_util.AnnotationType.STRIKEOUT);
|
2199
|
+
expect(data.quadPoints).toBeUndefined();
|
2200
|
+
done();
|
2201
|
+
}, done.fail);
|
2202
|
+
});
|
2203
|
+
it("should set quadpoints if defined", function (done) {
|
2204
|
+
const strikeOutDict = new _primitives.Dict();
|
2205
|
+
strikeOutDict.set("Type", _primitives.Name.get("Annot"));
|
2206
|
+
strikeOutDict.set("Subtype", _primitives.Name.get("StrikeOut"));
|
2207
|
+
strikeOutDict.set("Rect", [10, 10, 20, 20]);
|
2208
|
+
strikeOutDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
|
2209
|
+
|
2210
|
+
const strikeOutRef = _primitives.Ref.get(121, 0);
|
2211
|
+
|
2212
|
+
const xref = new _test_utils.XRefMock([{
|
2213
|
+
ref: strikeOutRef,
|
2214
|
+
data: strikeOutDict
|
2215
|
+
}]);
|
2216
|
+
|
2217
|
+
_annotation.AnnotationFactory.create(xref, strikeOutRef, pdfManagerMock, idFactoryMock).then(({
|
2218
|
+
data
|
2219
|
+
}) => {
|
2220
|
+
expect(data.annotationType).toEqual(_util.AnnotationType.STRIKEOUT);
|
2221
|
+
expect(data.quadPoints).toEqual([[{
|
2222
|
+
x: 11,
|
2223
|
+
y: 11
|
2224
|
+
}, {
|
2225
|
+
x: 12,
|
2226
|
+
y: 12
|
2227
|
+
}, {
|
2228
|
+
x: 13,
|
2229
|
+
y: 13
|
2230
|
+
}, {
|
2231
|
+
x: 14,
|
2232
|
+
y: 14
|
2233
|
+
}]]);
|
2234
|
+
done();
|
2235
|
+
}, done.fail);
|
2236
|
+
});
|
2237
|
+
});
|
1358
2238
|
});
|