pdfjs-dist 2.6.347 → 2.7.570

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pdfjs-dist might be problematic. Click here for more details.

Files changed (158) hide show
  1. package/README.md +3 -3
  2. package/bower.json +1 -1
  3. package/build/pdf.js +2050 -1087
  4. package/build/pdf.js.map +1 -1
  5. package/build/pdf.min.js +1 -1
  6. package/build/pdf.worker.js +18219 -10436
  7. package/build/pdf.worker.js.map +1 -1
  8. package/build/pdf.worker.min.js +1 -1
  9. package/es5/build/pdf.d.ts +1 -0
  10. package/es5/build/pdf.js +6623 -6654
  11. package/es5/build/pdf.js.map +1 -1
  12. package/es5/build/pdf.min.js +1 -1
  13. package/es5/build/pdf.worker.js +20815 -13888
  14. package/es5/build/pdf.worker.js.map +1 -1
  15. package/es5/build/pdf.worker.min.js +1 -1
  16. package/es5/image_decoders/pdf.image_decoders.js +3817 -4946
  17. package/es5/image_decoders/pdf.image_decoders.js.map +1 -1
  18. package/es5/image_decoders/pdf.image_decoders.min.js +1 -1
  19. package/es5/web/pdf_viewer.css +18 -15
  20. package/es5/web/pdf_viewer.js +1094 -514
  21. package/es5/web/pdf_viewer.js.map +1 -1
  22. package/image_decoders/pdf.image_decoders.js +774 -168
  23. package/image_decoders/pdf.image_decoders.js.map +1 -1
  24. package/image_decoders/pdf.image_decoders.min.js +1 -1
  25. package/lib/core/annotation.js +556 -108
  26. package/lib/core/cff_parser.js +7 -1
  27. package/lib/core/charsets.js +1 -1
  28. package/lib/core/cmap.js +20 -1
  29. package/lib/core/core_utils.js +162 -3
  30. package/lib/core/crypto.js +1 -1
  31. package/lib/core/default_appearance.js +132 -0
  32. package/lib/core/document.js +115 -9
  33. package/lib/core/encodings.js +1 -1
  34. package/lib/core/evaluator.js +168 -74
  35. package/lib/core/fonts.js +97 -11
  36. package/lib/core/function.js +5 -10
  37. package/lib/core/glyphlist.js +11 -4529
  38. package/lib/core/image_utils.js +30 -1
  39. package/lib/core/jpg.js +1 -1
  40. package/lib/core/jpx.js +5 -5
  41. package/lib/core/murmurhash3.js +1 -1
  42. package/lib/core/obj.js +123 -39
  43. package/lib/core/pattern.js +4 -4
  44. package/lib/core/primitives.js +24 -5
  45. package/lib/core/standard_fonts.js +1 -1
  46. package/lib/core/stream.js +5 -1
  47. package/lib/core/unicode.js +15 -1387
  48. package/lib/core/worker.js +58 -17
  49. package/lib/core/writer.js +68 -4
  50. package/lib/display/annotation_layer.js +712 -119
  51. package/lib/display/annotation_storage.js +21 -4
  52. package/lib/display/api.js +88 -18
  53. package/lib/display/canvas.js +414 -375
  54. package/lib/display/display_utils.js +11 -4
  55. package/lib/display/fetch_stream.js +3 -3
  56. package/lib/display/font_loader.js +2 -3
  57. package/lib/display/metadata.js +54 -20
  58. package/lib/display/node_stream.js +1 -1
  59. package/lib/display/optional_content_config.js +1 -1
  60. package/lib/display/pattern_helper.js +109 -113
  61. package/lib/display/svg.js +5 -5
  62. package/lib/display/text_layer.js +54 -54
  63. package/lib/display/transport_stream.js +4 -4
  64. package/lib/display/webgl.js +65 -68
  65. package/lib/examples/node/domstubs.js +9 -4
  66. package/lib/pdf.js +2 -2
  67. package/lib/pdf.sandbox.js +311 -0
  68. package/lib/pdf.worker.js +2 -2
  69. package/lib/shared/scripting_utils.js +84 -0
  70. package/lib/shared/util.js +129 -14
  71. package/lib/{display → shared}/xml_parser.js +112 -4
  72. package/lib/test/unit/annotation_spec.js +831 -109
  73. package/lib/test/unit/annotation_storage_spec.js +28 -10
  74. package/lib/test/unit/api_spec.js +190 -160
  75. package/lib/test/unit/bidi_spec.js +6 -6
  76. package/lib/test/unit/cff_parser_spec.js +73 -73
  77. package/lib/test/unit/clitests_helper.js +2 -0
  78. package/lib/test/unit/cmap_spec.js +48 -74
  79. package/lib/test/unit/core_utils_spec.js +34 -0
  80. package/lib/test/unit/crypto_spec.js +162 -199
  81. package/lib/test/unit/custom_spec.js +7 -18
  82. package/lib/test/unit/default_appearance_spec.js +54 -0
  83. package/lib/test/unit/display_svg_spec.js +24 -19
  84. package/lib/test/unit/display_utils_spec.js +1 -1
  85. package/lib/test/unit/document_spec.js +187 -20
  86. package/lib/test/unit/evaluator_spec.js +30 -30
  87. package/lib/test/unit/function_spec.js +165 -165
  88. package/lib/test/unit/jasmine-boot.js +52 -53
  89. package/lib/test/unit/metadata_spec.js +2 -2
  90. package/lib/test/unit/murmurhash3_spec.js +29 -16
  91. package/lib/test/unit/network_spec.js +21 -21
  92. package/lib/test/unit/pdf_find_controller_spec.js +131 -69
  93. package/lib/test/unit/pdf_find_utils_spec.js +10 -10
  94. package/lib/test/unit/scripting_spec.js +1104 -0
  95. package/lib/test/unit/stream_spec.js +8 -8
  96. package/lib/test/unit/test_utils.js +16 -19
  97. package/lib/test/unit/testreporter.js +11 -4
  98. package/lib/test/unit/type1_parser_spec.js +23 -23
  99. package/lib/test/unit/ui_utils_spec.js +78 -35
  100. package/lib/test/unit/unicode_spec.js +7 -7
  101. package/lib/test/unit/util_spec.js +26 -3
  102. package/lib/test/unit/writer_spec.js +16 -1
  103. package/lib/test/unit/xml_spec.js +117 -0
  104. package/lib/web/annotation_layer_builder.js +18 -6
  105. package/lib/web/app.js +579 -161
  106. package/lib/web/app_options.js +14 -0
  107. package/lib/web/base_tree_viewer.js +50 -0
  108. package/lib/web/base_viewer.js +350 -14
  109. package/lib/web/chromecom.js +9 -1
  110. package/lib/web/debugger.js +1 -2
  111. package/lib/web/download_manager.js +0 -15
  112. package/lib/web/firefox_print_service.js +6 -4
  113. package/lib/web/firefoxcom.js +84 -69
  114. package/lib/web/generic_scripting.js +55 -0
  115. package/lib/web/genericcom.js +9 -1
  116. package/lib/web/grab_to_pan.js +1 -1
  117. package/lib/web/interfaces.js +9 -3
  118. package/lib/web/pdf_attachment_viewer.js +1 -3
  119. package/lib/web/pdf_cursor_tools.js +20 -13
  120. package/lib/web/pdf_document_properties.js +48 -61
  121. package/lib/web/pdf_find_bar.js +1 -3
  122. package/lib/web/pdf_find_controller.js +58 -12
  123. package/lib/web/pdf_history.js +43 -21
  124. package/lib/web/pdf_layer_viewer.js +1 -9
  125. package/lib/web/pdf_link_service.js +108 -78
  126. package/lib/web/pdf_outline_viewer.js +166 -10
  127. package/lib/web/pdf_page_view.js +14 -14
  128. package/lib/web/pdf_presentation_mode.js +21 -31
  129. package/lib/web/pdf_rendering_queue.js +8 -1
  130. package/lib/web/pdf_sidebar.js +62 -107
  131. package/lib/web/pdf_sidebar_resizer.js +11 -21
  132. package/lib/web/pdf_single_page_viewer.js +8 -0
  133. package/lib/web/pdf_thumbnail_view.js +26 -26
  134. package/lib/web/pdf_thumbnail_viewer.js +13 -2
  135. package/lib/web/pdf_viewer.component.js +2 -2
  136. package/lib/web/pdf_viewer.js +3 -1
  137. package/lib/web/preferences.js +33 -44
  138. package/lib/web/text_layer_builder.js +2 -9
  139. package/lib/web/ui_utils.js +78 -46
  140. package/lib/web/viewer_compatibility.js +1 -2
  141. package/package.json +4 -1
  142. package/types/display/annotation_layer.d.ts +18 -3
  143. package/types/display/api.d.ts +110 -54
  144. package/types/display/canvas.d.ts +1 -1
  145. package/types/display/display_utils.d.ts +96 -95
  146. package/types/display/fetch_stream.d.ts +2 -2
  147. package/types/display/metadata.d.ts +4 -0
  148. package/types/display/pattern_helper.d.ts +1 -1
  149. package/types/display/text_layer.d.ts +7 -7
  150. package/types/display/transport_stream.d.ts +1 -1
  151. package/types/shared/scripting_utils.d.ts +12 -0
  152. package/types/shared/util.d.ts +281 -250
  153. package/types/shared/xml_parser.d.ts +64 -0
  154. package/web/pdf_viewer.css +18 -15
  155. package/web/pdf_viewer.js +809 -408
  156. package/web/pdf_viewer.js.map +1 -1
  157. package/webpack.js +1 -1
  158. package/types/display/xml_parser.d.ts +0 -35
@@ -31,6 +31,8 @@ var _primitives = require("../../core/primitives.js");
31
31
 
32
32
  var _parser = require("../../core/parser.js");
33
33
 
34
+ var _api = require("../../display/api.js");
35
+
34
36
  var _evaluator = require("../../core/evaluator.js");
35
37
 
36
38
  var _stream = require("../../core/stream.js");
@@ -64,6 +66,10 @@ describe("annotation", function () {
64
66
  return this.ensure(this.pdfDocument.catalog, prop, args);
65
67
  }
66
68
 
69
+ ensureDoc(prop, args) {
70
+ return this.ensure(this.pdfDocument, prop, args);
71
+ }
72
+
67
73
  }
68
74
 
