pdfjs-dist 2.5.207 → 2.6.347

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.

Files changed (133) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +867 -216
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +10214 -8547
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/es5/build/pdf.js +2023 -1046
  9. package/es5/build/pdf.js.map +1 -1
  10. package/es5/build/pdf.min.js +22 -0
  11. package/es5/build/pdf.worker.js +11136 -8144
  12. package/es5/build/pdf.worker.js.map +1 -1
  13. package/es5/build/pdf.worker.min.js +22 -0
  14. package/es5/image_decoders/pdf.image_decoders.js +12529 -0
  15. package/es5/image_decoders/pdf.image_decoders.js.map +1 -0
  16. package/es5/image_decoders/pdf.image_decoders.min.js +22 -0
  17. package/es5/web/images/shadow.png +0 -0
  18. package/es5/web/pdf_viewer.css +8 -5
  19. package/es5/web/pdf_viewer.js +195 -51
  20. package/es5/web/pdf_viewer.js.map +1 -1
  21. package/image_decoders/pdf.image_decoders.js +24 -16
  22. package/image_decoders/pdf.image_decoders.js.map +1 -1
  23. package/image_decoders/pdf.image_decoders.min.js +1 -1
  24. package/lib/core/annotation.js +479 -43
  25. package/lib/core/cff_parser.js +643 -615
  26. package/lib/core/chunked_stream.js +64 -50
  27. package/lib/core/colorspace.js +126 -104
  28. package/lib/core/crypto.js +37 -0
  29. package/lib/core/document.js +128 -75
  30. package/lib/core/evaluator.js +3015 -2754
  31. package/lib/core/fonts.js +47 -46
  32. package/lib/core/function.js +79 -6
  33. package/lib/core/image.js +364 -357
  34. package/lib/core/image_utils.js +109 -8
  35. package/lib/core/jpg.js +8 -3
  36. package/lib/core/obj.js +255 -34
  37. package/lib/core/operator_list.js +17 -15
  38. package/lib/core/parser.js +40 -3
  39. package/lib/core/pattern.js +24 -11
  40. package/lib/core/primitives.js +112 -53
  41. package/lib/core/type1_parser.js +2 -0
  42. package/lib/core/worker.js +102 -37
  43. package/lib/core/writer.js +242 -0
  44. package/lib/display/annotation_layer.js +51 -10
  45. package/lib/display/annotation_storage.js +89 -0
  46. package/lib/display/api.js +140 -54
  47. package/lib/display/canvas.js +215 -46
  48. package/lib/display/display_utils.js +55 -18
  49. package/lib/display/fetch_stream.js +6 -0
  50. package/lib/display/font_loader.js +26 -15
  51. package/lib/display/metadata.js +1 -7
  52. package/lib/display/network.js +0 -14
  53. package/lib/display/node_utils.js +87 -0
  54. package/lib/display/optional_content_config.js +184 -0
  55. package/lib/display/svg.js +1 -1
  56. package/lib/display/text_layer.js +4 -1
  57. package/lib/pdf.js +2 -2
  58. package/lib/pdf.worker.js +2 -2
  59. package/lib/shared/is_node.js +1 -1
  60. package/lib/shared/util.js +13 -10
  61. package/lib/test/unit/annotation_spec.js +520 -50
  62. package/lib/test/unit/annotation_storage_spec.js +83 -0
  63. package/lib/test/unit/api_spec.js +16 -6
  64. package/lib/test/unit/cmap_spec.js +4 -4
  65. package/lib/test/unit/colorspace_spec.js +216 -24
  66. package/lib/test/unit/crypto_spec.js +51 -4
  67. package/lib/test/unit/custom_spec.js +129 -1
  68. package/lib/test/unit/document_spec.js +112 -1
  69. package/lib/test/unit/evaluator_spec.js +29 -10
  70. package/lib/test/unit/jasmine-boot.js +1 -1
  71. package/lib/test/unit/metadata_spec.js +3 -3
  72. package/lib/test/unit/primitives_spec.js +242 -63
  73. package/lib/test/unit/test_utils.js +42 -89
  74. package/lib/test/unit/testreporter.js +17 -6
  75. package/lib/test/unit/util_spec.js +13 -12
  76. package/lib/test/unit/writer_spec.js +84 -0
  77. package/lib/web/annotation_layer_builder.js +13 -9
  78. package/lib/web/app.js +231 -26
  79. package/lib/web/app_options.js +1 -6
  80. package/lib/web/base_tree_viewer.js +100 -0
  81. package/lib/web/base_viewer.js +53 -4
  82. package/lib/web/download_manager.js +3 -10
  83. package/lib/web/firefox_print_service.js +32 -12
  84. package/lib/web/firefoxcom.js +20 -6
  85. package/lib/web/interfaces.js +1 -1
  86. package/lib/web/pdf_attachment_viewer.js +80 -38
  87. package/lib/web/pdf_find_controller.js +2 -1
  88. package/lib/web/pdf_layer_viewer.js +208 -0
  89. package/lib/web/pdf_outline_viewer.js +24 -57
  90. package/lib/web/pdf_page_view.js +29 -6
  91. package/lib/web/pdf_print_service.js +13 -11
  92. package/lib/web/pdf_sidebar.js +46 -25
  93. package/lib/web/pdf_thumbnail_view.js +16 -3
  94. package/lib/web/pdf_thumbnail_viewer.js +17 -1
  95. package/lib/web/pdf_viewer.component.js +2 -2
  96. package/lib/web/preferences.js +1 -1
  97. package/lib/web/toolbar.js +1 -1
  98. package/lib/web/ui_utils.js +7 -1
  99. package/package.json +3 -1
  100. package/types/display/annotation_layer.d.ts +61 -0
  101. package/types/display/annotation_storage.d.ts +36 -0
  102. package/types/display/api.d.ts +1107 -0
  103. package/types/display/api_compatibility.d.ts +1 -0
  104. package/types/display/canvas.d.ts +4 -0
  105. package/types/display/content_disposition.d.ts +7 -0
  106. package/types/display/display_utils.d.ts +243 -0
  107. package/types/display/fetch_stream.d.ts +67 -0
  108. package/types/display/font_loader.d.ts +19 -0
  109. package/types/display/metadata.d.ts +9 -0
  110. package/types/display/network.d.ts +80 -0
  111. package/types/display/network_utils.d.ts +14 -0
  112. package/types/display/node_stream.d.ts +72 -0
  113. package/types/display/node_utils.d.ts +6 -0
  114. package/types/display/optional_content_config.d.ts +12 -0
  115. package/types/display/pattern_helper.d.ts +5 -0
  116. package/types/display/svg.d.ts +2 -0
  117. package/types/display/text_layer.d.ts +83 -0
  118. package/types/display/transport_stream.d.ts +57 -0
  119. package/types/display/webgl.d.ts +20 -0
  120. package/types/display/worker_options.d.ts +27 -0
  121. package/types/display/xml_parser.d.ts +35 -0
  122. package/types/pdf.d.ts +33 -0
  123. package/types/shared/compatibility.d.ts +1 -0
  124. package/types/shared/is_node.d.ts +1 -0
  125. package/types/shared/message_handler.d.ts +62 -0
  126. package/types/shared/util.d.ts +421 -0
  127. package/web/images/shadow.png +0 -0
  128. package/web/pdf_viewer.css +8 -5
  129. package/web/pdf_viewer.js +109 -33
  130. package/web/pdf_viewer.js.map +1 -1
  131. package/webpack.js +1 -9
  132. package/es5/web/images/texture.png +0 -0
  133. package/web/images/texture.png +0 -0
