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