69
75
  function HandlerMock() {
@@ -80,17 +86,29 @@ describe("annotation", function () {
80
86
 
81
87
  };
82
88
  let pdfManagerMock, idFactoryMock, partialEvaluator;
83
- beforeAll(function (done) {
89
+ beforeAll(async function (done) {
84
90
  pdfManagerMock = new PDFManagerMock({
85
91
  docBaseUrl: null
86
92
  });
93
+ const CMapReaderFactory = new _api.DefaultCMapReaderFactory({
94
+ baseUrl: _test_utils.CMAP_PARAMS.cMapUrl,
95
+ isCompressed: _test_utils.CMAP_PARAMS.cMapPacked
96
+ });
97
+ const builtInCMapCache = new Map();
98
+ builtInCMapCache.set("UniJIS-UTF16-H", await CMapReaderFactory.fetch({
99
+ name: "UniJIS-UTF16-H"
100
+ }));
101
+ builtInCMapCache.set("Adobe-Japan1-UCS2", await CMapReaderFactory.fetch({
102
+ name: "Adobe-Japan1-UCS2"
103
+ }));
87
104
  idFactoryMock = (0, _test_utils.createIdFactory)(0);
88
105
  partialEvaluator = new _evaluator.PartialEvaluator({
89
106
  xref: new _test_utils.XRefMock(),
90
107
  handler: new HandlerMock(),
91
108
  pageIndex: 0,
92
109
  idFactory: (0, _test_utils.createIdFactory)(0),
93
- fontCache: new _primitives.RefSetCache()
110
+ fontCache: new _primitives.RefSetCache(),
111
+ builtInCMapCache
94
112
  });
95
113
  done();
96
114
  });
@@ -193,35 +211,56 @@ describe("annotation", function () {
193
211
  expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual(null);
194
212
  }
195
213
  });
196
- it("should process valid quadpoints arrays", function () {
214
+ it("should process quadpoints in the standard order", function () {
197
215
  rect = [10, 10, 20, 20];
198
- dict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18]);
216
+ dict.set("QuadPoints", [10, 20, 20, 20, 10, 10, 20, 10, 11, 19, 19, 19, 11, 11, 19, 11]);
199
217
  expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual([[{
200
- x: 11,
201
- y: 11
218
+ x: 10,
219
+ y: 20
202
220
  }, {
203
- x: 12,
204
- y: 12
221
+ x: 20,
222
+ y: 20
205
223
  }, {
206
- x: 13,
207
- y: 13
224
+ x: 10,
225
+ y: 10
208
226
  }, {
209
- x: 14,
210
- y: 14
227
+ x: 20,
228
+ y: 10
211
229
  }], [{
212
- x: 15,
213
- y: 15
230
+ x: 11,
231
+ y: 19
214
232
  }, {
215
- x: 16,
216
- y: 16
233
+ x: 19,
234
+ y: 19
217
235
  }, {
218
- x: 17,
219
- y: 17
236
+ x: 11,
237
+ y: 11
220
238
  }, {
221
- x: 18,
222
- y: 18
239
+ x: 19,
240
+ y: 11
223
241
  }]]);
224
242
  });
243
+ it("should normalize and process quadpoints in non-standard orders", function () {
244
+ rect = [10, 10, 20, 20];
245
+ const nonStandardOrders = [[10, 20, 20, 20, 20, 10, 10, 10], [10, 10, 20, 10, 10, 20, 20, 20], [10, 10, 20, 10, 20, 20, 10, 20]];
246
+
247
+ for (const nonStandardOrder of nonStandardOrders) {
248
+ dict.set("QuadPoints", nonStandardOrder);
249
+ expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual([[{
250
+ x: 10,
251
+ y: 20
252
+ }, {
253
+ x: 20,
254
+ y: 20
255
+ }, {
256
+ x: 10,
257
+ y: 10
258
+ }, {
259
+ x: 20,
260
+ y: 10
261
+ }]]);
262
+ }
263
+ });
225
264
  });
226
265
  describe("Annotation", function () {
227
266
  let dict, ref;
@@ -275,6 +314,7 @@ describe("annotation", function () {
275
314
  expect(annotation.hasFlag(_util.AnnotationFlag.NOZOOM)).toEqual(true);
276
315
  expect(annotation.hasFlag(_util.AnnotationFlag.PRINT)).toEqual(true);
277
316
  expect(annotation.hasFlag(_util.AnnotationFlag.READONLY)).toEqual(false);
317
+ expect(annotation.hasFlag(_util.AnnotationFlag.HIDDEN)).toEqual(false);
278
318
  });
279
319
  it("should be viewable and not printable by default", function () {
280
320
  const annotation = new _annotation.Annotation({
@@ -1121,7 +1161,7 @@ describe("annotation", function () {
1121
1161
  annotationDict.set("Type", _primitives.Name.get("Annot"));
1122
1162
  annotationDict.set("Subtype", _primitives.Name.get("Link"));
1123
1163
  annotationDict.set("Rect", [10, 10, 20, 20]);
1124
- annotationDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
1164
+ annotationDict.set("QuadPoints", [10, 20, 20, 20, 10, 10, 20, 10]);
1125
1165
 
1126
1166
  const annotationRef = _primitives.Ref.get(121, 0);
1127
1167
 
@@ -1135,17 +1175,17 @@ describe("annotation", function () {
1135
1175
  }) => {
1136
1176
  expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
1137
1177
  expect(data.quadPoints).toEqual([[{
1138
- x: 11,
1139
- y: 11
1178
+ x: 10,
1179
+ y: 20
1140
1180
  }, {
1141
- x: 12,
1142
- y: 12
1181
+ x: 20,
1182
+ y: 20
1143
1183
  }, {
1144
- x: 13,
1145
- y: 13
1184
+ x: 10,
1185
+ y: 10
1146
1186
  }, {
1147
- x: 14,
1148
- y: 14
1187
+ x: 20,
1188
+ y: 10
1149
1189
  }]]);
1150
1190
  done();
1151
1191
  }, done.fail);
@@ -1244,7 +1284,7 @@ describe("annotation", function () {
1244
1284
  });
1245
1285
  });
1246
1286
  describe("TextWidgetAnnotation", function () {
1247
- let textWidgetDict, fontRefObj;
1287
+ let textWidgetDict, helvRefObj, gothRefObj;
1248
1288
  beforeEach(function (done) {
1249
1289
  textWidgetDict = new _primitives.Dict();
1250
1290
  textWidgetDict.set("Type", _primitives.Name.get("Annot"));
@@ -1254,16 +1294,42 @@ describe("annotation", function () {
1254
1294
  helvDict.set("BaseFont", _primitives.Name.get("Helvetica"));
1255
1295
  helvDict.set("Type", _primitives.Name.get("Font"));
1256
1296
  helvDict.set("Subtype", _primitives.Name.get("Type1"));
1257
-
1258
- const fontRef = _primitives.Ref.get(314, 0);
1259
-
1260
- fontRefObj = {
1261
- ref: fontRef,
1297
+ const gothDict = new _primitives.Dict();
1298
+ gothDict.set("BaseFont", _primitives.Name.get("MSGothic"));
1299
+ gothDict.set("Type", _primitives.Name.get("Font"));
1300
+ gothDict.set("Subtype", _primitives.Name.get("Type0"));
1301
+ gothDict.set("Encoding", _primitives.Name.get("UniJIS-UTF16-H"));
1302
+ gothDict.set("Name", _primitives.Name.get("MSGothic"));
1303
+ const cidSysInfoDict = new _primitives.Dict();
1304
+ cidSysInfoDict.set("Ordering", "Japan1");
1305
+ cidSysInfoDict.set("Registry", "Adobe");
1306
+ cidSysInfoDict.set("Supplement", "5");
1307
+ const fontDescriptorDict = new _primitives.Dict();
1308
+ fontDescriptorDict.set("FontName", _primitives.Name.get("MSGothic"));
1309
+ fontDescriptorDict.set("CapHeight", "680");
1310
+ const gothDescendantDict = new _primitives.Dict();
1311
+ gothDescendantDict.set("BaseFont", _primitives.Name.get("MSGothic"));
1312
+ gothDescendantDict.set("CIDSystemInfo", cidSysInfoDict);
1313
+ gothDescendantDict.set("Subtype", _primitives.Name.get("CIDFontType2"));
1314
+ gothDescendantDict.set("Type", _primitives.Name.get("Font"));
1315
+ gothDescendantDict.set("FontDescriptor", fontDescriptorDict);
1316
+ gothDict.set("DescendantFonts", [gothDescendantDict]);
1317
+
1318
+ const helvRef = _primitives.Ref.get(314, 0);
1319
+
1320
+ const gothRef = _primitives.Ref.get(159, 0);
1321
+
1322
+ helvRefObj = {
1323
+ ref: helvRef,
1262
1324
  data: helvDict
1263
1325
  };
1326
+ gothRefObj = {
1327
+ ref: gothRef,
1328
+ data: gothDict
1329
+ };
1264
1330
  const resourceDict = new _primitives.Dict();
1265
1331
  const fontDict = new _primitives.Dict();
1266
- fontDict.set("Helv", fontRef);
1332
+ fontDict.set("Helv", helvRef);
1267
1333
  resourceDict.set("Font", fontDict);
1268
1334
  textWidgetDict.set("DA", "/Helv 5 Tf");
1269
1335
  textWidgetDict.set("DR", resourceDict);
@@ -1271,9 +1337,11 @@ describe("annotation", function () {
1271
1337
  done();
1272
1338
  });
1273
1339
  afterEach(function () {
1274
- textWidgetDict = fontRefObj = null;
1340
+ textWidgetDict = helvRefObj = gothRefObj = null;
1275
1341
  });
1276
1342
  it("should handle unknown text alignment, maximum length and flags", function (done) {
1343
+ textWidgetDict.set("DV", "foo");
1344
+
1277
1345
  const textWidgetRef = _primitives.Ref.get(124, 0);
1278
1346
 
1279
1347
  const xref = new _test_utils.XRefMock([{
@@ -1288,8 +1356,10 @@ describe("annotation", function () {
1288
1356
  expect(data.textAlignment).toEqual(null);
1289
1357
  expect(data.maxLen).toEqual(null);
1290
1358
  expect(data.readOnly).toEqual(false);
1359
+ expect(data.hidden).toEqual(false);
1291
1360
  expect(data.multiLine).toEqual(false);
1292
1361
  expect(data.comb).toEqual(false);
1362
+ expect(data.defaultFieldValue).toEqual("foo");
1293
1363
  done();
1294
1364
  }, done.fail);
1295
1365
  });
@@ -1312,6 +1382,7 @@ describe("annotation", function () {
1312
1382
  expect(data.textAlignment).toEqual(null);
1313
1383
  expect(data.maxLen).toEqual(null);
1314
1384
  expect(data.readOnly).toEqual(false);
1385
+ expect(data.hidden).toEqual(false);
1315
1386
  expect(data.multiLine).toEqual(false);
1316
1387
  expect(data.comb).toEqual(false);
1317
1388
  done();
@@ -1336,6 +1407,7 @@ describe("annotation", function () {
1336
1407
  expect(data.textAlignment).toEqual(1);
1337
1408
  expect(data.maxLen).toEqual(20);
1338
1409
  expect(data.readOnly).toEqual(true);
1410
+ expect(data.hidden).toEqual(false);
1339
1411
  expect(data.multiLine).toEqual(true);
1340
1412
  done();
1341
1413
  }, done.fail);
@@ -1415,20 +1487,74 @@ describe("annotation", function () {
1415
1487
  const xref = new _test_utils.XRefMock([{
1416
1488
  ref: textWidgetRef,
1417
1489
  data: textWidgetDict
1418
- }, fontRefObj]);
1490
+ }, helvRefObj]);
1419
1491
  const task = new _worker.WorkerTask("test print");
1420
1492
  partialEvaluator.xref = xref;
1421
1493
 
1422
1494
  _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1423
1495
  const id = annotation.data.id;
1424
1496
  const annotationStorage = {};
1425
- annotationStorage[id] = "test\\print";
1497
+ annotationStorage[id] = {
1498
+ value: "test\\print"
1499
+ };
1426
1500
  return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1427
1501
  }, done.fail).then(appearance => {
1428
1502
  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
1503
  done();
1430
1504
  }, done.fail);
1431
1505
  });
1506
+ it("should render regular text in Japanese for printing", function (done) {
1507
+ textWidgetDict.get("DR").get("Font").set("Goth", gothRefObj.ref);
1508
+ textWidgetDict.set("DA", "/Goth 5 Tf");
1509
+
1510
+ const textWidgetRef = _primitives.Ref.get(271, 0);
1511
+
1512
+ const xref = new _test_utils.XRefMock([{
1513
+ ref: textWidgetRef,
1514
+ data: textWidgetDict
1515
+ }, gothRefObj]);
1516
+ const task = new _worker.WorkerTask("test print");
1517
+ partialEvaluator.xref = xref;
1518
+
1519
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1520
+ const id = annotation.data.id;
1521
+ const annotationStorage = {};
1522
+ annotationStorage[id] = {
1523
+ value: "こんにちは世界の"
1524
+ };
1525
+ return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1526
+ }, done.fail).then(appearance => {
1527
+ const utf16String = "\x30\x53\x30\x93\x30\x6b\x30\x61" + "\x30\x6f\x4e\x16\x75\x4c\x30\x6e";
1528
+ expect(appearance).toEqual("/Tx BMC q BT /Goth 5 Tf 1 0 0 1 0 0 Tm" + ` 2.00 2.00 Td (${utf16String}) Tj ET Q EMC`);
1529
+ done();
1530
+ }, done.fail);
1531
+ });
1532
+ it("should render regular text for printing using normal appearance", function (done) {
1533
+ const textWidgetRef = _primitives.Ref.get(271, 0);
1534
+
1535
+ const appearanceStatesDict = new _primitives.Dict();
1536
+ const normalAppearanceDict = new _primitives.Dict();
1537
+ const normalAppearanceStream = new _stream.StringStream("0.1 0.2 0.3 rg");
1538
+ normalAppearanceStream.dict = normalAppearanceDict;
1539
+ appearanceStatesDict.set("N", normalAppearanceStream);
1540
+ textWidgetDict.set("AP", appearanceStatesDict);
1541
+ const xref = new _test_utils.XRefMock([{
1542
+ ref: textWidgetRef,
1543
+ data: textWidgetDict
1544
+ }, helvRefObj]);
1545
+ const task = new _worker.WorkerTask("test print");
1546
+ partialEvaluator.xref = xref;
1547
+
1548
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1549
+ const annotationStorage = {};
1550
+ return annotation.getOperatorList(partialEvaluator, task, false, annotationStorage);
1551
+ }).then(opList => {
1552
+ expect(opList.argsArray.length).toEqual(3);
1553
+ expect(opList.fnArray).toEqual([_util.OPS.beginAnnotation, _util.OPS.setFillRGBColor, _util.OPS.endAnnotation]);
1554
+ expect(opList.argsArray[1]).toEqual(new Uint8ClampedArray([26, 51, 76]));
1555
+ done();
1556
+ }).catch(done.fail);
1557
+ });
1432
1558
  it("should render auto-sized text for printing", function (done) {
1433
1559
  textWidgetDict.set("DA", "/Helv 0 Tf");
1434
1560
 
@@ -1437,17 +1563,45 @@ describe("annotation", function () {
1437
1563
  const xref = new _test_utils.XRefMock([{
1438
1564
  ref: textWidgetRef,
1439
1565
  data: textWidgetDict
1440
- }, fontRefObj]);
1566
+ }, helvRefObj]);
1441
1567
  const task = new _worker.WorkerTask("test print");
1442
1568
  partialEvaluator.xref = xref;
1443
1569
 
1444
1570
  _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1445
1571
  const id = annotation.data.id;
1446
1572
  const annotationStorage = {};
1447
- annotationStorage[id] = "test (print)";
1573
+ annotationStorage[id] = {
1574
+ value: "test (print)"
1575
+ };
1448
1576
  return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1449
1577
  }, 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");
1578
+ expect(appearance).toEqual("/Tx BMC q BT /Helv 11 Tf 0 g 1 0 0 1 0 0 Tm" + " 2.00 2.00 Td (test \\(print\\)) Tj ET Q EMC");
1579
+ done();
1580
+ }, done.fail);
1581
+ });
1582
+ it("should render auto-sized text in Japanese for printing", function (done) {
1583
+ textWidgetDict.get("DR").get("Font").set("Goth", gothRefObj.ref);
1584
+ textWidgetDict.set("DA", "/Goth 0 Tf");
1585
+
1586
+ const textWidgetRef = _primitives.Ref.get(271, 0);
1587
+
1588
+ const xref = new _test_utils.XRefMock([{
1589
+ ref: textWidgetRef,
1590
+ data: textWidgetDict
1591
+ }, gothRefObj]);
1592
+ const task = new _worker.WorkerTask("test print");
1593
+ partialEvaluator.xref = xref;
1594
+
1595
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1596
+ const id = annotation.data.id;
1597
+ const annotationStorage = {};
1598
+ annotationStorage[id] = {
1599
+ value: "こんにちは世界の"
1600
+ };
1601
+ return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1602
+ }, done.fail).then(appearance => {
1603
+ const utf16String = "\x30\x53\x30\x93\x30\x6b\x30\x61" + "\x30\x6f\x4e\x16\x75\x4c\x30\x6e";
1604
+ expect(appearance).toEqual("/Tx BMC q BT /Goth 9 Tf 0 g 1 0 0 1 0 0 Tm" + ` 2.00 2.00 Td (${utf16String}) Tj ET Q EMC`);
1451
1605
  done();
1452
1606
  }, done.fail);
1453
1607
  });
@@ -1459,14 +1613,16 @@ describe("annotation", function () {
1459
1613
  const xref = new _test_utils.XRefMock([{
1460
1614
  ref: textWidgetRef,
1461
1615
  data: textWidgetDict
1462
- }, fontRefObj]);
1616
+ }, helvRefObj]);
1463
1617
  const task = new _worker.WorkerTask("test print");
1464
1618
  partialEvaluator.xref = xref;
1465
1619
 
1466
1620
  _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1467
1621
  const id = annotation.data.id;
1468
1622
  const annotationStorage = {};
1469
- annotationStorage[id] = "mypassword";
1623
+ annotationStorage[id] = {
1624
+ value: "mypassword"
1625
+ };
1470
1626
  return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1471
1627
  }, done.fail).then(appearance => {
1472
1628
  expect(appearance).toEqual(null);
@@ -1481,20 +1637,48 @@ describe("annotation", function () {
1481
1637
  const xref = new _test_utils.XRefMock([{
1482
1638
  ref: textWidgetRef,
1483
1639
  data: textWidgetDict
1484
- }, fontRefObj]);
1640
+ }, helvRefObj]);
1485
1641
  const task = new _worker.WorkerTask("test print");
1486
1642
  partialEvaluator.xref = xref;
1487
1643
 
1488
1644
  _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1489
1645
  const id = annotation.data.id;
1490
1646
  const annotationStorage = {};
1491
- annotationStorage[id] = "a aa aaa aaaa aaaaa aaaaaa " + "pneumonoultramicroscopicsilicovolcanoconiosis";
1647
+ annotationStorage[id] = {
1648
+ value: "a aa aaa aaaa aaaaa aaaaaa " + "pneumonoultramicroscopicsilicovolcanoconiosis"
1649
+ };
1492
1650
  return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1493
1651
  }, done.fail).then(appearance => {
1494
1652
  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
1653
  done();
1496
1654
  }, done.fail);
