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/CHANGELOG.md +39 -27
- package/LICENSE +7 -7
- package/README.md +181 -175
- package/js/data/Courier-Bold.afm +342 -342
- package/js/data/Courier-BoldOblique.afm +342 -342
- package/js/data/Courier-Oblique.afm +342 -342
- package/js/data/Courier.afm +342 -342
- package/js/data/Helvetica-Bold.afm +2827 -2827
- package/js/data/Helvetica-BoldOblique.afm +2827 -2827
- package/js/data/Helvetica-Oblique.afm +3051 -3051
- package/js/data/Helvetica.afm +3051 -3051
- package/js/data/Symbol.afm +213 -213
- package/js/data/Times-Bold.afm +2588 -2588
- package/js/data/Times-BoldItalic.afm +2384 -2384
- package/js/data/Times-Italic.afm +2667 -2667
- package/js/data/Times-Roman.afm +2419 -2419
- package/js/data/ZapfDingbats.afm +225 -225
- package/js/pdfkit.es5.js +574 -96
- package/js/pdfkit.es5.js.map +1 -1
- package/js/pdfkit.esnext.js +660 -255
- package/js/pdfkit.esnext.js.map +1 -1
- package/js/pdfkit.js +588 -119
- package/js/pdfkit.js.map +1 -1
- package/js/pdfkit.standalone.js +13183 -16170
- package/package.json +85 -85
package/js/pdfkit.esnext.js
CHANGED
|
@@ -7,8 +7,8 @@ import { EventEmitter } from 'events';
|
|
|
7
7
|
import LineBreaker from 'linebreak';
|
|
8
8
|
import PNG from 'png-js';
|
|
9
9
|
|
|
10
|
-
/*
|
|
11
|
-
PDFAbstractReference - abstract class for PDF reference
|
|
10
|
+
/*
|
|
11
|
+
PDFAbstractReference - abstract class for PDF reference
|
|
12
12
|
*/
|
|
13
13
|
class PDFAbstractReference {
|
|
14
14
|
toString() {
|
|
@@ -17,8 +17,8 @@ class PDFAbstractReference {
|
|
|
17
17
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
/*
|
|
21
|
-
PDFNameTree - represents a name tree object
|
|
20
|
+
/*
|
|
21
|
+
PDFNameTree - represents a name tree object
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
class PDFNameTree {
|
|
@@ -58,9 +58,9 @@ class PDFNameTree {
|
|
|
58
58
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
/*
|
|
62
|
-
PDFObject - converts JavaScript types into their corresponding PDF types.
|
|
63
|
-
By Devon Govett
|
|
61
|
+
/*
|
|
62
|
+
PDFObject - converts JavaScript types into their corresponding PDF types.
|
|
63
|
+
By Devon Govett
|
|
64
64
|
*/
|
|
65
65
|
|
|
66
66
|
var pad = (str, length) => (Array(length + 1).join('0') + str).slice(-length);
|
|
@@ -176,9 +176,9 @@ class PDFObject {
|
|
|
176
176
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
/*
|
|
180
|
-
PDFReference - represents a reference to another object in the PDF object heirarchy
|
|
181
|
-
By Devon Govett
|
|
179
|
+
/*
|
|
180
|
+
PDFReference - represents a reference to another object in the PDF object heirarchy
|
|
181
|
+
By Devon Govett
|
|
182
182
|
*/
|
|
183
183
|
|
|
184
184
|
class PDFReference extends PDFAbstractReference {
|
|
@@ -264,9 +264,9 @@ class PDFReference extends PDFAbstractReference {
|
|
|
264
264
|
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
/*
|
|
268
|
-
PDFPage - represents a single page in the PDF document
|
|
269
|
-
By Devon Govett
|
|
267
|
+
/*
|
|
268
|
+
PDFPage - represents a single page in the PDF document
|
|
269
|
+
By Devon Govett
|
|
270
270
|
*/
|
|
271
271
|
var DEFAULT_MARGINS = {
|
|
272
272
|
top: 72,
|
|
@@ -406,11 +406,11 @@ class PDFPage {
|
|
|
406
406
|
|
|
407
407
|
}
|
|
408
408
|
|
|
409
|
-
/**
|
|
410
|
-
* Check if value is in a range group.
|
|
411
|
-
* @param {number} value
|
|
412
|
-
* @param {number[]} rangeGroup
|
|
413
|
-
* @returns {boolean}
|
|
409
|
+
/**
|
|
410
|
+
* Check if value is in a range group.
|
|
411
|
+
* @param {number} value
|
|
412
|
+
* @param {number[]} rangeGroup
|
|
413
|
+
* @returns {boolean}
|
|
414
414
|
*/
|
|
415
415
|
function inRange(value, rangeGroup) {
|
|
416
416
|
if (value < rangeGroup[0]) return false;
|
|
@@ -440,9 +440,9 @@ function inRange(value, rangeGroup) {
|
|
|
440
440
|
|
|
441
441
|
/* eslint-disable prettier/prettier */
|
|
442
442
|
|
|
443
|
-
/**
|
|
444
|
-
* A.1 Unassigned code points in Unicode 3.2
|
|
445
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-A.1
|
|
443
|
+
/**
|
|
444
|
+
* A.1 Unassigned code points in Unicode 3.2
|
|
445
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-A.1
|
|
446
446
|
*/
|
|
447
447
|
|
|
448
448
|
var 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];
|
|
@@ -451,9 +451,9 @@ var unassigned_code_points = [0x0221, 0x0221, 0x0234, 0x024f, 0x02ae, 0x02af, 0x
|
|
|
451
451
|
var isUnassignedCodePoint = character => inRange(character, unassigned_code_points);
|
|
452
452
|
/* eslint-disable prettier/prettier */
|
|
453
453
|
|
|
454
|
-
/**
|
|
455
|
-
* B.1 Commonly mapped to nothing
|
|
456
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-B.1
|
|
454
|
+
/**
|
|
455
|
+
* B.1 Commonly mapped to nothing
|
|
456
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-B.1
|
|
457
457
|
*/
|
|
458
458
|
|
|
459
459
|
|
|
@@ -463,9 +463,9 @@ var commonly_mapped_to_nothing = [0x00ad, 0x00ad, 0x034f, 0x034f, 0x1806, 0x1806
|
|
|
463
463
|
var isCommonlyMappedToNothing = character => inRange(character, commonly_mapped_to_nothing);
|
|
464
464
|
/* eslint-disable prettier/prettier */
|
|
465
465
|
|
|
466
|
-
/**
|
|
467
|
-
* C.1.2 Non-ASCII space characters
|
|
468
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.1.2
|
|
466
|
+
/**
|
|
467
|
+
* C.1.2 Non-ASCII space characters
|
|
468
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.1.2
|
|
469
469
|
*/
|
|
470
470
|
|
|
471
471
|
|
|
@@ -511,9 +511,9 @@ var isNonASCIISpaceCharacter = character => inRange(character, non_ASCII_space_c
|
|
|
511
511
|
|
|
512
512
|
|
|
513
513
|
var non_ASCII_controls_characters = [
|
|
514
|
-
/**
|
|
515
|
-
* C.2.2 Non-ASCII control characters
|
|
516
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.2.2
|
|
514
|
+
/**
|
|
515
|
+
* C.2.2 Non-ASCII control characters
|
|
516
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.2.2
|
|
517
517
|
*/
|
|
518
518
|
0x0080, 0x009f
|
|
519
519
|
/* [CONTROL CHARACTERS] */
|
|
@@ -549,9 +549,9 @@ var non_ASCII_controls_characters = [
|
|
|
549
549
|
/* [MUSICAL CONTROL CHARACTERS] */
|
|
550
550
|
];
|
|
551
551
|
var non_character_codepoints = [
|
|
552
|
-
/**
|
|
553
|
-
* C.4 Non-character code points
|
|
554
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.4
|
|
552
|
+
/**
|
|
553
|
+
* C.4 Non-character code points
|
|
554
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.4
|
|
555
555
|
*/
|
|
556
556
|
0xfdd0, 0xfdef
|
|
557
557
|
/* [NONCHARACTER CODE POINTS] */
|
|
@@ -588,23 +588,23 @@ var non_character_codepoints = [
|
|
|
588
588
|
, 0x10fffe, 0x10ffff
|
|
589
589
|
/* [NONCHARACTER CODE POINTS] */
|
|
590
590
|
];
|
|
591
|
-
/**
|
|
592
|
-
* 2.3. Prohibited Output
|
|
591
|
+
/**
|
|
592
|
+
* 2.3. Prohibited Output
|
|
593
593
|
*/
|
|
594
594
|
|
|
595
595
|
var prohibited_characters = [
|
|
596
|
-
/**
|
|
597
|
-
* C.2.1 ASCII control characters
|
|
598
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.2.1
|
|
596
|
+
/**
|
|
597
|
+
* C.2.1 ASCII control characters
|
|
598
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.2.1
|
|
599
599
|
*/
|
|
600
600
|
0, 0x001f
|
|
601
601
|
/* [CONTROL CHARACTERS] */
|
|
602
602
|
, 0x007f, 0x007f
|
|
603
603
|
/* DELETE */
|
|
604
604
|
,
|
|
605
|
-
/**
|
|
606
|
-
* C.8 Change display properties or are deprecated
|
|
607
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.8
|
|
605
|
+
/**
|
|
606
|
+
* C.8 Change display properties or are deprecated
|
|
607
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.8
|
|
608
608
|
*/
|
|
609
609
|
0x0340, 0x0340
|
|
610
610
|
/* COMBINING GRAVE TONE MARK */
|
|
@@ -637,28 +637,28 @@ var prohibited_characters = [
|
|
|
637
637
|
, 0x206f, 0x206f
|
|
638
638
|
/* NOMINAL DIGIT SHAPES */
|
|
639
639
|
,
|
|
640
|
-
/**
|
|
641
|
-
* C.7 Inappropriate for canonical representation
|
|
642
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.7
|
|
640
|
+
/**
|
|
641
|
+
* C.7 Inappropriate for canonical representation
|
|
642
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.7
|
|
643
643
|
*/
|
|
644
644
|
0x2ff0, 0x2ffb
|
|
645
645
|
/* [IDEOGRAPHIC DESCRIPTION CHARACTERS] */
|
|
646
646
|
,
|
|
647
|
-
/**
|
|
648
|
-
* C.5 Surrogate codes
|
|
649
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.5
|
|
647
|
+
/**
|
|
648
|
+
* C.5 Surrogate codes
|
|
649
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.5
|
|
650
650
|
*/
|
|
651
651
|
0xd800, 0xdfff,
|
|
652
|
-
/**
|
|
653
|
-
* C.3 Private use
|
|
654
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.3
|
|
652
|
+
/**
|
|
653
|
+
* C.3 Private use
|
|
654
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.3
|
|
655
655
|
*/
|
|
656
656
|
0xe000, 0xf8ff
|
|
657
657
|
/* [PRIVATE USE, PLANE 0] */
|
|
658
658
|
,
|
|
659
|
-
/**
|
|
660
|
-
* C.6 Inappropriate for plain text
|
|
661
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.6
|
|
659
|
+
/**
|
|
660
|
+
* C.6 Inappropriate for plain text
|
|
661
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.6
|
|
662
662
|
*/
|
|
663
663
|
0xfff9, 0xfff9
|
|
664
664
|
/* INTERLINEAR ANNOTATION ANCHOR */
|
|
@@ -671,18 +671,18 @@ var prohibited_characters = [
|
|
|
671
671
|
, 0xfffd, 0xfffd
|
|
672
672
|
/* REPLACEMENT CHARACTER */
|
|
673
673
|
,
|
|
674
|
-
/**
|
|
675
|
-
* C.9 Tagging characters
|
|
676
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.9
|
|
674
|
+
/**
|
|
675
|
+
* C.9 Tagging characters
|
|
676
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.9
|
|
677
677
|
*/
|
|
678
678
|
0xe0001, 0xe0001
|
|
679
679
|
/* LANGUAGE TAG */
|
|
680
680
|
, 0xe0020, 0xe007f
|
|
681
681
|
/* [TAGGING CHARACTERS] */
|
|
682
682
|
,
|
|
683
|
-
/**
|
|
684
|
-
* C.3 Private use
|
|
685
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.3
|
|
683
|
+
/**
|
|
684
|
+
* C.3 Private use
|
|
685
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.3
|
|
686
686
|
*/
|
|
687
687
|
0xf0000, 0xffffd
|
|
688
688
|
/* [PRIVATE USE, PLANE 15] */
|
|
@@ -694,9 +694,9 @@ var prohibited_characters = [
|
|
|
694
694
|
var isProhibitedCharacter = character => inRange(character, non_ASCII_space_characters) || inRange(character, prohibited_characters) || inRange(character, non_ASCII_controls_characters) || inRange(character, non_character_codepoints);
|
|
695
695
|
/* eslint-disable prettier/prettier */
|
|
696
696
|
|
|
697
|
-
/**
|
|
698
|
-
* D.1 Characters with bidirectional property "R" or "AL"
|
|
699
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-D.1
|
|
697
|
+
/**
|
|
698
|
+
* D.1 Characters with bidirectional property "R" or "AL"
|
|
699
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-D.1
|
|
700
700
|
*/
|
|
701
701
|
|
|
702
702
|
|
|
@@ -706,9 +706,9 @@ var bidirectional_r_al = [0x05be, 0x05be, 0x05c0, 0x05c0, 0x05c3, 0x05c3, 0x05d0
|
|
|
706
706
|
var isBidirectionalRAL = character => inRange(character, bidirectional_r_al);
|
|
707
707
|
/* eslint-disable prettier/prettier */
|
|
708
708
|
|
|
709
|
-
/**
|
|
710
|
-
* D.2 Characters with bidirectional property "L"
|
|
711
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-D.2
|
|
709
|
+
/**
|
|
710
|
+
* D.2 Characters with bidirectional property "L"
|
|
711
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-D.2
|
|
712
712
|
*/
|
|
713
713
|
|
|
714
714
|
|
|
@@ -717,15 +717,15 @@ var bidirectional_l = [0x0041, 0x005a, 0x0061, 0x007a, 0x00aa, 0x00aa, 0x00b5, 0
|
|
|
717
717
|
|
|
718
718
|
var isBidirectionalL = character => inRange(character, bidirectional_l);
|
|
719
719
|
|
|
720
|
-
/**
|
|
721
|
-
* non-ASCII space characters [StringPrep, C.1.2] that can be
|
|
722
|
-
* mapped to SPACE (U+0020)
|
|
720
|
+
/**
|
|
721
|
+
* non-ASCII space characters [StringPrep, C.1.2] that can be
|
|
722
|
+
* mapped to SPACE (U+0020)
|
|
723
723
|
*/
|
|
724
724
|
|
|
725
725
|
var mapping2space = isNonASCIISpaceCharacter;
|
|
726
|
-
/**
|
|
727
|
-
* the "commonly mapped to nothing" characters [StringPrep, B.1]
|
|
728
|
-
* that can be mapped to nothing.
|
|
726
|
+
/**
|
|
727
|
+
* the "commonly mapped to nothing" characters [StringPrep, B.1]
|
|
728
|
+
* that can be mapped to nothing.
|
|
729
729
|
*/
|
|
730
730
|
|
|
731
731
|
var mapping2nothing = isCommonlyMappedToNothing; // utils
|
|
@@ -735,12 +735,12 @@ var getCodePoint = character => character.codePointAt(0);
|
|
|
735
735
|
var first = x => x[0];
|
|
736
736
|
|
|
737
737
|
var last = x => x[x.length - 1];
|
|
738
|
-
/**
|
|
739
|
-
* Convert provided string into an array of Unicode Code Points.
|
|
740
|
-
* Based on https://stackoverflow.com/a/21409165/1556249
|
|
741
|
-
* and https://www.npmjs.com/package/code-point-at.
|
|
742
|
-
* @param {string} input
|
|
743
|
-
* @returns {number[]}
|
|
738
|
+
/**
|
|
739
|
+
* Convert provided string into an array of Unicode Code Points.
|
|
740
|
+
* Based on https://stackoverflow.com/a/21409165/1556249
|
|
741
|
+
* and https://www.npmjs.com/package/code-point-at.
|
|
742
|
+
* @param {string} input
|
|
743
|
+
* @returns {number[]}
|
|
744
744
|
*/
|
|
745
745
|
|
|
746
746
|
|
|
@@ -766,12 +766,12 @@ function toCodePoints(input) {
|
|
|
766
766
|
|
|
767
767
|
return codepoints;
|
|
768
768
|
}
|
|
769
|
-
/**
|
|
770
|
-
* SASLprep.
|
|
771
|
-
* @param {string} input
|
|
772
|
-
* @param {Object} opts
|
|
773
|
-
* @param {boolean} opts.allowUnassigned
|
|
774
|
-
* @returns {string}
|
|
769
|
+
/**
|
|
770
|
+
* SASLprep.
|
|
771
|
+
* @param {string} input
|
|
772
|
+
* @param {Object} opts
|
|
773
|
+
* @param {boolean} opts.allowUnassigned
|
|
774
|
+
* @returns {string}
|
|
775
775
|
*/
|
|
776
776
|
|
|
777
777
|
|
|
@@ -817,10 +817,10 @@ function saslprep(input) {
|
|
|
817
817
|
if (hasBidiRAL && hasBidiL) {
|
|
818
818
|
throw new Error('String must not contain RandALCat and LCat at the same time,' + ' see https://tools.ietf.org/html/rfc3454#section-6');
|
|
819
819
|
}
|
|
820
|
-
/**
|
|
821
|
-
* 4.2 If a string contains any RandALCat character, a RandALCat
|
|
822
|
-
* character MUST be the first character of the string, and a
|
|
823
|
-
* RandALCat character MUST be the last character of the string.
|
|
820
|
+
/**
|
|
821
|
+
* 4.2 If a string contains any RandALCat character, a RandALCat
|
|
822
|
+
* character MUST be the first character of the string, and a
|
|
823
|
+
* RandALCat character MUST be the last character of the string.
|
|
824
824
|
*/
|
|
825
825
|
|
|
826
826
|
|
|
@@ -834,9 +834,9 @@ function saslprep(input) {
|
|
|
834
834
|
return normalized_input;
|
|
835
835
|
}
|
|
836
836
|
|
|
837
|
-
/*
|
|
838
|
-
PDFSecurity - represents PDF security settings
|
|
839
|
-
By Yang Liu <hi@zesik.com>
|
|
837
|
+
/*
|
|
838
|
+
PDFSecurity - represents PDF security settings
|
|
839
|
+
By Yang Liu <hi@zesik.com>
|
|
840
840
|
*/
|
|
841
841
|
|
|
842
842
|
class PDFSecurity {
|
|
@@ -849,7 +849,7 @@ class PDFSecurity {
|
|
|
849
849
|
continue;
|
|
850
850
|
}
|
|
851
851
|
|
|
852
|
-
infoStr += "".concat(key, ": ").concat(info[key]
|
|
852
|
+
infoStr += "".concat(key, ": ").concat(info[key], "\n");
|
|
853
853
|
}
|
|
854
854
|
|
|
855
855
|
return wordArrayToBuffer(CryptoJS.MD5(infoStr));
|
|
@@ -1272,45 +1272,9 @@ function wordArrayToBuffer(wordArray) {
|
|
|
1272
1272
|
|
|
1273
1273
|
var PASSWORD_PADDING = [0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a];
|
|
1274
1274
|
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
function _arrayWithHoles(arr) {
|
|
1280
|
-
if (Array.isArray(arr)) return arr;
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
function _iterableToArrayLimit(arr, i) {
|
|
1284
|
-
var _arr = [];
|
|
1285
|
-
var _n = true;
|
|
1286
|
-
var _d = false;
|
|
1287
|
-
var _e = undefined;
|
|
1288
|
-
|
|
1289
|
-
try {
|
|
1290
|
-
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
|
1291
|
-
_arr.push(_s.value);
|
|
1292
|
-
|
|
1293
|
-
if (i && _arr.length === i) break;
|
|
1294
|
-
}
|
|
1295
|
-
} catch (err) {
|
|
1296
|
-
_d = true;
|
|
1297
|
-
_e = err;
|
|
1298
|
-
} finally {
|
|
1299
|
-
try {
|
|
1300
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
1301
|
-
} finally {
|
|
1302
|
-
if (_d) throw _e;
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1306
|
-
return _arr;
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
function _nonIterableRest() {
|
|
1310
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
var number = PDFObject.number;
|
|
1275
|
+
var {
|
|
1276
|
+
number
|
|
1277
|
+
} = PDFObject;
|
|
1314
1278
|
|
|
1315
1279
|
class PDFGradient {
|
|
1316
1280
|
constructor(doc) {
|
|
@@ -1353,15 +1317,16 @@ class PDFGradient {
|
|
|
1353
1317
|
|
|
1354
1318
|
embed(m) {
|
|
1355
1319
|
var fn;
|
|
1320
|
+
var stopsLength = this.stops.length;
|
|
1356
1321
|
|
|
1357
|
-
if (
|
|
1322
|
+
if (stopsLength === 0) {
|
|
1358
1323
|
return;
|
|
1359
1324
|
}
|
|
1360
1325
|
|
|
1361
1326
|
this.embedded = true;
|
|
1362
1327
|
this.matrix = m; // if the last stop comes before 100%, add a copy at 100%
|
|
1363
1328
|
|
|
1364
|
-
var last = this.stops[
|
|
1329
|
+
var last = this.stops[stopsLength - 1];
|
|
1365
1330
|
|
|
1366
1331
|
if (last[0] < 1) {
|
|
1367
1332
|
this.stops.push([1, last[1], last[2]]);
|
|
@@ -1371,7 +1336,7 @@ class PDFGradient {
|
|
|
1371
1336
|
var encode = [];
|
|
1372
1337
|
var stops = [];
|
|
1373
1338
|
|
|
1374
|
-
for (var i = 0
|
|
1339
|
+
for (var i = 0; i < stopsLength - 1; i++) {
|
|
1375
1340
|
encode.push(0, 1);
|
|
1376
1341
|
|
|
1377
1342
|
if (i + 2 !== stopsLength) {
|
|
@@ -1390,7 +1355,7 @@ class PDFGradient {
|
|
|
1390
1355
|
} // if there are only two stops, we don't need a stitching function
|
|
1391
1356
|
|
|
1392
1357
|
|
|
1393
|
-
if (
|
|
1358
|
+
if (stopsLength === 1) {
|
|
1394
1359
|
fn = stops[0];
|
|
1395
1360
|
} else {
|
|
1396
1361
|
fn = this.doc.ref({
|
|
@@ -1411,7 +1376,7 @@ class PDFGradient {
|
|
|
1411
1376
|
Type: 'Pattern',
|
|
1412
1377
|
PatternType: 2,
|
|
1413
1378
|
Shading: shader,
|
|
1414
|
-
Matrix: this.matrix.map(
|
|
1379
|
+
Matrix: this.matrix.map(number)
|
|
1415
1380
|
});
|
|
1416
1381
|
pattern.end();
|
|
1417
1382
|
|
|
@@ -1483,22 +1448,8 @@ class PDFGradient {
|
|
|
1483
1448
|
|
|
1484
1449
|
apply(op) {
|
|
1485
1450
|
// apply gradient transform to existing document ctm
|
|
1486
|
-
var
|
|
1487
|
-
|
|
1488
|
-
m1 = _this$doc$_ctm[1],
|
|
1489
|
-
m2 = _this$doc$_ctm[2],
|
|
1490
|
-
m3 = _this$doc$_ctm[3],
|
|
1491
|
-
m4 = _this$doc$_ctm[4],
|
|
1492
|
-
m5 = _this$doc$_ctm[5];
|
|
1493
|
-
|
|
1494
|
-
var _this$transform = _slicedToArray(this.transform, 6),
|
|
1495
|
-
m11 = _this$transform[0],
|
|
1496
|
-
m12 = _this$transform[1],
|
|
1497
|
-
m21 = _this$transform[2],
|
|
1498
|
-
m22 = _this$transform[3],
|
|
1499
|
-
dx = _this$transform[4],
|
|
1500
|
-
dy = _this$transform[5];
|
|
1501
|
-
|
|
1451
|
+
var [m0, m1, m2, m3, m4, m5] = this.doc._ctm;
|
|
1452
|
+
var [m11, m12, m21, m22, dx, dy] = this.transform;
|
|
1502
1453
|
var m = [m0 * m11 + m2 * m12, m1 * m11 + m3 * m12, m0 * m21 + m2 * m22, m1 * m21 + m3 * m22, m0 * dx + m2 * dy + m4, m1 * dx + m3 * dy + m5];
|
|
1503
1454
|
|
|
1504
1455
|
if (!this.embedded || m.join(' ') !== this.matrix.join(' ')) {
|
|
@@ -1569,9 +1520,11 @@ var Gradient = {
|
|
|
1569
1520
|
PDFRadialGradient
|
|
1570
1521
|
};
|
|
1571
1522
|
|
|
1572
|
-
var
|
|
1573
|
-
|
|
1574
|
-
|
|
1523
|
+
var {
|
|
1524
|
+
PDFGradient: PDFGradient$1,
|
|
1525
|
+
PDFLinearGradient: PDFLinearGradient$1,
|
|
1526
|
+
PDFRadialGradient: PDFRadialGradient$1
|
|
1527
|
+
} = Gradient;
|
|
1575
1528
|
var ColorMixin = {
|
|
1576
1529
|
initColor() {
|
|
1577
1530
|
// The opacity dictionaries
|
|
@@ -1701,10 +1654,7 @@ var ColorMixin = {
|
|
|
1701
1654
|
var key = "".concat(fillOpacity, "_").concat(strokeOpacity);
|
|
1702
1655
|
|
|
1703
1656
|
if (this._opacityRegistry[key]) {
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
dictionary = _this$_opacityRegistr[0];
|
|
1707
|
-
name = _this$_opacityRegistr[1];
|
|
1657
|
+
[dictionary, name] = this._opacityRegistry[key];
|
|
1708
1658
|
} else {
|
|
1709
1659
|
dictionary = {
|
|
1710
1660
|
Type: 'ExtGState'
|
|
@@ -2043,7 +1993,7 @@ var runners = {
|
|
|
2043
1993
|
cy = a[5];
|
|
2044
1994
|
px = a[2];
|
|
2045
1995
|
py = a[3];
|
|
2046
|
-
return doc.bezierCurveTo(...
|
|
1996
|
+
return doc.bezierCurveTo(...a);
|
|
2047
1997
|
},
|
|
2048
1998
|
|
|
2049
1999
|
c(doc, a) {
|
|
@@ -2193,20 +2143,12 @@ var runners = {
|
|
|
2193
2143
|
};
|
|
2194
2144
|
|
|
2195
2145
|
var solveArc = function solveArc(doc, x, y, coords) {
|
|
2196
|
-
var
|
|
2197
|
-
rx = _coords[0],
|
|
2198
|
-
ry = _coords[1],
|
|
2199
|
-
rot = _coords[2],
|
|
2200
|
-
large = _coords[3],
|
|
2201
|
-
sweep = _coords[4],
|
|
2202
|
-
ex = _coords[5],
|
|
2203
|
-
ey = _coords[6];
|
|
2204
|
-
|
|
2146
|
+
var [rx, ry, rot, large, sweep, ex, ey] = coords;
|
|
2205
2147
|
var segs = arcToSegments(ex, ey, rx, ry, large, sweep, rot, x, y);
|
|
2206
2148
|
|
|
2207
2149
|
for (var seg of segs) {
|
|
2208
|
-
var bez = segmentToBezier(...
|
|
2209
|
-
doc.bezierCurveTo(...
|
|
2150
|
+
var bez = segmentToBezier(...seg);
|
|
2151
|
+
doc.bezierCurveTo(...bez);
|
|
2210
2152
|
}
|
|
2211
2153
|
}; // from Inkscape svgtopdf, thanks!
|
|
2212
2154
|
|
|
@@ -2296,7 +2238,9 @@ class SVGPath {
|
|
|
2296
2238
|
|
|
2297
2239
|
}
|
|
2298
2240
|
|
|
2299
|
-
var
|
|
2241
|
+
var {
|
|
2242
|
+
number: number$1
|
|
2243
|
+
} = PDFObject; // This constant is used to approximate a symmetrical arc using a cubic
|
|
2300
2244
|
// Bezier curve.
|
|
2301
2245
|
|
|
2302
2246
|
var KAPPA = 4.0 * ((Math.sqrt(2) - 1.0) / 3.0);
|
|
@@ -2580,15 +2524,7 @@ var VectorMixin = {
|
|
|
2580
2524
|
transform(m11, m12, m21, m22, dx, dy) {
|
|
2581
2525
|
// keep track of the current transformation matrix
|
|
2582
2526
|
var m = this._ctm;
|
|
2583
|
-
|
|
2584
|
-
var _m = _slicedToArray(m, 6),
|
|
2585
|
-
m0 = _m[0],
|
|
2586
|
-
m1 = _m[1],
|
|
2587
|
-
m2 = _m[2],
|
|
2588
|
-
m3 = _m[3],
|
|
2589
|
-
m4 = _m[4],
|
|
2590
|
-
m5 = _m[5];
|
|
2591
|
-
|
|
2527
|
+
var [m0, m1, m2, m3, m4, m5] = m;
|
|
2592
2528
|
m[0] = m0 * m11 + m2 * m12;
|
|
2593
2529
|
m[1] = m1 * m11 + m3 * m12;
|
|
2594
2530
|
m[2] = m0 * m21 + m2 * m22;
|
|
@@ -2612,10 +2548,7 @@ var VectorMixin = {
|
|
|
2612
2548
|
var x = y = 0;
|
|
2613
2549
|
|
|
2614
2550
|
if (options.origin != null) {
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
x = _options$origin[0];
|
|
2618
|
-
y = _options$origin[1];
|
|
2551
|
+
[x, y] = options.origin;
|
|
2619
2552
|
var x1 = x * cos - y * sin;
|
|
2620
2553
|
var y1 = x * sin + y * cos;
|
|
2621
2554
|
x -= x1;
|
|
@@ -2641,10 +2574,7 @@ var VectorMixin = {
|
|
|
2641
2574
|
var x = y = 0;
|
|
2642
2575
|
|
|
2643
2576
|
if (options.origin != null) {
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
x = _options$origin2[0];
|
|
2647
|
-
y = _options$origin2[1];
|
|
2577
|
+
[x, y] = options.origin;
|
|
2648
2578
|
x -= xFactor * x;
|
|
2649
2579
|
y -= yFactor * y;
|
|
2650
2580
|
}
|
|
@@ -2920,13 +2850,14 @@ class StandardFont extends PDFFont {
|
|
|
2920
2850
|
this.name = name;
|
|
2921
2851
|
this.id = id;
|
|
2922
2852
|
this.font = new AFMFont(STANDARD_FONTS[this.name]());
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2853
|
+
({
|
|
2854
|
+
ascender: this.ascender,
|
|
2855
|
+
descender: this.descender,
|
|
2856
|
+
bbox: this.bbox,
|
|
2857
|
+
lineGap: this.lineGap,
|
|
2858
|
+
xHeight: this.xHeight,
|
|
2859
|
+
capHeight: this.capHeight
|
|
2860
|
+
} = this.font);
|
|
2930
2861
|
}
|
|
2931
2862
|
|
|
2932
2863
|
embed() {
|
|
@@ -3077,10 +3008,10 @@ class EmbeddedFont extends PDFFont {
|
|
|
3077
3008
|
}
|
|
3078
3009
|
|
|
3079
3010
|
encode(text, features) {
|
|
3080
|
-
var
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3011
|
+
var {
|
|
3012
|
+
glyphs,
|
|
3013
|
+
positions
|
|
3014
|
+
} = this.layout(text, features);
|
|
3084
3015
|
var res = [];
|
|
3085
3016
|
|
|
3086
3017
|
for (var i = 0; i < glyphs.length; i++) {
|
|
@@ -3139,7 +3070,9 @@ class EmbeddedFont extends PDFFont {
|
|
|
3139
3070
|
|
|
3140
3071
|
var tag = [1, 2, 3, 4, 5, 6].map(i => String.fromCharCode((this.id.charCodeAt(i) || 74) + 16)).join('');
|
|
3141
3072
|
var name = tag + '+' + this.font.postscriptName;
|
|
3142
|
-
var
|
|
3073
|
+
var {
|
|
3074
|
+
bbox
|
|
3075
|
+
} = this.font;
|
|
3143
3076
|
var descriptor = this.document.ref({
|
|
3144
3077
|
Type: 'FontDescriptor',
|
|
3145
3078
|
FontName: name,
|
|
@@ -3160,9 +3093,9 @@ class EmbeddedFont extends PDFFont {
|
|
|
3160
3093
|
}
|
|
3161
3094
|
|
|
3162
3095
|
descriptor.end();
|
|
3163
|
-
var
|
|
3096
|
+
var descendantFontData = {
|
|
3164
3097
|
Type: 'Font',
|
|
3165
|
-
Subtype:
|
|
3098
|
+
Subtype: 'CIDFontType0',
|
|
3166
3099
|
BaseFont: name,
|
|
3167
3100
|
CIDSystemInfo: {
|
|
3168
3101
|
Registry: new String('Adobe'),
|
|
@@ -3171,7 +3104,14 @@ class EmbeddedFont extends PDFFont {
|
|
|
3171
3104
|
},
|
|
3172
3105
|
FontDescriptor: descriptor,
|
|
3173
3106
|
W: [0, this.widths]
|
|
3174
|
-
}
|
|
3107
|
+
};
|
|
3108
|
+
|
|
3109
|
+
if (!isCFF) {
|
|
3110
|
+
descendantFontData.Subtype = 'CIDFontType2';
|
|
3111
|
+
descendantFontData.CIDToGIDMap = 'Identity';
|
|
3112
|
+
}
|
|
3113
|
+
|
|
3114
|
+
var descendantFont = this.document.ref(descendantFontData);
|
|
3175
3115
|
descendantFont.end();
|
|
3176
3116
|
this.dictionary.data = {
|
|
3177
3117
|
Type: 'Font',
|
|
@@ -3269,9 +3209,10 @@ var FontsMixin = {
|
|
|
3269
3209
|
|
|
3270
3210
|
if (typeof src === 'string' && this._registeredFonts[src]) {
|
|
3271
3211
|
cacheKey = src;
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3212
|
+
({
|
|
3213
|
+
src,
|
|
3214
|
+
family
|
|
3215
|
+
} = this._registeredFonts[src]);
|
|
3275
3216
|
} else {
|
|
3276
3217
|
cacheKey = family || src;
|
|
3277
3218
|
|
|
@@ -3384,7 +3325,9 @@ class LineWrapper extends EventEmitter {
|
|
|
3384
3325
|
}); // handle left aligning last lines of paragraphs
|
|
3385
3326
|
|
|
3386
3327
|
this.on('lastLine', options => {
|
|
3387
|
-
var
|
|
3328
|
+
var {
|
|
3329
|
+
align
|
|
3330
|
+
} = options;
|
|
3388
3331
|
|
|
3389
3332
|
if (align === 'justify') {
|
|
3390
3333
|
options.align = 'left';
|
|
@@ -3446,6 +3389,11 @@ class LineWrapper extends EventEmitter {
|
|
|
3446
3389
|
mustShrink = w > this.spaceLeft && l > 0;
|
|
3447
3390
|
mightGrow = w <= this.spaceLeft && l < word.length;
|
|
3448
3391
|
}
|
|
3392
|
+
} // check for the edge case where a single character cannot fit into a line.
|
|
3393
|
+
|
|
3394
|
+
|
|
3395
|
+
if (l === 0 && this.spaceLeft === this.lineWidth) {
|
|
3396
|
+
l = 1;
|
|
3449
3397
|
} // send a required break unless this is the last piece and a linebreak is not specified
|
|
3450
3398
|
|
|
3451
3399
|
|
|
@@ -3506,13 +3454,17 @@ class LineWrapper extends EventEmitter {
|
|
|
3506
3454
|
var textWidth = 0;
|
|
3507
3455
|
var wc = 0;
|
|
3508
3456
|
var lc = 0;
|
|
3509
|
-
var
|
|
3457
|
+
var {
|
|
3458
|
+
y
|
|
3459
|
+
} = this.document; // used to reset Y pos if options.continued (below)
|
|
3510
3460
|
|
|
3511
3461
|
var emitLine = () => {
|
|
3512
3462
|
options.textWidth = textWidth + this.wordSpacing * (wc - 1);
|
|
3513
3463
|
options.wordCount = wc;
|
|
3514
3464
|
options.lineWidth = this.lineWidth;
|
|
3515
|
-
|
|
3465
|
+
({
|
|
3466
|
+
y
|
|
3467
|
+
} = this.document);
|
|
3516
3468
|
this.emit('line', buffer, options, this);
|
|
3517
3469
|
return lc++;
|
|
3518
3470
|
};
|
|
@@ -3638,7 +3590,7 @@ class LineWrapper extends EventEmitter {
|
|
|
3638
3590
|
this.document.x = this.startX;
|
|
3639
3591
|
|
|
3640
3592
|
if (this.document._fillColor) {
|
|
3641
|
-
this.document.fillColor(...
|
|
3593
|
+
this.document.fillColor(...this.document._fillColor);
|
|
3642
3594
|
}
|
|
3643
3595
|
|
|
3644
3596
|
this.emit('pageBreak', options, this);
|
|
@@ -3654,7 +3606,9 @@ class LineWrapper extends EventEmitter {
|
|
|
3654
3606
|
|
|
3655
3607
|
}
|
|
3656
3608
|
|
|
3657
|
-
var
|
|
3609
|
+
var {
|
|
3610
|
+
number: number$2
|
|
3611
|
+
} = PDFObject;
|
|
3658
3612
|
var TextMixin = {
|
|
3659
3613
|
initText() {
|
|
3660
3614
|
this._line = this._line.bind(this); // Current coordinates
|
|
@@ -3727,8 +3681,10 @@ var TextMixin = {
|
|
|
3727
3681
|
},
|
|
3728
3682
|
|
|
3729
3683
|
heightOfString(text, options) {
|
|
3730
|
-
var
|
|
3731
|
-
|
|
3684
|
+
var {
|
|
3685
|
+
x,
|
|
3686
|
+
y
|
|
3687
|
+
} = this;
|
|
3732
3688
|
options = this._initOptions(options);
|
|
3733
3689
|
options.height = Infinity; // don't break pages
|
|
3734
3690
|
|
|
@@ -3850,7 +3806,7 @@ var TextMixin = {
|
|
|
3850
3806
|
var val = this._textOptions[key];
|
|
3851
3807
|
|
|
3852
3808
|
if (key !== 'continued') {
|
|
3853
|
-
if (result[key]
|
|
3809
|
+
if (result[key] === undefined) {
|
|
3854
3810
|
result[key] = val;
|
|
3855
3811
|
}
|
|
3856
3812
|
}
|
|
@@ -3871,6 +3827,8 @@ var TextMixin = {
|
|
|
3871
3827
|
if (result.width == null) {
|
|
3872
3828
|
result.width = this.page.width - this.x - this.page.margins.right;
|
|
3873
3829
|
}
|
|
3830
|
+
|
|
3831
|
+
result.width = Math.max(result.width, 0);
|
|
3874
3832
|
}
|
|
3875
3833
|
|
|
3876
3834
|
if (!result.columns) {
|
|
@@ -4068,10 +4026,7 @@ var TextMixin = {
|
|
|
4068
4026
|
positions = [];
|
|
4069
4027
|
|
|
4070
4028
|
for (var word of words) {
|
|
4071
|
-
var
|
|
4072
|
-
_this$_font$encode2 = _slicedToArray(_this$_font$encode, 2),
|
|
4073
|
-
encodedWord = _this$_font$encode2[0],
|
|
4074
|
-
positionsWord = _this$_font$encode2[1];
|
|
4029
|
+
var [encodedWord, positionsWord] = this._font.encode(word, options.features);
|
|
4075
4030
|
|
|
4076
4031
|
encoded = encoded.concat(encodedWord);
|
|
4077
4032
|
positions = positions.concat(positionsWord); // add the word spacing to the end of the word
|
|
@@ -4089,12 +4044,7 @@ var TextMixin = {
|
|
|
4089
4044
|
positions[positions.length - 1] = space;
|
|
4090
4045
|
}
|
|
4091
4046
|
} else {
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
var _this$_font$encode4 = _slicedToArray(_this$_font$encode3, 2);
|
|
4095
|
-
|
|
4096
|
-
encoded = _this$_font$encode4[0];
|
|
4097
|
-
positions = _this$_font$encode4[1];
|
|
4047
|
+
[encoded, positions] = this._font.encode(text, options.features);
|
|
4098
4048
|
}
|
|
4099
4049
|
|
|
4100
4050
|
var scale = this._fontSize / 1000;
|
|
@@ -4244,6 +4194,7 @@ class PNGImage {
|
|
|
4244
4194
|
}
|
|
4245
4195
|
|
|
4246
4196
|
embed(document) {
|
|
4197
|
+
var dataDecoded = false;
|
|
4247
4198
|
this.document = document;
|
|
4248
4199
|
|
|
4249
4200
|
if (this.obj) {
|
|
@@ -4251,6 +4202,7 @@ class PNGImage {
|
|
|
4251
4202
|
}
|
|
4252
4203
|
|
|
4253
4204
|
var hasAlphaChannel = this.image.hasAlphaChannel;
|
|
4205
|
+
var isInterlaced = this.image.interlaceMethod === 1;
|
|
4254
4206
|
this.obj = this.document.ref({
|
|
4255
4207
|
Type: 'XObject',
|
|
4256
4208
|
Subtype: 'Image',
|
|
@@ -4262,7 +4214,7 @@ class PNGImage {
|
|
|
4262
4214
|
|
|
4263
4215
|
if (!hasAlphaChannel) {
|
|
4264
4216
|
var params = this.document.ref({
|
|
4265
|
-
Predictor: 15,
|
|
4217
|
+
Predictor: isInterlaced ? 1 : 15,
|
|
4266
4218
|
Colors: this.image.colors,
|
|
4267
4219
|
BitsPerComponent: this.image.bits,
|
|
4268
4220
|
Columns: this.width
|
|
@@ -4291,7 +4243,9 @@ class PNGImage {
|
|
|
4291
4243
|
} else if (this.image.transparency.rgb) {
|
|
4292
4244
|
// Use Color Key Masking (spec section 4.8.5)
|
|
4293
4245
|
// An array with N elements, where N is two times the number of color components.
|
|
4294
|
-
var
|
|
4246
|
+
var {
|
|
4247
|
+
rgb
|
|
4248
|
+
} = this.image.transparency;
|
|
4295
4249
|
var mask = [];
|
|
4296
4250
|
|
|
4297
4251
|
for (var x of rgb) {
|
|
@@ -4302,14 +4256,20 @@ class PNGImage {
|
|
|
4302
4256
|
} else if (this.image.transparency.indexed) {
|
|
4303
4257
|
// Create a transparency SMask for the image based on the data
|
|
4304
4258
|
// in the PLTE and tRNS sections. See below for details on SMasks.
|
|
4259
|
+
dataDecoded = true;
|
|
4305
4260
|
return this.loadIndexedAlphaChannel();
|
|
4306
4261
|
} else if (hasAlphaChannel) {
|
|
4307
4262
|
// For PNG color types 4 and 6, the transparency data is stored as a alpha
|
|
4308
4263
|
// channel mixed in with the main image data. Separate this data out into an
|
|
4309
4264
|
// SMask object and store it separately in the PDF.
|
|
4265
|
+
dataDecoded = true;
|
|
4310
4266
|
return this.splitAlphaChannel();
|
|
4311
4267
|
}
|
|
4312
4268
|
|
|
4269
|
+
if (isInterlaced && !dataDecoded) {
|
|
4270
|
+
return this.decodeData();
|
|
4271
|
+
}
|
|
4272
|
+
|
|
4313
4273
|
this.finalize();
|
|
4314
4274
|
}
|
|
4315
4275
|
|
|
@@ -4379,11 +4339,18 @@ class PNGImage {
|
|
|
4379
4339
|
});
|
|
4380
4340
|
}
|
|
4381
4341
|
|
|
4342
|
+
decodeData() {
|
|
4343
|
+
this.image.decodePixels(pixels => {
|
|
4344
|
+
this.imgData = zlib.deflateSync(pixels);
|
|
4345
|
+
this.finalize();
|
|
4346
|
+
});
|
|
4347
|
+
}
|
|
4348
|
+
|
|
4382
4349
|
}
|
|
4383
4350
|
|
|
4384
|
-
/*
|
|
4385
|
-
PDFImage - embeds images in PDF documents
|
|
4386
|
-
By Devon Govett
|
|
4351
|
+
/*
|
|
4352
|
+
PDFImage - embeds images in PDF documents
|
|
4353
|
+
By Devon Govett
|
|
4387
4354
|
*/
|
|
4388
4355
|
|
|
4389
4356
|
class PDFImage {
|
|
@@ -4472,10 +4439,7 @@ var ImagesMixin = {
|
|
|
4472
4439
|
w = image.width * options.scale;
|
|
4473
4440
|
h = image.height * options.scale;
|
|
4474
4441
|
} else if (options.fit) {
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
bw = _options$fit[0];
|
|
4478
|
-
bh = _options$fit[1];
|
|
4442
|
+
[bw, bh] = options.fit;
|
|
4479
4443
|
bp = bw / bh;
|
|
4480
4444
|
ip = image.width / image.height;
|
|
4481
4445
|
|
|
@@ -4487,10 +4451,7 @@ var ImagesMixin = {
|
|
|
4487
4451
|
w = bh * ip;
|
|
4488
4452
|
}
|
|
4489
4453
|
} else if (options.cover) {
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
bw = _options$cover[0];
|
|
4493
|
-
bh = _options$cover[1];
|
|
4454
|
+
[bw, bh] = options.cover;
|
|
4494
4455
|
bp = bw / bh;
|
|
4495
4456
|
ip = image.width / image.height;
|
|
4496
4457
|
|
|
@@ -4568,6 +4529,10 @@ var AnnotationsMixin = {
|
|
|
4568
4529
|
options.Rect = this._convertRect(x, y, w, h);
|
|
4569
4530
|
options.Border = [0, 0, 0];
|
|
4570
4531
|
|
|
4532
|
+
if (options.Subtype === 'Link' && typeof options.F === 'undefined') {
|
|
4533
|
+
options.F = 1 << 2; // Print Annotation Flag
|
|
4534
|
+
}
|
|
4535
|
+
|
|
4571
4536
|
if (options.Subtype !== 'Link') {
|
|
4572
4537
|
if (options.C == null) {
|
|
4573
4538
|
options.C = this._normalizeColor(options.color || [0, 0, 0]);
|
|
@@ -4649,12 +4614,7 @@ var AnnotationsMixin = {
|
|
|
4649
4614
|
_markup(x, y, w, h) {
|
|
4650
4615
|
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
4651
4616
|
|
|
4652
|
-
var
|
|
4653
|
-
_this$_convertRect2 = _slicedToArray(_this$_convertRect, 4),
|
|
4654
|
-
x1 = _this$_convertRect2[0],
|
|
4655
|
-
y1 = _this$_convertRect2[1],
|
|
4656
|
-
x2 = _this$_convertRect2[2],
|
|
4657
|
-
y2 = _this$_convertRect2[3];
|
|
4617
|
+
var [x1, y1, x2, y2] = this._convertRect(x, y, w, h);
|
|
4658
4618
|
|
|
4659
4619
|
options.QuadPoints = [x1, y2, x2, y2, x1, y1, x2, y1];
|
|
4660
4620
|
options.Contents = new String();
|
|
@@ -4721,14 +4681,7 @@ var AnnotationsMixin = {
|
|
|
4721
4681
|
|
|
4722
4682
|
var x2 = x1 + w; // apply current transformation matrix to points
|
|
4723
4683
|
|
|
4724
|
-
var
|
|
4725
|
-
m0 = _this$_ctm[0],
|
|
4726
|
-
m1 = _this$_ctm[1],
|
|
4727
|
-
m2 = _this$_ctm[2],
|
|
4728
|
-
m3 = _this$_ctm[3],
|
|
4729
|
-
m4 = _this$_ctm[4],
|
|
4730
|
-
m5 = _this$_ctm[5];
|
|
4731
|
-
|
|
4684
|
+
var [m0, m1, m2, m3, m4, m5] = this._ctm;
|
|
4732
4685
|
x1 = m0 * x1 + m2 * y1 + m4;
|
|
4733
4686
|
y1 = m1 * x1 + m3 * y1 + m5;
|
|
4734
4687
|
x2 = m0 * x2 + m2 * y2 + m4;
|
|
@@ -4819,9 +4772,443 @@ var OutlineMixin = {
|
|
|
4819
4772
|
|
|
4820
4773
|
};
|
|
4821
4774
|
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4775
|
+
var FIELD_FLAGS = {
|
|
4776
|
+
readOnly: 1,
|
|
4777
|
+
required: 2,
|
|
4778
|
+
noExport: 4,
|
|
4779
|
+
multiline: 0x1000,
|
|
4780
|
+
password: 0x2000,
|
|
4781
|
+
toggleToOffButton: 0x4000,
|
|
4782
|
+
radioButton: 0x8000,
|
|
4783
|
+
pushButton: 0x10000,
|
|
4784
|
+
combo: 0x20000,
|
|
4785
|
+
edit: 0x40000,
|
|
4786
|
+
sort: 0x80000,
|
|
4787
|
+
multiSelect: 0x200000,
|
|
4788
|
+
noSpell: 0x400000
|
|
4789
|
+
};
|
|
4790
|
+
var FIELD_JUSTIFY = {
|
|
4791
|
+
left: 0,
|
|
4792
|
+
center: 1,
|
|
4793
|
+
right: 2
|
|
4794
|
+
};
|
|
4795
|
+
var VALUE_MAP = {
|
|
4796
|
+
value: 'V',
|
|
4797
|
+
defaultValue: 'DV'
|
|
4798
|
+
};
|
|
4799
|
+
var FORMAT_SPECIAL = {
|
|
4800
|
+
zip: '0',
|
|
4801
|
+
zipPlus4: '1',
|
|
4802
|
+
zip4: '1',
|
|
4803
|
+
phone: '2',
|
|
4804
|
+
ssn: '3'
|
|
4805
|
+
};
|
|
4806
|
+
var FORMAT_DEFAULT = {
|
|
4807
|
+
number: {
|
|
4808
|
+
nDec: 0,
|
|
4809
|
+
sepComma: false,
|
|
4810
|
+
negStyle: 'MinusBlack',
|
|
4811
|
+
currency: '',
|
|
4812
|
+
currencyPrepend: true
|
|
4813
|
+
},
|
|
4814
|
+
percent: {
|
|
4815
|
+
nDec: 0,
|
|
4816
|
+
sepComma: false
|
|
4817
|
+
}
|
|
4818
|
+
};
|
|
4819
|
+
var AcroFormMixin = {
|
|
4820
|
+
/**
|
|
4821
|
+
* Must call if adding AcroForms to a document. Must also call font() before
|
|
4822
|
+
* this method to set the default font.
|
|
4823
|
+
*/
|
|
4824
|
+
initForm() {
|
|
4825
|
+
if (!this._font) {
|
|
4826
|
+
throw new Error('Must set a font before calling initForm method');
|
|
4827
|
+
}
|
|
4828
|
+
|
|
4829
|
+
this._acroform = {
|
|
4830
|
+
fonts: {},
|
|
4831
|
+
defaultFont: this._font.name
|
|
4832
|
+
};
|
|
4833
|
+
this._acroform.fonts[this._font.id] = this._font.ref();
|
|
4834
|
+
var data = {
|
|
4835
|
+
Fields: [],
|
|
4836
|
+
NeedAppearances: true,
|
|
4837
|
+
DA: new String("/".concat(this._font.id, " 0 Tf 0 g")),
|
|
4838
|
+
DR: {
|
|
4839
|
+
Font: {}
|
|
4840
|
+
}
|
|
4841
|
+
};
|
|
4842
|
+
data.DR.Font[this._font.id] = this._font.ref();
|
|
4843
|
+
var AcroForm = this.ref(data);
|
|
4844
|
+
this._root.data.AcroForm = AcroForm;
|
|
4845
|
+
return this;
|
|
4846
|
+
},
|
|
4847
|
+
|
|
4848
|
+
/**
|
|
4849
|
+
* Called automatically by document.js
|
|
4850
|
+
*/
|
|
4851
|
+
endAcroForm() {
|
|
4852
|
+
if (this._root.data.AcroForm) {
|
|
4853
|
+
if (!Object.keys(this._acroform.fonts).length && !this._acroform.defaultFont) {
|
|
4854
|
+
throw new Error('No fonts specified for PDF form');
|
|
4855
|
+
}
|
|
4856
|
+
|
|
4857
|
+
var fontDict = this._root.data.AcroForm.data.DR.Font;
|
|
4858
|
+
Object.keys(this._acroform.fonts).forEach(name => {
|
|
4859
|
+
fontDict[name] = this._acroform.fonts[name];
|
|
4860
|
+
});
|
|
4861
|
+
|
|
4862
|
+
this._root.data.AcroForm.data.Fields.forEach(fieldRef => {
|
|
4863
|
+
this._endChild(fieldRef);
|
|
4864
|
+
});
|
|
4865
|
+
|
|
4866
|
+
this._root.data.AcroForm.end();
|
|
4867
|
+
}
|
|
4868
|
+
|
|
4869
|
+
return this;
|
|
4870
|
+
},
|
|
4871
|
+
|
|
4872
|
+
_endChild(ref) {
|
|
4873
|
+
if (Array.isArray(ref.data.Kids)) {
|
|
4874
|
+
ref.data.Kids.forEach(childRef => {
|
|
4875
|
+
this._endChild(childRef);
|
|
4876
|
+
});
|
|
4877
|
+
ref.end();
|
|
4878
|
+
}
|
|
4879
|
+
|
|
4880
|
+
return this;
|
|
4881
|
+
},
|
|
4882
|
+
|
|
4883
|
+
/**
|
|
4884
|
+
* Creates and adds a form field to the document. Form fields are intermediate
|
|
4885
|
+
* nodes in a PDF form that are used to specify form name heirarchy and form
|
|
4886
|
+
* value defaults.
|
|
4887
|
+
* @param {string} name - field name (T attribute in field dictionary)
|
|
4888
|
+
* @param {object} options - other attributes to include in field dictionary
|
|
4889
|
+
*/
|
|
4890
|
+
formField(name) {
|
|
4891
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
4892
|
+
|
|
4893
|
+
var fieldDict = this._fieldDict(name, null, options);
|
|
4894
|
+
|
|
4895
|
+
var fieldRef = this.ref(fieldDict);
|
|
4896
|
+
|
|
4897
|
+
this._addToParent(fieldRef);
|
|
4898
|
+
|
|
4899
|
+
return fieldRef;
|
|
4900
|
+
},
|
|
4901
|
+
|
|
4902
|
+
/**
|
|
4903
|
+
* Creates and adds a Form Annotation to the document. Form annotations are
|
|
4904
|
+
* called Widget annotations internally within a PDF file.
|
|
4905
|
+
* @param {string} name - form field name (T attribute of widget annotation
|
|
4906
|
+
* dictionary)
|
|
4907
|
+
* @param {number} x
|
|
4908
|
+
* @param {number} y
|
|
4909
|
+
* @param {number} w
|
|
4910
|
+
* @param {number} h
|
|
4911
|
+
* @param {object} options
|
|
4912
|
+
*/
|
|
4913
|
+
formAnnotation(name, type, x, y, w, h) {
|
|
4914
|
+
var options = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
|
|
4915
|
+
|
|
4916
|
+
var fieldDict = this._fieldDict(name, type, options);
|
|
4917
|
+
|
|
4918
|
+
fieldDict.Subtype = 'Widget';
|
|
4919
|
+
|
|
4920
|
+
if (fieldDict.F === undefined) {
|
|
4921
|
+
fieldDict.F = 4; // print the annotation
|
|
4922
|
+
} // Add Field annot to page, and get it's ref
|
|
4923
|
+
|
|
4924
|
+
|
|
4925
|
+
this.annotate(x, y, w, h, fieldDict);
|
|
4926
|
+
var annotRef = this.page.annotations[this.page.annotations.length - 1];
|
|
4927
|
+
return this._addToParent(annotRef);
|
|
4928
|
+
},
|
|
4929
|
+
|
|
4930
|
+
formText(name, x, y, w, h) {
|
|
4931
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
4932
|
+
return this.formAnnotation(name, 'text', x, y, w, h, options);
|
|
4933
|
+
},
|
|
4934
|
+
|
|
4935
|
+
formPushButton(name, x, y, w, h) {
|
|
4936
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
4937
|
+
return this.formAnnotation(name, 'pushButton', x, y, w, h, options);
|
|
4938
|
+
},
|
|
4939
|
+
|
|
4940
|
+
formCombo(name, x, y, w, h) {
|
|
4941
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
4942
|
+
return this.formAnnotation(name, 'combo', x, y, w, h, options);
|
|
4943
|
+
},
|
|
4944
|
+
|
|
4945
|
+
formList(name, x, y, w, h) {
|
|
4946
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
4947
|
+
return this.formAnnotation(name, 'list', x, y, w, h, options);
|
|
4948
|
+
},
|
|
4949
|
+
|
|
4950
|
+
formRadioButton(name, x, y, w, h) {
|
|
4951
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
4952
|
+
return this.formAnnotation(name, 'radioButton', x, y, w, h, options);
|
|
4953
|
+
},
|
|
4954
|
+
|
|
4955
|
+
formCheckbox(name, x, y, w, h) {
|
|
4956
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
4957
|
+
return this.formAnnotation(name, 'checkbox', x, y, w, h, options);
|
|
4958
|
+
},
|
|
4959
|
+
|
|
4960
|
+
_addToParent(fieldRef) {
|
|
4961
|
+
var parent = fieldRef.data.Parent;
|
|
4962
|
+
|
|
4963
|
+
if (parent) {
|
|
4964
|
+
if (!parent.data.Kids) {
|
|
4965
|
+
parent.data.Kids = [];
|
|
4966
|
+
}
|
|
4967
|
+
|
|
4968
|
+
parent.data.Kids.push(fieldRef);
|
|
4969
|
+
} else {
|
|
4970
|
+
this._root.data.AcroForm.data.Fields.push(fieldRef);
|
|
4971
|
+
}
|
|
4972
|
+
|
|
4973
|
+
return this;
|
|
4974
|
+
},
|
|
4975
|
+
|
|
4976
|
+
_fieldDict(name, type) {
|
|
4977
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
4978
|
+
|
|
4979
|
+
if (!this._acroform) {
|
|
4980
|
+
throw new Error('Call document.initForms() method before adding form elements to document');
|
|
4981
|
+
}
|
|
4982
|
+
|
|
4983
|
+
var opts = Object.assign({}, options);
|
|
4984
|
+
|
|
4985
|
+
if (type !== null) {
|
|
4986
|
+
opts = this._resolveType(type, options);
|
|
4987
|
+
}
|
|
4988
|
+
|
|
4989
|
+
opts = this._resolveFlags(opts);
|
|
4990
|
+
opts = this._resolveJustify(opts);
|
|
4991
|
+
opts = this._resolveFont(opts);
|
|
4992
|
+
opts = this._resolveStrings(opts);
|
|
4993
|
+
opts = this._resolveColors(opts);
|
|
4994
|
+
opts = this._resolveFormat(opts);
|
|
4995
|
+
opts.T = new String(name);
|
|
4996
|
+
|
|
4997
|
+
if (opts.parent) {
|
|
4998
|
+
opts.Parent = opts.parent;
|
|
4999
|
+
delete opts.parent;
|
|
5000
|
+
}
|
|
5001
|
+
|
|
5002
|
+
return opts;
|
|
5003
|
+
},
|
|
5004
|
+
|
|
5005
|
+
_resolveType(type, opts) {
|
|
5006
|
+
if (type === 'text') {
|
|
5007
|
+
opts.FT = 'Tx';
|
|
5008
|
+
} else if (type === 'pushButton') {
|
|
5009
|
+
opts.FT = 'Btn';
|
|
5010
|
+
opts.pushButton = true;
|
|
5011
|
+
} else if (type === 'radioButton') {
|
|
5012
|
+
opts.FT = 'Btn';
|
|
5013
|
+
opts.radioButton = true;
|
|
5014
|
+
} else if (type === 'checkbox') {
|
|
5015
|
+
opts.FT = 'Btn';
|
|
5016
|
+
} else if (type === 'combo') {
|
|
5017
|
+
opts.FT = 'Ch';
|
|
5018
|
+
opts.combo = true;
|
|
5019
|
+
} else if (type === 'list') {
|
|
5020
|
+
opts.FT = 'Ch';
|
|
5021
|
+
} else {
|
|
5022
|
+
throw new Error("Invalid form annotation type '".concat(type, "'"));
|
|
5023
|
+
}
|
|
5024
|
+
|
|
5025
|
+
return opts;
|
|
5026
|
+
},
|
|
5027
|
+
|
|
5028
|
+
_resolveFormat(opts) {
|
|
5029
|
+
var f = opts.format;
|
|
5030
|
+
|
|
5031
|
+
if (f && f.type) {
|
|
5032
|
+
var fnKeystroke;
|
|
5033
|
+
var fnFormat;
|
|
5034
|
+
var params = '';
|
|
5035
|
+
|
|
5036
|
+
if (FORMAT_SPECIAL[f.type] !== undefined) {
|
|
5037
|
+
fnKeystroke = "AFSpecial_Keystroke";
|
|
5038
|
+
fnFormat = "AFSpecial_Format";
|
|
5039
|
+
params = FORMAT_SPECIAL[f.type];
|
|
5040
|
+
} else {
|
|
5041
|
+
var format = f.type.charAt(0).toUpperCase() + f.type.slice(1);
|
|
5042
|
+
fnKeystroke = "AF".concat(format, "_Keystroke");
|
|
5043
|
+
fnFormat = "AF".concat(format, "_Format");
|
|
5044
|
+
|
|
5045
|
+
if (f.type === 'date') {
|
|
5046
|
+
fnKeystroke += 'Ex';
|
|
5047
|
+
params = String(f.param);
|
|
5048
|
+
} else if (f.type === 'time') {
|
|
5049
|
+
params = String(f.param);
|
|
5050
|
+
} else if (f.type === 'number') {
|
|
5051
|
+
var p = Object.assign({}, FORMAT_DEFAULT.number, f);
|
|
5052
|
+
params = String([String(p.nDec), p.sepComma ? '0' : '1', '"' + p.negStyle + '"', 'null', '"' + p.currency + '"', String(p.currencyPrepend)].join(','));
|
|
5053
|
+
} else if (f.type === 'percent') {
|
|
5054
|
+
var _p = Object.assign({}, FORMAT_DEFAULT.percent, f);
|
|
5055
|
+
|
|
5056
|
+
params = String([String(_p.nDec), _p.sepComma ? '0' : '1'].join(','));
|
|
5057
|
+
}
|
|
5058
|
+
}
|
|
5059
|
+
|
|
5060
|
+
opts.AA = opts.AA ? opts.AA : {};
|
|
5061
|
+
opts.AA.K = {
|
|
5062
|
+
S: 'JavaScript',
|
|
5063
|
+
JS: new String("".concat(fnKeystroke, "(").concat(params, ");"))
|
|
5064
|
+
};
|
|
5065
|
+
opts.AA.F = {
|
|
5066
|
+
S: 'JavaScript',
|
|
5067
|
+
JS: new String("".concat(fnFormat, "(").concat(params, ");"))
|
|
5068
|
+
};
|
|
5069
|
+
}
|
|
5070
|
+
|
|
5071
|
+
delete opts.format;
|
|
5072
|
+
return opts;
|
|
5073
|
+
},
|
|
5074
|
+
|
|
5075
|
+
_resolveColors(opts) {
|
|
5076
|
+
var color = this._normalizeColor(opts.backgroundColor);
|
|
5077
|
+
|
|
5078
|
+
if (color) {
|
|
5079
|
+
if (!opts.MK) {
|
|
5080
|
+
opts.MK = {};
|
|
5081
|
+
}
|
|
5082
|
+
|
|
5083
|
+
opts.MK.BG = color;
|
|
5084
|
+
}
|
|
5085
|
+
|
|
5086
|
+
color = this._normalizeColor(opts.borderColor);
|
|
5087
|
+
|
|
5088
|
+
if (color) {
|
|
5089
|
+
if (!opts.MK) {
|
|
5090
|
+
opts.MK = {};
|
|
5091
|
+
}
|
|
5092
|
+
|
|
5093
|
+
opts.MK.BC = color;
|
|
5094
|
+
}
|
|
5095
|
+
|
|
5096
|
+
delete opts.backgroundColor;
|
|
5097
|
+
delete opts.borderColor;
|
|
5098
|
+
return opts;
|
|
5099
|
+
},
|
|
5100
|
+
|
|
5101
|
+
_resolveFlags(options) {
|
|
5102
|
+
var result = 0;
|
|
5103
|
+
Object.keys(options).forEach(key => {
|
|
5104
|
+
if (FIELD_FLAGS[key]) {
|
|
5105
|
+
result |= FIELD_FLAGS[key];
|
|
5106
|
+
delete options[key];
|
|
5107
|
+
}
|
|
5108
|
+
});
|
|
5109
|
+
|
|
5110
|
+
if (result !== 0) {
|
|
5111
|
+
options.Ff = options.Ff ? options.Ff : 0;
|
|
5112
|
+
options.Ff |= result;
|
|
5113
|
+
}
|
|
5114
|
+
|
|
5115
|
+
return options;
|
|
5116
|
+
},
|
|
5117
|
+
|
|
5118
|
+
_resolveJustify(options) {
|
|
5119
|
+
var result = 0;
|
|
5120
|
+
|
|
5121
|
+
if (options.align !== undefined) {
|
|
5122
|
+
if (typeof FIELD_JUSTIFY[options.align] === 'number') {
|
|
5123
|
+
result = FIELD_JUSTIFY[options.align];
|
|
5124
|
+
}
|
|
5125
|
+
|
|
5126
|
+
delete options.align;
|
|
5127
|
+
}
|
|
5128
|
+
|
|
5129
|
+
if (result !== 0) {
|
|
5130
|
+
options.Q = result; // default
|
|
5131
|
+
}
|
|
5132
|
+
|
|
5133
|
+
return options;
|
|
5134
|
+
},
|
|
5135
|
+
|
|
5136
|
+
_resolveFont(options) {
|
|
5137
|
+
// add current font to document-level AcroForm dict if necessary
|
|
5138
|
+
if (this._acroform.fonts[this._font.id] === null) {
|
|
5139
|
+
this._acroform.fonts[this._font.id] = this._font.ref();
|
|
5140
|
+
} // add current font to field's resource dict (RD) if not the default acroform font
|
|
5141
|
+
|
|
5142
|
+
|
|
5143
|
+
if (this._acroform.defaultFont !== this._font.name) {
|
|
5144
|
+
options.DR = {
|
|
5145
|
+
Font: {}
|
|
5146
|
+
};
|
|
5147
|
+
options.DR.Font[this._font.id] = this._font.ref();
|
|
5148
|
+
options.DA = new String("/".concat(this._font.id, " 0 Tf 0 g"));
|
|
5149
|
+
}
|
|
5150
|
+
|
|
5151
|
+
return options;
|
|
5152
|
+
},
|
|
5153
|
+
|
|
5154
|
+
_resolveStrings(options) {
|
|
5155
|
+
var select = [];
|
|
5156
|
+
|
|
5157
|
+
function appendChoices(a) {
|
|
5158
|
+
if (Array.isArray(a)) {
|
|
5159
|
+
for (var idx = 0; idx < a.length; idx++) {
|
|
5160
|
+
if (typeof a[idx] === 'string') {
|
|
5161
|
+
select.push(new String(a[idx]));
|
|
5162
|
+
} else {
|
|
5163
|
+
select.push(a[idx]);
|
|
5164
|
+
}
|
|
5165
|
+
}
|
|
5166
|
+
}
|
|
5167
|
+
}
|
|
5168
|
+
|
|
5169
|
+
appendChoices(options.Opt);
|
|
5170
|
+
|
|
5171
|
+
if (options.select) {
|
|
5172
|
+
appendChoices(options.select);
|
|
5173
|
+
delete options.select;
|
|
5174
|
+
}
|
|
5175
|
+
|
|
5176
|
+
if (select.length) {
|
|
5177
|
+
options.Opt = select;
|
|
5178
|
+
}
|
|
5179
|
+
|
|
5180
|
+
if (options.value || options.defaultValue) ;
|
|
5181
|
+
|
|
5182
|
+
Object.keys(VALUE_MAP).forEach(key => {
|
|
5183
|
+
if (options[key] !== undefined) {
|
|
5184
|
+
options[VALUE_MAP[key]] = options[key];
|
|
5185
|
+
delete options[key];
|
|
5186
|
+
}
|
|
5187
|
+
});
|
|
5188
|
+
['V', 'DV'].forEach(key => {
|
|
5189
|
+
if (typeof options[key] === 'string') {
|
|
5190
|
+
options[key] = new String(options[key]);
|
|
5191
|
+
}
|
|
5192
|
+
});
|
|
5193
|
+
|
|
5194
|
+
if (options.MK && options.MK.CA) {
|
|
5195
|
+
options.MK.CA = new String(options.MK.CA);
|
|
5196
|
+
}
|
|
5197
|
+
|
|
5198
|
+
if (options.label) {
|
|
5199
|
+
options.MK = options.MK ? options.MK : {};
|
|
5200
|
+
options.MK.CA = new String(options.label);
|
|
5201
|
+
delete options.label;
|
|
5202
|
+
}
|
|
5203
|
+
|
|
5204
|
+
return options;
|
|
5205
|
+
}
|
|
5206
|
+
|
|
5207
|
+
};
|
|
5208
|
+
|
|
5209
|
+
/*
|
|
5210
|
+
PDFDocument - represents an entire PDF document
|
|
5211
|
+
By Devon Govett
|
|
4825
5212
|
*/
|
|
4826
5213
|
|
|
4827
5214
|
class PDFDocument extends stream.Readable {
|
|
@@ -4918,7 +5305,9 @@ class PDFDocument extends stream.Readable {
|
|
|
4918
5305
|
addPage(options) {
|
|
4919
5306
|
// end the current page if needed
|
|
4920
5307
|
if (options == null) {
|
|
4921
|
-
|
|
5308
|
+
({
|
|
5309
|
+
options
|
|
5310
|
+
} = this);
|
|
4922
5311
|
}
|
|
4923
5312
|
|
|
4924
5313
|
if (!this.options.bufferPages) {
|
|
@@ -4992,6 +5381,19 @@ class PDFDocument extends stream.Readable {
|
|
|
4992
5381
|
this._root.data.Names.data.Dests.add(name, args);
|
|
4993
5382
|
}
|
|
4994
5383
|
|
|
5384
|
+
addNamedJavaScript(name, js) {
|
|
5385
|
+
if (!this._root.data.Names.data.JavaScript) {
|
|
5386
|
+
this._root.data.Names.data.JavaScript = new PDFNameTree();
|
|
5387
|
+
}
|
|
5388
|
+
|
|
5389
|
+
var data = {
|
|
5390
|
+
JS: new String(js),
|
|
5391
|
+
S: 'JavaScript'
|
|
5392
|
+
};
|
|
5393
|
+
|
|
5394
|
+
this._root.data.Names.data.JavaScript.add(name, data);
|
|
5395
|
+
}
|
|
5396
|
+
|
|
4995
5397
|
ref(data) {
|
|
4996
5398
|
var ref = new PDFReference(this, this._offsets.length + 1, data);
|
|
4997
5399
|
|
|
@@ -5069,6 +5471,8 @@ class PDFDocument extends stream.Readable {
|
|
|
5069
5471
|
|
|
5070
5472
|
this._root.data.Names.end();
|
|
5071
5473
|
|
|
5474
|
+
this.endAcroForm();
|
|
5475
|
+
|
|
5072
5476
|
if (this._security) {
|
|
5073
5477
|
this._security.end();
|
|
5074
5478
|
}
|
|
@@ -5139,6 +5543,7 @@ mixin(TextMixin);
|
|
|
5139
5543
|
mixin(ImagesMixin);
|
|
5140
5544
|
mixin(AnnotationsMixin);
|
|
5141
5545
|
mixin(OutlineMixin);
|
|
5546
|
+
mixin(AcroFormMixin);
|
|
5142
5547
|
|
|
5143
5548
|
export default PDFDocument;
|
|
5144
5549
|
//# sourceMappingURL=pdfkit.esnext.js.map
|