pdfkit 0.10.0 → 0.11.0

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.
package/js/pdfkit.js CHANGED
@@ -1,18 +1,16 @@
1
1
  'use strict';
2
2
 
3
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
-
5
- var stream = _interopDefault(require('stream'));
3
+ var stream = require('stream');
6
4
  var fs = require('fs');
7
- var zlib = _interopDefault(require('zlib'));
8
- var CryptoJS = _interopDefault(require('crypto-js'));
9
- var fontkit = _interopDefault(require('fontkit'));
5
+ var zlib = require('zlib');
6
+ var CryptoJS = require('crypto-js');
7
+ var fontkit = require('fontkit');
10
8
  var events = require('events');
11
- var LineBreaker = _interopDefault(require('linebreak'));
12
- var PNG = _interopDefault(require('png-js'));
9
+ var LineBreaker = require('linebreak');
10
+ var PNG = require('png-js');
13
11
 
14
- /*
15
- PDFAbstractReference - abstract class for PDF reference
12
+ /*
13
+ PDFAbstractReference - abstract class for PDF reference
16
14
  */
17
15
  class PDFAbstractReference {
18
16
  toString() {
@@ -21,8 +19,8 @@ class PDFAbstractReference {
21
19
 
22
20
  }
23
21
 
24
- /*
25
- PDFNameTree - represents a name tree object
22
+ /*
23
+ PDFNameTree - represents a name tree object
26
24
  */
27
25
 
28
26
  class PDFNameTree {
@@ -62,9 +60,9 @@ class PDFNameTree {
62
60
 
63
61
  }
64
62
 
65
- /*
66
- PDFObject - converts JavaScript types into their corresponding PDF types.
67
- By Devon Govett
63
+ /*
64
+ PDFObject - converts JavaScript types into their corresponding PDF types.
65
+ By Devon Govett
68
66
  */
69
67
 
70
68
  const pad = (str, length) => (Array(length + 1).join('0') + str).slice(-length);
@@ -177,9 +175,9 @@ class PDFObject {
177
175
 
178
176
  }
179
177
 
180
- /*
181
- PDFReference - represents a reference to another object in the PDF object heirarchy
182
- By Devon Govett
178
+ /*
179
+ PDFReference - represents a reference to another object in the PDF object heirarchy
180
+ By Devon Govett
183
181
  */
184
182
 
185
183
  class PDFReference extends PDFAbstractReference {
@@ -264,9 +262,9 @@ class PDFReference extends PDFAbstractReference {
264
262
 
265
263
  }
266
264
 
267
- /*
268
- PDFPage - represents a single page in the PDF document
269
- By Devon Govett
265
+ /*
266
+ PDFPage - represents a single page in the PDF document
267
+ By Devon Govett
270
268
  */
271
269
  const DEFAULT_MARGINS = {
272
270
  top: 72,
@@ -405,11 +403,11 @@ class PDFPage {
405
403
 
406
404
  }
407
405
 
408
- /**
409
- * Check if value is in a range group.
410
- * @param {number} value
411
- * @param {number[]} rangeGroup
412
- * @returns {boolean}
406
+ /**
407
+ * Check if value is in a range group.
408
+ * @param {number} value
409
+ * @param {number[]} rangeGroup
410
+ * @returns {boolean}
413
411
  */
414
412
  function inRange(value, rangeGroup) {
415
413
  if (value < rangeGroup[0]) return false;
@@ -439,9 +437,9 @@ function inRange(value, rangeGroup) {
439
437
 
440
438
  /* eslint-disable prettier/prettier */
441
439
 
442
- /**
443
- * A.1 Unassigned code points in Unicode 3.2
444
- * @link https://tools.ietf.org/html/rfc3454#appendix-A.1
440
+ /**
441
+ * A.1 Unassigned code points in Unicode 3.2
442
+ * @link https://tools.ietf.org/html/rfc3454#appendix-A.1
445
443
  */
446
444
 
447
445
  const unassigned_code_points = [0x0221, 0x0221, 0x0234, 0x024f, 0x02ae, 0x02af, 0x02ef, 0x02ff, 0x0350, 0x035f, 0x0370, 0x0373, 0x0376, 0x0379, 0x037b, 0x037d, 0x037f, 0x0383, 0x038b, 0x038b, 0x038d, 0x038d, 0x03a2, 0x03a2, 0x03cf, 0x03cf, 0x03f7, 0x03ff, 0x0487, 0x0487, 0x04cf, 0x04cf, 0x04f6, 0x04f7, 0x04fa, 0x04ff, 0x0510, 0x0530, 0x0557, 0x0558, 0x0560, 0x0560, 0x0588, 0x0588, 0x058b, 0x0590, 0x05a2, 0x05a2, 0x05ba, 0x05ba, 0x05c5, 0x05cf, 0x05eb, 0x05ef, 0x05f5, 0x060b, 0x060d, 0x061a, 0x061c, 0x061e, 0x0620, 0x0620, 0x063b, 0x063f, 0x0656, 0x065f, 0x06ee, 0x06ef, 0x06ff, 0x06ff, 0x070e, 0x070e, 0x072d, 0x072f, 0x074b, 0x077f, 0x07b2, 0x0900, 0x0904, 0x0904, 0x093a, 0x093b, 0x094e, 0x094f, 0x0955, 0x0957, 0x0971, 0x0980, 0x0984, 0x0984, 0x098d, 0x098e, 0x0991, 0x0992, 0x09a9, 0x09a9, 0x09b1, 0x09b1, 0x09b3, 0x09b5, 0x09ba, 0x09bb, 0x09bd, 0x09bd, 0x09c5, 0x09c6, 0x09c9, 0x09ca, 0x09ce, 0x09d6, 0x09d8, 0x09db, 0x09de, 0x09de, 0x09e4, 0x09e5, 0x09fb, 0x0a01, 0x0a03, 0x0a04, 0x0a0b, 0x0a0e, 0x0a11, 0x0a12, 0x0a29, 0x0a29, 0x0a31, 0x0a31, 0x0a34, 0x0a34, 0x0a37, 0x0a37, 0x0a3a, 0x0a3b, 0x0a3d, 0x0a3d, 0x0a43, 0x0a46, 0x0a49, 0x0a4a, 0x0a4e, 0x0a58, 0x0a5d, 0x0a5d, 0x0a5f, 0x0a65, 0x0a75, 0x0a80, 0x0a84, 0x0a84, 0x0a8c, 0x0a8c, 0x0a8e, 0x0a8e, 0x0a92, 0x0a92, 0x0aa9, 0x0aa9, 0x0ab1, 0x0ab1, 0x0ab4, 0x0ab4, 0x0aba, 0x0abb, 0x0ac6, 0x0ac6, 0x0aca, 0x0aca, 0x0ace, 0x0acf, 0x0ad1, 0x0adf, 0x0ae1, 0x0ae5, 0x0af0, 0x0b00, 0x0b04, 0x0b04, 0x0b0d, 0x0b0e, 0x0b11, 0x0b12, 0x0b29, 0x0b29, 0x0b31, 0x0b31, 0x0b34, 0x0b35, 0x0b3a, 0x0b3b, 0x0b44, 0x0b46, 0x0b49, 0x0b4a, 0x0b4e, 0x0b55, 0x0b58, 0x0b5b, 0x0b5e, 0x0b5e, 0x0b62, 0x0b65, 0x0b71, 0x0b81, 0x0b84, 0x0b84, 0x0b8b, 0x0b8d, 0x0b91, 0x0b91, 0x0b96, 0x0b98, 0x0b9b, 0x0b9b, 0x0b9d, 0x0b9d, 0x0ba0, 0x0ba2, 0x0ba5, 0x0ba7, 0x0bab, 0x0bad, 0x0bb6, 0x0bb6, 0x0bba, 0x0bbd, 0x0bc3, 0x0bc5, 0x0bc9, 0x0bc9, 0x0bce, 0x0bd6, 0x0bd8, 0x0be6, 0x0bf3, 0x0c00, 0x0c04, 0x0c04, 0x0c0d, 0x0c0d, 0x0c11, 0x0c11, 0x0c29, 0x0c29, 0x0c34, 0x0c34, 0x0c3a, 0x0c3d, 0x0c45, 0x0c45, 0x0c49, 0x0c49, 0x0c4e, 0x0c54, 0x0c57, 0x0c5f, 0x0c62, 0x0c65, 0x0c70, 0x0c81, 0x0c84, 0x0c84, 0x0c8d, 0x0c8d, 0x0c91, 0x0c91, 0x0ca9, 0x0ca9, 0x0cb4, 0x0cb4, 0x0cba, 0x0cbd, 0x0cc5, 0x0cc5, 0x0cc9, 0x0cc9, 0x0cce, 0x0cd4, 0x0cd7, 0x0cdd, 0x0cdf, 0x0cdf, 0x0ce2, 0x0ce5, 0x0cf0, 0x0d01, 0x0d04, 0x0d04, 0x0d0d, 0x0d0d, 0x0d11, 0x0d11, 0x0d29, 0x0d29, 0x0d3a, 0x0d3d, 0x0d44, 0x0d45, 0x0d49, 0x0d49, 0x0d4e, 0x0d56, 0x0d58, 0x0d5f, 0x0d62, 0x0d65, 0x0d70, 0x0d81, 0x0d84, 0x0d84, 0x0d97, 0x0d99, 0x0db2, 0x0db2, 0x0dbc, 0x0dbc, 0x0dbe, 0x0dbf, 0x0dc7, 0x0dc9, 0x0dcb, 0x0dce, 0x0dd5, 0x0dd5, 0x0dd7, 0x0dd7, 0x0de0, 0x0df1, 0x0df5, 0x0e00, 0x0e3b, 0x0e3e, 0x0e5c, 0x0e80, 0x0e83, 0x0e83, 0x0e85, 0x0e86, 0x0e89, 0x0e89, 0x0e8b, 0x0e8c, 0x0e8e, 0x0e93, 0x0e98, 0x0e98, 0x0ea0, 0x0ea0, 0x0ea4, 0x0ea4, 0x0ea6, 0x0ea6, 0x0ea8, 0x0ea9, 0x0eac, 0x0eac, 0x0eba, 0x0eba, 0x0ebe, 0x0ebf, 0x0ec5, 0x0ec5, 0x0ec7, 0x0ec7, 0x0ece, 0x0ecf, 0x0eda, 0x0edb, 0x0ede, 0x0eff, 0x0f48, 0x0f48, 0x0f6b, 0x0f70, 0x0f8c, 0x0f8f, 0x0f98, 0x0f98, 0x0fbd, 0x0fbd, 0x0fcd, 0x0fce, 0x0fd0, 0x0fff, 0x1022, 0x1022, 0x1028, 0x1028, 0x102b, 0x102b, 0x1033, 0x1035, 0x103a, 0x103f, 0x105a, 0x109f, 0x10c6, 0x10cf, 0x10f9, 0x10fa, 0x10fc, 0x10ff, 0x115a, 0x115e, 0x11a3, 0x11a7, 0x11fa, 0x11ff, 0x1207, 0x1207, 0x1247, 0x1247, 0x1249, 0x1249, 0x124e, 0x124f, 0x1257, 0x1257, 0x1259, 0x1259, 0x125e, 0x125f, 0x1287, 0x1287, 0x1289, 0x1289, 0x128e, 0x128f, 0x12af, 0x12af, 0x12b1, 0x12b1, 0x12b6, 0x12b7, 0x12bf, 0x12bf, 0x12c1, 0x12c1, 0x12c6, 0x12c7, 0x12cf, 0x12cf, 0x12d7, 0x12d7, 0x12ef, 0x12ef, 0x130f, 0x130f, 0x1311, 0x1311, 0x1316, 0x1317, 0x131f, 0x131f, 0x1347, 0x1347, 0x135b, 0x1360, 0x137d, 0x139f, 0x13f5, 0x1400, 0x1677, 0x167f, 0x169d, 0x169f, 0x16f1, 0x16ff, 0x170d, 0x170d, 0x1715, 0x171f, 0x1737, 0x173f, 0x1754, 0x175f, 0x176d, 0x176d, 0x1771, 0x1771, 0x1774, 0x177f, 0x17dd, 0x17df, 0x17ea, 0x17ff, 0x180f, 0x180f, 0x181a, 0x181f, 0x1878, 0x187f, 0x18aa, 0x1dff, 0x1e9c, 0x1e9f, 0x1efa, 0x1eff, 0x1f16, 0x1f17, 0x1f1e, 0x1f1f, 0x1f46, 0x1f47, 0x1f4e, 0x1f4f, 0x1f58, 0x1f58, 0x1f5a, 0x1f5a, 0x1f5c, 0x1f5c, 0x1f5e, 0x1f5e, 0x1f7e, 0x1f7f, 0x1fb5, 0x1fb5, 0x1fc5, 0x1fc5, 0x1fd4, 0x1fd5, 0x1fdc, 0x1fdc, 0x1ff0, 0x1ff1, 0x1ff5, 0x1ff5, 0x1fff, 0x1fff, 0x2053, 0x2056, 0x2058, 0x205e, 0x2064, 0x2069, 0x2072, 0x2073, 0x208f, 0x209f, 0x20b2, 0x20cf, 0x20eb, 0x20ff, 0x213b, 0x213c, 0x214c, 0x2152, 0x2184, 0x218f, 0x23cf, 0x23ff, 0x2427, 0x243f, 0x244b, 0x245f, 0x24ff, 0x24ff, 0x2614, 0x2615, 0x2618, 0x2618, 0x267e, 0x267f, 0x268a, 0x2700, 0x2705, 0x2705, 0x270a, 0x270b, 0x2728, 0x2728, 0x274c, 0x274c, 0x274e, 0x274e, 0x2753, 0x2755, 0x2757, 0x2757, 0x275f, 0x2760, 0x2795, 0x2797, 0x27b0, 0x27b0, 0x27bf, 0x27cf, 0x27ec, 0x27ef, 0x2b00, 0x2e7f, 0x2e9a, 0x2e9a, 0x2ef4, 0x2eff, 0x2fd6, 0x2fef, 0x2ffc, 0x2fff, 0x3040, 0x3040, 0x3097, 0x3098, 0x3100, 0x3104, 0x312d, 0x3130, 0x318f, 0x318f, 0x31b8, 0x31ef, 0x321d, 0x321f, 0x3244, 0x3250, 0x327c, 0x327e, 0x32cc, 0x32cf, 0x32ff, 0x32ff, 0x3377, 0x337a, 0x33de, 0x33df, 0x33ff, 0x33ff, 0x4db6, 0x4dff, 0x9fa6, 0x9fff, 0xa48d, 0xa48f, 0xa4c7, 0xabff, 0xd7a4, 0xd7ff, 0xfa2e, 0xfa2f, 0xfa6b, 0xfaff, 0xfb07, 0xfb12, 0xfb18, 0xfb1c, 0xfb37, 0xfb37, 0xfb3d, 0xfb3d, 0xfb3f, 0xfb3f, 0xfb42, 0xfb42, 0xfb45, 0xfb45, 0xfbb2, 0xfbd2, 0xfd40, 0xfd4f, 0xfd90, 0xfd91, 0xfdc8, 0xfdcf, 0xfdfd, 0xfdff, 0xfe10, 0xfe1f, 0xfe24, 0xfe2f, 0xfe47, 0xfe48, 0xfe53, 0xfe53, 0xfe67, 0xfe67, 0xfe6c, 0xfe6f, 0xfe75, 0xfe75, 0xfefd, 0xfefe, 0xff00, 0xff00, 0xffbf, 0xffc1, 0xffc8, 0xffc9, 0xffd0, 0xffd1, 0xffd8, 0xffd9, 0xffdd, 0xffdf, 0xffe7, 0xffe7, 0xffef, 0xfff8, 0x10000, 0x102ff, 0x1031f, 0x1031f, 0x10324, 0x1032f, 0x1034b, 0x103ff, 0x10426, 0x10427, 0x1044e, 0x1cfff, 0x1d0f6, 0x1d0ff, 0x1d127, 0x1d129, 0x1d1de, 0x1d3ff, 0x1d455, 0x1d455, 0x1d49d, 0x1d49d, 0x1d4a0, 0x1d4a1, 0x1d4a3, 0x1d4a4, 0x1d4a7, 0x1d4a8, 0x1d4ad, 0x1d4ad, 0x1d4ba, 0x1d4ba, 0x1d4bc, 0x1d4bc, 0x1d4c1, 0x1d4c1, 0x1d4c4, 0x1d4c4, 0x1d506, 0x1d506, 0x1d50b, 0x1d50c, 0x1d515, 0x1d515, 0x1d51d, 0x1d51d, 0x1d53a, 0x1d53a, 0x1d53f, 0x1d53f, 0x1d545, 0x1d545, 0x1d547, 0x1d549, 0x1d551, 0x1d551, 0x1d6a4, 0x1d6a7, 0x1d7ca, 0x1d7cd, 0x1d800, 0x1fffd, 0x2a6d7, 0x2f7ff, 0x2fa1e, 0x2fffd, 0x30000, 0x3fffd, 0x40000, 0x4fffd, 0x50000, 0x5fffd, 0x60000, 0x6fffd, 0x70000, 0x7fffd, 0x80000, 0x8fffd, 0x90000, 0x9fffd, 0xa0000, 0xafffd, 0xb0000, 0xbfffd, 0xc0000, 0xcfffd, 0xd0000, 0xdfffd, 0xe0000, 0xe0000, 0xe0002, 0xe001f, 0xe0080, 0xefffd];
@@ -450,9 +448,9 @@ const unassigned_code_points = [0x0221, 0x0221, 0x0234, 0x024f, 0x02ae, 0x02af,
450
448
  const isUnassignedCodePoint = character => inRange(character, unassigned_code_points);
451
449
  /* eslint-disable prettier/prettier */
452
450
 
453
- /**
454
- * B.1 Commonly mapped to nothing
455
- * @link https://tools.ietf.org/html/rfc3454#appendix-B.1
451
+ /**
452
+ * B.1 Commonly mapped to nothing
453
+ * @link https://tools.ietf.org/html/rfc3454#appendix-B.1
456
454
  */
457
455
 
458
456
 
@@ -462,9 +460,9 @@ const commonly_mapped_to_nothing = [0x00ad, 0x00ad, 0x034f, 0x034f, 0x1806, 0x18
462
460
  const isCommonlyMappedToNothing = character => inRange(character, commonly_mapped_to_nothing);
463
461
  /* eslint-disable prettier/prettier */
464
462
 
465
- /**
466
- * C.1.2 Non-ASCII space characters
467
- * @link https://tools.ietf.org/html/rfc3454#appendix-C.1.2
463
+ /**
464
+ * C.1.2 Non-ASCII space characters
465
+ * @link https://tools.ietf.org/html/rfc3454#appendix-C.1.2
468
466
  */
469
467
 
470
468
 
@@ -510,9 +508,9 @@ const isNonASCIISpaceCharacter = character => inRange(character, non_ASCII_space
510
508
 
511
509
 
512
510
  const non_ASCII_controls_characters = [
513
- /**
514
- * C.2.2 Non-ASCII control characters
515
- * @link https://tools.ietf.org/html/rfc3454#appendix-C.2.2
511
+ /**
512
+ * C.2.2 Non-ASCII control characters
513
+ * @link https://tools.ietf.org/html/rfc3454#appendix-C.2.2
516
514
  */
517
515
  0x0080, 0x009f
518
516
  /* [CONTROL CHARACTERS] */
@@ -548,9 +546,9 @@ const non_ASCII_controls_characters = [
548
546
  /* [MUSICAL CONTROL CHARACTERS] */
549
547
  ];
550
548
  const non_character_codepoints = [
551
- /**
552
- * C.4 Non-character code points
553
- * @link https://tools.ietf.org/html/rfc3454#appendix-C.4
549
+ /**
550
+ * C.4 Non-character code points
551
+ * @link https://tools.ietf.org/html/rfc3454#appendix-C.4
554
552
  */
555
553
  0xfdd0, 0xfdef
556
554
  /* [NONCHARACTER CODE POINTS] */
@@ -587,23 +585,23 @@ const non_character_codepoints = [
587
585
  , 0x10fffe, 0x10ffff
588
586
  /* [NONCHARACTER CODE POINTS] */
589
587
  ];
590
- /**
591
- * 2.3. Prohibited Output
588
+ /**
589
+ * 2.3. Prohibited Output
592
590
  */
593
591
 
594
592
  const prohibited_characters = [
595
- /**
596
- * C.2.1 ASCII control characters
597
- * @link https://tools.ietf.org/html/rfc3454#appendix-C.2.1
593
+ /**
594
+ * C.2.1 ASCII control characters
595
+ * @link https://tools.ietf.org/html/rfc3454#appendix-C.2.1
598
596
  */
599
597
  0, 0x001f
600
598
  /* [CONTROL CHARACTERS] */
601
599
  , 0x007f, 0x007f
602
600
  /* DELETE */
603
601
  ,
604
- /**
605
- * C.8 Change display properties or are deprecated
606
- * @link https://tools.ietf.org/html/rfc3454#appendix-C.8
602
+ /**
603
+ * C.8 Change display properties or are deprecated
604
+ * @link https://tools.ietf.org/html/rfc3454#appendix-C.8
607
605
  */
608
606
  0x0340, 0x0340
609
607
  /* COMBINING GRAVE TONE MARK */
@@ -636,28 +634,28 @@ const prohibited_characters = [
636
634
  , 0x206f, 0x206f
637
635
  /* NOMINAL DIGIT SHAPES */
638
636
  ,
639
- /**
640
- * C.7 Inappropriate for canonical representation
641
- * @link https://tools.ietf.org/html/rfc3454#appendix-C.7
637
+ /**
638
+ * C.7 Inappropriate for canonical representation
639
+ * @link https://tools.ietf.org/html/rfc3454#appendix-C.7
642
640
  */
643
641
  0x2ff0, 0x2ffb
644
642
  /* [IDEOGRAPHIC DESCRIPTION CHARACTERS] */
645
643
  ,
646
- /**
647
- * C.5 Surrogate codes
648
- * @link https://tools.ietf.org/html/rfc3454#appendix-C.5
644
+ /**
645
+ * C.5 Surrogate codes
646
+ * @link https://tools.ietf.org/html/rfc3454#appendix-C.5
649
647
  */
650
648
  0xd800, 0xdfff,
651
- /**
652
- * C.3 Private use
653
- * @link https://tools.ietf.org/html/rfc3454#appendix-C.3
649
+ /**
650
+ * C.3 Private use
651
+ * @link https://tools.ietf.org/html/rfc3454#appendix-C.3
654
652
  */
655
653
  0xe000, 0xf8ff
656
654
  /* [PRIVATE USE, PLANE 0] */
657
655
  ,
658
- /**
659
- * C.6 Inappropriate for plain text
660
- * @link https://tools.ietf.org/html/rfc3454#appendix-C.6
656
+ /**
657
+ * C.6 Inappropriate for plain text
658
+ * @link https://tools.ietf.org/html/rfc3454#appendix-C.6
661
659
  */
662
660
  0xfff9, 0xfff9
663
661
  /* INTERLINEAR ANNOTATION ANCHOR */
@@ -670,18 +668,18 @@ const prohibited_characters = [
670
668
  , 0xfffd, 0xfffd
671
669
  /* REPLACEMENT CHARACTER */
672
670
  ,
673
- /**
674
- * C.9 Tagging characters
675
- * @link https://tools.ietf.org/html/rfc3454#appendix-C.9
671
+ /**
672
+ * C.9 Tagging characters
673
+ * @link https://tools.ietf.org/html/rfc3454#appendix-C.9
676
674
  */
677
675
  0xe0001, 0xe0001
678
676
  /* LANGUAGE TAG */
679
677
  , 0xe0020, 0xe007f
680
678
  /* [TAGGING CHARACTERS] */
681
679
  ,
682
- /**
683
- * C.3 Private use
684
- * @link https://tools.ietf.org/html/rfc3454#appendix-C.3
680
+ /**
681
+ * C.3 Private use
682
+ * @link https://tools.ietf.org/html/rfc3454#appendix-C.3
685
683
  */
686
684
  0xf0000, 0xffffd
687
685
  /* [PRIVATE USE, PLANE 15] */
@@ -693,9 +691,9 @@ const prohibited_characters = [
693
691
  const isProhibitedCharacter = character => inRange(character, non_ASCII_space_characters) || inRange(character, prohibited_characters) || inRange(character, non_ASCII_controls_characters) || inRange(character, non_character_codepoints);
694
692
  /* eslint-disable prettier/prettier */
695
693
 
696
- /**
697
- * D.1 Characters with bidirectional property "R" or "AL"
698
- * @link https://tools.ietf.org/html/rfc3454#appendix-D.1
694
+ /**
695
+ * D.1 Characters with bidirectional property "R" or "AL"
696
+ * @link https://tools.ietf.org/html/rfc3454#appendix-D.1
699
697
  */
700
698
 
701
699
 
@@ -705,9 +703,9 @@ const bidirectional_r_al = [0x05be, 0x05be, 0x05c0, 0x05c0, 0x05c3, 0x05c3, 0x05
705
703
  const isBidirectionalRAL = character => inRange(character, bidirectional_r_al);
706
704
  /* eslint-disable prettier/prettier */
707
705
 
708
- /**
709
- * D.2 Characters with bidirectional property "L"
710
- * @link https://tools.ietf.org/html/rfc3454#appendix-D.2
706
+ /**
707
+ * D.2 Characters with bidirectional property "L"
708
+ * @link https://tools.ietf.org/html/rfc3454#appendix-D.2
711
709
  */
712
710
 
713
711
 
@@ -716,15 +714,15 @@ const bidirectional_l = [0x0041, 0x005a, 0x0061, 0x007a, 0x00aa, 0x00aa, 0x00b5,
716
714
 
717
715
  const isBidirectionalL = character => inRange(character, bidirectional_l);
718
716
 
719
- /**
720
- * non-ASCII space characters [StringPrep, C.1.2] that can be
721
- * mapped to SPACE (U+0020)
717
+ /**
718
+ * non-ASCII space characters [StringPrep, C.1.2] that can be
719
+ * mapped to SPACE (U+0020)
722
720
  */
723
721
 
724
722
  const mapping2space = isNonASCIISpaceCharacter;
725
- /**
726
- * the "commonly mapped to nothing" characters [StringPrep, B.1]
727
- * that can be mapped to nothing.
723
+ /**
724
+ * the "commonly mapped to nothing" characters [StringPrep, B.1]
725
+ * that can be mapped to nothing.
728
726
  */
729
727
 
730
728
  const mapping2nothing = isCommonlyMappedToNothing; // utils
@@ -734,12 +732,12 @@ const getCodePoint = character => character.codePointAt(0);
734
732
  const first = x => x[0];
735
733
 
736
734
  const last = x => x[x.length - 1];
737
- /**
738
- * Convert provided string into an array of Unicode Code Points.
739
- * Based on https://stackoverflow.com/a/21409165/1556249
740
- * and https://www.npmjs.com/package/code-point-at.
741
- * @param {string} input
742
- * @returns {number[]}
735
+ /**
736
+ * Convert provided string into an array of Unicode Code Points.
737
+ * Based on https://stackoverflow.com/a/21409165/1556249
738
+ * and https://www.npmjs.com/package/code-point-at.
739
+ * @param {string} input
740
+ * @returns {number[]}
743
741
  */
744
742
 
745
743
 
@@ -765,12 +763,12 @@ function toCodePoints(input) {
765
763
 
766
764
  return codepoints;
767
765
  }
768
- /**
769
- * SASLprep.
770
- * @param {string} input
771
- * @param {Object} opts
772
- * @param {boolean} opts.allowUnassigned
773
- * @returns {string}
766
+ /**
767
+ * SASLprep.
768
+ * @param {string} input
769
+ * @param {Object} opts
770
+ * @param {boolean} opts.allowUnassigned
771
+ * @returns {string}
774
772
  */
775
773
 
776
774
 
@@ -814,10 +812,10 @@ function saslprep(input, opts = {}) {
814
812
  if (hasBidiRAL && hasBidiL) {
815
813
  throw new Error('String must not contain RandALCat and LCat at the same time,' + ' see https://tools.ietf.org/html/rfc3454#section-6');
816
814
  }
817
- /**
818
- * 4.2 If a string contains any RandALCat character, a RandALCat
819
- * character MUST be the first character of the string, and a
820
- * RandALCat character MUST be the last character of the string.
815
+ /**
816
+ * 4.2 If a string contains any RandALCat character, a RandALCat
817
+ * character MUST be the first character of the string, and a
818
+ * RandALCat character MUST be the last character of the string.
821
819
  */
822
820
 
823
821
 
@@ -831,9 +829,9 @@ function saslprep(input, opts = {}) {
831
829
  return normalized_input;
832
830
  }
833
831
 
834
- /*
835
- PDFSecurity - represents PDF security settings
836
- By Yang Liu <hi@zesik.com>
832
+ /*
833
+ PDFSecurity - represents PDF security settings
834
+ By Yang Liu <hi@zesik.com>
837
835
  */
838
836
 
839
837
  class PDFSecurity {
@@ -845,7 +843,7 @@ class PDFSecurity {
845
843
  continue;
846
844
  }
847
845
 
848
- infoStr += `${key}: ${info[key].toString()}\n`;
846
+ infoStr += `${key}: ${info[key]}\n`;
849
847
  }
850
848
 
851
849
  return wordArrayToBuffer(CryptoJS.MD5(infoStr));
@@ -1304,15 +1302,16 @@ class PDFGradient {
1304
1302
 
1305
1303
  embed(m) {
1306
1304
  let fn;
1305
+ const stopsLength = this.stops.length;
1307
1306
 
1308
- if (this.stops.length === 0) {
1307
+ if (stopsLength === 0) {
1309
1308
  return;
1310
1309
  }
1311
1310
 
1312
1311
  this.embedded = true;
1313
1312
  this.matrix = m; // if the last stop comes before 100%, add a copy at 100%
1314
1313
 
1315
- const last = this.stops[this.stops.length - 1];
1314
+ const last = this.stops[stopsLength - 1];
1316
1315
 
1317
1316
  if (last[0] < 1) {
1318
1317
  this.stops.push([1, last[1], last[2]]);
@@ -1322,7 +1321,7 @@ class PDFGradient {
1322
1321
  const encode = [];
1323
1322
  const stops = [];
1324
1323
 
1325
- for (let i = 0, stopsLength = this.stops.length - 1; i < stopsLength; i++) {
1324
+ for (let i = 0; i < stopsLength - 1; i++) {
1326
1325
  encode.push(0, 1);
1327
1326
 
1328
1327
  if (i + 2 !== stopsLength) {
@@ -1341,7 +1340,7 @@ class PDFGradient {
1341
1340
  } // if there are only two stops, we don't need a stitching function
1342
1341
 
1343
1342
 
1344
- if (stops.length === 1) {
1343
+ if (stopsLength === 1) {
1345
1344
  fn = stops[0];
1346
1345
  } else {
1347
1346
  fn = this.doc.ref({
@@ -1362,7 +1361,7 @@ class PDFGradient {
1362
1361
  Type: 'Pattern',
1363
1362
  PatternType: 2,
1364
1363
  Shading: shader,
1365
- Matrix: this.matrix.map(v => number(v))
1364
+ Matrix: this.matrix.map(number)
1366
1365
  });
1367
1366
  pattern.end();
1368
1367
 
@@ -1979,7 +1978,7 @@ const runners = {
1979
1978
  cy = a[5];
1980
1979
  px = a[2];
1981
1980
  py = a[3];
1982
- return doc.bezierCurveTo(...(a || []));
1981
+ return doc.bezierCurveTo(...a);
1983
1982
  },
1984
1983
 
1985
1984
  c(doc, a) {
@@ -2133,8 +2132,8 @@ const solveArc = function (doc, x, y, coords) {
2133
2132
  const segs = arcToSegments(ex, ey, rx, ry, large, sweep, rot, x, y);
2134
2133
 
2135
2134
  for (let seg of segs) {
2136
- const bez = segmentToBezier(...(seg || []));
2137
- doc.bezierCurveTo(...(bez || []));
2135
+ const bez = segmentToBezier(...seg);
2136
+ doc.bezierCurveTo(...bez);
2138
2137
  }
2139
2138
  }; // from Inkscape svgtopdf, thanks!
2140
2139
 
@@ -3144,9 +3143,9 @@ class EmbeddedFont extends PDFFont {
3144
3143
  }
3145
3144
 
3146
3145
  descriptor.end();
3147
- const descendantFont = this.document.ref({
3146
+ const descendantFontData = {
3148
3147
  Type: 'Font',
3149
- Subtype: isCFF ? 'CIDFontType0' : 'CIDFontType2',
3148
+ Subtype: 'CIDFontType0',
3150
3149
  BaseFont: name,
3151
3150
  CIDSystemInfo: {
3152
3151
  Registry: new String('Adobe'),
@@ -3155,7 +3154,14 @@ class EmbeddedFont extends PDFFont {
3155
3154
  },
3156
3155
  FontDescriptor: descriptor,
3157
3156
  W: [0, this.widths]
3158
- });
3157
+ };
3158
+
3159
+ if (!isCFF) {
3160
+ descendantFontData.Subtype = 'CIDFontType2';
3161
+ descendantFontData.CIDToGIDMap = 'Identity';
3162
+ }
3163
+
3164
+ const descendantFont = this.document.ref(descendantFontData);
3159
3165
  descendantFont.end();
3160
3166
  this.dictionary.data = {
3161
3167
  Type: 'Font',
@@ -3453,6 +3459,11 @@ class LineWrapper extends events.EventEmitter {
3453
3459
  mustShrink = w > this.spaceLeft && l > 0;
3454
3460
  mightGrow = w <= this.spaceLeft && l < word.length;
3455
3461
  }
3462
+ } // check for the edge case where a single character cannot fit into a line.
3463
+
3464
+
3465
+ if (l === 0 && this.spaceLeft === this.lineWidth) {
3466
+ l = 1;
3456
3467
  } // send a required break unless this is the last piece and a linebreak is not specified
3457
3468
 
3458
3469
 
@@ -3649,7 +3660,7 @@ class LineWrapper extends events.EventEmitter {
3649
3660
  this.document.x = this.startX;
3650
3661
 
3651
3662
  if (this.document._fillColor) {
3652
- this.document.fillColor(...(this.document._fillColor || []));
3663
+ this.document.fillColor(...this.document._fillColor);
3653
3664
  }
3654
3665
 
3655
3666
  this.emit('pageBreak', options, this);
@@ -3860,7 +3871,7 @@ var TextMixin = {
3860
3871
  const val = this._textOptions[key];
3861
3872
 
3862
3873
  if (key !== 'continued') {
3863
- if (result[key] == null) {
3874
+ if (result[key] === undefined) {
3864
3875
  result[key] = val;
3865
3876
  }
3866
3877
  }
@@ -3881,6 +3892,8 @@ var TextMixin = {
3881
3892
  if (result.width == null) {
3882
3893
  result.width = this.page.width - this.x - this.page.margins.right;
3883
3894
  }
3895
+
3896
+ result.width = Math.max(result.width, 0);
3884
3897
  }
3885
3898
 
3886
3899
  if (!result.columns) {
@@ -4243,6 +4256,7 @@ class PNGImage {
4243
4256
  }
4244
4257
 
4245
4258
  embed(document) {
4259
+ let dataDecoded = false;
4246
4260
  this.document = document;
4247
4261
 
4248
4262
  if (this.obj) {
@@ -4250,6 +4264,7 @@ class PNGImage {
4250
4264
  }
4251
4265
 
4252
4266
  const hasAlphaChannel = this.image.hasAlphaChannel;
4267
+ const isInterlaced = this.image.interlaceMethod === 1;
4253
4268
  this.obj = this.document.ref({
4254
4269
  Type: 'XObject',
4255
4270
  Subtype: 'Image',
@@ -4261,7 +4276,7 @@ class PNGImage {
4261
4276
 
4262
4277
  if (!hasAlphaChannel) {
4263
4278
  const params = this.document.ref({
4264
- Predictor: 15,
4279
+ Predictor: isInterlaced ? 1 : 15,
4265
4280
  Colors: this.image.colors,
4266
4281
  BitsPerComponent: this.image.bits,
4267
4282
  Columns: this.width
@@ -4303,14 +4318,20 @@ class PNGImage {
4303
4318
  } else if (this.image.transparency.indexed) {
4304
4319
  // Create a transparency SMask for the image based on the data
4305
4320
  // in the PLTE and tRNS sections. See below for details on SMasks.
4321
+ dataDecoded = true;
4306
4322
  return this.loadIndexedAlphaChannel();
4307
4323
  } else if (hasAlphaChannel) {
4308
4324
  // For PNG color types 4 and 6, the transparency data is stored as a alpha
4309
4325
  // channel mixed in with the main image data. Separate this data out into an
4310
4326
  // SMask object and store it separately in the PDF.
4327
+ dataDecoded = true;
4311
4328
  return this.splitAlphaChannel();
4312
4329
  }
4313
4330
 
4331
+ if (isInterlaced && !dataDecoded) {
4332
+ return this.decodeData();
4333
+ }
4334
+
4314
4335
  this.finalize();
4315
4336
  }
4316
4337
 
@@ -4380,11 +4401,18 @@ class PNGImage {
4380
4401
  });
4381
4402
  }
4382
4403
 
4404
+ decodeData() {
4405
+ this.image.decodePixels(pixels => {
4406
+ this.imgData = zlib.deflateSync(pixels);
4407
+ this.finalize();
4408
+ });
4409
+ }
4410
+
4383
4411
  }
4384
4412
 
4385
- /*
4386
- PDFImage - embeds images in PDF documents
4387
- By Devon Govett
4413
+ /*
4414
+ PDFImage - embeds images in PDF documents
4415
+ By Devon Govett
4388
4416
  */
4389
4417
 
4390
4418
  class PDFImage {
@@ -4562,6 +4590,10 @@ var AnnotationsMixin = {
4562
4590
  options.Rect = this._convertRect(x, y, w, h);
4563
4591
  options.Border = [0, 0, 0];
4564
4592
 
4593
+ if (options.Subtype === 'Link' && typeof options.F === 'undefined') {
4594
+ options.F = 1 << 2; // Print Annotation Flag
4595
+ }
4596
+
4565
4597
  if (options.Subtype !== 'Link') {
4566
4598
  if (options.C == null) {
4567
4599
  options.C = this._normalizeColor(options.color || [0, 0, 0]);
@@ -4787,9 +4819,430 @@ var OutlineMixin = {
4787
4819
 
4788
4820
  };
4789
4821
 
4790
- /*
4791
- PDFDocument - represents an entire PDF document
4792
- By Devon Govett
4822
+ const FIELD_FLAGS = {
4823
+ readOnly: 1,
4824
+ required: 2,
4825
+ noExport: 4,
4826
+ multiline: 0x1000,
4827
+ password: 0x2000,
4828
+ toggleToOffButton: 0x4000,
4829
+ radioButton: 0x8000,
4830
+ pushButton: 0x10000,
4831
+ combo: 0x20000,
4832
+ edit: 0x40000,
4833
+ sort: 0x80000,
4834
+ multiSelect: 0x200000,
4835
+ noSpell: 0x400000
4836
+ };
4837
+ const FIELD_JUSTIFY = {
4838
+ left: 0,
4839
+ center: 1,
4840
+ right: 2
4841
+ };
4842
+ const VALUE_MAP = {
4843
+ value: 'V',
4844
+ defaultValue: 'DV'
4845
+ };
4846
+ const FORMAT_SPECIAL = {
4847
+ zip: '0',
4848
+ zipPlus4: '1',
4849
+ zip4: '1',
4850
+ phone: '2',
4851
+ ssn: '3'
4852
+ };
4853
+ const FORMAT_DEFAULT = {
4854
+ number: {
4855
+ nDec: 0,
4856
+ sepComma: false,
4857
+ negStyle: 'MinusBlack',
4858
+ currency: '',
4859
+ currencyPrepend: true
4860
+ },
4861
+ percent: {
4862
+ nDec: 0,
4863
+ sepComma: false
4864
+ }
4865
+ };
4866
+ var AcroFormMixin = {
4867
+ /**
4868
+ * Must call if adding AcroForms to a document. Must also call font() before
4869
+ * this method to set the default font.
4870
+ */
4871
+ initForm() {
4872
+ if (!this._font) {
4873
+ throw new Error('Must set a font before calling initForm method');
4874
+ }
4875
+
4876
+ this._acroform = {
4877
+ fonts: {},
4878
+ defaultFont: this._font.name
4879
+ };
4880
+ this._acroform.fonts[this._font.id] = this._font.ref();
4881
+ let data = {
4882
+ Fields: [],
4883
+ NeedAppearances: true,
4884
+ DA: new String(`/${this._font.id} 0 Tf 0 g`),
4885
+ DR: {
4886
+ Font: {}
4887
+ }
4888
+ };
4889
+ data.DR.Font[this._font.id] = this._font.ref();
4890
+ const AcroForm = this.ref(data);
4891
+ this._root.data.AcroForm = AcroForm;
4892
+ return this;
4893
+ },
4894
+
4895
+ /**
4896
+ * Called automatically by document.js
4897
+ */
4898
+ endAcroForm() {
4899
+ if (this._root.data.AcroForm) {
4900
+ if (!Object.keys(this._acroform.fonts).length && !this._acroform.defaultFont) {
4901
+ throw new Error('No fonts specified for PDF form');
4902
+ }
4903
+
4904
+ let fontDict = this._root.data.AcroForm.data.DR.Font;
4905
+ Object.keys(this._acroform.fonts).forEach(name => {
4906
+ fontDict[name] = this._acroform.fonts[name];
4907
+ });
4908
+
4909
+ this._root.data.AcroForm.data.Fields.forEach(fieldRef => {
4910
+ this._endChild(fieldRef);
4911
+ });
4912
+
4913
+ this._root.data.AcroForm.end();
4914
+ }
4915
+
4916
+ return this;
4917
+ },
4918
+
4919
+ _endChild(ref) {
4920
+ if (Array.isArray(ref.data.Kids)) {
4921
+ ref.data.Kids.forEach(childRef => {
4922
+ this._endChild(childRef);
4923
+ });
4924
+ ref.end();
4925
+ }
4926
+
4927
+ return this;
4928
+ },
4929
+
4930
+ /**
4931
+ * Creates and adds a form field to the document. Form fields are intermediate
4932
+ * nodes in a PDF form that are used to specify form name heirarchy and form
4933
+ * value defaults.
4934
+ * @param {string} name - field name (T attribute in field dictionary)
4935
+ * @param {object} options - other attributes to include in field dictionary
4936
+ */
4937
+ formField(name, options = {}) {
4938
+ let fieldDict = this._fieldDict(name, null, options);
4939
+
4940
+ let fieldRef = this.ref(fieldDict);
4941
+
4942
+ this._addToParent(fieldRef);
4943
+
4944
+ return fieldRef;
4945
+ },
4946
+
4947
+ /**
4948
+ * Creates and adds a Form Annotation to the document. Form annotations are
4949
+ * called Widget annotations internally within a PDF file.
4950
+ * @param {string} name - form field name (T attribute of widget annotation
4951
+ * dictionary)
4952
+ * @param {number} x
4953
+ * @param {number} y
4954
+ * @param {number} w
4955
+ * @param {number} h
4956
+ * @param {object} options
4957
+ */
4958
+ formAnnotation(name, type, x, y, w, h, options = {}) {
4959
+ let fieldDict = this._fieldDict(name, type, options);
4960
+
4961
+ fieldDict.Subtype = 'Widget';
4962
+
4963
+ if (fieldDict.F === undefined) {
4964
+ fieldDict.F = 4; // print the annotation
4965
+ } // Add Field annot to page, and get it's ref
4966
+
4967
+
4968
+ this.annotate(x, y, w, h, fieldDict);
4969
+ let annotRef = this.page.annotations[this.page.annotations.length - 1];
4970
+ return this._addToParent(annotRef);
4971
+ },
4972
+
4973
+ formText(name, x, y, w, h, options = {}) {
4974
+ return this.formAnnotation(name, 'text', x, y, w, h, options);
4975
+ },
4976
+
4977
+ formPushButton(name, x, y, w, h, options = {}) {
4978
+ return this.formAnnotation(name, 'pushButton', x, y, w, h, options);
4979
+ },
4980
+
4981
+ formCombo(name, x, y, w, h, options = {}) {
4982
+ return this.formAnnotation(name, 'combo', x, y, w, h, options);
4983
+ },
4984
+
4985
+ formList(name, x, y, w, h, options = {}) {
4986
+ return this.formAnnotation(name, 'list', x, y, w, h, options);
4987
+ },
4988
+
4989
+ formRadioButton(name, x, y, w, h, options = {}) {
4990
+ return this.formAnnotation(name, 'radioButton', x, y, w, h, options);
4991
+ },
4992
+
4993
+ formCheckbox(name, x, y, w, h, options = {}) {
4994
+ return this.formAnnotation(name, 'checkbox', x, y, w, h, options);
4995
+ },
4996
+
4997
+ _addToParent(fieldRef) {
4998
+ let parent = fieldRef.data.Parent;
4999
+
5000
+ if (parent) {
5001
+ if (!parent.data.Kids) {
5002
+ parent.data.Kids = [];
5003
+ }
5004
+
5005
+ parent.data.Kids.push(fieldRef);
5006
+ } else {
5007
+ this._root.data.AcroForm.data.Fields.push(fieldRef);
5008
+ }
5009
+
5010
+ return this;
5011
+ },
5012
+
5013
+ _fieldDict(name, type, options = {}) {
5014
+ if (!this._acroform) {
5015
+ throw new Error('Call document.initForms() method before adding form elements to document');
5016
+ }
5017
+
5018
+ let opts = Object.assign({}, options);
5019
+
5020
+ if (type !== null) {
5021
+ opts = this._resolveType(type, options);
5022
+ }
5023
+
5024
+ opts = this._resolveFlags(opts);
5025
+ opts = this._resolveJustify(opts);
5026
+ opts = this._resolveFont(opts);
5027
+ opts = this._resolveStrings(opts);
5028
+ opts = this._resolveColors(opts);
5029
+ opts = this._resolveFormat(opts);
5030
+ opts.T = new String(name);
5031
+
5032
+ if (opts.parent) {
5033
+ opts.Parent = opts.parent;
5034
+ delete opts.parent;
5035
+ }
5036
+
5037
+ return opts;
5038
+ },
5039
+
5040
+ _resolveType(type, opts) {
5041
+ if (type === 'text') {
5042
+ opts.FT = 'Tx';
5043
+ } else if (type === 'pushButton') {
5044
+ opts.FT = 'Btn';
5045
+ opts.pushButton = true;
5046
+ } else if (type === 'radioButton') {
5047
+ opts.FT = 'Btn';
5048
+ opts.radioButton = true;
5049
+ } else if (type === 'checkbox') {
5050
+ opts.FT = 'Btn';
5051
+ } else if (type === 'combo') {
5052
+ opts.FT = 'Ch';
5053
+ opts.combo = true;
5054
+ } else if (type === 'list') {
5055
+ opts.FT = 'Ch';
5056
+ } else {
5057
+ throw new Error(`Invalid form annotation type '${type}'`);
5058
+ }
5059
+
5060
+ return opts;
5061
+ },
5062
+
5063
+ _resolveFormat(opts) {
5064
+ const f = opts.format;
5065
+
5066
+ if (f && f.type) {
5067
+ let fnKeystroke;
5068
+ let fnFormat;
5069
+ let params = '';
5070
+
5071
+ if (FORMAT_SPECIAL[f.type] !== undefined) {
5072
+ fnKeystroke = `AFSpecial_Keystroke`;
5073
+ fnFormat = `AFSpecial_Format`;
5074
+ params = FORMAT_SPECIAL[f.type];
5075
+ } else {
5076
+ let format = f.type.charAt(0).toUpperCase() + f.type.slice(1);
5077
+ fnKeystroke = `AF${format}_Keystroke`;
5078
+ fnFormat = `AF${format}_Format`;
5079
+
5080
+ if (f.type === 'date') {
5081
+ fnKeystroke += 'Ex';
5082
+ params = String(f.param);
5083
+ } else if (f.type === 'time') {
5084
+ params = String(f.param);
5085
+ } else if (f.type === 'number') {
5086
+ let p = Object.assign({}, FORMAT_DEFAULT.number, f);
5087
+ params = String([String(p.nDec), p.sepComma ? '0' : '1', '"' + p.negStyle + '"', 'null', '"' + p.currency + '"', String(p.currencyPrepend)].join(','));
5088
+ } else if (f.type === 'percent') {
5089
+ let p = Object.assign({}, FORMAT_DEFAULT.percent, f);
5090
+ params = String([String(p.nDec), p.sepComma ? '0' : '1'].join(','));
5091
+ }
5092
+ }
5093
+
5094
+ opts.AA = opts.AA ? opts.AA : {};
5095
+ opts.AA.K = {
5096
+ S: 'JavaScript',
5097
+ JS: new String(`${fnKeystroke}(${params});`)
5098
+ };
5099
+ opts.AA.F = {
5100
+ S: 'JavaScript',
5101
+ JS: new String(`${fnFormat}(${params});`)
5102
+ };
5103
+ }
5104
+
5105
+ delete opts.format;
5106
+ return opts;
5107
+ },
5108
+
5109
+ _resolveColors(opts) {
5110
+ let color = this._normalizeColor(opts.backgroundColor);
5111
+
5112
+ if (color) {
5113
+ if (!opts.MK) {
5114
+ opts.MK = {};
5115
+ }
5116
+
5117
+ opts.MK.BG = color;
5118
+ }
5119
+
5120
+ color = this._normalizeColor(opts.borderColor);
5121
+
5122
+ if (color) {
5123
+ if (!opts.MK) {
5124
+ opts.MK = {};
5125
+ }
5126
+
5127
+ opts.MK.BC = color;
5128
+ }
5129
+
5130
+ delete opts.backgroundColor;
5131
+ delete opts.borderColor;
5132
+ return opts;
5133
+ },
5134
+
5135
+ _resolveFlags(options) {
5136
+ let result = 0;
5137
+ Object.keys(options).forEach(key => {
5138
+ if (FIELD_FLAGS[key]) {
5139
+ result |= FIELD_FLAGS[key];
5140
+ delete options[key];
5141
+ }
5142
+ });
5143
+
5144
+ if (result !== 0) {
5145
+ options.Ff = options.Ff ? options.Ff : 0;
5146
+ options.Ff |= result;
5147
+ }
5148
+
5149
+ return options;
5150
+ },
5151
+
5152
+ _resolveJustify(options) {
5153
+ let result = 0;
5154
+
5155
+ if (options.align !== undefined) {
5156
+ if (typeof FIELD_JUSTIFY[options.align] === 'number') {
5157
+ result = FIELD_JUSTIFY[options.align];
5158
+ }
5159
+
5160
+ delete options.align;
5161
+ }
5162
+
5163
+ if (result !== 0) {
5164
+ options.Q = result; // default
5165
+ }
5166
+
5167
+ return options;
5168
+ },
5169
+
5170
+ _resolveFont(options) {
5171
+ // add current font to document-level AcroForm dict if necessary
5172
+ if (this._acroform.fonts[this._font.id] === null) {
5173
+ this._acroform.fonts[this._font.id] = this._font.ref();
5174
+ } // add current font to field's resource dict (RD) if not the default acroform font
5175
+
5176
+
5177
+ if (this._acroform.defaultFont !== this._font.name) {
5178
+ options.DR = {
5179
+ Font: {}
5180
+ };
5181
+ options.DR.Font[this._font.id] = this._font.ref();
5182
+ options.DA = new String(`/${this._font.id} 0 Tf 0 g`);
5183
+ }
5184
+
5185
+ return options;
5186
+ },
5187
+
5188
+ _resolveStrings(options) {
5189
+ let select = [];
5190
+
5191
+ function appendChoices(a) {
5192
+ if (Array.isArray(a)) {
5193
+ for (let idx = 0; idx < a.length; idx++) {
5194
+ if (typeof a[idx] === 'string') {
5195
+ select.push(new String(a[idx]));
5196
+ } else {
5197
+ select.push(a[idx]);
5198
+ }
5199
+ }
5200
+ }
5201
+ }
5202
+
5203
+ appendChoices(options.Opt);
5204
+
5205
+ if (options.select) {
5206
+ appendChoices(options.select);
5207
+ delete options.select;
5208
+ }
5209
+
5210
+ if (select.length) {
5211
+ options.Opt = select;
5212
+ }
5213
+
5214
+ if (options.value || options.defaultValue) ;
5215
+
5216
+ Object.keys(VALUE_MAP).forEach(key => {
5217
+ if (options[key] !== undefined) {
5218
+ options[VALUE_MAP[key]] = options[key];
5219
+ delete options[key];
5220
+ }
5221
+ });
5222
+ ['V', 'DV'].forEach(key => {
5223
+ if (typeof options[key] === 'string') {
5224
+ options[key] = new String(options[key]);
5225
+ }
5226
+ });
5227
+
5228
+ if (options.MK && options.MK.CA) {
5229
+ options.MK.CA = new String(options.MK.CA);
5230
+ }
5231
+
5232
+ if (options.label) {
5233
+ options.MK = options.MK ? options.MK : {};
5234
+ options.MK.CA = new String(options.label);
5235
+ delete options.label;
5236
+ }
5237
+
5238
+ return options;
5239
+ }
5240
+
5241
+ };
5242
+
5243
+ /*
5244
+ PDFDocument - represents an entire PDF document
5245
+ By Devon Govett
4793
5246
  */
4794
5247
 
4795
5248
  class PDFDocument extends stream.Readable {
@@ -4957,6 +5410,19 @@ class PDFDocument extends stream.Readable {
4957
5410
  this._root.data.Names.data.Dests.add(name, args);
4958
5411
  }
4959
5412
 
5413
+ addNamedJavaScript(name, js) {
5414
+ if (!this._root.data.Names.data.JavaScript) {
5415
+ this._root.data.Names.data.JavaScript = new PDFNameTree();
5416
+ }
5417
+
5418
+ let data = {
5419
+ JS: new String(js),
5420
+ S: 'JavaScript'
5421
+ };
5422
+
5423
+ this._root.data.Names.data.JavaScript.add(name, data);
5424
+ }
5425
+
4960
5426
  ref(data) {
4961
5427
  const ref = new PDFReference(this, this._offsets.length + 1, data);
4962
5428
 
@@ -5037,6 +5503,8 @@ Please pipe the document into a Node stream.\
5037
5503
 
5038
5504
  this._root.data.Names.end();
5039
5505
 
5506
+ this.endAcroForm();
5507
+
5040
5508
  if (this._security) {
5041
5509
  this._security.end();
5042
5510
  }
@@ -5107,6 +5575,7 @@ mixin(TextMixin);
5107
5575
  mixin(ImagesMixin);
5108
5576
  mixin(AnnotationsMixin);
5109
5577
  mixin(OutlineMixin);
5578
+ mixin(AcroFormMixin);
5110
5579
 
5111
5580
  module.exports = PDFDocument;
5112
5581
  //# sourceMappingURL=pdfkit.js.map