1497
1655
  });
1656
+ it("should render multiline text in Japanese for printing", function (done) {
1657
+ textWidgetDict.set("Ff", _util.AnnotationFieldFlag.MULTILINE);
1658
+ textWidgetDict.get("DR").get("Font").set("Goth", gothRefObj.ref);
1659
+ textWidgetDict.set("DA", "/Goth 5 Tf");
1660
+
1661
+ const textWidgetRef = _primitives.Ref.get(271, 0);
1662
+
1663
+ const xref = new _test_utils.XRefMock([{
1664
+ ref: textWidgetRef,
1665
+ data: textWidgetDict
1666
+ }, gothRefObj]);
1667
+ const task = new _worker.WorkerTask("test print");
1668
+ partialEvaluator.xref = xref;
1669
+
1670
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1671
+ const id = annotation.data.id;
1672
+ const annotationStorage = {};
1673
+ annotationStorage[id] = {
1674
+ value: "こんにちは世界の"
1675
+ };
1676
+ return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1677
+ }, done.fail).then(appearance => {
1678
+ expect(appearance).toEqual("/Tx BMC q BT /Goth 5 Tf 1 0 0 1 0 10 Tm " + "2.00 -5.00 Td (\x30\x53\x30\x93\x30\x6b\x30\x61\x30\x6f) Tj\n" + "0.00 -5.00 Td (\x4e\x16\x75\x4c\x30\x6e) Tj ET Q EMC");
1679
+ done();
1680
+ }, done.fail);
1681
+ });
1498
1682
  it("should render multiline text with various EOL for printing", function (done) {
1499
1683
  textWidgetDict.set("Ff", _util.AnnotationFieldFlag.MULTILINE);
1500
1684
  textWidgetDict.set("Rect", [0, 0, 128, 10]);
@@ -1504,7 +1688,7 @@ describe("annotation", function () {
1504
1688
  const xref = new _test_utils.XRefMock([{
1505
1689
  ref: textWidgetRef,
1506
1690
  data: textWidgetDict
1507
- }, fontRefObj]);
1691
+ }, helvRefObj]);
1508
1692
  const task = new _worker.WorkerTask("test print");
1509
1693
  partialEvaluator.xref = xref;
1510
1694
  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";
@@ -1512,7 +1696,9 @@ describe("annotation", function () {
1512
1696
  _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1513
1697
  const id = annotation.data.id;
1514
1698
  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.";
1699
+ annotationStorage[id] = {
1700
+ value: "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."
1701
+ };
1516
1702
  return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1517
1703
  }, done.fail).then(appearance => {
1518
1704
  expect(appearance).toEqual(expectedAppearance);
@@ -1528,42 +1714,188 @@ describe("annotation", function () {
1528
1714
  const xref = new _test_utils.XRefMock([{
1529
1715
  ref: textWidgetRef,
1530
1716
  data: textWidgetDict
1531
- }, fontRefObj]);
1717
+ }, helvRefObj]);
1532
1718
  const task = new _worker.WorkerTask("test print");
1533
1719
  partialEvaluator.xref = xref;
1534
1720
 
1535
1721
  _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1536
1722
  const id = annotation.data.id;
1537
1723
  const annotationStorage = {};
1538
- annotationStorage[id] = "aa(aa)a\\";
1724
+ annotationStorage[id] = {
1725
+ value: "aa(aa)a\\"
1726
+ };
1539
1727
  return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1540
1728
  }, done.fail).then(appearance => {
1541
1729
  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
1730
  done();
1543
1731
  }, done.fail);