@@ -31,12 +31,21 @@ var _primitives = require("../../core/primitives.js");
31
31
 
32
32
  var _parser = require("../../core/parser.js");
33
33
 
34
+ var _evaluator = require("../../core/evaluator.js");
35
+
34
36
  var _stream = require("../../core/stream.js");
35
37
 
38
+ var _worker = require("../../core/worker.js");
39
+
36
40
  describe("annotation", function () {
37
41
  class PDFManagerMock {
38
42
  constructor(params) {
39
43
  this.docBaseUrl = params.docBaseUrl || null;
44
+ this.pdfDocument = {
45
+ catalog: {
46
+ acroForm: new _primitives.Dict()
47
+ }
48
+ };
40
49
  }
41
50
 
42
51
  ensure(obj, prop, args) {
@@ -51,19 +60,44 @@ describe("annotation", function () {
51
60
  });
52
61
  }
53
62
 
63
+ ensureCatalog(prop, args) {
64
+ return this.ensure(this.pdfDocument.catalog, prop, args);
65
+ }
66
+
67
+ }
68
+
69
+ function HandlerMock() {
70
+ this.inputs = [];
54
71
  }
55
72
 
56
- let pdfManagerMock, idFactoryMock;
73
+ HandlerMock.prototype = {
74
+ send(name, data) {
75
+ this.inputs.push({
76
+ name,
77
+ data
78
+ });
79
+ }
80
+
81
+ };
82
+ let pdfManagerMock, idFactoryMock, partialEvaluator;
57
83
  beforeAll(function (done) {
58
84
  pdfManagerMock = new PDFManagerMock({
59
85
  docBaseUrl: null
60
86
  });
61
87
  idFactoryMock = (0, _test_utils.createIdFactory)(0);
88
+ partialEvaluator = new _evaluator.PartialEvaluator({
89
+ xref: new _test_utils.XRefMock(),
90
+ handler: new HandlerMock(),
91
+ pageIndex: 0,
92
+ idFactory: (0, _test_utils.createIdFactory)(0),
93
+ fontCache: new _primitives.RefSetCache()
94
+ });
62
95
  done();
63
96
  });
64
97
  afterAll(function () {
65
98
  pdfManagerMock = null;
66
99
  idFactoryMock = null;
100
+ partialEvaluator = null;
67
101
  });
68
102
  describe("AnnotationFactory", function () {
69
103
  it("should get id for annotation", function (done) {
@@ -1210,16 +1244,34 @@ describe("annotation", function () {
1210
1244
  });
1211
1245
  });
1212
1246
  describe("TextWidgetAnnotation", function () {
1213
- let textWidgetDict;
1247
+ let textWidgetDict, fontRefObj;
1214
1248
  beforeEach(function (done) {
1215
1249
  textWidgetDict = new _primitives.Dict();
1216
1250
  textWidgetDict.set("Type", _primitives.Name.get("Annot"));
1217
1251
  textWidgetDict.set("Subtype", _primitives.Name.get("Widget"));
1218
1252
  textWidgetDict.set("FT", _primitives.Name.get("Tx"));
1253
+ const helvDict = new _primitives.Dict();
1254
+ helvDict.set("BaseFont", _primitives.Name.get("Helvetica"));
1255
+ helvDict.set("Type", _primitives.Name.get("Font"));
1256
+ helvDict.set("Subtype", _primitives.Name.get("Type1"));
1257
+
1258
+ const fontRef = _primitives.Ref.get(314, 0);
1259
+
1260
+ fontRefObj = {
1261
+ ref: fontRef,
1262
+ data: helvDict
1263
+ };
1264
+ const resourceDict = new _primitives.Dict();
1265
+ const fontDict = new _primitives.Dict();
1266
+ fontDict.set("Helv", fontRef);
1267
+ resourceDict.set("Font", fontDict);
1268
+ textWidgetDict.set("DA", "/Helv 5 Tf");
1269
+ textWidgetDict.set("DR", resourceDict);
1270
+ textWidgetDict.set("Rect", [0, 0, 32, 10]);
1219
1271
  done();
1220
1272
  });
1221
1273
  afterEach(function () {
1222
- textWidgetDict = null;
1274
+ textWidgetDict = fontRefObj = null;
1223
1275
  });
1224
1276
  it("should handle unknown text alignment, maximum length and flags", function (done) {
1225
1277
  const textWidgetRef = _primitives.Ref.get(124, 0);
@@ -1357,6 +1409,164 @@ describe("annotation", function () {
1357
1409
 
1358
1410
  promise.then(done, done.fail);
1359
1411
  });
1412
+ it("should render regular text for printing", function (done) {
1413
+ const textWidgetRef = _primitives.Ref.get(271, 0);
1414
+
1415
+ const xref = new _test_utils.XRefMock([{
1416
+ ref: textWidgetRef,
1417
+ data: textWidgetDict
1418
+ }, fontRefObj]);
1419
+ const task = new _worker.WorkerTask("test print");
1420
+ partialEvaluator.xref = xref;
1421
+
1422
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1423
+ const id = annotation.data.id;
1424
+ const annotationStorage = {};
1425
+ annotationStorage[id] = "test\\print";
1426
+ return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1427
+ }, done.fail).then(appearance => {
1428
+ expect(appearance).toEqual("/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 0 Tm" + " 2.00 2.00 Td (test\\\\print) Tj ET Q EMC");
1429
+ done();
1430
+ }, done.fail);
1431
+ });
1432
+ it("should render auto-sized text for printing", function (done) {
1433
+ textWidgetDict.set("DA", "/Helv 0 Tf");
1434
+
1435
+ const textWidgetRef = _primitives.Ref.get(271, 0);
1436
+
1437
+ const xref = new _test_utils.XRefMock([{
1438
+ ref: textWidgetRef,
1439
+ data: textWidgetDict
1440
+ }, fontRefObj]);
1441
+ const task = new _worker.WorkerTask("test print");
1442
+ partialEvaluator.xref = xref;
1443
+
1444
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1445
+ const id = annotation.data.id;
1446
+ const annotationStorage = {};
1447
+ annotationStorage[id] = "test (print)";
1448
+ return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1449
+ }, done.fail).then(appearance => {
1450
+ expect(appearance).toEqual("/Tx BMC q BT /Helv 11 Tf 1 0 0 1 0 0 Tm" + " 2.00 2.00 Td (test \\(print\\)) Tj ET Q EMC");
1451
+ done();
1452
+ }, done.fail);
1453
+ });
1454
+ it("should not render a password for printing", function (done) {
1455
+ textWidgetDict.set("Ff", _util.AnnotationFieldFlag.PASSWORD);
1456
+
1457
+ const textWidgetRef = _primitives.Ref.get(271, 0);
1458
+
1459
+ const xref = new _test_utils.XRefMock([{
1460
+ ref: textWidgetRef,
1461
+ data: textWidgetDict
1462
+ }, fontRefObj]);
1463
+ const task = new _worker.WorkerTask("test print");
1464
+ partialEvaluator.xref = xref;
1465
+
1466
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1467
+ const id = annotation.data.id;
1468
+ const annotationStorage = {};
1469
+ annotationStorage[id] = "mypassword";
1470
+ return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1471
+ }, done.fail).then(appearance => {
1472
+ expect(appearance).toEqual(null);
1473
+ done();
1474
+ }, done.fail);
1475
+ });
1476
+ it("should render multiline text for printing", function (done) {
1477
+ textWidgetDict.set("Ff", _util.AnnotationFieldFlag.MULTILINE);
1478
+
1479
+ const textWidgetRef = _primitives.Ref.get(271, 0);
1480
+
1481
+ const xref = new _test_utils.XRefMock([{
1482
+ ref: textWidgetRef,
1483
+ data: textWidgetDict
1484
+ }, fontRefObj]);
1485
+ const task = new _worker.WorkerTask("test print");
1486
+ partialEvaluator.xref = xref;
1487
+
1488
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1489
+ const id = annotation.data.id;
1490
+ const annotationStorage = {};
1491
+ annotationStorage[id] = "a aa aaa aaaa aaaaa aaaaaa " + "pneumonoultramicroscopicsilicovolcanoconiosis";
1492
+ return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1493
+ }, done.fail).then(appearance => {
1494
+ expect(appearance).toEqual("/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 10 Tm " + "2.00 -5.00 Td (a aa aaa ) Tj\n" + "0.00 -5.00 Td (aaaa aaaaa ) Tj\n" + "0.00 -5.00 Td (aaaaaa ) Tj\n" + "0.00 -5.00 Td (pneumonoultr) Tj\n" + "0.00 -5.00 Td (amicroscopi) Tj\n" + "0.00 -5.00 Td (csilicovolca) Tj\n" + "0.00 -5.00 Td (noconiosis) Tj ET Q EMC");
1495
+ done();
1496
+ }, done.fail);
1497
+ });
1498
+ it("should render multiline text with various EOL for printing", function (done) {
1499
+ textWidgetDict.set("Ff", _util.AnnotationFieldFlag.MULTILINE);
1500
+ textWidgetDict.set("Rect", [0, 0, 128, 10]);
1501
+
1502
+ const textWidgetRef = _primitives.Ref.get(271, 0);
1503
+
1504
+ const xref = new _test_utils.XRefMock([{
1505
+ ref: textWidgetRef,
1506
+ data: textWidgetDict
1507
+ }, fontRefObj]);
1508
+ const task = new _worker.WorkerTask("test print");
1509
+ partialEvaluator.xref = xref;
1510
+ const expectedAppearance = "/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 10 Tm " + "2.00 -5.00 Td " + "(Lorem ipsum dolor sit amet, consectetur adipiscing elit.) Tj\n" + "0.00 -5.00 Td " + "(Aliquam vitae felis ac lectus bibendum ultricies quis non) Tj\n" + "0.00 -5.00 Td " + "( diam.) Tj\n" + "0.00 -5.00 Td " + "(Morbi id porttitor quam, a iaculis dui.) Tj\n" + "0.00 -5.00 Td " + "(Pellentesque habitant morbi tristique senectus et netus ) Tj\n" + "0.00 -5.00 Td " + "(et malesuada fames ac turpis egestas.) Tj\n" + "0.00 -5.00 Td () Tj\n" + "0.00 -5.00 Td () Tj\n" + "0.00 -5.00 Td " + "(Nulla consectetur, ligula in tincidunt placerat, velit ) Tj\n" + "0.00 -5.00 Td " + "(augue consectetur orci, sed mattis libero nunc ut massa.) Tj\n" + "0.00 -5.00 Td " + "(Etiam facilisis tempus interdum.) Tj ET Q EMC";
1511
+
1512
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1513
+ const id = annotation.data.id;
1514
+ const annotationStorage = {};
1515
+ annotationStorage[id] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r" + "Aliquam vitae felis ac lectus bibendum ultricies quis non diam.\n" + "Morbi id porttitor quam, a iaculis dui.\r\n" + "Pellentesque habitant morbi tristique senectus et " + "netus et malesuada fames ac turpis egestas.\n\r\n\r" + "Nulla consectetur, ligula in tincidunt placerat, " + "velit augue consectetur orci, sed mattis libero nunc ut massa.\r" + "Etiam facilisis tempus interdum.";
1516
+ return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1517
+ }, done.fail).then(appearance => {
1518
+ expect(appearance).toEqual(expectedAppearance);
1519
+ done();
1520
+ }, done.fail);
1521
+ });
1522
+ it("should render comb for printing", function (done) {
1523
+ textWidgetDict.set("Ff", _util.AnnotationFieldFlag.COMB);
1524
+ textWidgetDict.set("MaxLen", 4);
1525
+
1526
+ const textWidgetRef = _primitives.Ref.get(271, 0);
1527
+
1528
+ const xref = new _test_utils.XRefMock([{
1529
+ ref: textWidgetRef,
1530
+ data: textWidgetDict
1531
+ }, fontRefObj]);
1532
+ const task = new _worker.WorkerTask("test print");
1533
+ partialEvaluator.xref = xref;
1534
+
1535
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1536
+ const id = annotation.data.id;
1537
+ const annotationStorage = {};
1538
+ annotationStorage[id] = "aa(aa)a\\";
1539
+ return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1540
+ }, done.fail).then(appearance => {
1541
+ expect(appearance).toEqual("/Tx BMC q BT /Helv 5 Tf 1 0 0 1 2 2 Tm" + " (a) Tj 8.00 0 Td (a) Tj 8.00 0 Td (\\() Tj" + " 8.00 0 Td (a) Tj 8.00 0 Td (a) Tj" + " 8.00 0 Td (\\)) Tj 8.00 0 Td (a) Tj" + " 8.00 0 Td (\\\\) Tj ET Q EMC");
1542
+ done();
1543
+ }, done.fail);
1544
+ });
1545
+ it("should save text", function (done) {
1546
+ const textWidgetRef = _primitives.Ref.get(123, 0);
1547
+
1548
+ const xref = new _test_utils.XRefMock([{
1549
+ ref: textWidgetRef,
1550
+ data: textWidgetDict
1551
+ }]);
1552
+ partialEvaluator.xref = xref;
1553
+ const task = new _worker.WorkerTask("test save");
1554
+
1555
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1556
+ const annotationStorage = {};
1557
+ annotationStorage[annotation.data.id] = "hello world";
1558
+ return annotation.save(partialEvaluator, task, annotationStorage);
1559
+ }, done.fail).then(data => {
1560
+ expect(data.length).toEqual(2);
1561
+ const [oldData, newData] = data;
1562
+ expect(oldData.ref).toEqual(_primitives.Ref.get(123, 0));
1563
+ expect(newData.ref).toEqual(_primitives.Ref.get(1, 0));
1564
+ oldData.data = oldData.data.replace(/\(D:[0-9]+\)/, "(date)");
1565
+ expect(oldData.data).toEqual("123 0 obj\n" + "<< /Type /Annot /Subtype /Widget /FT /Tx /DA (/Helv 5 Tf) /DR " + "<< /Font << /Helv 314 0 R>>>> /Rect [0 0 32 10] " + "/V (hello world) /AP << /N 1 0 R>> /M (date)>>\nendobj\n");
1566
+ expect(newData.data).toEqual("1 0 obj\n<< /Length 77 /Subtype /Form /Resources " + "<< /Font << /Helv 314 0 R>>>> /BBox [0 0 32 10]>> stream\n" + "/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 0 Tm 2.00 2.00 Td (hello world) Tj " + "ET Q EMC\nendstream\nendobj\n");
1567
+ done();
1568
+ }, done.fail);
1569
+ });
1360
1570
  });
