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
@@ -24,7 +24,7 @@
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.CFFFDSelect = exports.CFFCompiler = exports.CFFPrivateDict = exports.CFFTopDict = exports.CFFCharset = exports.CFFIndex = exports.CFFStrings = exports.CFFHeader = exports.CFF = exports.CFFParser = exports.CFFStandardStrings = void 0;
27
+ exports.CFFTopDict = exports.CFFStrings = exports.CFFStandardStrings = exports.CFFPrivateDict = exports.CFFParser = exports.CFFIndex = exports.CFFHeader = exports.CFFFDSelect = exports.CFFCompiler = exports.CFFCharset = exports.CFF = void 0;
28
28
 
29
29
  var _util = require("../shared/util.js");
30
30
 
@@ -1387,6 +1387,12 @@ class CFFCompiler {
1387
1387
  }
1388
1388
  }
1389
1389
 
1390
+ const xuid = cff.topDict.getByName("XUID");
1391
+
1392
+ if (xuid && xuid.length > 16) {
1393
+ cff.topDict.removeByName("XUID");
1394
+ }
1395
+
1390
1396
  cff.topDict.setByName("charset", 0);
1391
1397
  var compiled = this.compileTopDicts([cff.topDict], output.length, cff.isCIDFont);
1392
1398
  output.add(compiled.output);