1544
1732
  });
1733
+ it("should render comb with Japanese text for printing", function (done) {
1734
+ textWidgetDict.set("Ff", _util.AnnotationFieldFlag.COMB);
1735
+ textWidgetDict.set("MaxLen", 4);
1736
+ textWidgetDict.get("DR").get("Font").set("Goth", gothRefObj.ref);
1737
+ textWidgetDict.set("DA", "/Goth 5 Tf");
1738
+ textWidgetDict.set("Rect", [0, 0, 32, 10]);
1739
+
1740
+ const textWidgetRef = _primitives.Ref.get(271, 0);
1741
+
1742
+ const xref = new _test_utils.XRefMock([{
1743
+ ref: textWidgetRef,
1744
+ data: textWidgetDict
1745
+ }, gothRefObj]);
1746
+ const task = new _worker.WorkerTask("test print");
1747
+ partialEvaluator.xref = xref;
1748
+
1749
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1750
+ const id = annotation.data.id;
1751
+ const annotationStorage = {};
1752
+ annotationStorage[id] = {
1753
+ value: "こんにちは世界の"
1754
+ };
1755
+ return annotation._getAppearance(partialEvaluator, task, annotationStorage);
1756
+ }, done.fail).then(appearance => {
1757
+ expect(appearance).toEqual("/Tx BMC q BT /Goth 5 Tf 1 0 0 1 2 2 Tm" + " (\x30\x53) Tj 8.00 0 Td (\x30\x93) Tj 8.00 0 Td (\x30\x6b) Tj" + " 8.00 0 Td (\x30\x61) Tj 8.00 0 Td (\x30\x6f) Tj" + " 8.00 0 Td (\x4e\x16) Tj 8.00 0 Td (\x75\x4c) Tj" + " 8.00 0 Td (\x30\x6e) Tj ET Q EMC");
1758
+ done();
1759
+ }, done.fail);
1760
+ });
1545
1761
  it("should save text", function (done) {
1546
1762
  const textWidgetRef = _primitives.Ref.get(123, 0);
1547
1763
 
1548
1764
  const xref = new _test_utils.XRefMock([{
1549
1765
  ref: textWidgetRef,
1550
1766
  data: textWidgetDict
1551
- }]);
1767
+ }, helvRefObj]);
1552
1768
  partialEvaluator.xref = xref;
1553
1769
  const task = new _worker.WorkerTask("test save");
1554
1770
 
1555
1771
  _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1556
1772
  const annotationStorage = {};
1557
- annotationStorage[annotation.data.id] = "hello world";
1773
+ annotationStorage[annotation.data.id] = {
1774
+ value: "hello world"
1775
+ };
1558
1776
  return annotation.save(partialEvaluator, task, annotationStorage);
1559
1777
  }, done.fail).then(data => {
1560
1778
  expect(data.length).toEqual(2);
1561
1779
  const [oldData, newData] = data;
1562
1780
  expect(oldData.ref).toEqual(_primitives.Ref.get(123, 0));
1563
- expect(newData.ref).toEqual(_primitives.Ref.get(1, 0));
1781
+ expect(newData.ref).toEqual(_primitives.Ref.get(2, 0));
1564
1782
  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");
1783
+ 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 2 0 R>> /M (date)>>\nendobj\n");
1784
+ expect(newData.data).toEqual("2 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");
1785
+ done();
1786
+ }, done.fail);
1787
+ });
1788
+ it("should get field object for usage in JS sandbox", function (done) {
1789
+ const textWidgetRef = _primitives.Ref.get(123, 0);
1790
+
1791
+ const xDictRef = _primitives.Ref.get(141, 0);
1792
+
1793
+ const dDictRef = _primitives.Ref.get(262, 0);
1794
+
1795
+ const next0Ref = _primitives.Ref.get(314, 0);
1796
+
1797
+ const next1Ref = _primitives.Ref.get(271, 0);
1798
+
1799
+ const next2Ref = _primitives.Ref.get(577, 0);
1800
+
1801
+ const next00Ref = _primitives.Ref.get(413, 0);
1802
+
1803
+ const xDict = new _primitives.Dict();
1804
+ const dDict = new _primitives.Dict();
1805
+ const next0Dict = new _primitives.Dict();
1806
+ const next1Dict = new _primitives.Dict();
1807
+ const next2Dict = new _primitives.Dict();
1808
+ const next00Dict = new _primitives.Dict();
1809
+ const xref = new _test_utils.XRefMock([{
1810
+ ref: textWidgetRef,
1811
+ data: textWidgetDict
1812
+ }, {
1813
+ ref: xDictRef,
1814
+ data: xDict
1815
+ }, {
1816
+ ref: dDictRef,
1817
+ data: dDict
1818
+ }, {
1819
+ ref: next0Ref,
1820
+ data: next0Dict
1821
+ }, {
1822
+ ref: next00Ref,
1823
+ data: next00Dict
1824
+ }, {
1825
+ ref: next1Ref,
1826
+ data: next1Dict
1827
+ }, {
1828
+ ref: next2Ref,
1829
+ data: next2Dict
1830
+ }]);
1831
+
1832
+ const JS = _primitives.Name.get("JavaScript");
1833
+
1834
+ const additionalActionsDict = new _primitives.Dict();
1835
+ const eDict = new _primitives.Dict();
1836
+ eDict.set("JS", "hello()");
1837
+ eDict.set("S", JS);
1838
+ additionalActionsDict.set("E", eDict);
1839
+ xDict.set("JS", "world()");
1840
+ xDict.set("S", JS);
1841
+ xDict.set("Next", [next0Ref, next1Ref, next2Ref, xDictRef]);
1842
+ next0Dict.set("JS", "olleh()");
1843
+ next0Dict.set("S", JS);
1844
+ next0Dict.set("Next", next00Ref);
1845
+ next00Dict.set("JS", "foo()");
1846
+ next00Dict.set("S", JS);
1847
+ next00Dict.set("Next", next0Ref);
1848
+ next1Dict.set("JS", "dlrow()");
1849
+ next1Dict.set("S", JS);
1850
+ next1Dict.set("Next", xDictRef);
1851
+ next2Dict.set("JS", "oof()");
1852
+ next2Dict.set("S", JS);
1853
+ dDict.set("JS", "bar()");
1854
+ dDict.set("S", JS);
1855
+ dDict.set("Next", dDictRef);
1856
+ additionalActionsDict.set("D", dDictRef);
1857
+ additionalActionsDict.set("X", xDictRef);
1858
+ textWidgetDict.set("AA", additionalActionsDict);
1859
+ partialEvaluator.xref = xref;
1860
+
1861
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1862
+ return annotation.getFieldObject();
1863
+ }).then(object => {
1864
+ const actions = object.actions;
1865
+ expect(actions["Mouse Enter"]).toEqual(["hello()"]);
1866
+ expect(actions["Mouse Exit"]).toEqual(["world()", "olleh()", "foo()", "dlrow()", "oof()"]);
1867
+ expect(actions["Mouse Down"]).toEqual(["bar()"]);
1868
+ done();
1869
+ }, done.fail);
1870
+ });
1871
+ it("should save Japanese text", function (done) {
1872
+ textWidgetDict.get("DR").get("Font").set("Goth", gothRefObj.ref);
1873
+ textWidgetDict.set("DA", "/Goth 5 Tf");
1874
+
1875
+ const textWidgetRef = _primitives.Ref.get(123, 0);
1876
+
1877
+ const xref = new _test_utils.XRefMock([{
1878
+ ref: textWidgetRef,
1879
+ data: textWidgetDict
1880
+ }, gothRefObj]);
1881
+ partialEvaluator.xref = xref;
1882
+ const task = new _worker.WorkerTask("test save");
1883
+
1884
+ _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1885
+ const annotationStorage = {};
1886
+ annotationStorage[annotation.data.id] = {
1887
+ value: "こんにちは世界の"
1888
+ };
1889
+ return annotation.save(partialEvaluator, task, annotationStorage);
1890
+ }, done.fail).then(data => {
1891
+ const utf16String = "\x30\x53\x30\x93\x30\x6b\x30\x61" + "\x30\x6f\x4e\x16\x75\x4c\x30\x6e";
1892
+ expect(data.length).toEqual(2);
1893
+ const [oldData, newData] = data;
1894
+ expect(oldData.ref).toEqual(_primitives.Ref.get(123, 0));
1895
+ expect(newData.ref).toEqual(_primitives.Ref.get(2, 0));
1896
+ oldData.data = oldData.data.replace(/\(D:[0-9]+\)/, "(date)");
1897
+ expect(oldData.data).toEqual("123 0 obj\n" + "<< /Type /Annot /Subtype /Widget /FT /Tx /DA (/Goth 5 Tf) /DR " + "<< /Font << /Helv 314 0 R /Goth 159 0 R>>>> /Rect [0 0 32 10] " + `/V (\xfe\xff${utf16String}) /AP << /N 2 0 R>> /M (date)>>\nendobj\n`);
1898
+ expect(newData.data).toEqual("2 0 obj\n<< /Length 82 /Subtype /Form /Resources " + "<< /Font << /Helv 314 0 R /Goth 159 0 R>>>> /BBox [0 0 32 10]>> stream\n" + `/Tx BMC q BT /Goth 5 Tf 1 0 0 1 0 0 Tm 2.00 2.00 Td (${utf16String}) Tj ` + "ET Q EMC\nendstream\nendobj\n");
1567
1899
  done();
1568
1900
  }, done.fail);