1361
1571
  describe("ButtonWidgetAnnotation", function () {
1362
1572
  let buttonWidgetDict;
@@ -1373,10 +1583,10 @@ describe("annotation", function () {
1373
1583
  it("should handle checkboxes with export value", function (done) {
1374
1584
  buttonWidgetDict.set("V", _primitives.Name.get("1"));
1375
1585
  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);
1586
+ const normalAppearanceDict = new _primitives.Dict();
1587
+ normalAppearanceDict.set("Off", 0);
1588
+ normalAppearanceDict.set("Checked", 1);
1589
+ appearanceStatesDict.set("N", normalAppearanceDict);
1380
1590
  buttonWidgetDict.set("AP", appearanceStatesDict);
1381
1591
 
1382
1592
  const buttonWidgetRef = _primitives.Ref.get(124, 0);
@@ -1417,6 +1627,113 @@ describe("annotation", function () {
1417
1627
  done();
1418
1628
  }, done.fail);
1419
1629
  });
1630
+ it("should handle checkboxes without /Off appearance", function (done) {
1631
+ buttonWidgetDict.set("V", _primitives.Name.get("1"));
1632
+ const appearanceStatesDict = new _primitives.Dict();
1633
+ const normalAppearanceDict = new _primitives.Dict();
1634
+ normalAppearanceDict.set("Checked", 1);
1635
+ appearanceStatesDict.set("N", normalAppearanceDict);
1636
+ buttonWidgetDict.set("AP", appearanceStatesDict);
1637
+
1638
+ const buttonWidgetRef = _primitives.Ref.get(124, 0);
1639
+
1640
+ const xref = new _test_utils.XRefMock([{
1641
+ ref: buttonWidgetRef,
1642
+ data: buttonWidgetDict
1643
+ }]);
1644
+
1645
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
1646
+ data
1647
+ }) => {
1648
+ expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
1649
+ expect(data.checkBox).toEqual(true);
1650
+ expect(data.fieldValue).toEqual("1");
1651
+ expect(data.radioButton).toEqual(false);
1652
+ expect(data.exportValue).toEqual("Checked");
1653
+ done();
1654
+ }, done.fail);
1655
+ });
1656
+ it("should render checkboxes for printing", function (done) {
1657
+ const appearanceStatesDict = new _primitives.Dict();
1658
+ const normalAppearanceDict = new _primitives.Dict();
1659
+ const checkedAppearanceDict = new _primitives.Dict();
1660
+ const uncheckedAppearanceDict = new _primitives.Dict();
1661
+ const checkedStream = new _stream.StringStream("0.1 0.2 0.3 rg");
1662
+ checkedStream.dict = checkedAppearanceDict;
1663
+ const uncheckedStream = new _stream.StringStream("0.3 0.2 0.1 rg");
1664
+ uncheckedStream.dict = uncheckedAppearanceDict;
1665
+ checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
1666
+ checkedAppearanceDict.set("FormType", 1);
1667
+ checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
1668
+ normalAppearanceDict.set("Checked", checkedStream);
1669
+ normalAppearanceDict.set("Off", uncheckedStream);
1670
+ appearanceStatesDict.set("N", normalAppearanceDict);
1671
+ buttonWidgetDict.set("AP", appearanceStatesDict);
1672
+
1673
+ const buttonWidgetRef = _primitives.Ref.get(124, 0);
1674
+
1675
+ const xref = new _test_utils.XRefMock([{
1676
+ ref: buttonWidgetRef,
1677
+ data: buttonWidgetDict
1678
+ }]);
1679
+ const task = new _worker.WorkerTask("test print");
1680
+
1681
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1682
+ const annotationStorage = {};
1683
+ annotationStorage[annotation.data.id] = true;
1684
+ return Promise.all([annotation, annotation.getOperatorList(partialEvaluator, task, false, annotationStorage)]);
1685
+ }, done.fail).then(([annotation, opList]) => {
1686
+ expect(opList.argsArray.length).toEqual(3);
1687
+ expect(opList.fnArray).toEqual([_util.OPS.beginAnnotation, _util.OPS.setFillRGBColor, _util.OPS.endAnnotation]);
1688
+ expect(opList.argsArray[1]).toEqual(new Uint8ClampedArray([26, 51, 76]));
1689
+ return annotation;
1690
+ }, done.fail).then(annotation => {
1691
+ const annotationStorage = {};
1692
+ annotationStorage[annotation.data.id] = false;
1693
+ return annotation.getOperatorList(partialEvaluator, task, false, annotationStorage);
1694
+ }, done.fail).then(opList => {
1695
+ expect(opList.argsArray.length).toEqual(3);
1696
+ expect(opList.fnArray).toEqual([_util.OPS.beginAnnotation, _util.OPS.setFillRGBColor, _util.OPS.endAnnotation]);
1697
+ expect(opList.argsArray[1]).toEqual(new Uint8ClampedArray([76, 51, 26]));
1698
+ done();
1699
+ }, done.fail);
1700
+ });
1701
+ it("should save checkboxes", function (done) {
1702
+ const appearanceStatesDict = new _primitives.Dict();
1703
+ const normalAppearanceDict = new _primitives.Dict();
1704
+ normalAppearanceDict.set("Checked", _primitives.Ref.get(314, 0));
1705
+ normalAppearanceDict.set("Off", _primitives.Ref.get(271, 0));
1706
+ appearanceStatesDict.set("N", normalAppearanceDict);
1707
+ buttonWidgetDict.set("AP", appearanceStatesDict);
1708
+ buttonWidgetDict.set("V", _primitives.Name.get("Off"));
1709
+
1710
+ const buttonWidgetRef = _primitives.Ref.get(123, 0);
1711
+
1712
+ const xref = new _test_utils.XRefMock([{
1713
+ ref: buttonWidgetRef,
1714
+ data: buttonWidgetDict
1715
+ }]);
1716
+ partialEvaluator.xref = xref;
1717
+ const task = new _worker.WorkerTask("test save");
1718
+
1719
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1720
+ const annotationStorage = {};
1721
+ annotationStorage[annotation.data.id] = true;
1722
+ return Promise.all([annotation, annotation.save(partialEvaluator, task, annotationStorage)]);
1723
+ }, done.fail).then(([annotation, [oldData]]) => {
1724
+ oldData.data = oldData.data.replace(/\(D:[0-9]+\)/, "(date)");
1725
+ expect(oldData.ref).toEqual(_primitives.Ref.get(123, 0));
1726
+ expect(oldData.data).toEqual("123 0 obj\n" + "<< /Type /Annot /Subtype /Widget /FT /Btn " + "/AP << /N << /Checked 314 0 R /Off 271 0 R>>>> " + "/V /Checked /AS /Checked /M (date)>>\nendobj\n");
1727
+ return annotation;
1728
+ }, done.fail).then(annotation => {
1729
+ const annotationStorage = {};
1730
+ annotationStorage[annotation.data.id] = false;
1731
+ return annotation.save(partialEvaluator, task, annotationStorage);
1732
+ }, done.fail).then(data => {
1733
+ expect(data).toEqual(null);
1734
+ done();
1735
+ }, done.fail);
1736
+ });
1420
1737
  it("should handle radio buttons with a field value", function (done) {
1421
1738
  const parentDict = new _primitives.Dict();
1422
1739
  parentDict.set("V", _primitives.Name.get("1"));
@@ -1472,18 +1789,133 @@ describe("annotation", function () {
1472
1789
  done();
1473
1790
  }, done.fail);
1474
1791
  });