@@ -24,7 +24,7 @@
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.ExpertSubsetCharset = exports.ExpertCharset = exports.ISOAdobeCharset = void 0;
27
+ exports.ISOAdobeCharset = exports.ExpertSubsetCharset = exports.ExpertCharset = void 0;
28
28
  const ISOAdobeCharset = [".notdef", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "quoteleft", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "exclamdown", "cent", "sterling", "fraction", "yen", "florin", "section", "currency", "quotesingle", "quotedblleft", "guillemotleft", "guilsinglleft", "guilsinglright", "fi", "fl", "endash", "dagger", "daggerdbl", "periodcentered", "paragraph", "bullet", "quotesinglbase", "quotedblbase", "quotedblright", "guillemotright", "ellipsis", "perthousand", "questiondown", "grave", "acute", "circumflex", "tilde", "macron", "breve", "dotaccent", "dieresis", "ring", "cedilla", "hungarumlaut", "ogonek", "caron", "emdash", "AE", "ordfeminine", "Lslash", "Oslash", "OE", "ordmasculine", "ae", "dotlessi", "lslash", "oslash", "oe", "germandbls", "onesuperior", "logicalnot", "mu", "trademark", "Eth", "onehalf", "plusminus", "Thorn", "onequarter", "divide", "brokenbar", "degree", "thorn", "threequarters", "twosuperior", "registered", "minus", "eth", "multiply", "threesuperior", "copyright", "Aacute", "Acircumflex", "Adieresis", "Agrave", "Aring", "Atilde", "Ccedilla", "Eacute", "Ecircumflex", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Ntilde", "Oacute", "Ocircumflex", "Odieresis", "Ograve", "Otilde", "Scaron", "Uacute", "Ucircumflex", "Udieresis", "Ugrave", "Yacute", "Ydieresis", "Zcaron", "aacute", "acircumflex", "adieresis", "agrave", "aring", "atilde", "ccedilla", "eacute", "ecircumflex", "edieresis", "egrave", "iacute", "icircumflex", "idieresis", "igrave", "ntilde", "oacute", "ocircumflex", "odieresis", "ograve", "otilde", "scaron", "uacute", "ucircumflex", "udieresis", "ugrave", "yacute", "ydieresis", "zcaron"];
29
29
  exports.ISOAdobeCharset = ISOAdobeCharset;
30
30
  const ExpertCharset = [".notdef", "space", "exclamsmall", "Hungarumlautsmall", "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "comma", "hyphen", "period", "fraction", "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle", "colon", "semicolon", "commasuperior", "threequartersemdash", "periodsuperior", "questionsmall", "asuperior", "bsuperior", "centsuperior", "dsuperior", "esuperior", "isuperior", "lsuperior", "msuperior", "nsuperior", "osuperior", "rsuperior", "ssuperior", "tsuperior", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior", "parenrightinferior", "Circumflexsmall", "hyphensuperior", "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall", "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall", "exclamdownsmall", "centoldstyle", "Lslashsmall", "Scaronsmall", "Zcaronsmall", "Dieresissmall", "Brevesmall", "Caronsmall", "Dotaccentsmall", "Macronsmall", "figuredash", "hypheninferior", "Ogoneksmall", "Ringsmall", "Cedillasmall", "onequarter", "onehalf", "threequarters", "questiondownsmall", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds", "zerosuperior", "onesuperior", "twosuperior", "threesuperior", "foursuperior", "fivesuperior", "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior", "zeroinferior", "oneinferior", "twoinferior", "threeinferior", "fourinferior", "fiveinferior", "sixinferior", "seveninferior", "eightinferior", "nineinferior", "centinferior", "dollarinferior", "periodinferior", "commainferior", "Agravesmall", "Aacutesmall", "Acircumflexsmall", "Atildesmall", "Adieresissmall", "Aringsmall", "AEsmall", "Ccedillasmall", "Egravesmall", "Eacutesmall", "Ecircumflexsmall", "Edieresissmall", "Igravesmall", "Iacutesmall", "Icircumflexsmall", "Idieresissmall", "Ethsmall", "Ntildesmall", "Ogravesmall", "Oacutesmall", "Ocircumflexsmall", "Otildesmall", "Odieresissmall", "OEsmall", "Oslashsmall", "Ugravesmall", "Uacutesmall", "Ucircumflexsmall", "Udieresissmall", "Yacutesmall", "Thornsmall", "Ydieresissmall"];
package/lib/core/cmap.js CHANGED
@@ -24,7 +24,7 @@
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.CMapFactory = exports.IdentityCMap = exports.CMap = void 0;
27
+ exports.IdentityCMap = exports.CMapFactory = exports.CMap = void 0;
28
28
 
29
29
  var _util = require("../shared/util.js");
30
30
 
@@ -165,6 +165,25 @@ class CMap {
165
165
  out.length = 1;
166
166
  }
167
167
 
168
+ getCharCodeLength(charCode) {
169
+ const codespaceRanges = this.codespaceRanges;
170
+
171
+ for (let n = 0, nn = codespaceRanges.length; n < nn; n++) {
172
+ const codespaceRange = codespaceRanges[n];
173
+
174
+ for (let k = 0, kk = codespaceRange.length; k < kk;) {
175
+ const low = codespaceRange[k++];
176
+ const high = codespaceRange[k++];
177
+
178
+ if (charCode >= low && charCode <= high) {
179
+ return n + 1;
180
+ }
181
+ }
182
+ }
183
+
184
+ return 1;
185
+ }
186
+
168
187
  get length() {
169
188
  return this._map.length;
170
189
  }
@@ -24,18 +24,24 @@
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.getLookupTableFactory = getLookupTableFactory;
27
+ exports.collectActions = collectActions;
28
+ exports.escapePDFName = escapePDFName;
29
+ exports.getArrayLookupTableFactory = getArrayLookupTableFactory;
28
30
  exports.getInheritableProperty = getInheritableProperty;
29
- exports.toRomanNumerals = toRomanNumerals;
31
+ exports.getLookupTableFactory = getLookupTableFactory;
32
+ exports.isWhiteSpace = isWhiteSpace;
30
33
  exports.log2 = log2;
34
+ exports.parseXFAPath = parseXFAPath;
31
35
  exports.readInt8 = readInt8;
32
36
  exports.readUint16 = readUint16;
33
37
  exports.readUint32 = readUint32;
34
- exports.isWhiteSpace = isWhiteSpace;
38
+ exports.toRomanNumerals = toRomanNumerals;
35
39
  exports.XRefParseException = exports.XRefEntryException = exports.MissingDataException = void 0;
36
40
 
37
41
  var _util = require("../shared/util.js");
38
42
 
43
+ var _primitives = require("./primitives.js");
44
+
39
45
  function getLookupTableFactory(initializer) {
40
46
  let lookup;
41
47
  return function () {
@@ -49,6 +55,25 @@ function getLookupTableFactory(initializer) {
49
55
  };
50
56
  }
51
57
 
58
+ function getArrayLookupTableFactory(initializer) {
59
+ let lookup;
60
+ return function () {
61
+ if (initializer) {
62
+ let arr = initializer();
63
+ initializer = null;
64
+ lookup = Object.create(null);
65
+
66
+ for (let i = 0, ii = arr.length; i < ii; i += 2) {
67
+ lookup[arr[i]] = arr[i + 1];
68
+ }
69
+
70
+ arr = null;
71
+ }
72
+
73
+ return lookup;
74
+ };
75
+ }
76
+
52
77
  class MissingDataException extends _util.BaseException {
53
78
  constructor(begin, end) {
54
79
  super(`Missing data [${begin}, ${end})`);
@@ -149,4 +174,138 @@ function readUint32(data, offset) {
149
174
 
150
175
  function isWhiteSpace(ch) {
151
176
  return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a;
177
+ }
178
+
179
+ function parseXFAPath(path) {
180
+ const positionPattern = /(.+)\[([0-9]+)\]$/;
181
+ return path.split(".").map(component => {
182
+ const m = component.match(positionPattern);
183
+
184
+ if (m) {
185
+ return {
186
+ name: m[1],
187
+ pos: parseInt(m[2], 10)
188
+ };
189
+ }
190
+
191
+ return {
192
+ name: component,
193
+ pos: 0
194
+ };
195
+ });
196
+ }
197
+
198
+ function escapePDFName(str) {
199
+ const buffer = [];
200
+ let start = 0;
201
+
202
+ for (let i = 0, ii = str.length; i < ii; i++) {
203
+ const char = str.charCodeAt(i);
204
+
205
+ if (char < 0x21 || char > 0x7e || char === 0x23 || char === 0x28 || char === 0x29 || char === 0x3c || char === 0x3e || char === 0x5b || char === 0x5d || char === 0x7b || char === 0x7d || char === 0x2f || char === 0x25) {
206
+ if (start < i) {
207
+ buffer.push(str.substring(start, i));
208
+ }
209
+
210
+ buffer.push(`#${char.toString(16)}`);
211
+ start = i + 1;
212
+ }
213
+ }
214
+
215
+ if (buffer.length === 0) {
216
+ return str;
217
+ }
218
+
219
+ if (start < str.length) {
220
+ buffer.push(str.substring(start, str.length));
221
+ }
222
+
223
+ return buffer.join("");
224
+ }
225
+
226
+ function _collectJS(entry, xref, list, parents) {
227
+ if (!entry) {
228
+ return;
229
+ }
230
+
231
+ let parent = null;
232
+
233
+ if ((0, _primitives.isRef)(entry)) {
234
+ if (parents.has(entry)) {
235
+ return;
236
+ }
237
+
238
+ parent = entry;
239
+ parents.put(parent);
240
+ entry = xref.fetch(entry);
241
+ }
242
+
243
+ if (Array.isArray(entry)) {
244
+ for (const element of entry) {
245
+ _collectJS(element, xref, list, parents);
246
+ }
247
+ } else if (entry instanceof _primitives.Dict) {
248
+ if ((0, _primitives.isName)(entry.get("S"), "JavaScript") && entry.has("JS")) {
249
+ const js = entry.get("JS");
250
+ let code;
251
+
252
+ if ((0, _primitives.isStream)(js)) {
253
+ code = (0, _util.bytesToString)(js.getBytes());
254
+ } else {
255
+ code = js;
256
+ }
257
+
258
+ code = (0, _util.stringToPDFString)(code);
259
+
260
+ if (code) {
261
+ list.push(code);
262
+ }
263
+ }
264
+
265
+ _collectJS(entry.getRaw("Next"), xref, list, parents);
266
+ }
267
+
268
+ if (parent) {
269
+ parents.remove(parent);
270
+ }
271
+ }
272
+
273
+ function collectActions(xref, dict, eventType) {
274
+ const actions = Object.create(null);
275
+
276
+ if (dict.has("AA")) {
277
+ const additionalActions = dict.get("AA");
278
+
279
+ for (const key of additionalActions.getKeys()) {
280
+ const action = eventType[key];
281
+
282
+ if (!action) {
283
+ continue;
284
+ }
285
+
286
+ const actionDict = additionalActions.getRaw(key);
287
+ const parents = new _primitives.RefSet();
288
+ const list = [];
289
+
290
+ _collectJS(actionDict, xref, list, parents);
291
+
292
+ if (list.length > 0) {
293
+ actions[action] = list;
294
+ }
295
+ }
296
+ }
297
+
298
+ if (dict.has("A")) {
299
+ const actionDict = dict.get("A");
300
+ const parents = new _primitives.RefSet();
301
+ const list = [];
302
+
303
+ _collectJS(actionDict, xref, list, parents);
304
+
305
+ if (list.length > 0) {
306
+ actions.Action = list;
307
+ }
308
+ }
309
+
310
+ return (0, _util.objectSize)(actions) > 0 ? actions : null;
152
311
  }
@@ -24,7 +24,7 @@
24
24
  Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
- exports.calculateSHA512 = exports.calculateSHA384 = exports.calculateSHA256 = exports.calculateMD5 = exports.PDF20 = exports.PDF17 = exports.CipherTransformFactory = exports.ARCFourCipher = exports.AES256Cipher = exports.AES128Cipher = void 0;
27
+ exports.PDF20 = exports.PDF17 = exports.CipherTransformFactory = exports.calculateSHA512 = exports.calculateSHA384 = exports.calculateSHA256 = exports.calculateMD5 = exports.ARCFourCipher = exports.AES256Cipher = exports.AES128Cipher = void 0;
28
28
 
29
29
  var _util = require("../shared/util.js");
30
30
 
@@ -0,0 +1,132 @@
1
+ /**
2
+ * @licstart The following is the entire license notice for the
3
+ * Javascript code in this page
4
+ *
5
+ * Copyright 2020 Mozilla Foundation
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ * @licend The above is the entire license notice for the
20
+ * Javascript code in this page
21
+ */
22
+ "use strict";
23
+
24
+ Object.defineProperty(exports, "__esModule", {
25
+ value: true
26
+ });
27
+ exports.createDefaultAppearance = createDefaultAppearance;
28
+ exports.parseDefaultAppearance = parseDefaultAppearance;
29
+
30
+ var _primitives = require("./primitives.js");
31
+
32
+ var _util = require("../shared/util.js");
33
+
34
+ var _colorspace = require("./colorspace.js");
35
+
36
+ var _core_utils = require("./core_utils.js");
37
+
38
+ var _evaluator = require("./evaluator.js");
39
+
40
+ var _stream = require("./stream.js");
41
+
42
+ class DefaultAppearanceEvaluator extends _evaluator.EvaluatorPreprocessor {
43
+ constructor(str) {
44
+ super(new _stream.StringStream(str));
45
+ }
46
+
47
+ parse() {
48
+ const operation = {
49
+ fn: 0,
50
+ args: []
51
+ };
52
+ const result = {
53
+ fontSize: 0,
54
+ fontName: _primitives.Name.get(""),
55
+ fontColor: new Uint8ClampedArray([0, 0, 0])
56
+ };
57
+
58
+ try {
59
+ while (true) {
60
+ operation.args.length = 0;
61
+
62
+ if (!this.read(operation)) {
63
+ break;
64
+ }
65
+
66
+ if (this.savedStatesDepth !== 0) {
67
+ continue;
68
+ }
69
+
70
+ const {
71
+ fn,
72
+ args
73
+ } = operation;
74
+
75
+ switch (fn | 0) {
76
+ case _util.OPS.setFont:
77
+ const [fontName, fontSize] = args;
78
+
79
+ if ((0, _primitives.isName)(fontName)) {
80
+ result.fontName = fontName;
81
+ }
82
+
83
+ if (typeof fontSize === "number" && fontSize > 0) {
84
+ result.fontSize = fontSize;
85
+ }
86
+
87
+ break;
88
+
89
+ case _util.OPS.setFillRGBColor:
90
+ _colorspace.ColorSpace.singletons.rgb.getRgbItem(args, 0, result.fontColor, 0);
91
+
92
+ break;
93
+
94
+ case _util.OPS.setFillGray:
95
+ _colorspace.ColorSpace.singletons.gray.getRgbItem(args, 0, result.fontColor, 0);
96
+
97
+ break;
98
+
99
+ case _util.OPS.setFillColorSpace:
100
+ _colorspace.ColorSpace.singletons.cmyk.getRgbItem(args, 0, result.fontColor, 0);
101
+
102
+ break;
103
+ }
104
+ }
105
+ } catch (reason) {
106
+ (0, _util.warn)(`parseDefaultAppearance - ignoring errors: "${reason}".`);
107
+ }
108
+
109
+ return result;
110
+ }
111
+
112
+ }
113
+
114
+ function parseDefaultAppearance(str) {
115
+ return new DefaultAppearanceEvaluator(str).parse();
116
+ }
117
+
118
+ function createDefaultAppearance({
119
+ fontSize,
120
+ fontName,
121
+ fontColor
122
+ }) {
123
+ let colorCmd;
124
+
125
+ if (fontColor.every(c => c === 0)) {
126
+ colorCmd = "0 g";
127
+ } else {
128
+ colorCmd = Array.from(fontColor).map(c => (c / 255).toFixed(2)).join(" ") + " rg";
129
+ }
130
+
131
+ return `/${(0, _core_utils.escapePDFName)(fontName.name)} ${fontSize} Tf ${colorCmd}`;
132
+ }
@@ -63,7 +63,8 @@ class Page {
63
63
  globalIdFactory,
64
64
  fontCache,
65
65
  builtInCMapCache,
66
- globalImageCache
66
+ globalImageCache,
67
+ nonBlendModesSet
67
68
  }) {
68
69
  this.pdfManager = pdfManager;
69
70
  this.pageIndex = pageIndex;
@@ -73,6 +74,7 @@ class Page {
73
74
  this.fontCache = fontCache;
74
75
  this.builtInCMapCache = builtInCMapCache;
75
76
  this.globalImageCache = globalImageCache;
77
+ this.nonBlendModesSet = nonBlendModesSet;
76
78
  this.evaluatorOptions = pdfManager.evaluatorOptions;
77
79
  this.resourcesPromise = null;
78
80
  const idCounters = {
@@ -270,7 +272,7 @@ class Page {
270
272
  const pageListPromise = dataPromises.then(([contentStream]) => {
271
273
  const opList = new _operator_list.OperatorList(intent, sink);
272
274
  handler.send("StartRenderPage", {
273
- transparency: partialEvaluator.hasBlendModes(this.resources),
275
+ transparency: partialEvaluator.hasBlendModes(this.resources, this.nonBlendModesSet),
274
276
  pageIndex: this.pageIndex,
275
277
  intent
276
278
  });
@@ -294,7 +296,7 @@ class Page {
294
296
  const opListPromises = [];
295
297
 
296
298
  for (const annotation of annotations) {
297
- if (isAnnotationRenderable(annotation, intent)) {
299
+ if (isAnnotationRenderable(annotation, intent) && !annotation.isHidden(annotationStorage)) {
298
300
  opListPromises.push(annotation.getOperatorList(partialEvaluator, task, renderInteractiveForms, annotationStorage).catch(function (reason) {
299
301
  (0, _util.warn)("getOperatorList - ignoring annotation data during " + `"${task.name}" task: "${reason}".`);
300
302
  return null;
@@ -365,7 +367,9 @@ class Page {
365
367
  }
366
368
 
367
369
  get annotations() {
368
- return (0, _util.shadow)(this, "annotations", this._getInheritableProperty("Annots") || []);
370
+ const annots = this._getInheritableProperty("Annots");
371
+
372
+ return (0, _util.shadow)(this, "annotations", Array.isArray(annots) ? annots : []);
369
373
  }
370
374
 
371
375
  get _parsedAnnotations() {
@@ -386,6 +390,11 @@ class Page {
386
390
  return (0, _util.shadow)(this, "_parsedAnnotations", parsedAnnotations);
387
391
  }
388
392
 
393
+ get jsActions() {
394
+ const actions = (0, _core_utils.collectActions)(this.xref, this.pageDict, _util.PageActionEventType);
395
+ return (0, _util.shadow)(this, "jsActions", actions);
396
+ }
397
+
389
398
  }
390
399
 
391
400
  exports.Page = Page;
@@ -601,9 +610,18 @@ class PDFDocument {
601
610
 
602
611
  _hasOnlyDocumentSignatures(fields, recursionDepth = 0) {
603
612
  const RECURSION_LIMIT = 10;
613
+
614
+ if (!Array.isArray(fields)) {
615
+ return false;
616
+ }
617
+
604
618
  return fields.every(field => {
605
619
  field = this.xref.fetchIfRef(field);
606
620
 
621
+ if (!(field instanceof _primitives.Dict)) {
622
+ return false;
623
+ }
624
+
607
625
  if (field.has("Kids")) {
608
626
  if (++recursionDepth > RECURSION_LIMIT) {
609
627
  (0, _util.warn)("_hasOnlyDocumentSignatures: maximum recursion depth reached");
@@ -622,6 +640,7 @@ class PDFDocument {
622
640
 
623
641
  get formInfo() {
624
642
  const formInfo = {
643
+ hasFields: false,
625
644
  hasAcroForm: false,
626
645
  hasXfa: false
627
646
  };
@@ -632,11 +651,11 @@ class PDFDocument {
632
651
  }
633
652
 
634
653
  try {
635
- const xfa = acroForm.get("XFA");
636
- const hasXfa = Array.isArray(xfa) && xfa.length > 0 || (0, _primitives.isStream)(xfa) && !xfa.isEmpty;
637
- formInfo.hasXfa = hasXfa;
638
654
  const fields = acroForm.get("Fields");
639
655
  const hasFields = Array.isArray(fields) && fields.length > 0;
656
+ formInfo.hasFields = hasFields;
657
+ const xfa = acroForm.get("XFA");
658
+ formInfo.hasXfa = Array.isArray(xfa) && xfa.length > 0 || (0, _primitives.isStream)(xfa) && !xfa.isEmpty;
640
659
  const sigFlags = acroForm.get("SigFlags");
641
660
 
642
661
  const hasOnlyDocumentSignatures = !!(sigFlags & 0x1) && this._hasOnlyDocumentSignatures(fields);
@@ -647,7 +666,7 @@ class PDFDocument {
647
666
  throw ex;
648
667
  }
649
668
 
650
- (0, _util.info)("Cannot fetch form information.");
669
+ (0, _util.warn)(`Cannot fetch form information: "${ex}".`);
651
670
  }
652
671
 
653
672
  return (0, _util.shadow)(this, "formInfo", formInfo);
@@ -789,7 +808,8 @@ class PDFDocument {
789
808
  globalIdFactory: this._globalIdFactory,
790
809
  fontCache: catalog.fontCache,
791
810
  builtInCMapCache: catalog.builtInCMapCache,
792
- globalImageCache: catalog.globalImageCache
811
+ globalImageCache: catalog.globalImageCache,
812
+ nonBlendModesSet: catalog.nonBlendModesSet
793
813
  });
794
814
  });
795
815
  }
@@ -812,6 +832,92 @@ class PDFDocument {
812
832
  return this.catalog ? this.catalog.cleanup(manuallyTriggered) : (0, _primitives.clearPrimitiveCaches)();
813
833
  }
814
834
 
835
+ _collectFieldObjects(name, fieldRef, promises) {
836
+ const field = this.xref.fetchIfRef(fieldRef);
837
+
838
+ if (field.has("T")) {
839
+ const partName = (0, _util.stringToPDFString)(field.get("T"));
840
+
841
+ if (name === "") {
842
+ name = partName;
843
+ } else {
844
+ name = `${name}.${partName}`;
845
+ }
846
+ }
847
+
848
+ if (!promises.has(name)) {
849
+ promises.set(name, []);
850
+ }
851
+
852
+ promises.get(name).push(_annotation.AnnotationFactory.create(this.xref, fieldRef, this.pdfManager, this._localIdFactory).then(annotation => annotation && annotation.getFieldObject()).catch(function (reason) {
853
+ (0, _util.warn)(`_collectFieldObjects: "${reason}".`);
854
+ return null;
855
+ }));
856
+
857
+ if (field.has("Kids")) {
858
+ const kids = field.get("Kids");
859
+
860
+ for (const kid of kids) {
861
+ this._collectFieldObjects(name, kid, promises);
862
+ }
863
+ }
864
+ }
865
+
866
+ get fieldObjects() {
867
+ if (!this.formInfo.hasFields) {
868
+ return (0, _util.shadow)(this, "fieldObjects", Promise.resolve(null));
869
+ }
870
+
871
+ const allFields = Object.create(null);
872
+ const fieldPromises = new Map();
873
+
874
+ for (const fieldRef of this.catalog.acroForm.get("Fields")) {
875
+ this._collectFieldObjects("", fieldRef, fieldPromises);
876
+ }
877
+
878
+ const allPromises = [];
879
+
880
+ for (const [name, promises] of fieldPromises) {
881
+ allPromises.push(Promise.all(promises).then(fields => {
882
+ fields = fields.filter(field => !!field);
883
+
884
+ if (fields.length > 0) {
885
+ allFields[name] = fields;
886
+ }
887
+ }));
888
+ }
889
+
890
+ return (0, _util.shadow)(this, "fieldObjects", Promise.all(allPromises).then(() => allFields));
891
+ }
892
+
893
+ get hasJSActions() {
894
+ return (0, _util.shadow)(this, "hasJSActions", this.fieldObjects.then(fieldObjects => {
895
+ return fieldObjects !== null && Object.values(fieldObjects).some(fieldObject => fieldObject.some(object => object.actions !== null)) || !!this.catalog.jsActions;
896
+ }));
897
+ }
898
+
899
+ get calculationOrderIds() {
900
+ const acroForm = this.catalog.acroForm;
901
+
902
+ if (!acroForm || !acroForm.has("CO")) {
903
+ return (0, _util.shadow)(this, "calculationOrderIds", null);
904
+ }
905
+
906
+ const calculationOrder = acroForm.get("CO");
907
+
908
+ if (!Array.isArray(calculationOrder) || calculationOrder.length === 0) {
909
+ return (0, _util.shadow)(this, "calculationOrderIds", null);
910
+ }
911
+
912
+ const ids = calculationOrder.filter(_primitives.isRef).map(ref => ref.toString());
913
+
914
+ if (ids.length === 0) {
915
+ return (0, _util.shadow)(this, "calculationOrderIds", null);
916
+ }
917
+
918
+ return (0, _util.shadow)(this, "calculationOrderIds", ids);
919
+ }
920
+
815
921
  }
816
922
 
817
923
  exports.PDFDocument = PDFDocument;
@@ -25,7 +25,7 @@ Object.defineProperty(exports, "__esModule", {
25
25
  value: true
26
26
  });
27
27
  exports.getEncoding = getEncoding;
28
- exports.ExpertEncoding = exports.ZapfDingbatsEncoding = exports.SymbolSetEncoding = exports.MacRomanEncoding = exports.StandardEncoding = exports.WinAnsiEncoding = void 0;
28
+ exports.ZapfDingbatsEncoding = exports.WinAnsiEncoding = exports.SymbolSetEncoding = exports.StandardEncoding = exports.MacRomanEncoding = exports.ExpertEncoding = void 0;
29
29
  const ExpertEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclamsmall", "Hungarumlautsmall", "", "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "comma", "hyphen", "period", "fraction", "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle", "colon", "semicolon", "commasuperior", "threequartersemdash", "periodsuperior", "questionsmall", "", "asuperior", "bsuperior", "centsuperior", "dsuperior", "esuperior", "", "", "", "isuperior", "", "", "lsuperior", "msuperior", "nsuperior", "osuperior", "", "", "rsuperior", "ssuperior", "tsuperior", "", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior", "", "parenrightinferior", "Circumflexsmall", "hyphensuperior", "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall", "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "exclamdownsmall", "centoldstyle", "Lslashsmall", "", "", "Scaronsmall", "Zcaronsmall", "Dieresissmall", "Brevesmall", "Caronsmall", "", "Dotaccentsmall", "", "", "Macronsmall", "", "", "figuredash", "hypheninferior", "", "", "Ogoneksmall", "Ringsmall", "Cedillasmall", "", "", "", "onequarter", "onehalf", "threequarters", "questiondownsmall", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds", "", "", "zerosuperior", "onesuperior", "twosuperior", "threesuperior", "foursuperior", "fivesuperior", "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior", "zeroinferior", "oneinferior", "twoinferior", "threeinferior", "fourinferior", "fiveinferior", "sixinferior", "seveninferior", "eightinferior", "nineinferior", "centinferior", "dollarinferior", "periodinferior", "commainferior", "Agravesmall", "Aacutesmall", "Acircumflexsmall", "Atildesmall", "Adieresissmall", "Aringsmall", "AEsmall", "Ccedillasmall", "Egravesmall", "Eacutesmall", "Ecircumflexsmall", "Edieresissmall", "Igravesmall", "Iacutesmall", "Icircumflexsmall", "Idieresissmall", "Ethsmall", "Ntildesmall", "Ogravesmall", "Oacutesmall", "Ocircumflexsmall", "Otildesmall", "Odieresissmall", "OEsmall", "Oslashsmall", "Ugravesmall", "Uacutesmall", "Ucircumflexsmall", "Udieresissmall", "Yacutesmall", "Thornsmall", "Ydieresissmall"];
30
30
  exports.ExpertEncoding = ExpertEncoding;
31
31
  const MacExpertEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclamsmall", "Hungarumlautsmall", "centoldstyle", "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "comma", "hyphen", "period", "fraction", "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle", "colon", "semicolon", "", "threequartersemdash", "", "questionsmall", "", "", "", "", "Ethsmall", "", "", "onequarter", "onehalf", "threequarters", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds", "", "", "", "", "", "", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior", "", "parenrightinferior", "Circumflexsmall", "hypheninferior", "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall", "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall", "", "", "asuperior", "centsuperior", "", "", "", "", "Aacutesmall", "Agravesmall", "Acircumflexsmall", "Adieresissmall", "Atildesmall", "Aringsmall", "Ccedillasmall", "Eacutesmall", "Egravesmall", "Ecircumflexsmall", "Edieresissmall", "Iacutesmall", "Igravesmall", "Icircumflexsmall", "Idieresissmall", "Ntildesmall", "Oacutesmall", "Ogravesmall", "Ocircumflexsmall", "Odieresissmall", "Otildesmall", "Uacutesmall", "Ugravesmall", "Ucircumflexsmall", "Udieresissmall", "", "eightsuperior", "fourinferior", "threeinferior", "sixinferior", "eightinferior", "seveninferior", "Scaronsmall", "", "centinferior", "twoinferior", "", "Dieresissmall", "", "Caronsmall", "osuperior", "fiveinferior", "", "commainferior", "periodinferior", "Yacutesmall", "", "dollarinferior", "", "", "Thornsmall", "", "nineinferior", "zeroinferior", "Zcaronsmall", "AEsmall", "Oslashsmall", "questiondownsmall", "oneinferior", "Lslashsmall", "", "", "", "", "", "", "Cedillasmall", "", "", "", "", "", "OEsmall", "figuredash", "hyphensuperior", "", "", "", "", "exclamdownsmall", "", "Ydieresissmall", "", "onesuperior", "twosuperior", "threesuperior", "foursuperior", "fivesuperior", "sixsuperior", "sevensuperior", "ninesuperior", "zerosuperior", "", "esuperior", "rsuperior", "tsuperior", "", "", "isuperior", "ssuperior", "dsuperior", "", "", "", "", "", "lsuperior", "Ogoneksmall", "Brevesmall", "Macronsmall", "bsuperior", "nsuperior", "msuperior", "commasuperior", "periodsuperior", "Dotaccentsmall", "Ringsmall", "", "", "", ""];