1569
1901
  });
@@ -1582,6 +1914,7 @@ describe("annotation", function () {
1582
1914
  });
1583
1915
  it("should handle checkboxes with export value", function (done) {
1584
1916
  buttonWidgetDict.set("V", _primitives.Name.get("1"));
1917
+ buttonWidgetDict.set("DV", _primitives.Name.get("2"));
1585
1918
  const appearanceStatesDict = new _primitives.Dict();
1586
1919
  const normalAppearanceDict = new _primitives.Dict();
1587
1920
  normalAppearanceDict.set("Off", 0);
@@ -1602,6 +1935,7 @@ describe("annotation", function () {
1602
1935
  expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
1603
1936
  expect(data.checkBox).toEqual(true);
1604
1937
  expect(data.fieldValue).toEqual("1");
1938
+ expect(data.defaultFieldValue).toEqual("2");
1605
1939
  expect(data.radioButton).toEqual(false);
1606
1940
  expect(data.exportValue).toEqual("Checked");
1607
1941
  done();
@@ -1609,6 +1943,7 @@ describe("annotation", function () {
1609
1943
  });
1610
1944
  it("should handle checkboxes without export value", function (done) {
1611
1945
  buttonWidgetDict.set("V", _primitives.Name.get("1"));
1946
+ buttonWidgetDict.set("DV", _primitives.Name.get("2"));
1612
1947
 
1613
1948
  const buttonWidgetRef = _primitives.Ref.get(124, 0);
1614
1949
 
@@ -1623,12 +1958,14 @@ describe("annotation", function () {
1623
1958
  expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
1624
1959
  expect(data.checkBox).toEqual(true);
1625
1960
  expect(data.fieldValue).toEqual("1");
1961
+ expect(data.defaultFieldValue).toEqual("2");
1626
1962
  expect(data.radioButton).toEqual(false);
1627
1963
  done();
1628
1964
  }, done.fail);
1629
1965
  });
1630
1966
  it("should handle checkboxes without /Off appearance", function (done) {
1631
1967
  buttonWidgetDict.set("V", _primitives.Name.get("1"));
1968
+ buttonWidgetDict.set("DV", _primitives.Name.get("2"));
1632
1969
  const appearanceStatesDict = new _primitives.Dict();
1633
1970
  const normalAppearanceDict = new _primitives.Dict();
1634
1971
  normalAppearanceDict.set("Checked", 1);
@@ -1648,11 +1985,53 @@ describe("annotation", function () {
1648
1985
  expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
1649
1986
  expect(data.checkBox).toEqual(true);
1650
1987
  expect(data.fieldValue).toEqual("1");
1988
+ expect(data.defaultFieldValue).toEqual("2");
1651
1989
  expect(data.radioButton).toEqual(false);
1652
1990
  expect(data.exportValue).toEqual("Checked");
1653
1991
  done();
1654
1992
  }, done.fail);
1655
1993
  });
1994
+ it("should render checkbox with fallback font for printing", function (done) {
1995
+ const appearanceStatesDict = new _primitives.Dict();
1996
+ const normalAppearanceDict = new _primitives.Dict();
1997
+ const checkedAppearanceDict = new _primitives.Dict();
1998
+ const uncheckedAppearanceDict = new _primitives.Dict();
1999
+ const checkedStream = new _stream.StringStream("/ 12 Tf (4) Tj");
2000
+ checkedStream.dict = checkedAppearanceDict;
2001
+ const uncheckedStream = new _stream.StringStream("");
2002
+ uncheckedStream.dict = uncheckedAppearanceDict;
2003
+ checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
2004
+ checkedAppearanceDict.set("FormType", 1);
2005
+ checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
2006
+ normalAppearanceDict.set("Checked", checkedStream);
2007
+ normalAppearanceDict.set("Off", uncheckedStream);
2008
+ appearanceStatesDict.set("N", normalAppearanceDict);
2009
+ buttonWidgetDict.set("AP", appearanceStatesDict);
2010
+
2011
+ const buttonWidgetRef = _primitives.Ref.get(124, 0);
2012
+
2013
+ const xref = new _test_utils.XRefMock([{
2014
+ ref: buttonWidgetRef,
2015
+ data: buttonWidgetDict
2016
+ }]);
2017
+ const task = new _worker.WorkerTask("test print");
2018
+ partialEvaluator.options = {
2019
+ ignoreErrors: true
2020
+ };
2021
+
2022
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
2023
+ const annotationStorage = {};
2024
+ annotationStorage[annotation.data.id] = {
2025
+ value: true
2026
+ };
2027
+ return annotation.getOperatorList(partialEvaluator, task, false, annotationStorage);
2028
+ }).then(opList => {
2029
+ expect(opList.argsArray.length).toEqual(5);
2030
+ expect(opList.fnArray).toEqual([_util.OPS.beginAnnotation, _util.OPS.dependency, _util.OPS.setFont, _util.OPS.showText, _util.OPS.endAnnotation]);
2031
+ expect(opList.argsArray[3][0][0].fontChar).toEqual("✔");
2032
+ done();
2033
+ }).catch(done.fail);
2034
+ });
1656
2035
  it("should render checkboxes for printing", function (done) {
1657
2036
  const appearanceStatesDict = new _primitives.Dict();
1658
2037
  const normalAppearanceDict = new _primitives.Dict();
@@ -1680,7 +2059,9 @@ describe("annotation", function () {
1680
2059
 
1681
2060
  _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1682
2061
  const annotationStorage = {};
1683
- annotationStorage[annotation.data.id] = true;
2062
+ annotationStorage[annotation.data.id] = {
2063
+ value: true
2064
+ };
1684
2065
  return Promise.all([annotation, annotation.getOperatorList(partialEvaluator, task, false, annotationStorage)]);
1685
2066
  }, done.fail).then(([annotation, opList]) => {
1686
2067
  expect(opList.argsArray.length).toEqual(3);
@@ -1689,7 +2070,9 @@ describe("annotation", function () {
1689
2070
  return annotation;
1690
2071
  }, done.fail).then(annotation => {
1691
2072
  const annotationStorage = {};
1692
- annotationStorage[annotation.data.id] = false;
2073
+ annotationStorage[annotation.data.id] = {
2074
+ value: false
2075
+ };
1693
2076
  return annotation.getOperatorList(partialEvaluator, task, false, annotationStorage);
1694
2077
  }, done.fail).then(opList => {
1695
2078
  expect(opList.argsArray.length).toEqual(3);
@@ -1698,6 +2081,92 @@ describe("annotation", function () {
1698
2081
  done();
1699
2082
  }, done.fail);
1700
2083
  });
2084
+ it("should render checkboxes for printing two times", function (done) {
2085
+ const appearanceStatesDict = new _primitives.Dict();
2086
+ const normalAppearanceDict = new _primitives.Dict();
2087
+ const checkedAppearanceDict = new _primitives.Dict();
2088
+ const uncheckedAppearanceDict = new _primitives.Dict();
2089
+ const checkedStream = new _stream.StringStream("0.1 0.2 0.3 rg");
2090
+ checkedStream.dict = checkedAppearanceDict;
2091
+ const uncheckedStream = new _stream.StringStream("0.3 0.2 0.1 rg");
2092
+ uncheckedStream.dict = uncheckedAppearanceDict;
2093
+ checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
2094
+ checkedAppearanceDict.set("FormType", 1);
2095
+ checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
2096
+ normalAppearanceDict.set("Checked", checkedStream);
2097
+ normalAppearanceDict.set("Off", uncheckedStream);
2098
+ appearanceStatesDict.set("N", normalAppearanceDict);
2099
+ buttonWidgetDict.set("AP", appearanceStatesDict);
2100
+ buttonWidgetDict.set("AS", _primitives.Name.get("Off"));
2101
+
2102
+ const buttonWidgetRef = _primitives.Ref.get(1249, 0);
2103
+
2104
+ const xref = new _test_utils.XRefMock([{
2105
+ ref: buttonWidgetRef,
2106
+ data: buttonWidgetDict
2107
+ }]);
2108
+ const task = new _worker.WorkerTask("test print");
2109
+
2110
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
2111
+ const annotationStorage = {};
2112
+ annotationStorage[annotation.data.id] = {
2113
+ value: true
2114
+ };
2115
+ return Promise.all([annotation, annotation.getOperatorList(partialEvaluator, task, false, annotationStorage)]);
2116
+ }).then(([annotation, opList]) => {
2117
+ expect(opList.argsArray.length).toEqual(3);
2118
+ expect(opList.fnArray).toEqual([_util.OPS.beginAnnotation, _util.OPS.setFillRGBColor, _util.OPS.endAnnotation]);
2119
+ expect(opList.argsArray[1]).toEqual(new Uint8ClampedArray([26, 51, 76]));
2120
+ return annotation;
2121
+ }).then(annotation => {
2122
+ const annotationStorage = {};
2123
+ annotationStorage[annotation.data.id] = {
2124
+ value: true
2125
+ };
2126
+ return annotation.getOperatorList(partialEvaluator, task, false, annotationStorage);
2127
+ }).then(opList => {
2128
+ expect(opList.argsArray.length).toEqual(3);
2129
+ expect(opList.fnArray).toEqual([_util.OPS.beginAnnotation, _util.OPS.setFillRGBColor, _util.OPS.endAnnotation]);
2130
+ expect(opList.argsArray[1]).toEqual(new Uint8ClampedArray([26, 51, 76]));
2131
+ done();
2132
+ }).catch(done.fail);
2133
+ });
2134
+ it("should render checkboxes for printing using normal appearance", function (done) {
2135
+ const appearanceStatesDict = new _primitives.Dict();
2136
+ const normalAppearanceDict = new _primitives.Dict();
2137
+ const checkedAppearanceDict = new _primitives.Dict();
2138
+ const uncheckedAppearanceDict = new _primitives.Dict();
2139
+ const checkedStream = new _stream.StringStream("0.1 0.2 0.3 rg");
2140
+ checkedStream.dict = checkedAppearanceDict;
2141
+ const uncheckedStream = new _stream.StringStream("0.3 0.2 0.1 rg");
2142
+ uncheckedStream.dict = uncheckedAppearanceDict;
2143
+ checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
2144
+ checkedAppearanceDict.set("FormType", 1);
2145
+ checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
2146
+ normalAppearanceDict.set("Checked", checkedStream);
2147
+ normalAppearanceDict.set("Off", uncheckedStream);
2148
+ appearanceStatesDict.set("N", normalAppearanceDict);
2149
+ buttonWidgetDict.set("AP", appearanceStatesDict);
2150
+ buttonWidgetDict.set("AS", _primitives.Name.get("Checked"));
2151
+
2152
+ const buttonWidgetRef = _primitives.Ref.get(124, 0);
2153
+
2154
+ const xref = new _test_utils.XRefMock([{
2155
+ ref: buttonWidgetRef,
2156
+ data: buttonWidgetDict
2157
+ }]);
2158
+ const task = new _worker.WorkerTask("test print");
2159
+
2160
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
2161
+ const annotationStorage = {};
2162
+ return annotation.getOperatorList(partialEvaluator, task, false, annotationStorage);
2163
+ }).then(opList => {
2164
+ expect(opList.argsArray.length).toEqual(3);
2165
+ expect(opList.fnArray).toEqual([_util.OPS.beginAnnotation, _util.OPS.setFillRGBColor, _util.OPS.endAnnotation]);
2166
+ expect(opList.argsArray[1]).toEqual(new Uint8ClampedArray([26, 51, 76]));
2167
+ done();
2168
+ }).catch(done.fail);
2169
+ });
1701
2170
  it("should save checkboxes", function (done) {
1702
2171
  const appearanceStatesDict = new _primitives.Dict();
1703
2172
  const normalAppearanceDict = new _primitives.Dict();
@@ -1718,7 +2187,9 @@ describe("annotation", function () {
1718
2187
 
1719
2188
  _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1720
2189
  const annotationStorage = {};
1721
- annotationStorage[annotation.data.id] = true;
2190
+ annotationStorage[annotation.data.id] = {
2191
+ value: true
2192
+ };
1722
2193
  return Promise.all([annotation, annotation.save(partialEvaluator, task, annotationStorage)]);
1723
2194
  }, done.fail).then(([annotation, [oldData]]) => {
1724
2195
  oldData.data = oldData.data.replace(/\(D:[0-9]+\)/, "(date)");
@@ -1727,7 +2198,9 @@ describe("annotation", function () {
1727
2198
  return annotation;
1728
2199
  }, done.fail).then(annotation => {
1729
2200
  const annotationStorage = {};
1730
- annotationStorage[annotation.data.id] = false;
2201
+ annotationStorage[annotation.data.id] = {
2202
+ value: false
2203
+ };
1731
2204
  return annotation.save(partialEvaluator, task, annotationStorage);
1732
2205
  }, done.fail).then(data => {
1733
2206
  expect(data).toEqual(null);
@@ -1763,6 +2236,35 @@ describe("annotation", function () {
1763
2236
  done();
1764
2237
  }, done.fail);
1765
2238
  });
2239
+ it("should handle radio buttons with a field value not an ascii string", function (done) {
2240
+ const parentDict = new _primitives.Dict();
2241
+ parentDict.set("V", _primitives.Name.get("\x91I=\x91\xf0\x93\xe0\x97e3"));
2242
+ const normalAppearanceStateDict = new _primitives.Dict();
2243
+ normalAppearanceStateDict.set("\x91I=\x91\xf0\x93\xe0\x97e3", null);
2244
+ const appearanceStatesDict = new _primitives.Dict();
2245
+ appearanceStatesDict.set("N", normalAppearanceStateDict);
2246
+ buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.RADIO);
2247
+ buttonWidgetDict.set("Parent", parentDict);
2248
+ buttonWidgetDict.set("AP", appearanceStatesDict);
2249
+
2250
+ const buttonWidgetRef = _primitives.Ref.get(124, 0);
2251
+
2252
+ const xref = new _test_utils.XRefMock([{
2253
+ ref: buttonWidgetRef,
2254
+ data: buttonWidgetDict
2255
+ }]);
2256
+
2257
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
2258
+ data
2259
+ }) => {
2260
+ expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
2261
+ expect(data.checkBox).toEqual(false);
2262
+ expect(data.radioButton).toEqual(true);
2263
+ expect(data.fieldValue).toEqual("‚I=‚ðfiàŠe3");
2264
+ expect(data.buttonValue).toEqual("‚I=‚ðfiàŠe3");
2265
+ done();
2266
+ }, done.fail);
2267
+ });
1766
2268
  it("should handle radio buttons without a field value", function (done) {
1767
2269
  const normalAppearanceStateDict = new _primitives.Dict();
1768
2270
  normalAppearanceStateDict.set("2", null);
@@ -1817,7 +2319,9 @@ describe("annotation", function () {
1817
2319
 
1818
2320
  _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1819
2321
  const annotationStorage = {};
1820
- annotationStorage[annotation.data.id] = true;
2322
+ annotationStorage[annotation.data.id] = {
2323
+ value: true
2324
+ };
1821
2325
  return Promise.all([annotation, annotation.getOperatorList(partialEvaluator, task, false, annotationStorage)]);
1822
2326
  }, done.fail).then(([annotation, opList]) => {
1823
2327
  expect(opList.argsArray.length).toEqual(3);
@@ -1826,7 +2330,9 @@ describe("annotation", function () {
1826
2330
  return annotation;
1827
2331
  }, done.fail).then(annotation => {
1828
2332
  const annotationStorage = {};
1829
- annotationStorage[annotation.data.id] = false;
2333
+ annotationStorage[annotation.data.id] = {
2334
+ value: false
2335
+ };
1830
2336
  return annotation.getOperatorList(partialEvaluator, task, false, annotationStorage);
1831
2337
  }, done.fail).then(opList => {
1832
2338
  expect(opList.argsArray.length).toEqual(3);
@@ -1835,6 +2341,43 @@ describe("annotation", function () {
1835
2341
  done();
1836
2342
  }, done.fail);
1837
2343
  });
2344
+ it("should render radio buttons for printing using normal appearance", function (done) {
2345
+ const appearanceStatesDict = new _primitives.Dict();
2346
+ const normalAppearanceDict = new _primitives.Dict();
2347
+ const checkedAppearanceDict = new _primitives.Dict();
2348
+ const uncheckedAppearanceDict = new _primitives.Dict();
2349
+ const checkedStream = new _stream.StringStream("0.1 0.2 0.3 rg");
2350
+ checkedStream.dict = checkedAppearanceDict;
2351
+ const uncheckedStream = new _stream.StringStream("0.3 0.2 0.1 rg");
2352
+ uncheckedStream.dict = uncheckedAppearanceDict;
2353
+ checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
2354
+ checkedAppearanceDict.set("FormType", 1);
2355
+ checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
2356
+ normalAppearanceDict.set("Checked", checkedStream);
2357
+ normalAppearanceDict.set("Off", uncheckedStream);
2358
+ appearanceStatesDict.set("N", normalAppearanceDict);
2359
+ buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.RADIO);
2360
+ buttonWidgetDict.set("AP", appearanceStatesDict);
2361
+ buttonWidgetDict.set("AS", _primitives.Name.get("Off"));
2362
+
2363
+ const buttonWidgetRef = _primitives.Ref.get(124, 0);
2364
+
2365
+ const xref = new _test_utils.XRefMock([{
2366
+ ref: buttonWidgetRef,
2367
+ data: buttonWidgetDict
2368
+ }]);
2369
+ const task = new _worker.WorkerTask("test print");
2370
+
2371
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
2372
+ const annotationStorage = {};
2373
+ return annotation.getOperatorList(partialEvaluator, task, false, annotationStorage);
2374
+ }).then(opList => {
2375
+ expect(opList.argsArray.length).toEqual(3);
2376
+ expect(opList.fnArray).toEqual([_util.OPS.beginAnnotation, _util.OPS.setFillRGBColor, _util.OPS.endAnnotation]);
2377
+ expect(opList.argsArray[1]).toEqual(new Uint8ClampedArray([76, 51, 26]));
2378
+ done();
2379
+ }).catch(done.fail);
2380
+ });
1838
2381
  it("should save radio buttons", function (done) {
1839
2382
  const appearanceStatesDict = new _primitives.Dict();
1840
2383
  const normalAppearanceDict = new _primitives.Dict();
@@ -1866,7 +2409,9 @@ describe("annotation", function () {
1866
2409
 
1867
2410
  _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
1868
2411
  const annotationStorage = {};
1869
- annotationStorage[annotation.data.id] = true;
2412
+ annotationStorage[annotation.data.id] = {
2413
+ value: true
2414
+ };
1870
2415
  return Promise.all([annotation, annotation.save(partialEvaluator, task, annotationStorage)]);
1871
2416
  }, done.fail).then(([annotation, data]) => {
1872
2417
  expect(data.length).toEqual(2);
@@ -1879,13 +2424,159 @@ describe("annotation", function () {
1879
2424
  return annotation;
1880
2425
  }, done.fail).then(annotation => {
1881
2426
  const annotationStorage = {};
1882
- annotationStorage[annotation.data.id] = false;
2427
+ annotationStorage[annotation.data.id] = {
2428
+ value: false
2429
+ };
1883
2430
  return annotation.save(partialEvaluator, task, annotationStorage);
1884
2431
  }, done.fail).then(data => {
1885
2432
  expect(data).toEqual(null);
1886
2433
  done();
1887
2434
  }, done.fail);
1888
2435
  });
2436
+ it("should save radio buttons without a field value", function (done) {
2437
+ const appearanceStatesDict = new _primitives.Dict();
2438
+ const normalAppearanceDict = new _primitives.Dict();
2439
+ normalAppearanceDict.set("Checked", _primitives.Ref.get(314, 0));
2440
+ normalAppearanceDict.set("Off", _primitives.Ref.get(271, 0));
2441
+ appearanceStatesDict.set("N", normalAppearanceDict);
2442
+ buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.RADIO);
2443
+ buttonWidgetDict.set("AP", appearanceStatesDict);
2444
+
2445
+ const buttonWidgetRef = _primitives.Ref.get(123, 0);
2446
+
2447
+ const parentRef = _primitives.Ref.get(456, 0);
2448
+
2449
+ const parentDict = new _primitives.Dict();
2450
+ parentDict.set("Kids", [buttonWidgetRef]);
2451
+ buttonWidgetDict.set("Parent", parentRef);
2452
+ const xref = new _test_utils.XRefMock([{
2453
+ ref: buttonWidgetRef,
2454
+ data: buttonWidgetDict
2455
+ }, {
2456
+ ref: parentRef,
2457
+ data: parentDict
2458
+ }]);
2459
+ parentDict.xref = xref;
2460
+ buttonWidgetDict.xref = xref;
2461
+ partialEvaluator.xref = xref;
2462
+ const task = new _worker.WorkerTask("test save");
2463
+
2464
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
2465
+ const annotationStorage = {};
2466
+ annotationStorage[annotation.data.id] = {
2467
+ value: true
2468
+ };
2469
+ return Promise.all([annotation, annotation.save(partialEvaluator, task, annotationStorage)]);
2470
+ }).then(([annotation, data]) => {
2471
+ expect(data.length).toEqual(2);
2472
+ const [radioData, parentData] = data;
2473
+ radioData.data = radioData.data.replace(/\(D:[0-9]+\)/, "(date)");
2474
+ expect(radioData.ref).toEqual(_primitives.Ref.get(123, 0));
2475
+ 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");
2476
+ expect(parentData.ref).toEqual(_primitives.Ref.get(456, 0));
2477
+ expect(parentData.data).toEqual("456 0 obj\n<< /Kids [123 0 R] /V /Checked>>\nendobj\n");
2478
+ done();
2479
+ }).catch(done.fail);
2480
+ });
2481
+ it("should save nothing", function (done) {
2482
+ const buttonWidgetRef = _primitives.Ref.get(124, 0);
2483
+
2484
+ const xref = new _test_utils.XRefMock([{
2485
+ ref: buttonWidgetRef,
2486
+ data: buttonWidgetDict
2487
+ }]);
2488
+ const task = new _worker.WorkerTask("test save");
2489
+
2490
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
2491
+ return annotation.save(partialEvaluator, task, {});
2492
+ }).then(data => {
2493
+ expect(data).toEqual(null);
2494
+ done();
2495
+ }).catch(done.fail);
2496
+ });
2497
+ it("should handle push buttons", function (done) {
2498
+ const buttonWidgetRef = _primitives.Ref.get(124, 0);
2499
+
2500
+ buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.PUSHBUTTON);
2501
+ const actionDict = new _primitives.Dict();
2502
+ actionDict.set("S", _primitives.Name.get("JavaScript"));
2503
+ actionDict.set("JS", "do_something();");
2504
+ buttonWidgetDict.set("A", actionDict);
2505
+ const xref = new _test_utils.XRefMock([{
2506
+ ref: buttonWidgetRef,
2507
+ data: buttonWidgetDict
2508
+ }]);
2509
+
2510
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
2511
+ data
2512
+ }) => {
2513
+ expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
2514
+ expect(data.pushButton).toEqual(true);
2515
+ expect(data.actions.Action).toEqual(["do_something();"]);
2516
+ done();
2517
+ }, done.fail);
2518
+ });
2519
+ it("should handle push buttons that act as a tooltip only", function (done) {
2520
+ const buttonWidgetRef = _primitives.Ref.get(124, 0);
2521
+
2522
+ buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.PUSHBUTTON);
2523
+ buttonWidgetDict.set("TU", "An alternative text");
2524
+ const xref = new _test_utils.XRefMock([{
2525
+ ref: buttonWidgetRef,
2526
+ data: buttonWidgetDict
2527
+ }]);
2528
+
2529
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
2530
+ data
2531
+ }) => {
2532
+ expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
2533
+ expect(data.pushButton).toEqual(true);
2534
+ expect(data.alternativeText).toEqual("An alternative text");
2535
+ done();
2536
+ }, done.fail);
2537
+ });
2538
+ it("should handle URL in A dict in push buttons", function (done) {
2539
+ const buttonWidgetRef = _primitives.Ref.get(124, 0);
2540
+
2541
+ buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.PUSHBUTTON);
2542
+ const actionDict = new _primitives.Dict();
2543
+ actionDict.set("S", _primitives.Name.get("JavaScript"));
2544
+ actionDict.set("JS", "app.launchURL('https://developer.mozilla.org/en-US/', true)");
2545
+ buttonWidgetDict.set("A", actionDict);
2546
+ const xref = new _test_utils.XRefMock([{
2547
+ ref: buttonWidgetRef,
2548
+ data: buttonWidgetDict
2549
+ }]);
2550
+
2551
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
2552
+ data
2553
+ }) => {
2554
+ expect(data.url).toEqual("https://developer.mozilla.org/en-US/");
2555
+ done();
2556
+ }, done.fail);
2557
+ });
2558
+ it("should handle URL in AA dict in push buttons", function (done) {
2559
+ const buttonWidgetRef = _primitives.Ref.get(124, 0);
2560
+
2561
+ buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.PUSHBUTTON);
2562
+ const dDict = new _primitives.Dict();
2563
+ dDict.set("S", _primitives.Name.get("JavaScript"));
2564
+ dDict.set("JS", "app.launchURL('https://developer.mozilla.org/en-US/', true)");
2565
+ const actionDict = new _primitives.Dict();
2566
+ actionDict.set("D", dDict);
2567
+ buttonWidgetDict.set("AA", actionDict);
2568
+ const xref = new _test_utils.XRefMock([{
2569
+ ref: buttonWidgetRef,
2570
+ data: buttonWidgetDict
2571
+ }]);
2572
+
2573
+ _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
2574
+ data
2575
+ }) => {
2576
+ expect(data.url).toEqual("https://developer.mozilla.org/en-US/");
2577
+ done();
2578
+ }, done.fail);
2579
+ });
1889
2580
  });