1792
+ it("should render radio buttons for printing", function (done) {
1793
+ const appearanceStatesDict = new _primitives.Dict();
1794
+ const normalAppearanceDict = new _primitives.Dict();
1795
+ const checkedAppearanceDict = new _primitives.Dict();
1796
+ const uncheckedAppearanceDict = new _primitives.Dict();
1797
+ const checkedStream = new _stream.StringStream("0.1 0.2 0.3 rg");
1798
+ checkedStream.dict = checkedAppearanceDict;
1799
+ const uncheckedStream = new _stream.StringStream("0.3 0.2 0.1 rg");
1800
+ uncheckedStream.dict = uncheckedAppearanceDict;
1801
+ checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
1802
+ checkedAppearanceDict.set("FormType", 1);
1803
+ checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
1804
+ normalAppearanceDict.set("Checked", checkedStream);
1805
+ normalAppearanceDict.set("Off", uncheckedStream);
1806
+ appearanceStatesDict.set("N", normalAppearanceDict);
1807
+ buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.RADIO);
1808
+ buttonWidgetDict.set("AP", appearanceStatesDict);
1809
+
1810
+ const buttonWidgetRef = _primitives.Ref.get(124, 0);
1811
+
1812
+ const xref = new _test_utils.XRefMock([{
1813
+ ref: buttonWidgetRef,
1814
+ data: buttonWidgetDict
1815
+ }]);
1816
+ const task = new _worker.WorkerTask("test print");
1817
+
1818
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1819
+ const annotationStorage = {};
1820
+ annotationStorage[annotation.data.id] = true;
1821
+ return Promise.all([annotation, annotation.getOperatorList(partialEvaluator, task, false, annotationStorage)]);
1822
+ }, done.fail).then(([annotation, opList]) => {
1823
+ expect(opList.argsArray.length).toEqual(3);
1824
+ expect(opList.fnArray).toEqual([_util.OPS.beginAnnotation, _util.OPS.setFillRGBColor, _util.OPS.endAnnotation]);
1825
+ expect(opList.argsArray[1]).toEqual(new Uint8ClampedArray([26, 51, 76]));
1826
+ return annotation;
1827
+ }, done.fail).then(annotation => {
1828
+ const annotationStorage = {};
1829
+ annotationStorage[annotation.data.id] = false;
1830
+ return annotation.getOperatorList(partialEvaluator, task, false, annotationStorage);
1831
+ }, done.fail).then(opList => {
1832
+ expect(opList.argsArray.length).toEqual(3);
1833
+ expect(opList.fnArray).toEqual([_util.OPS.beginAnnotation, _util.OPS.setFillRGBColor, _util.OPS.endAnnotation]);
1834
+ expect(opList.argsArray[1]).toEqual(new Uint8ClampedArray([76, 51, 26]));
1835
+ done();
1836
+ }, done.fail);
1837
+ });
1838
+ it("should save radio buttons", function (done) {
1839
+ const appearanceStatesDict = new _primitives.Dict();
1840
+ const normalAppearanceDict = new _primitives.Dict();
1841
+ normalAppearanceDict.set("Checked", _primitives.Ref.get(314, 0));
1842
+ normalAppearanceDict.set("Off", _primitives.Ref.get(271, 0));
1843
+ appearanceStatesDict.set("N", normalAppearanceDict);
1844
+ buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.RADIO);
1845
+ buttonWidgetDict.set("AP", appearanceStatesDict);
1846
+
1847
+ const buttonWidgetRef = _primitives.Ref.get(123, 0);
1848
+
1849
+ const parentRef = _primitives.Ref.get(456, 0);
1850
+
1851
+ const parentDict = new _primitives.Dict();
1852
+ parentDict.set("V", _primitives.Name.get("Off"));
1853
+ parentDict.set("Kids", [buttonWidgetRef]);
1854
+ buttonWidgetDict.set("Parent", parentRef);
1855
+ const xref = new _test_utils.XRefMock([{
1856
+ ref: buttonWidgetRef,
1857
+ data: buttonWidgetDict
1858
+ }, {
1859
+ ref: parentRef,
1860
+ data: parentDict
1861
+ }]);
1862
+ parentDict.xref = xref;
1863
+ buttonWidgetDict.xref = xref;
1864
+ partialEvaluator.xref = xref;
1865
+ const task = new _worker.WorkerTask("test save");
1866
+
1867
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1868
+ const annotationStorage = {};
1869
+ annotationStorage[annotation.data.id] = true;
1870
+ return Promise.all([annotation, annotation.save(partialEvaluator, task, annotationStorage)]);
1871
+ }, done.fail).then(([annotation, data]) => {
1872
+ expect(data.length).toEqual(2);
1873
+ const [radioData, parentData] = data;
1874
+ radioData.data = radioData.data.replace(/\(D:[0-9]+\)/, "(date)");
1875
+ expect(radioData.ref).toEqual(_primitives.Ref.get(123, 0));
1876
+ expect(radioData.data).toEqual("123 0 obj\n" + "<< /Type /Annot /Subtype /Widget /FT /Btn /Ff 32768 " + "/AP << /N << /Checked 314 0 R /Off 271 0 R>>>> " + "/Parent 456 0 R /AS /Checked /M (date)>>\nendobj\n");
1877
+ expect(parentData.ref).toEqual(_primitives.Ref.get(456, 0));
1878
+ expect(parentData.data).toEqual("456 0 obj\n<< /V /Checked /Kids [123 0 R]>>\nendobj\n");
1879
+ return annotation;
1880
+ }, done.fail).then(annotation => {
1881
+ const annotationStorage = {};
1882
+ annotationStorage[annotation.data.id] = false;
1883
+ return annotation.save(partialEvaluator, task, annotationStorage);
1884
+ }, done.fail).then(data => {
1885
+ expect(data).toEqual(null);
1886
+ done();
1887
+ }, done.fail);
1888
+ });
1475
1889
  });
