1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | 'use strict';
|
23 |
|
24 | var _annotation = require('../../core/annotation');
|
25 |
|
26 | var _util = require('../../shared/util');
|
27 |
|
28 | var _primitives = require('../../core/primitives');
|
29 |
|
30 | var _parser = require('../../core/parser');
|
31 |
|
32 | var _stream = require('../../core/stream');
|
33 |
|
34 | var _test_utils = require('./test_utils');
|
35 |
|
36 | describe('annotation', function () {
|
37 | function PDFManagerMock(params) {
|
38 | this.docBaseUrl = params.docBaseUrl || null;
|
39 | }
|
40 | PDFManagerMock.prototype = {};
|
41 | function IdFactoryMock(params) {
|
42 | var uniquePrefix = params.prefix || 'p0_';
|
43 | var idCounters = { obj: params.startObjId || 0 };
|
44 | return {
|
45 | createObjId: function createObjId() {
|
46 | return uniquePrefix + ++idCounters.obj;
|
47 | }
|
48 | };
|
49 | }
|
50 | IdFactoryMock.prototype = {};
|
51 | var pdfManagerMock, idFactoryMock;
|
52 | beforeAll(function (done) {
|
53 | pdfManagerMock = new PDFManagerMock({ docBaseUrl: null });
|
54 | idFactoryMock = new IdFactoryMock({});
|
55 | done();
|
56 | });
|
57 | afterAll(function () {
|
58 | pdfManagerMock = null;
|
59 | idFactoryMock = null;
|
60 | });
|
61 | describe('AnnotationFactory', function () {
|
62 | it('should get id for annotation', function () {
|
63 | var annotationDict = new _primitives.Dict();
|
64 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
65 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
66 | var annotationRef = new _primitives.Ref(10, 0);
|
67 | var xref = new _test_utils.XRefMock([{
|
68 | ref: annotationRef,
|
69 | data: annotationDict
|
70 | }]);
|
71 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
72 | var data = annotation.data;
|
73 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
74 | expect(data.id).toEqual('10R');
|
75 | });
|
76 | it('should handle, and get fallback id\'s for, annotations that are not ' + 'indirect objects (issue 7569)', function () {
|
77 | var annotationDict = new _primitives.Dict();
|
78 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
79 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
80 | var xref = new _test_utils.XRefMock();
|
81 | var idFactory = new IdFactoryMock({
|
82 | prefix: 'p0_',
|
83 | startObjId: 0
|
84 | });
|
85 | var annotation1 = _annotation.AnnotationFactory.create(xref, annotationDict, pdfManagerMock, idFactory);
|
86 | var annotation2 = _annotation.AnnotationFactory.create(xref, annotationDict, pdfManagerMock, idFactory);
|
87 | var data1 = annotation1.data,
|
88 | data2 = annotation2.data;
|
89 | expect(data1.annotationType).toEqual(_util.AnnotationType.LINK);
|
90 | expect(data2.annotationType).toEqual(_util.AnnotationType.LINK);
|
91 | expect(data1.id).toEqual('annot_p0_1');
|
92 | expect(data2.id).toEqual('annot_p0_2');
|
93 | });
|
94 | it('should handle missing /Subtype', function () {
|
95 | var annotationDict = new _primitives.Dict();
|
96 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
97 | var annotationRef = new _primitives.Ref(1, 0);
|
98 | var xref = new _test_utils.XRefMock([{
|
99 | ref: annotationRef,
|
100 | data: annotationDict
|
101 | }]);
|
102 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
103 | var data = annotation.data;
|
104 | expect(data.annotationType).toBeUndefined();
|
105 | });
|
106 | });
|
107 | describe('Annotation', function () {
|
108 | var dict, ref;
|
109 | beforeAll(function (done) {
|
110 | dict = new _primitives.Dict();
|
111 | ref = new _primitives.Ref(1, 0);
|
112 | done();
|
113 | });
|
114 | afterAll(function () {
|
115 | dict = ref = null;
|
116 | });
|
117 | it('should set and get flags', function () {
|
118 | var annotation = new _annotation.Annotation({
|
119 | dict: dict,
|
120 | ref: ref
|
121 | });
|
122 | annotation.setFlags(13);
|
123 | expect(annotation.hasFlag(_util.AnnotationFlag.INVISIBLE)).toEqual(true);
|
124 | expect(annotation.hasFlag(_util.AnnotationFlag.NOZOOM)).toEqual(true);
|
125 | expect(annotation.hasFlag(_util.AnnotationFlag.PRINT)).toEqual(true);
|
126 | expect(annotation.hasFlag(_util.AnnotationFlag.READONLY)).toEqual(false);
|
127 | });
|
128 | it('should be viewable and not printable by default', function () {
|
129 | var annotation = new _annotation.Annotation({
|
130 | dict: dict,
|
131 | ref: ref
|
132 | });
|
133 | expect(annotation.viewable).toEqual(true);
|
134 | expect(annotation.printable).toEqual(false);
|
135 | });
|
136 | it('should set and get a valid rectangle', function () {
|
137 | var annotation = new _annotation.Annotation({
|
138 | dict: dict,
|
139 | ref: ref
|
140 | });
|
141 | annotation.setRectangle([117, 694, 164.298, 720]);
|
142 | expect(annotation.rectangle).toEqual([117, 694, 164.298, 720]);
|
143 | });
|
144 | it('should not set and get an invalid rectangle', function () {
|
145 | var annotation = new _annotation.Annotation({
|
146 | dict: dict,
|
147 | ref: ref
|
148 | });
|
149 | annotation.setRectangle([117, 694, 164.298]);
|
150 | expect(annotation.rectangle).toEqual([0, 0, 0, 0]);
|
151 | });
|
152 | it('should reject a color if it is not an array', function () {
|
153 | var annotation = new _annotation.Annotation({
|
154 | dict: dict,
|
155 | ref: ref
|
156 | });
|
157 | annotation.setColor('red');
|
158 | expect(annotation.color).toEqual(new Uint8Array([0, 0, 0]));
|
159 | });
|
160 | it('should set and get a transparent color', function () {
|
161 | var annotation = new _annotation.Annotation({
|
162 | dict: dict,
|
163 | ref: ref
|
164 | });
|
165 | annotation.setColor([]);
|
166 | expect(annotation.color).toEqual(null);
|
167 | });
|
168 | it('should set and get a grayscale color', function () {
|
169 | var annotation = new _annotation.Annotation({
|
170 | dict: dict,
|
171 | ref: ref
|
172 | });
|
173 | annotation.setColor([0.4]);
|
174 | expect(annotation.color).toEqual(new Uint8Array([102, 102, 102]));
|
175 | });
|
176 | it('should set and get an RGB color', function () {
|
177 | var annotation = new _annotation.Annotation({
|
178 | dict: dict,
|
179 | ref: ref
|
180 | });
|
181 | annotation.setColor([0, 0, 1]);
|
182 | expect(annotation.color).toEqual(new Uint8Array([0, 0, 255]));
|
183 | });
|
184 | it('should set and get a CMYK color', function () {
|
185 | var annotation = new _annotation.Annotation({
|
186 | dict: dict,
|
187 | ref: ref
|
188 | });
|
189 | annotation.setColor([0.1, 0.92, 0.84, 0.02]);
|
190 | expect(annotation.color).toEqual(new Uint8Array([233, 59, 47]));
|
191 | });
|
192 | it('should not set and get an invalid color', function () {
|
193 | var annotation = new _annotation.Annotation({
|
194 | dict: dict,
|
195 | ref: ref
|
196 | });
|
197 | annotation.setColor([0.4, 0.6]);
|
198 | expect(annotation.color).toEqual(new Uint8Array([0, 0, 0]));
|
199 | });
|
200 | });
|
201 | describe('AnnotationBorderStyle', function () {
|
202 | it('should set and get a valid width', function () {
|
203 | var borderStyle = new _annotation.AnnotationBorderStyle();
|
204 | borderStyle.setWidth(3);
|
205 | expect(borderStyle.width).toEqual(3);
|
206 | });
|
207 | it('should not set and get an invalid width', function () {
|
208 | var borderStyle = new _annotation.AnnotationBorderStyle();
|
209 | borderStyle.setWidth('three');
|
210 | expect(borderStyle.width).toEqual(1);
|
211 | });
|
212 | it('should set and get a valid style', function () {
|
213 | var borderStyle = new _annotation.AnnotationBorderStyle();
|
214 | borderStyle.setStyle(_primitives.Name.get('D'));
|
215 | expect(borderStyle.style).toEqual(_util.AnnotationBorderStyleType.DASHED);
|
216 | });
|
217 | it('should not set and get an invalid style', function () {
|
218 | var borderStyle = new _annotation.AnnotationBorderStyle();
|
219 | borderStyle.setStyle('Dashed');
|
220 | expect(borderStyle.style).toEqual(_util.AnnotationBorderStyleType.SOLID);
|
221 | });
|
222 | it('should set and get a valid dash array', function () {
|
223 | var borderStyle = new _annotation.AnnotationBorderStyle();
|
224 | borderStyle.setDashArray([1, 2, 3]);
|
225 | expect(borderStyle.dashArray).toEqual([1, 2, 3]);
|
226 | });
|
227 | it('should not set and get an invalid dash array', function () {
|
228 | var borderStyle = new _annotation.AnnotationBorderStyle();
|
229 | borderStyle.setDashArray([0, 0]);
|
230 | expect(borderStyle.dashArray).toEqual([3]);
|
231 | });
|
232 | it('should set and get a valid horizontal corner radius', function () {
|
233 | var borderStyle = new _annotation.AnnotationBorderStyle();
|
234 | borderStyle.setHorizontalCornerRadius(3);
|
235 | expect(borderStyle.horizontalCornerRadius).toEqual(3);
|
236 | });
|
237 | it('should not set and get an invalid horizontal corner radius', function () {
|
238 | var borderStyle = new _annotation.AnnotationBorderStyle();
|
239 | borderStyle.setHorizontalCornerRadius('three');
|
240 | expect(borderStyle.horizontalCornerRadius).toEqual(0);
|
241 | });
|
242 | it('should set and get a valid vertical corner radius', function () {
|
243 | var borderStyle = new _annotation.AnnotationBorderStyle();
|
244 | borderStyle.setVerticalCornerRadius(3);
|
245 | expect(borderStyle.verticalCornerRadius).toEqual(3);
|
246 | });
|
247 | it('should not set and get an invalid horizontal corner radius', function () {
|
248 | var borderStyle = new _annotation.AnnotationBorderStyle();
|
249 | borderStyle.setVerticalCornerRadius('three');
|
250 | expect(borderStyle.verticalCornerRadius).toEqual(0);
|
251 | });
|
252 | });
|
253 | describe('LinkAnnotation', function () {
|
254 | it('should correctly parse a URI action', function () {
|
255 | var actionDict = new _primitives.Dict();
|
256 | actionDict.set('Type', _primitives.Name.get('Action'));
|
257 | actionDict.set('S', _primitives.Name.get('URI'));
|
258 | actionDict.set('URI', 'http://www.ctan.org/tex-archive/info/lshort');
|
259 | var annotationDict = new _primitives.Dict();
|
260 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
261 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
262 | annotationDict.set('A', actionDict);
|
263 | var annotationRef = new _primitives.Ref(820, 0);
|
264 | var xref = new _test_utils.XRefMock([{
|
265 | ref: annotationRef,
|
266 | data: annotationDict
|
267 | }]);
|
268 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
269 | var data = annotation.data;
|
270 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
271 | expect(data.url).toEqual('http://www.ctan.org/tex-archive/info/lshort');
|
272 | expect(data.unsafeUrl).toEqual('http://www.ctan.org/tex-archive/info/lshort');
|
273 | expect(data.dest).toBeUndefined();
|
274 | });
|
275 | it('should correctly parse a URI action, where the URI entry ' + 'is missing a protocol', function () {
|
276 | var actionDict = new _primitives.Dict();
|
277 | actionDict.set('Type', _primitives.Name.get('Action'));
|
278 | actionDict.set('S', _primitives.Name.get('URI'));
|
279 | actionDict.set('URI', 'www.hmrc.gov.uk');
|
280 | var annotationDict = new _primitives.Dict();
|
281 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
282 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
283 | annotationDict.set('A', actionDict);
|
284 | var annotationRef = new _primitives.Ref(353, 0);
|
285 | var xref = new _test_utils.XRefMock([{
|
286 | ref: annotationRef,
|
287 | data: annotationDict
|
288 | }]);
|
289 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
290 | var data = annotation.data;
|
291 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
292 | expect(data.url).toEqual('http://www.hmrc.gov.uk/');
|
293 | expect(data.unsafeUrl).toEqual('http://www.hmrc.gov.uk');
|
294 | expect(data.dest).toBeUndefined();
|
295 | });
|
296 | it('should correctly parse a URI action, where the URI entry ' + 'has an incorrect encoding (bug 1122280)', function () {
|
297 | var actionStream = new _stream.StringStream('<<\n' + '/Type /Action\n' + '/S /URI\n' + '/URI (http://www.example.com/\\303\\274\\303\\266\\303\\244)\n' + '>>\n');
|
298 | var lexer = new _parser.Lexer(actionStream);
|
299 | var parser = new _parser.Parser(lexer);
|
300 | var actionDict = parser.getObj();
|
301 | var annotationDict = new _primitives.Dict();
|
302 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
303 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
304 | annotationDict.set('A', actionDict);
|
305 | var annotationRef = new _primitives.Ref(8, 0);
|
306 | var xref = new _test_utils.XRefMock([{
|
307 | ref: annotationRef,
|
308 | data: annotationDict
|
309 | }]);
|
310 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
311 | var data = annotation.data;
|
312 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
313 | expect(data.url).toEqual(new URL((0, _util.stringToUTF8String)('http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4')).href);
|
314 | expect(data.unsafeUrl).toEqual((0, _util.stringToUTF8String)('http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4'));
|
315 | expect(data.dest).toBeUndefined();
|
316 | });
|
317 | it('should correctly parse a GoTo action', function () {
|
318 | var actionDict = new _primitives.Dict();
|
319 | actionDict.set('Type', _primitives.Name.get('Action'));
|
320 | actionDict.set('S', _primitives.Name.get('GoTo'));
|
321 | actionDict.set('D', 'page.157');
|
322 | var annotationDict = new _primitives.Dict();
|
323 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
324 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
325 | annotationDict.set('A', actionDict);
|
326 | var annotationRef = new _primitives.Ref(798, 0);
|
327 | var xref = new _test_utils.XRefMock([{
|
328 | ref: annotationRef,
|
329 | data: annotationDict
|
330 | }]);
|
331 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
332 | var data = annotation.data;
|
333 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
334 | expect(data.url).toBeUndefined();
|
335 | expect(data.unsafeUrl).toBeUndefined();
|
336 | expect(data.dest).toEqual('page.157');
|
337 | });
|
338 | it('should correctly parse a GoToR action, where the FileSpec entry ' + 'is a string containing a relative URL', function () {
|
339 | var actionDict = new _primitives.Dict();
|
340 | actionDict.set('Type', _primitives.Name.get('Action'));
|
341 | actionDict.set('S', _primitives.Name.get('GoToR'));
|
342 | actionDict.set('F', '../../0013/001346/134685E.pdf');
|
343 | actionDict.set('D', '4.3');
|
344 | actionDict.set('NewWindow', true);
|
345 | var annotationDict = new _primitives.Dict();
|
346 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
347 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
348 | annotationDict.set('A', actionDict);
|
349 | var annotationRef = new _primitives.Ref(489, 0);
|
350 | var xref = new _test_utils.XRefMock([{
|
351 | ref: annotationRef,
|
352 | data: annotationDict
|
353 | }]);
|
354 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
355 | var data = annotation.data;
|
356 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
357 | expect(data.url).toBeUndefined();
|
358 | expect(data.unsafeUrl).toEqual('../../0013/001346/134685E.pdf#4.3');
|
359 | expect(data.dest).toBeUndefined();
|
360 | expect(data.newWindow).toEqual(true);
|
361 | });
|
362 | it('should correctly parse a GoToR action, containing a relative URL, ' + 'with the "docBaseUrl" parameter specified', function () {
|
363 | var actionDict = new _primitives.Dict();
|
364 | actionDict.set('Type', _primitives.Name.get('Action'));
|
365 | actionDict.set('S', _primitives.Name.get('GoToR'));
|
366 | actionDict.set('F', '../../0013/001346/134685E.pdf');
|
367 | actionDict.set('D', '4.3');
|
368 | var annotationDict = new _primitives.Dict();
|
369 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
370 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
371 | annotationDict.set('A', actionDict);
|
372 | var annotationRef = new _primitives.Ref(489, 0);
|
373 | var xref = new _test_utils.XRefMock([{
|
374 | ref: annotationRef,
|
375 | data: annotationDict
|
376 | }]);
|
377 | var pdfManager = new PDFManagerMock({ docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf' });
|
378 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManager, idFactoryMock);
|
379 | var data = annotation.data;
|
380 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
381 | expect(data.url).toEqual('http://www.example.com/0013/001346/134685E.pdf#4.3');
|
382 | expect(data.unsafeUrl).toEqual('../../0013/001346/134685E.pdf#4.3');
|
383 | expect(data.dest).toBeUndefined();
|
384 | });
|
385 | it('should correctly parse a GoToR action, with named destination', function () {
|
386 | var actionDict = new _primitives.Dict();
|
387 | actionDict.set('Type', _primitives.Name.get('Action'));
|
388 | actionDict.set('S', _primitives.Name.get('GoToR'));
|
389 | actionDict.set('F', 'http://www.example.com/test.pdf');
|
390 | actionDict.set('D', '15');
|
391 | var annotationDict = new _primitives.Dict();
|
392 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
393 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
394 | annotationDict.set('A', actionDict);
|
395 | var annotationRef = new _primitives.Ref(495, 0);
|
396 | var xref = new _test_utils.XRefMock([{
|
397 | ref: annotationRef,
|
398 | data: annotationDict
|
399 | }]);
|
400 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
401 | var data = annotation.data;
|
402 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
403 | expect(data.url).toEqual('http://www.example.com/test.pdf#15');
|
404 | expect(data.unsafeUrl).toEqual('http://www.example.com/test.pdf#15');
|
405 | expect(data.dest).toBeUndefined();
|
406 | expect(data.newWindow).toBeFalsy();
|
407 | });
|
408 | it('should correctly parse a GoToR action, with explicit destination array', function () {
|
409 | var actionDict = new _primitives.Dict();
|
410 | actionDict.set('Type', _primitives.Name.get('Action'));
|
411 | actionDict.set('S', _primitives.Name.get('GoToR'));
|
412 | actionDict.set('F', 'http://www.example.com/test.pdf');
|
413 | actionDict.set('D', [14, _primitives.Name.get('XYZ'), null, 298.043, null]);
|
414 | var annotationDict = new _primitives.Dict();
|
415 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
416 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
417 | annotationDict.set('A', actionDict);
|
418 | var annotationRef = new _primitives.Ref(489, 0);
|
419 | var xref = new _test_utils.XRefMock([{
|
420 | ref: annotationRef,
|
421 | data: annotationDict
|
422 | }]);
|
423 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
424 | var data = annotation.data;
|
425 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
426 | expect(data.url).toEqual(new URL('http://www.example.com/test.pdf#' + '[14,{"name":"XYZ"},null,298.043,null]').href);
|
427 | expect(data.unsafeUrl).toEqual('http://www.example.com/test.pdf#' + '[14,{"name":"XYZ"},null,298.043,null]');
|
428 | expect(data.dest).toBeUndefined();
|
429 | expect(data.newWindow).toBeFalsy();
|
430 | });
|
431 | it('should correctly parse a Launch action, where the FileSpec dict ' + 'contains a relative URL, with the "docBaseUrl" parameter specified', function () {
|
432 | var fileSpecDict = new _primitives.Dict();
|
433 | fileSpecDict.set('Type', _primitives.Name.get('FileSpec'));
|
434 | fileSpecDict.set('F', 'Part II/Part II.pdf');
|
435 | fileSpecDict.set('UF', 'Part II/Part II.pdf');
|
436 | var actionDict = new _primitives.Dict();
|
437 | actionDict.set('Type', _primitives.Name.get('Action'));
|
438 | actionDict.set('S', _primitives.Name.get('Launch'));
|
439 | actionDict.set('F', fileSpecDict);
|
440 | actionDict.set('NewWindow', true);
|
441 | var annotationDict = new _primitives.Dict();
|
442 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
443 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
444 | annotationDict.set('A', actionDict);
|
445 | var annotationRef = new _primitives.Ref(88, 0);
|
446 | var xref = new _test_utils.XRefMock([{
|
447 | ref: annotationRef,
|
448 | data: annotationDict
|
449 | }]);
|
450 | var pdfManager = new PDFManagerMock({ docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf' });
|
451 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManager, idFactoryMock);
|
452 | var data = annotation.data;
|
453 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
454 | expect(data.url).toEqual(new URL('http://www.example.com/test/pdfs/Part II/Part II.pdf').href);
|
455 | expect(data.unsafeUrl).toEqual('Part II/Part II.pdf');
|
456 | expect(data.dest).toBeUndefined();
|
457 | expect(data.newWindow).toEqual(true);
|
458 | });
|
459 | it('should recover valid URLs from JavaScript actions having certain ' + 'white-listed formats', function () {
|
460 | function checkJsAction(params) {
|
461 | var jsEntry = params.jsEntry;
|
462 | var expectedUrl = params.expectedUrl;
|
463 | var expectedUnsafeUrl = params.expectedUnsafeUrl;
|
464 | var expectedNewWindow = params.expectedNewWindow;
|
465 | var actionDict = new _primitives.Dict();
|
466 | actionDict.set('Type', _primitives.Name.get('Action'));
|
467 | actionDict.set('S', _primitives.Name.get('JavaScript'));
|
468 | actionDict.set('JS', jsEntry);
|
469 | var annotationDict = new _primitives.Dict();
|
470 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
471 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
472 | annotationDict.set('A', actionDict);
|
473 | var annotationRef = new _primitives.Ref(46, 0);
|
474 | var xref = new _test_utils.XRefMock([{
|
475 | ref: annotationRef,
|
476 | data: annotationDict
|
477 | }]);
|
478 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
479 | var data = annotation.data;
|
480 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
481 | expect(data.url).toEqual(expectedUrl);
|
482 | expect(data.unsafeUrl).toEqual(expectedUnsafeUrl);
|
483 | expect(data.dest).toBeUndefined();
|
484 | expect(data.newWindow).toEqual(expectedNewWindow);
|
485 | }
|
486 | checkJsAction({
|
487 | jsEntry: 'function someFun() { return "qwerty"; } someFun();',
|
488 | expectedUrl: undefined,
|
489 | expectedUnsafeUrl: undefined,
|
490 | expectedNewWindow: undefined
|
491 | });
|
492 | checkJsAction({
|
493 | jsEntry: 'window.open(\'http://www.example.com/test.pdf\')',
|
494 | expectedUrl: new URL('http://www.example.com/test.pdf').href,
|
495 | expectedUnsafeUrl: 'http://www.example.com/test.pdf',
|
496 | expectedNewWindow: undefined
|
497 | });
|
498 | checkJsAction({
|
499 | jsEntry: new _stream.StringStream('app.launchURL("http://www.example.com/test.pdf", true)'),
|
500 | expectedUrl: new URL('http://www.example.com/test.pdf').href,
|
501 | expectedUnsafeUrl: 'http://www.example.com/test.pdf',
|
502 | expectedNewWindow: true
|
503 | });
|
504 | });
|
505 | it('should correctly parse a Named action', function () {
|
506 | var actionDict = new _primitives.Dict();
|
507 | actionDict.set('Type', _primitives.Name.get('Action'));
|
508 | actionDict.set('S', _primitives.Name.get('Named'));
|
509 | actionDict.set('N', _primitives.Name.get('GoToPage'));
|
510 | var annotationDict = new _primitives.Dict();
|
511 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
512 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
513 | annotationDict.set('A', actionDict);
|
514 | var annotationRef = new _primitives.Ref(12, 0);
|
515 | var xref = new _test_utils.XRefMock([{
|
516 | ref: annotationRef,
|
517 | data: annotationDict
|
518 | }]);
|
519 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
520 | var data = annotation.data;
|
521 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
522 | expect(data.url).toBeUndefined();
|
523 | expect(data.unsafeUrl).toBeUndefined();
|
524 | expect(data.action).toEqual('GoToPage');
|
525 | });
|
526 | it('should correctly parse a simple Dest', function () {
|
527 | var annotationDict = new _primitives.Dict();
|
528 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
529 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
530 | annotationDict.set('Dest', _primitives.Name.get('LI0'));
|
531 | var annotationRef = new _primitives.Ref(583, 0);
|
532 | var xref = new _test_utils.XRefMock([{
|
533 | ref: annotationRef,
|
534 | data: annotationDict
|
535 | }]);
|
536 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
537 | var data = annotation.data;
|
538 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
539 | expect(data.url).toBeUndefined();
|
540 | expect(data.unsafeUrl).toBeUndefined();
|
541 | expect(data.dest).toEqual('LI0');
|
542 | });
|
543 | it('should correctly parse a simple Dest, with explicit destination array', function () {
|
544 | var annotationDict = new _primitives.Dict();
|
545 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
546 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
547 | annotationDict.set('Dest', [new _primitives.Ref(17, 0), _primitives.Name.get('XYZ'), 0, 841.89, null]);
|
548 | var annotationRef = new _primitives.Ref(10, 0);
|
549 | var xref = new _test_utils.XRefMock([{
|
550 | ref: annotationRef,
|
551 | data: annotationDict
|
552 | }]);
|
553 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
554 | var data = annotation.data;
|
555 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
556 | expect(data.url).toBeUndefined();
|
557 | expect(data.unsafeUrl).toBeUndefined();
|
558 | expect(data.dest).toEqual([{
|
559 | num: 17,
|
560 | gen: 0
|
561 | }, { name: 'XYZ' }, 0, 841.89, null]);
|
562 | });
|
563 | it('should correctly parse a Dest, which violates the specification ' + 'by containing a dictionary', function () {
|
564 | var destDict = new _primitives.Dict();
|
565 | destDict.set('Type', _primitives.Name.get('Action'));
|
566 | destDict.set('S', _primitives.Name.get('GoTo'));
|
567 | destDict.set('D', 'page.157');
|
568 | var annotationDict = new _primitives.Dict();
|
569 | annotationDict.set('Type', _primitives.Name.get('Annot'));
|
570 | annotationDict.set('Subtype', _primitives.Name.get('Link'));
|
571 | annotationDict.set('Dest', destDict);
|
572 | var annotationRef = new _primitives.Ref(798, 0);
|
573 | var xref = new _test_utils.XRefMock([{
|
574 | ref: annotationRef,
|
575 | data: annotationDict
|
576 | }]);
|
577 | var annotation = _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock);
|
578 | var data = annotation.data;
|
579 | expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
|
580 | expect(data.url).toBeUndefined();
|
581 | expect(data.unsafeUrl).toBeUndefined();
|
582 | expect(data.dest).toEqual('page.157');
|
583 | });
|
584 | });
|
585 | describe('WidgetAnnotation', function () {
|
586 | var widgetDict;
|
587 | beforeEach(function (done) {
|
588 | widgetDict = new _primitives.Dict();
|
589 | widgetDict.set('Type', _primitives.Name.get('Annot'));
|
590 | widgetDict.set('Subtype', _primitives.Name.get('Widget'));
|
591 | done();
|
592 | });
|
593 | afterEach(function () {
|
594 | widgetDict = null;
|
595 | });
|
596 | it('should handle unknown field names', function () {
|
597 | var widgetRef = new _primitives.Ref(20, 0);
|
598 | var xref = new _test_utils.XRefMock([{
|
599 | ref: widgetRef,
|
600 | data: widgetDict
|
601 | }]);
|
602 | var annotation = _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock);
|
603 | var data = annotation.data;
|
604 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
605 | expect(data.fieldName).toEqual('');
|
606 | });
|
607 | it('should construct the field name when there are no ancestors', function () {
|
608 | widgetDict.set('T', 'foo');
|
609 | var widgetRef = new _primitives.Ref(21, 0);
|
610 | var xref = new _test_utils.XRefMock([{
|
611 | ref: widgetRef,
|
612 | data: widgetDict
|
613 | }]);
|
614 | var annotation = _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock);
|
615 | var data = annotation.data;
|
616 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
617 | expect(data.fieldName).toEqual('foo');
|
618 | });
|
619 | it('should construct the field name when there are ancestors', function () {
|
620 | var firstParent = new _primitives.Dict();
|
621 | firstParent.set('T', 'foo');
|
622 | var secondParent = new _primitives.Dict();
|
623 | secondParent.set('Parent', firstParent);
|
624 | secondParent.set('T', 'bar');
|
625 | widgetDict.set('Parent', secondParent);
|
626 | widgetDict.set('T', 'baz');
|
627 | var widgetRef = new _primitives.Ref(22, 0);
|
628 | var xref = new _test_utils.XRefMock([{
|
629 | ref: widgetRef,
|
630 | data: widgetDict
|
631 | }]);
|
632 | var annotation = _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock);
|
633 | var data = annotation.data;
|
634 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
635 | expect(data.fieldName).toEqual('foo.bar.baz');
|
636 | });
|
637 | it('should construct the field name if a parent is not a dictionary ' + '(issue 8143)', function () {
|
638 | var parentDict = new _primitives.Dict();
|
639 | parentDict.set('Parent', null);
|
640 | parentDict.set('T', 'foo');
|
641 | widgetDict.set('Parent', parentDict);
|
642 | widgetDict.set('T', 'bar');
|
643 | var widgetRef = new _primitives.Ref(22, 0);
|
644 | var xref = new _test_utils.XRefMock([{
|
645 | ref: widgetRef,
|
646 | data: widgetDict
|
647 | }]);
|
648 | var annotation = _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock);
|
649 | var data = annotation.data;
|
650 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
651 | expect(data.fieldName).toEqual('foo.bar');
|
652 | });
|
653 | });
|
654 | describe('TextWidgetAnnotation', function () {
|
655 | var textWidgetDict;
|
656 | beforeEach(function (done) {
|
657 | textWidgetDict = new _primitives.Dict();
|
658 | textWidgetDict.set('Type', _primitives.Name.get('Annot'));
|
659 | textWidgetDict.set('Subtype', _primitives.Name.get('Widget'));
|
660 | textWidgetDict.set('FT', _primitives.Name.get('Tx'));
|
661 | done();
|
662 | });
|
663 | afterEach(function () {
|
664 | textWidgetDict = null;
|
665 | });
|
666 | it('should handle unknown text alignment, maximum length and flags', function () {
|
667 | var textWidgetRef = new _primitives.Ref(124, 0);
|
668 | var xref = new _test_utils.XRefMock([{
|
669 | ref: textWidgetRef,
|
670 | data: textWidgetDict
|
671 | }]);
|
672 | var annotation = _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock);
|
673 | var data = annotation.data;
|
674 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
675 | expect(data.textAlignment).toEqual(null);
|
676 | expect(data.maxLen).toEqual(null);
|
677 | expect(data.readOnly).toEqual(false);
|
678 | expect(data.multiLine).toEqual(false);
|
679 | expect(data.comb).toEqual(false);
|
680 | });
|
681 | it('should not set invalid text alignment, maximum length and flags', function () {
|
682 | textWidgetDict.set('Q', 'center');
|
683 | textWidgetDict.set('MaxLen', 'five');
|
684 | textWidgetDict.set('Ff', 'readonly');
|
685 | var textWidgetRef = new _primitives.Ref(43, 0);
|
686 | var xref = new _test_utils.XRefMock([{
|
687 | ref: textWidgetRef,
|
688 | data: textWidgetDict
|
689 | }]);
|
690 | var annotation = _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock);
|
691 | var data = annotation.data;
|
692 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
693 | expect(data.textAlignment).toEqual(null);
|
694 | expect(data.maxLen).toEqual(null);
|
695 | expect(data.readOnly).toEqual(false);
|
696 | expect(data.multiLine).toEqual(false);
|
697 | expect(data.comb).toEqual(false);
|
698 | });
|
699 | it('should set valid text alignment, maximum length and flags', function () {
|
700 | textWidgetDict.set('Q', 1);
|
701 | textWidgetDict.set('MaxLen', 20);
|
702 | textWidgetDict.set('Ff', _util.AnnotationFieldFlag.READONLY + _util.AnnotationFieldFlag.MULTILINE);
|
703 | var textWidgetRef = new _primitives.Ref(84, 0);
|
704 | var xref = new _test_utils.XRefMock([{
|
705 | ref: textWidgetRef,
|
706 | data: textWidgetDict
|
707 | }]);
|
708 | var annotation = _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock);
|
709 | var data = annotation.data;
|
710 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
711 | expect(data.textAlignment).toEqual(1);
|
712 | expect(data.maxLen).toEqual(20);
|
713 | expect(data.readOnly).toEqual(true);
|
714 | expect(data.multiLine).toEqual(true);
|
715 | });
|
716 | it('should reject comb fields without a maximum length', function () {
|
717 | textWidgetDict.set('Ff', _util.AnnotationFieldFlag.COMB);
|
718 | var textWidgetRef = new _primitives.Ref(46, 0);
|
719 | var xref = new _test_utils.XRefMock([{
|
720 | ref: textWidgetRef,
|
721 | data: textWidgetDict
|
722 | }]);
|
723 | var annotation = _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock);
|
724 | var data = annotation.data;
|
725 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
726 | expect(data.comb).toEqual(false);
|
727 | });
|
728 | it('should accept comb fields with a maximum length', function () {
|
729 | textWidgetDict.set('MaxLen', 20);
|
730 | textWidgetDict.set('Ff', _util.AnnotationFieldFlag.COMB);
|
731 | var textWidgetRef = new _primitives.Ref(46, 0);
|
732 | var xref = new _test_utils.XRefMock([{
|
733 | ref: textWidgetRef,
|
734 | data: textWidgetDict
|
735 | }]);
|
736 | var annotation = _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock);
|
737 | var data = annotation.data;
|
738 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
739 | expect(data.comb).toEqual(true);
|
740 | });
|
741 | it('should only accept comb fields when the flags are valid', function () {
|
742 | var invalidFieldFlags = [_util.AnnotationFieldFlag.MULTILINE, _util.AnnotationFieldFlag.PASSWORD, _util.AnnotationFieldFlag.FILESELECT];
|
743 | var flags = _util.AnnotationFieldFlag.COMB + _util.AnnotationFieldFlag.MULTILINE + _util.AnnotationFieldFlag.PASSWORD + _util.AnnotationFieldFlag.FILESELECT;
|
744 | for (var i = 0, ii = invalidFieldFlags.length; i <= ii; i++) {
|
745 | textWidgetDict.set('MaxLen', 20);
|
746 | textWidgetDict.set('Ff', flags);
|
747 | var textWidgetRef = new _primitives.Ref(93, 0);
|
748 | var xref = new _test_utils.XRefMock([{
|
749 | ref: textWidgetRef,
|
750 | data: textWidgetDict
|
751 | }]);
|
752 | var annotation = _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock);
|
753 | var data = annotation.data;
|
754 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
755 | var valid = invalidFieldFlags.length === 0;
|
756 | expect(data.comb).toEqual(valid);
|
757 | if (!valid) {
|
758 | flags -= invalidFieldFlags.splice(-1, 1);
|
759 | }
|
760 | }
|
761 | });
|
762 | });
|
763 | describe('ButtonWidgetAnnotation', function () {
|
764 | var buttonWidgetDict;
|
765 | beforeEach(function (done) {
|
766 | buttonWidgetDict = new _primitives.Dict();
|
767 | buttonWidgetDict.set('Type', _primitives.Name.get('Annot'));
|
768 | buttonWidgetDict.set('Subtype', _primitives.Name.get('Widget'));
|
769 | buttonWidgetDict.set('FT', _primitives.Name.get('Btn'));
|
770 | done();
|
771 | });
|
772 | afterEach(function () {
|
773 | buttonWidgetDict = null;
|
774 | });
|
775 | it('should handle checkboxes', function () {
|
776 | buttonWidgetDict.set('V', _primitives.Name.get('1'));
|
777 | var buttonWidgetRef = new _primitives.Ref(124, 0);
|
778 | var xref = new _test_utils.XRefMock([{
|
779 | ref: buttonWidgetRef,
|
780 | data: buttonWidgetDict
|
781 | }]);
|
782 | var annotation = _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock);
|
783 | var data = annotation.data;
|
784 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
785 | expect(data.checkBox).toEqual(true);
|
786 | expect(data.fieldValue).toEqual('1');
|
787 | expect(data.radioButton).toEqual(false);
|
788 | });
|
789 | it('should handle radio buttons with a field value', function () {
|
790 | var parentDict = new _primitives.Dict();
|
791 | parentDict.set('V', _primitives.Name.get('1'));
|
792 | var normalAppearanceStateDict = new _primitives.Dict();
|
793 | normalAppearanceStateDict.set('2', null);
|
794 | var appearanceStatesDict = new _primitives.Dict();
|
795 | appearanceStatesDict.set('N', normalAppearanceStateDict);
|
796 | buttonWidgetDict.set('Ff', _util.AnnotationFieldFlag.RADIO);
|
797 | buttonWidgetDict.set('Parent', parentDict);
|
798 | buttonWidgetDict.set('AP', appearanceStatesDict);
|
799 | var buttonWidgetRef = new _primitives.Ref(124, 0);
|
800 | var xref = new _test_utils.XRefMock([{
|
801 | ref: buttonWidgetRef,
|
802 | data: buttonWidgetDict
|
803 | }]);
|
804 | var annotation = _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock);
|
805 | var data = annotation.data;
|
806 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
807 | expect(data.checkBox).toEqual(false);
|
808 | expect(data.radioButton).toEqual(true);
|
809 | expect(data.fieldValue).toEqual('1');
|
810 | expect(data.buttonValue).toEqual('2');
|
811 | });
|
812 | it('should handle radio buttons without a field value', function () {
|
813 | var normalAppearanceStateDict = new _primitives.Dict();
|
814 | normalAppearanceStateDict.set('2', null);
|
815 | var appearanceStatesDict = new _primitives.Dict();
|
816 | appearanceStatesDict.set('N', normalAppearanceStateDict);
|
817 | buttonWidgetDict.set('Ff', _util.AnnotationFieldFlag.RADIO);
|
818 | buttonWidgetDict.set('AP', appearanceStatesDict);
|
819 | var buttonWidgetRef = new _primitives.Ref(124, 0);
|
820 | var xref = new _test_utils.XRefMock([{
|
821 | ref: buttonWidgetRef,
|
822 | data: buttonWidgetDict
|
823 | }]);
|
824 | var annotation = _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock);
|
825 | var data = annotation.data;
|
826 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
827 | expect(data.checkBox).toEqual(false);
|
828 | expect(data.radioButton).toEqual(true);
|
829 | expect(data.fieldValue).toEqual(null);
|
830 | expect(data.buttonValue).toEqual('2');
|
831 | });
|
832 | });
|
833 | describe('ChoiceWidgetAnnotation', function () {
|
834 | var choiceWidgetDict;
|
835 | beforeEach(function (done) {
|
836 | choiceWidgetDict = new _primitives.Dict();
|
837 | choiceWidgetDict.set('Type', _primitives.Name.get('Annot'));
|
838 | choiceWidgetDict.set('Subtype', _primitives.Name.get('Widget'));
|
839 | choiceWidgetDict.set('FT', _primitives.Name.get('Ch'));
|
840 | done();
|
841 | });
|
842 | afterEach(function () {
|
843 | choiceWidgetDict = null;
|
844 | });
|
845 | it('should handle missing option arrays', function () {
|
846 | var choiceWidgetRef = new _primitives.Ref(122, 0);
|
847 | var xref = new _test_utils.XRefMock([{
|
848 | ref: choiceWidgetRef,
|
849 | data: choiceWidgetDict
|
850 | }]);
|
851 | var annotation = _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock);
|
852 | var data = annotation.data;
|
853 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
854 | expect(data.options).toEqual([]);
|
855 | });
|
856 | it('should handle option arrays with array elements', function () {
|
857 | var optionBarRef = new _primitives.Ref(20, 0);
|
858 | var optionBarStr = 'Bar';
|
859 | var optionOneRef = new _primitives.Ref(10, 0);
|
860 | var optionOneArr = ['bar_export', optionBarRef];
|
861 | var options = [['foo_export', 'Foo'], optionOneRef];
|
862 | var expected = [{
|
863 | exportValue: 'foo_export',
|
864 | displayValue: 'Foo'
|
865 | }, {
|
866 | exportValue: 'bar_export',
|
867 | displayValue: 'Bar'
|
868 | }];
|
869 | choiceWidgetDict.set('Opt', options);
|
870 | var choiceWidgetRef = new _primitives.Ref(123, 0);
|
871 | var xref = new _test_utils.XRefMock([{
|
872 | ref: choiceWidgetRef,
|
873 | data: choiceWidgetDict
|
874 | }, {
|
875 | ref: optionBarRef,
|
876 | data: optionBarStr
|
877 | }, {
|
878 | ref: optionOneRef,
|
879 | data: optionOneArr
|
880 | }]);
|
881 | var annotation = _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock);
|
882 | var data = annotation.data;
|
883 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
884 | expect(data.options).toEqual(expected);
|
885 | });
|
886 | it('should handle option arrays with string elements', function () {
|
887 | var optionBarRef = new _primitives.Ref(10, 0);
|
888 | var optionBarStr = 'Bar';
|
889 | var options = ['Foo', optionBarRef];
|
890 | var expected = [{
|
891 | exportValue: 'Foo',
|
892 | displayValue: 'Foo'
|
893 | }, {
|
894 | exportValue: 'Bar',
|
895 | displayValue: 'Bar'
|
896 | }];
|
897 | choiceWidgetDict.set('Opt', options);
|
898 | var choiceWidgetRef = new _primitives.Ref(981, 0);
|
899 | var xref = new _test_utils.XRefMock([{
|
900 | ref: choiceWidgetRef,
|
901 | data: choiceWidgetDict
|
902 | }, {
|
903 | ref: optionBarRef,
|
904 | data: optionBarStr
|
905 | }]);
|
906 | var annotation = _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock);
|
907 | var data = annotation.data;
|
908 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
909 | expect(data.options).toEqual(expected);
|
910 | });
|
911 | it('should handle inherited option arrays (issue 8094)', function () {
|
912 | var options = [['Value1', 'Description1'], ['Value2', 'Description2']];
|
913 | var expected = [{
|
914 | exportValue: 'Value1',
|
915 | displayValue: 'Description1'
|
916 | }, {
|
917 | exportValue: 'Value2',
|
918 | displayValue: 'Description2'
|
919 | }];
|
920 | var parentDict = new _primitives.Dict();
|
921 | parentDict.set('Opt', options);
|
922 | choiceWidgetDict.set('Parent', parentDict);
|
923 | var choiceWidgetRef = new _primitives.Ref(123, 0);
|
924 | var xref = new _test_utils.XRefMock([{
|
925 | ref: choiceWidgetRef,
|
926 | data: choiceWidgetDict
|
927 | }]);
|
928 | var annotation = _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock);
|
929 | var data = annotation.data;
|
930 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
931 | expect(data.options).toEqual(expected);
|
932 | });
|
933 | it('should sanitize display values in option arrays (issue 8947)', function () {
|
934 | var options = ['\xFE\xFF\x00F\x00o\x00o'];
|
935 | var expected = [{
|
936 | exportValue: '\xFE\xFF\x00F\x00o\x00o',
|
937 | displayValue: 'Foo'
|
938 | }];
|
939 | choiceWidgetDict.set('Opt', options);
|
940 | var choiceWidgetRef = new _primitives.Ref(984, 0);
|
941 | var xref = new _test_utils.XRefMock([{
|
942 | ref: choiceWidgetRef,
|
943 | data: choiceWidgetDict
|
944 | }]);
|
945 | var annotation = _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock);
|
946 | var data = annotation.data;
|
947 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
948 | expect(data.options).toEqual(expected);
|
949 | });
|
950 | it('should handle array field values', function () {
|
951 | var fieldValue = ['Foo', 'Bar'];
|
952 | choiceWidgetDict.set('V', fieldValue);
|
953 | var choiceWidgetRef = new _primitives.Ref(968, 0);
|
954 | var xref = new _test_utils.XRefMock([{
|
955 | ref: choiceWidgetRef,
|
956 | data: choiceWidgetDict
|
957 | }]);
|
958 | var annotation = _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock);
|
959 | var data = annotation.data;
|
960 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
961 | expect(data.fieldValue).toEqual(fieldValue);
|
962 | });
|
963 | it('should handle string field values', function () {
|
964 | var fieldValue = 'Foo';
|
965 | choiceWidgetDict.set('V', fieldValue);
|
966 | var choiceWidgetRef = new _primitives.Ref(978, 0);
|
967 | var xref = new _test_utils.XRefMock([{
|
968 | ref: choiceWidgetRef,
|
969 | data: choiceWidgetDict
|
970 | }]);
|
971 | var annotation = _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock);
|
972 | var data = annotation.data;
|
973 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
974 | expect(data.fieldValue).toEqual([fieldValue]);
|
975 | });
|
976 | it('should handle unknown flags', function () {
|
977 | var choiceWidgetRef = new _primitives.Ref(166, 0);
|
978 | var xref = new _test_utils.XRefMock([{
|
979 | ref: choiceWidgetRef,
|
980 | data: choiceWidgetDict
|
981 | }]);
|
982 | var annotation = _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock);
|
983 | var data = annotation.data;
|
984 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
985 | expect(data.readOnly).toEqual(false);
|
986 | expect(data.combo).toEqual(false);
|
987 | expect(data.multiSelect).toEqual(false);
|
988 | });
|
989 | it('should not set invalid flags', function () {
|
990 | choiceWidgetDict.set('Ff', 'readonly');
|
991 | var choiceWidgetRef = new _primitives.Ref(165, 0);
|
992 | var xref = new _test_utils.XRefMock([{
|
993 | ref: choiceWidgetRef,
|
994 | data: choiceWidgetDict
|
995 | }]);
|
996 | var annotation = _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock);
|
997 | var data = annotation.data;
|
998 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
999 | expect(data.readOnly).toEqual(false);
|
1000 | expect(data.combo).toEqual(false);
|
1001 | expect(data.multiSelect).toEqual(false);
|
1002 | });
|
1003 | it('should set valid flags', function () {
|
1004 | choiceWidgetDict.set('Ff', _util.AnnotationFieldFlag.READONLY + _util.AnnotationFieldFlag.COMBO + _util.AnnotationFieldFlag.MULTISELECT);
|
1005 | var choiceWidgetRef = new _primitives.Ref(512, 0);
|
1006 | var xref = new _test_utils.XRefMock([{
|
1007 | ref: choiceWidgetRef,
|
1008 | data: choiceWidgetDict
|
1009 | }]);
|
1010 | var annotation = _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock);
|
1011 | var data = annotation.data;
|
1012 | expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
|
1013 | expect(data.readOnly).toEqual(true);
|
1014 | expect(data.combo).toEqual(true);
|
1015 | expect(data.multiSelect).toEqual(true);
|
1016 | });
|
1017 | });
|
1018 | describe('LineAnnotation', function () {
|
1019 | it('should set the line coordinates', function () {
|
1020 | var lineDict = new _primitives.Dict();
|
1021 | lineDict.set('Type', _primitives.Name.get('Annot'));
|
1022 | lineDict.set('Subtype', _primitives.Name.get('Line'));
|
1023 | lineDict.set('L', [1, 2, 3, 4]);
|
1024 | var lineRef = new _primitives.Ref(122, 0);
|
1025 | var xref = new _test_utils.XRefMock([{
|
1026 | ref: lineRef,
|
1027 | data: lineDict
|
1028 | }]);
|
1029 | var annotation = _annotation.AnnotationFactory.create(xref, lineRef, pdfManagerMock, idFactoryMock);
|
1030 | var data = annotation.data;
|
1031 | expect(data.annotationType).toEqual(_util.AnnotationType.LINE);
|
1032 | expect(data.lineCoordinates).toEqual([1, 2, 3, 4]);
|
1033 | });
|
1034 | });
|
1035 | describe('FileAttachmentAnnotation', function () {
|
1036 | it('should correctly parse a file attachment', function () {
|
1037 | var fileStream = new _stream.StringStream('<<\n' + '/Type /EmbeddedFile\n' + '/Subtype /text#2Fplain\n' + '>>\n' + 'stream\n' + 'Test attachment' + 'endstream\n');
|
1038 | var lexer = new _parser.Lexer(fileStream);
|
1039 | var parser = new _parser.Parser(lexer, true);
|
1040 | var fileStreamRef = new _primitives.Ref(18, 0);
|
1041 | var fileStreamDict = parser.getObj();
|
1042 | var embeddedFileDict = new _primitives.Dict();
|
1043 | embeddedFileDict.set('F', fileStreamRef);
|
1044 | var fileSpecRef = new _primitives.Ref(19, 0);
|
1045 | var fileSpecDict = new _primitives.Dict();
|
1046 | fileSpecDict.set('Type', _primitives.Name.get('Filespec'));
|
1047 | fileSpecDict.set('Desc', '');
|
1048 | fileSpecDict.set('EF', embeddedFileDict);
|
1049 | fileSpecDict.set('UF', 'Test.txt');
|
1050 | var fileAttachmentRef = new _primitives.Ref(20, 0);
|
1051 | var fileAttachmentDict = new _primitives.Dict();
|
1052 | fileAttachmentDict.set('Type', _primitives.Name.get('Annot'));
|
1053 | fileAttachmentDict.set('Subtype', _primitives.Name.get('FileAttachment'));
|
1054 | fileAttachmentDict.set('FS', fileSpecRef);
|
1055 | fileAttachmentDict.set('T', 'Topic');
|
1056 | fileAttachmentDict.set('Contents', 'Test.txt');
|
1057 | var xref = new _test_utils.XRefMock([{
|
1058 | ref: fileStreamRef,
|
1059 | data: fileStreamDict
|
1060 | }, {
|
1061 | ref: fileSpecRef,
|
1062 | data: fileSpecDict
|
1063 | }, {
|
1064 | ref: fileAttachmentRef,
|
1065 | data: fileAttachmentDict
|
1066 | }]);
|
1067 | embeddedFileDict.assignXref(xref);
|
1068 | fileSpecDict.assignXref(xref);
|
1069 | fileAttachmentDict.assignXref(xref);
|
1070 | var annotation = _annotation.AnnotationFactory.create(xref, fileAttachmentRef, pdfManagerMock, idFactoryMock);
|
1071 | var data = annotation.data;
|
1072 | expect(data.annotationType).toEqual(_util.AnnotationType.FILEATTACHMENT);
|
1073 | expect(data.file.filename).toEqual('Test.txt');
|
1074 | expect(data.file.content).toEqual((0, _util.stringToBytes)('Test attachment'));
|
1075 | });
|
1076 | });
|
1077 | describe('PopupAnnotation', function () {
|
1078 | it('should inherit the parent flags when the Popup is not viewable, ' + 'but the parent is (PR 7352)', function () {
|
1079 | var parentDict = new _primitives.Dict();
|
1080 | parentDict.set('Type', _primitives.Name.get('Annot'));
|
1081 | parentDict.set('Subtype', _primitives.Name.get('Text'));
|
1082 | parentDict.set('F', 28);
|
1083 | var popupDict = new _primitives.Dict();
|
1084 | popupDict.set('Type', _primitives.Name.get('Annot'));
|
1085 | popupDict.set('Subtype', _primitives.Name.get('Popup'));
|
1086 | popupDict.set('F', 25);
|
1087 | popupDict.set('Parent', parentDict);
|
1088 | var popupRef = new _primitives.Ref(13, 0);
|
1089 | var xref = new _test_utils.XRefMock([{
|
1090 | ref: popupRef,
|
1091 | data: popupDict
|
1092 | }]);
|
1093 | var annotation = _annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock);
|
1094 | var data = annotation.data;
|
1095 | expect(data.annotationType).toEqual(_util.AnnotationType.POPUP);
|
1096 | expect(data.annotationFlags).toEqual(25);
|
1097 | expect(annotation.viewable).toEqual(true);
|
1098 | });
|
1099 | });
|
1100 | }); |
\ | No newline at end of file |