1890
2581
  describe("ChoiceWidgetAnnotation", function () {
1891
2582
  let choiceWidgetDict, fontRefObj;
@@ -2037,6 +2728,7 @@ describe("annotation", function () {
2037
2728
  const decodedString = "Foo";
2038
2729
  choiceWidgetDict.set("Opt", [encodedString]);
2039
2730
  choiceWidgetDict.set("V", encodedString);
2731
+ choiceWidgetDict.set("DV", _primitives.Name.get("foo"));
2040
2732
 
2041
2733
  const choiceWidgetRef = _primitives.Ref.get(984, 0);
2042
2734
 
@@ -2050,6 +2742,7 @@ describe("annotation", function () {
2050
2742
  }) => {
2051
2743
  expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
2052
2744
  expect(data.fieldValue).toEqual([decodedString]);
2745
+ expect(data.defaultFieldValue).toEqual("foo");
2053
2746
  expect(data.options).toEqual([{
2054
2747
  exportValue: decodedString,
2055
2748
  displayValue: decodedString
@@ -2096,6 +2789,7 @@ describe("annotation", function () {
2096
2789
  }) => {
2097
2790
  expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
2098
2791
  expect(data.readOnly).toEqual(false);
2792
+ expect(data.hidden).toEqual(false);
2099
2793
  expect(data.combo).toEqual(false);
2100
2794
  expect(data.multiSelect).toEqual(false);
2101
2795
  done();
@@ -2116,6 +2810,7 @@ describe("annotation", function () {
2116
2810
  }) => {
2117
2811
  expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
2118
2812
  expect(data.readOnly).toEqual(false);
2813
+ expect(data.hidden).toEqual(false);
2119
2814
  expect(data.combo).toEqual(false);
2120
2815
  expect(data.multiSelect).toEqual(false);
2121
2816
  done();
@@ -2136,6 +2831,7 @@ describe("annotation", function () {
2136
2831
  }) => {
2137
2832
  expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
2138
2833
  expect(data.readOnly).toEqual(true);
2834
+ expect(data.hidden).toEqual(false);
2139
2835
  expect(data.combo).toEqual(true);
2140
2836
  expect(data.multiSelect).toEqual(true);
2141
2837
  done();
@@ -2154,7 +2850,9 @@ describe("annotation", function () {
2154
2850
  _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
2155
2851
  const id = annotation.data.id;
2156
2852
  const annotationStorage = {};
2157
- annotationStorage[id] = "a value";
2853
+ annotationStorage[id] = {
2854
+ value: "a value"
2855
+ };
2158
2856
  return annotation._getAppearance(partialEvaluator, task, annotationStorage);
2159
2857
  }, done.fail).then(appearance => {
2160
2858
  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");
@@ -2176,7 +2874,9 @@ describe("annotation", function () {
2176
2874
 
2177
2875
  _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(annotation => {
2178
2876
  const annotationStorage = {};
2179
- annotationStorage[annotation.data.id] = "C";
2877
+ annotationStorage[annotation.data.id] = {
2878
+ value: "C"
2879
+ };
2180
2880
  return annotation.save(partialEvaluator, task, annotationStorage);
2181
2881
  }, done.fail).then(data => {
2182
2882
  expect(data.length).toEqual(2);
@@ -2482,7 +3182,7 @@ describe("annotation", function () {
2482
3182
  });
2483
3183
  });
2484
3184
  describe("HightlightAnnotation", function () {
2485
- it("should not set quadpoints if not defined", function (done) {
3185
+ it("should set quadpoints to null if not defined", function (done) {
2486
3186
  const highlightDict = new _primitives.Dict();
2487
3187
  highlightDict.set("Type", _primitives.Name.get("Annot"));
2488
3188
  highlightDict.set("Subtype", _primitives.Name.get("Highlight"));
@@ -2498,7 +3198,7 @@ describe("annotation", function () {
2498
3198
  data
2499
3199
  }) => {
2500
3200
  expect(data.annotationType).toEqual(_util.AnnotationType.HIGHLIGHT);
2501
- expect(data.quadPoints).toBeUndefined();
3201
+ expect(data.quadPoints).toEqual(null);
2502
3202
  done();
2503
3203
  }, done.fail);
2504
3204
  });
@@ -2507,7 +3207,7 @@ describe("annotation", function () {
2507
3207
  highlightDict.set("Type", _primitives.Name.get("Annot"));
2508
3208
  highlightDict.set("Subtype", _primitives.Name.get("Highlight"));
2509
3209
  highlightDict.set("Rect", [10, 10, 20, 20]);
2510
- highlightDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
3210
+ highlightDict.set("QuadPoints", [10, 20, 20, 20, 10, 10, 20, 10]);
2511
3211
 
2512
3212
  const highlightRef = _primitives.Ref.get(121, 0);
2513
3213
 
@@ -2521,24 +3221,46 @@ describe("annotation", function () {
2521
3221
  }) => {
2522
3222
  expect(data.annotationType).toEqual(_util.AnnotationType.HIGHLIGHT);
2523
3223
  expect(data.quadPoints).toEqual([[{
2524
- x: 11,
2525
- y: 11
3224
+ x: 10,
3225
+ y: 20
2526
3226
  }, {
2527
- x: 12,
2528
- y: 12
3227
+ x: 20,
3228
+ y: 20
2529
3229
  }, {
2530
- x: 13,
2531
- y: 13
3230
+ x: 10,
3231
+ y: 10
2532
3232
  }, {
2533
- x: 14,
2534
- y: 14
3233
+ x: 20,
3234
+ y: 10
2535
3235
  }]]);
2536
3236
  done();
2537
3237
  }, done.fail);
2538
3238
  });
3239
+ it("should set quadpoints to null when empty", function (done) {
3240
+ const highlightDict = new _primitives.Dict();
3241
+ highlightDict.set("Type", _primitives.Name.get("Annot"));
3242
+ highlightDict.set("Subtype", _primitives.Name.get("Highlight"));
3243
+ highlightDict.set("Rect", [10, 10, 20, 20]);
3244
+ highlightDict.set("QuadPoints", []);
3245
+
3246
+ const highlightRef = _primitives.Ref.get(121, 0);
3247
+
3248
+ const xref = new _test_utils.XRefMock([{
3249
+ ref: highlightRef,
3250
+ data: highlightDict
3251
+ }]);
3252
+
3253
+ _annotation.AnnotationFactory.create(xref, highlightRef, pdfManagerMock, idFactoryMock).then(({
3254
+ data
3255
+ }) => {
3256
+ expect(data.annotationType).toEqual(_util.AnnotationType.HIGHLIGHT);
3257
+ expect(data.quadPoints).toEqual(null);
3258
+ done();
3259
+ }, done.fail);
3260
+ });
2539
3261
  });
2540
3262
  describe("UnderlineAnnotation", function () {
2541
- it("should not set quadpoints if not defined", function (done) {
3263
+ it("should set quadpoints to null if not defined", function (done) {
2542
3264
  const underlineDict = new _primitives.Dict();
2543
3265
  underlineDict.set("Type", _primitives.Name.get("Annot"));
2544
3266
  underlineDict.set("Subtype", _primitives.Name.get("Underline"));
@@ -2554,7 +3276,7 @@ describe("annotation", function () {
2554
3276
  data
2555
3277
  }) => {
2556
3278
  expect(data.annotationType).toEqual(_util.AnnotationType.UNDERLINE);
2557
- expect(data.quadPoints).toBeUndefined();
3279
+ expect(data.quadPoints).toEqual(null);
2558
3280
  done();
2559
3281
  }, done.fail);
2560
3282
  });
@@ -2563,7 +3285,7 @@ describe("annotation", function () {
2563
3285
  underlineDict.set("Type", _primitives.Name.get("Annot"));
2564
3286
  underlineDict.set("Subtype", _primitives.Name.get("Underline"));
2565
3287
  underlineDict.set("Rect", [10, 10, 20, 20]);
2566
- underlineDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
3288
+ underlineDict.set("QuadPoints", [10, 20, 20, 20, 10, 10, 20, 10]);
2567
3289
 
2568
3290
  const underlineRef = _primitives.Ref.get(121, 0);
2569
3291
 
@@ -2577,24 +3299,24 @@ describe("annotation", function () {
2577
3299
  }) => {
2578
3300
  expect(data.annotationType).toEqual(_util.AnnotationType.UNDERLINE);
2579
3301
  expect(data.quadPoints).toEqual([[{
2580
- x: 11,
2581
- y: 11
3302
+ x: 10,
3303
+ y: 20
2582
3304
  }, {
2583
- x: 12,
2584
- y: 12
3305
+ x: 20,
3306
+ y: 20
2585
3307
  }, {
2586
- x: 13,
2587
- y: 13
3308
+ x: 10,
3309
+ y: 10
2588
3310
  }, {
2589
- x: 14,
2590
- y: 14
3311
+ x: 20,
3312
+ y: 10
2591
3313
  }]]);
2592
3314
  done();
2593
3315
  }, done.fail);
2594
3316
  });
2595
3317
  });
2596
3318
  describe("SquigglyAnnotation", function () {
2597
- it("should not set quadpoints if not defined", function (done) {
3319
+ it("should set quadpoints to null if not defined", function (done) {
2598
3320
  const squigglyDict = new _primitives.Dict();
2599
3321
  squigglyDict.set("Type", _primitives.Name.get("Annot"));
2600
3322
  squigglyDict.set("Subtype", _primitives.Name.get("Squiggly"));
@@ -2610,7 +3332,7 @@ describe("annotation", function () {
2610
3332
  data
2611
3333
  }) => {
2612
3334
  expect(data.annotationType).toEqual(_util.AnnotationType.SQUIGGLY);
2613
- expect(data.quadPoints).toBeUndefined();
3335
+ expect(data.quadPoints).toEqual(null);
2614
3336
  done();
2615
3337
  }, done.fail);
2616
3338
  });
@@ -2619,7 +3341,7 @@ describe("annotation", function () {
2619
3341
  squigglyDict.set("Type", _primitives.Name.get("Annot"));
2620
3342
  squigglyDict.set("Subtype", _primitives.Name.get("Squiggly"));
2621
3343
  squigglyDict.set("Rect", [10, 10, 20, 20]);
2622
- squigglyDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
3344
+ squigglyDict.set("QuadPoints", [10, 20, 20, 20, 10, 10, 20, 10]);
2623
3345
 
2624
3346
  const squigglyRef = _primitives.Ref.get(121, 0);
2625
3347
 
@@ -2633,24 +3355,24 @@ describe("annotation", function () {
2633
3355
  }) => {
2634
3356
  expect(data.annotationType).toEqual(_util.AnnotationType.SQUIGGLY);
2635
3357
  expect(data.quadPoints).toEqual([[{
2636
- x: 11,
2637
- y: 11
3358
+ x: 10,
3359
+ y: 20
2638
3360
  }, {
2639
- x: 12,
2640
- y: 12
3361
+ x: 20,
3362
+ y: 20
2641
3363
  }, {
2642
- x: 13,
2643
- y: 13
3364
+ x: 10,
3365
+ y: 10
2644
3366
  }, {
2645
- x: 14,
2646
- y: 14
3367
+ x: 20,
3368
+ y: 10
2647
3369
  }]]);
2648
3370
  done();
2649
3371
  }, done.fail);
2650
3372
  });
2651
3373
  });
2652
3374
  describe("StrikeOutAnnotation", function () {
2653
- it("should not set quadpoints if not defined", function (done) {
3375
+ it("should set quadpoints to null if not defined", function (done) {
2654
3376
  const strikeOutDict = new _primitives.Dict();
2655
3377
  strikeOutDict.set("Type", _primitives.Name.get("Annot"));
2656
3378
  strikeOutDict.set("Subtype", _primitives.Name.get("StrikeOut"));
@@ -2666,7 +3388,7 @@ describe("annotation", function () {
2666
3388
  data
2667
3389
  }) => {
2668
3390
  expect(data.annotationType).toEqual(_util.AnnotationType.STRIKEOUT);
2669
- expect(data.quadPoints).toBeUndefined();
3391
+ expect(data.quadPoints).toEqual(null);
2670
3392
  done();
2671
3393
  }, done.fail);
2672
3394
  });
@@ -2675,7 +3397,7 @@ describe("annotation", function () {
2675
3397
  strikeOutDict.set("Type", _primitives.Name.get("Annot"));
2676
3398
  strikeOutDict.set("Subtype", _primitives.Name.get("StrikeOut"));
2677
3399
  strikeOutDict.set("Rect", [10, 10, 20, 20]);
2678
- strikeOutDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
3400
+ strikeOutDict.set("QuadPoints", [10, 20, 20, 20, 10, 10, 20, 10]);
2679
3401
 
2680
3402
  const strikeOutRef = _primitives.Ref.get(121, 0);
2681
3403
 
@@ -2689,17 +3411,17 @@ describe("annotation", function () {
2689
3411
  }) => {
2690
3412
  expect(data.annotationType).toEqual(_util.AnnotationType.STRIKEOUT);
2691
3413
  expect(data.quadPoints).toEqual([[{
2692
- x: 11,
2693
- y: 11
3414
+ x: 10,
3415
+ y: 20
2694
3416
  }, {
2695
- x: 12,
2696
- y: 12
3417
+ x: 20,
3418
+ y: 20
2697
3419
  }, {
2698
- x: 13,
2699
- y: 13
3420
+ x: 10,
3421
+ y: 10
2700
3422
  }, {
2701
- x: 14,
2702
- y: 14
3423
+ x: 20,
3424
+ y: 10
2703
3425
  }]]);
2704
3426
  done();
2705
3427
  }, done.fail);