1476
1890
  describe("ChoiceWidgetAnnotation", function () {
1477
- let choiceWidgetDict;
1891
+ let choiceWidgetDict, fontRefObj;
1478
1892
  beforeEach(function (done) {
1479
1893
  choiceWidgetDict = new _primitives.Dict();
1480
1894
  choiceWidgetDict.set("Type", _primitives.Name.get("Annot"));
1481
1895
  choiceWidgetDict.set("Subtype", _primitives.Name.get("Widget"));
1482
1896
  choiceWidgetDict.set("FT", _primitives.Name.get("Ch"));
1897
+ const helvDict = new _primitives.Dict();
1898
+ helvDict.set("BaseFont", _primitives.Name.get("Helvetica"));
1899
+ helvDict.set("Type", _primitives.Name.get("Font"));
1900
+ helvDict.set("Subtype", _primitives.Name.get("Type1"));
1901
+
1902
+ const fontRef = _primitives.Ref.get(314, 0);
1903
+
1904
+ fontRefObj = {
1905
+ ref: fontRef,
1906
+ data: helvDict
1907
+ };
1908
+ const resourceDict = new _primitives.Dict();
1909
+ const fontDict = new _primitives.Dict();
1910
+ fontDict.set("Helv", fontRef);
1911
+ resourceDict.set("Font", fontDict);
1912
+ choiceWidgetDict.set("DA", "/Helv 5 Tf");
1913
+ choiceWidgetDict.set("DR", resourceDict);
1914
+ choiceWidgetDict.set("Rect", [0, 0, 32, 10]);
1483
1915
  done();
1484
1916
  });
1485
1917
  afterEach(function () {
1486
- choiceWidgetDict = null;
1918
+ choiceWidgetDict = fontRefObj = null;
1487
1919
  });
1488
1920
  it("should handle missing option arrays", function (done) {
1489
1921
  const choiceWidgetRef = _primitives.Ref.get(122, 0);
@@ -1600,13 +2032,11 @@ describe("annotation", function () {
1600
2032
  done();
1601
2033
  }, done.fail);
1602
2034
  });
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"
1608
- }];
1609
- choiceWidgetDict.set("Opt", options);
2035
+ it("should decode form values", function (done) {
2036
+ const encodedString = "\xFE\xFF\x00F\x00o\x00o";
2037
+ const decodedString = "Foo";
2038
+ choiceWidgetDict.set("Opt", [encodedString]);
2039
+ choiceWidgetDict.set("V", encodedString);
1610
2040
 
1611
2041
  const choiceWidgetRef = _primitives.Ref.get(984, 0);
1612
2042
 
@@ -1619,47 +2049,39 @@ describe("annotation", function () {
1619
2049
  data
1620
2050
  }) => {
1621
2051
  expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
1622
- expect(data.options).toEqual(expected);
2052
+ expect(data.fieldValue).toEqual([decodedString]);
2053
+ expect(data.options).toEqual([{
2054
+ exportValue: decodedString,
2055
+ displayValue: decodedString
2056
+ }]);
1623
2057
  done();
1624
2058
  }, done.fail);
1625
2059
  });
1626
- it("should handle array field values", function (done) {
1627
- const fieldValue = ["Foo", "Bar"];
1628
- choiceWidgetDict.set("V", fieldValue);
1629
-
1630
- const choiceWidgetRef = _primitives.Ref.get(968, 0);
1631
-
1632
- const xref = new _test_utils.XRefMock([{
1633
- ref: choiceWidgetRef,
1634
- data: choiceWidgetDict
1635
- }]);
2060
+ it("should convert the field value to an array", function (done) {
2061
+ const inputs = [null, "Foo", ["Foo", "Bar"]];
2062
+ const outputs = [[], ["Foo"], ["Foo", "Bar"]];
2063
+ let promise = Promise.resolve();
1636
2064
 
1637
- _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
1638
- data
1639
- }) => {
1640
- expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
1641
- expect(data.fieldValue).toEqual(fieldValue);
1642
- done();
1643
- }, done.fail);
1644
- });
1645
- it("should handle string field values", function (done) {
1646
- const fieldValue = "Foo";
1647
- choiceWidgetDict.set("V", fieldValue);
2065
+ for (let i = 0, ii = inputs.length; i < ii; i++) {
2066
+ promise = promise.then(() => {
2067
+ choiceWidgetDict.set("V", inputs[i]);
1648
2068
 
1649
- const choiceWidgetRef = _primitives.Ref.get(978, 0);
2069
+ const choiceWidgetRef = _primitives.Ref.get(968, 0);
1650
2070
 
1651
- const xref = new _test_utils.XRefMock([{
1652
- ref: choiceWidgetRef,
1653
- data: choiceWidgetDict
1654
- }]);
2071
+ const xref = new _test_utils.XRefMock([{
2072
+ ref: choiceWidgetRef,
2073
+ data: choiceWidgetDict
2074
+ }]);
2075
+ return _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
2076
+ data
2077
+ }) => {
2078
+ expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
2079
+ expect(data.fieldValue).toEqual(outputs[i]);
2080
+ });
2081
+ });
2082
+ }
1655
2083
 
1656
- _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
1657
- data
1658
- }) => {
1659
- expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
1660
- expect(data.fieldValue).toEqual([fieldValue]);
1661
- done();
1662
- }, done.fail);
2084
+ promise.then(done, done.fail);
1663
2085
  });
1664
2086
  it("should handle unknown flags", function (done) {
1665
2087
  const choiceWidgetRef = _primitives.Ref.get(166, 0);
@@ -1719,6 +2141,54 @@ describe("annotation", function () {
1719
2141
  done();
1720
2142
  }, done.fail);
1721
2143
  });
2144
+ it("should render choice for printing", function (done) {
2145
+ const choiceWidgetRef = _primitives.Ref.get(271, 0);
2146
+
2147
+ const xref = new _test_utils.XRefMock([{
2148
+ ref: choiceWidgetRef,
2149
+ data: choiceWidgetDict
2150
+ }, fontRefObj]);
2151
+ const task = new _worker.WorkerTask("test print");
2152
+ partialEvaluator.xref = xref;
2153
+
2154
+ _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
2155
+ const id = annotation.data.id;
2156
+ const annotationStorage = {};
2157
+ annotationStorage[id] = "a value";
2158
+ return annotation._getAppearance(partialEvaluator, task, annotationStorage);
2159
+ }, done.fail).then(appearance => {
2160
+ expect(appearance).toEqual("/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 0 Tm" + " 2.00 2.00 Td (a value) Tj ET Q EMC");
2161
+ done();
2162
+ }, done.fail);
2163
+ });
2164
+ it("should save choice", function (done) {
2165
+ choiceWidgetDict.set("Opt", ["A", "B", "C"]);
2166
+ choiceWidgetDict.set("V", "A");
2167
+
2168
+ const choiceWidgetRef = _primitives.Ref.get(123, 0);
2169
+
2170
+ const xref = new _test_utils.XRefMock([{
2171
+ ref: choiceWidgetRef,
2172
+ data: choiceWidgetDict
2173
+ }]);
2174
+ partialEvaluator.xref = xref;
2175
+ const task = new _worker.WorkerTask("test save");
2176
+
2177
+ _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
2178
+ const annotationStorage = {};
2179
+ annotationStorage[annotation.data.id] = "C";
2180
+ return annotation.save(partialEvaluator, task, annotationStorage);
2181
+ }, done.fail).then(data => {
2182
+ expect(data.length).toEqual(2);
2183
+ const [oldData, newData] = data;
2184
+ expect(oldData.ref).toEqual(_primitives.Ref.get(123, 0));
2185
+ expect(newData.ref).toEqual(_primitives.Ref.get(1, 0));
2186
+ oldData.data = oldData.data.replace(/\(D:[0-9]+\)/, "(date)");
2187
+ expect(oldData.data).toEqual("123 0 obj\n" + "<< /Type /Annot /Subtype /Widget /FT /Ch /DA (/Helv 5 Tf) /DR " + "<< /Font << /Helv 314 0 R>>>> " + "/Rect [0 0 32 10] /Opt [(A) (B) (C)] /V (C) " + "/AP << /N 1 0 R>> /M (date)>>\nendobj\n");
2188
+ expect(newData.data).toEqual("1 0 obj\n" + "<< /Length 67 /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " + "/BBox [0 0 32 10]>> stream\n" + "/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 0 Tm 2.00 2.00 Td (C) Tj ET Q EMC\n" + "endstream\nendobj\n");
2189
+ done();
2190
+ }, done.fail);
2191
+ });
1722
2192
  });
1723
2193
  describe("LineAnnotation", function () {
1724
2194
  it("should set the line coordinates", function (done) {