pdfkit 0.11.0 → 0.12.3
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 +61 -39
- package/LICENSE +7 -7
- package/README.md +182 -181
- 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/font/data/Courier-Bold.afm +342 -0
- package/js/font/data/Courier-BoldOblique.afm +342 -0
- package/js/font/data/Courier-Oblique.afm +342 -0
- package/js/font/data/Courier.afm +342 -0
- package/js/font/data/Helvetica-Bold.afm +2827 -0
- package/js/font/data/Helvetica-BoldOblique.afm +2827 -0
- package/js/font/data/Helvetica-Oblique.afm +3051 -0
- package/js/font/data/Helvetica.afm +3051 -0
- package/js/font/data/Symbol.afm +213 -0
- package/js/font/data/Times-Bold.afm +2588 -0
- package/js/font/data/Times-BoldItalic.afm +2384 -0
- package/js/font/data/Times-Italic.afm +2667 -0
- package/js/font/data/Times-Roman.afm +2419 -0
- package/js/font/data/ZapfDingbats.afm +225 -0
- package/js/pdfkit.es5.js +1277 -490
- package/js/pdfkit.es5.js.map +1 -1
- package/js/pdfkit.esnext.js +951 -190
- package/js/pdfkit.esnext.js.map +1 -1
- package/js/pdfkit.js +933 -189
- package/js/pdfkit.js.map +1 -1
- package/js/pdfkit.standalone.js +2894 -2011
- package/js/pdfkit.standalone.orig.js +68494 -0
- package/js/virtual-fs.js +3 -5
- package/package.json +93 -84
package/js/pdfkit.js
CHANGED
|
@@ -9,8 +9,8 @@ var events = require('events');
|
|
|
9
9
|
var LineBreaker = require('linebreak');
|
|
10
10
|
var PNG = require('png-js');
|
|
11
11
|
|
|
12
|
-
/*
|
|
13
|
-
PDFAbstractReference - abstract class for PDF reference
|
|
12
|
+
/*
|
|
13
|
+
PDFAbstractReference - abstract class for PDF reference
|
|
14
14
|
*/
|
|
15
15
|
class PDFAbstractReference {
|
|
16
16
|
toString() {
|
|
@@ -19,13 +19,15 @@ class PDFAbstractReference {
|
|
|
19
19
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/*
|
|
23
|
-
|
|
22
|
+
/*
|
|
23
|
+
PDFTree - abstract base class for name and number tree objects
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
class
|
|
27
|
-
constructor() {
|
|
28
|
-
this._items = {};
|
|
26
|
+
class PDFTree {
|
|
27
|
+
constructor(options = {}) {
|
|
28
|
+
this._items = {}; // disable /Limits output for this tree
|
|
29
|
+
|
|
30
|
+
this.limits = typeof options.limits === 'boolean' ? options.limits : true;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
add(key, val) {
|
|
@@ -38,19 +40,19 @@ class PDFNameTree {
|
|
|
38
40
|
|
|
39
41
|
toString() {
|
|
40
42
|
// Needs to be sorted by key
|
|
41
|
-
const sortedKeys = Object.keys(this._items).sort((a, b) =>
|
|
43
|
+
const sortedKeys = Object.keys(this._items).sort((a, b) => this._compareKeys(a, b));
|
|
42
44
|
const out = ['<<'];
|
|
43
45
|
|
|
44
|
-
if (sortedKeys.length > 1) {
|
|
46
|
+
if (this.limits && sortedKeys.length > 1) {
|
|
45
47
|
const first = sortedKeys[0],
|
|
46
48
|
last = sortedKeys[sortedKeys.length - 1];
|
|
47
|
-
out.push(` /Limits ${PDFObject.convert([
|
|
49
|
+
out.push(` /Limits ${PDFObject.convert([this._dataForKey(first), this._dataForKey(last)])}`);
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
out.push(
|
|
52
|
+
out.push(` /${this._keysName()} [`);
|
|
51
53
|
|
|
52
54
|
for (let key of sortedKeys) {
|
|
53
|
-
out.push(` ${PDFObject.convert(
|
|
55
|
+
out.push(` ${PDFObject.convert(this._dataForKey(key))} ${PDFObject.convert(this._items[key])}`);
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
out.push(']');
|
|
@@ -58,16 +60,32 @@ class PDFNameTree {
|
|
|
58
60
|
return out.join('\n');
|
|
59
61
|
}
|
|
60
62
|
|
|
63
|
+
_compareKeys()
|
|
64
|
+
/*a, b*/
|
|
65
|
+
{
|
|
66
|
+
throw new Error('Must be implemented by subclasses');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_keysName() {
|
|
70
|
+
throw new Error('Must be implemented by subclasses');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
_dataForKey()
|
|
74
|
+
/*k*/
|
|
75
|
+
{
|
|
76
|
+
throw new Error('Must be implemented by subclasses');
|
|
77
|
+
}
|
|
78
|
+
|
|
61
79
|
}
|
|
62
80
|
|
|
63
|
-
/*
|
|
64
|
-
PDFObject - converts JavaScript types into their corresponding PDF types.
|
|
65
|
-
By Devon Govett
|
|
81
|
+
/*
|
|
82
|
+
PDFObject - converts JavaScript types into their corresponding PDF types.
|
|
83
|
+
By Devon Govett
|
|
66
84
|
*/
|
|
67
85
|
|
|
68
86
|
const pad = (str, length) => (Array(length + 1).join('0') + str).slice(-length);
|
|
69
87
|
|
|
70
|
-
const escapableRe = /[\n\r\t\b\f
|
|
88
|
+
const escapableRe = /[\n\r\t\b\f()\\]/g;
|
|
71
89
|
const escapable = {
|
|
72
90
|
'\n': '\\n',
|
|
73
91
|
'\r': '\\r',
|
|
@@ -133,13 +151,13 @@ class PDFObject {
|
|
|
133
151
|
return `(${string})`; // Buffers are converted to PDF hex strings
|
|
134
152
|
} else if (Buffer.isBuffer(object)) {
|
|
135
153
|
return `<${object.toString('hex')}>`;
|
|
136
|
-
} else if (object instanceof PDFAbstractReference || object instanceof
|
|
154
|
+
} else if (object instanceof PDFAbstractReference || object instanceof PDFTree) {
|
|
137
155
|
return object.toString();
|
|
138
156
|
} else if (object instanceof Date) {
|
|
139
157
|
let string = `D:${pad(object.getUTCFullYear(), 4)}` + pad(object.getUTCMonth() + 1, 2) + pad(object.getUTCDate(), 2) + pad(object.getUTCHours(), 2) + pad(object.getUTCMinutes(), 2) + pad(object.getUTCSeconds(), 2) + 'Z'; // Encrypt the string when necessary
|
|
140
158
|
|
|
141
159
|
if (encryptFn) {
|
|
142
|
-
string = encryptFn(
|
|
160
|
+
string = encryptFn(Buffer.from(string, 'ascii')).toString('binary'); // Escape characters as required by the spec
|
|
143
161
|
|
|
144
162
|
string = string.replace(escapableRe, c => escapable[c]);
|
|
145
163
|
}
|
|
@@ -175,9 +193,9 @@ class PDFObject {
|
|
|
175
193
|
|
|
176
194
|
}
|
|
177
195
|
|
|
178
|
-
/*
|
|
179
|
-
PDFReference - represents a reference to another object in the PDF object heirarchy
|
|
180
|
-
By Devon Govett
|
|
196
|
+
/*
|
|
197
|
+
PDFReference - represents a reference to another object in the PDF object heirarchy
|
|
198
|
+
By Devon Govett
|
|
181
199
|
*/
|
|
182
200
|
|
|
183
201
|
class PDFReference extends PDFAbstractReference {
|
|
@@ -194,7 +212,7 @@ class PDFReference extends PDFAbstractReference {
|
|
|
194
212
|
|
|
195
213
|
write(chunk) {
|
|
196
214
|
if (!Buffer.isBuffer(chunk)) {
|
|
197
|
-
chunk =
|
|
215
|
+
chunk = Buffer.from(chunk + '\n', 'binary');
|
|
198
216
|
}
|
|
199
217
|
|
|
200
218
|
this.uncompressedLength += chunk.length;
|
|
@@ -262,9 +280,9 @@ class PDFReference extends PDFAbstractReference {
|
|
|
262
280
|
|
|
263
281
|
}
|
|
264
282
|
|
|
265
|
-
/*
|
|
266
|
-
PDFPage - represents a single page in the PDF document
|
|
267
|
-
By Devon Govett
|
|
283
|
+
/*
|
|
284
|
+
PDFPage - represents a single page in the PDF document
|
|
285
|
+
By Devon Govett
|
|
268
286
|
*/
|
|
269
287
|
const DEFAULT_MARGINS = {
|
|
270
288
|
top: 72,
|
|
@@ -359,7 +377,8 @@ class PDFPage {
|
|
|
359
377
|
Contents: this.content,
|
|
360
378
|
Resources: this.resources
|
|
361
379
|
});
|
|
362
|
-
|
|
380
|
+
this.markings = [];
|
|
381
|
+
} // Lazily create these objects
|
|
363
382
|
|
|
364
383
|
|
|
365
384
|
get fonts() {
|
|
@@ -387,6 +406,11 @@ class PDFPage {
|
|
|
387
406
|
return data.Annots != null ? data.Annots : data.Annots = [];
|
|
388
407
|
}
|
|
389
408
|
|
|
409
|
+
get structParentTreeKey() {
|
|
410
|
+
const data = this.dictionary.data;
|
|
411
|
+
return data.StructParents != null ? data.StructParents : data.StructParents = this.document.createStructParentTreeNextKey();
|
|
412
|
+
}
|
|
413
|
+
|
|
390
414
|
maxY() {
|
|
391
415
|
return this.height - this.margins.bottom;
|
|
392
416
|
}
|
|
@@ -403,11 +427,30 @@ class PDFPage {
|
|
|
403
427
|
|
|
404
428
|
}
|
|
405
429
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
430
|
+
/*
|
|
431
|
+
PDFNameTree - represents a name tree object
|
|
432
|
+
*/
|
|
433
|
+
|
|
434
|
+
class PDFNameTree extends PDFTree {
|
|
435
|
+
_compareKeys(a, b) {
|
|
436
|
+
return a.localeCompare(b);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
_keysName() {
|
|
440
|
+
return "Names";
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
_dataForKey(k) {
|
|
444
|
+
return new String(k);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Check if value is in a range group.
|
|
451
|
+
* @param {number} value
|
|
452
|
+
* @param {number[]} rangeGroup
|
|
453
|
+
* @returns {boolean}
|
|
411
454
|
*/
|
|
412
455
|
function inRange(value, rangeGroup) {
|
|
413
456
|
if (value < rangeGroup[0]) return false;
|
|
@@ -435,34 +478,28 @@ function inRange(value, rangeGroup) {
|
|
|
435
478
|
return false;
|
|
436
479
|
}
|
|
437
480
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
* A.1 Unassigned code points in Unicode 3.2
|
|
442
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-A.1
|
|
481
|
+
/**
|
|
482
|
+
* A.1 Unassigned code points in Unicode 3.2
|
|
483
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-A.1
|
|
443
484
|
*/
|
|
444
485
|
|
|
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];
|
|
446
|
-
/* eslint-enable */
|
|
486
|
+
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]; // prettier-ignore-end
|
|
447
487
|
|
|
448
|
-
const isUnassignedCodePoint = character => inRange(character, unassigned_code_points);
|
|
449
|
-
/* eslint-disable prettier/prettier */
|
|
488
|
+
const isUnassignedCodePoint = character => inRange(character, unassigned_code_points); // prettier-ignore-start
|
|
450
489
|
|
|
451
|
-
/**
|
|
452
|
-
* B.1 Commonly mapped to nothing
|
|
453
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-B.1
|
|
490
|
+
/**
|
|
491
|
+
* B.1 Commonly mapped to nothing
|
|
492
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-B.1
|
|
454
493
|
*/
|
|
455
494
|
|
|
456
495
|
|
|
457
|
-
const commonly_mapped_to_nothing = [0x00ad, 0x00ad, 0x034f, 0x034f, 0x1806, 0x1806, 0x180b, 0x180b, 0x180c, 0x180c, 0x180d, 0x180d, 0x200b, 0x200b, 0x200c, 0x200c, 0x200d, 0x200d, 0x2060, 0x2060, 0xfe00, 0xfe00, 0xfe01, 0xfe01, 0xfe02, 0xfe02, 0xfe03, 0xfe03, 0xfe04, 0xfe04, 0xfe05, 0xfe05, 0xfe06, 0xfe06, 0xfe07, 0xfe07, 0xfe08, 0xfe08, 0xfe09, 0xfe09, 0xfe0a, 0xfe0a, 0xfe0b, 0xfe0b, 0xfe0c, 0xfe0c, 0xfe0d, 0xfe0d, 0xfe0e, 0xfe0e, 0xfe0f, 0xfe0f, 0xfeff, 0xfeff];
|
|
458
|
-
/* eslint-enable */
|
|
496
|
+
const commonly_mapped_to_nothing = [0x00ad, 0x00ad, 0x034f, 0x034f, 0x1806, 0x1806, 0x180b, 0x180b, 0x180c, 0x180c, 0x180d, 0x180d, 0x200b, 0x200b, 0x200c, 0x200c, 0x200d, 0x200d, 0x2060, 0x2060, 0xfe00, 0xfe00, 0xfe01, 0xfe01, 0xfe02, 0xfe02, 0xfe03, 0xfe03, 0xfe04, 0xfe04, 0xfe05, 0xfe05, 0xfe06, 0xfe06, 0xfe07, 0xfe07, 0xfe08, 0xfe08, 0xfe09, 0xfe09, 0xfe0a, 0xfe0a, 0xfe0b, 0xfe0b, 0xfe0c, 0xfe0c, 0xfe0d, 0xfe0d, 0xfe0e, 0xfe0e, 0xfe0f, 0xfe0f, 0xfeff, 0xfeff]; // prettier-ignore-end
|
|
459
497
|
|
|
460
|
-
const isCommonlyMappedToNothing = character => inRange(character, commonly_mapped_to_nothing);
|
|
461
|
-
/* eslint-disable prettier/prettier */
|
|
498
|
+
const isCommonlyMappedToNothing = character => inRange(character, commonly_mapped_to_nothing); // prettier-ignore-start
|
|
462
499
|
|
|
463
|
-
/**
|
|
464
|
-
* C.1.2 Non-ASCII space characters
|
|
465
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.1.2
|
|
500
|
+
/**
|
|
501
|
+
* C.1.2 Non-ASCII space characters
|
|
502
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.1.2
|
|
466
503
|
*/
|
|
467
504
|
|
|
468
505
|
|
|
@@ -500,17 +537,15 @@ const non_ASCII_space_characters = [0x00a0, 0x00a0
|
|
|
500
537
|
/* MEDIUM MATHEMATICAL SPACE */
|
|
501
538
|
, 0x3000, 0x3000
|
|
502
539
|
/* IDEOGRAPHIC SPACE */
|
|
503
|
-
];
|
|
504
|
-
/* eslint-enable */
|
|
540
|
+
]; // prettier-ignore-end
|
|
505
541
|
|
|
506
|
-
const isNonASCIISpaceCharacter = character => inRange(character, non_ASCII_space_characters);
|
|
507
|
-
/* eslint-disable prettier/prettier */
|
|
542
|
+
const isNonASCIISpaceCharacter = character => inRange(character, non_ASCII_space_characters); // prettier-ignore-start
|
|
508
543
|
|
|
509
544
|
|
|
510
545
|
const non_ASCII_controls_characters = [
|
|
511
|
-
/**
|
|
512
|
-
* C.2.2 Non-ASCII control characters
|
|
513
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.2.2
|
|
546
|
+
/**
|
|
547
|
+
* C.2.2 Non-ASCII control characters
|
|
548
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.2.2
|
|
514
549
|
*/
|
|
515
550
|
0x0080, 0x009f
|
|
516
551
|
/* [CONTROL CHARACTERS] */
|
|
@@ -546,9 +581,9 @@ const non_ASCII_controls_characters = [
|
|
|
546
581
|
/* [MUSICAL CONTROL CHARACTERS] */
|
|
547
582
|
];
|
|
548
583
|
const non_character_codepoints = [
|
|
549
|
-
/**
|
|
550
|
-
* C.4 Non-character code points
|
|
551
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.4
|
|
584
|
+
/**
|
|
585
|
+
* C.4 Non-character code points
|
|
586
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.4
|
|
552
587
|
*/
|
|
553
588
|
0xfdd0, 0xfdef
|
|
554
589
|
/* [NONCHARACTER CODE POINTS] */
|
|
@@ -585,23 +620,23 @@ const non_character_codepoints = [
|
|
|
585
620
|
, 0x10fffe, 0x10ffff
|
|
586
621
|
/* [NONCHARACTER CODE POINTS] */
|
|
587
622
|
];
|
|
588
|
-
/**
|
|
589
|
-
* 2.3. Prohibited Output
|
|
623
|
+
/**
|
|
624
|
+
* 2.3. Prohibited Output
|
|
590
625
|
*/
|
|
591
626
|
|
|
592
627
|
const prohibited_characters = [
|
|
593
|
-
/**
|
|
594
|
-
* C.2.1 ASCII control characters
|
|
595
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.2.1
|
|
628
|
+
/**
|
|
629
|
+
* C.2.1 ASCII control characters
|
|
630
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.2.1
|
|
596
631
|
*/
|
|
597
632
|
0, 0x001f
|
|
598
633
|
/* [CONTROL CHARACTERS] */
|
|
599
634
|
, 0x007f, 0x007f
|
|
600
635
|
/* DELETE */
|
|
601
636
|
,
|
|
602
|
-
/**
|
|
603
|
-
* C.8 Change display properties or are deprecated
|
|
604
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.8
|
|
637
|
+
/**
|
|
638
|
+
* C.8 Change display properties or are deprecated
|
|
639
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.8
|
|
605
640
|
*/
|
|
606
641
|
0x0340, 0x0340
|
|
607
642
|
/* COMBINING GRAVE TONE MARK */
|
|
@@ -634,28 +669,28 @@ const prohibited_characters = [
|
|
|
634
669
|
, 0x206f, 0x206f
|
|
635
670
|
/* NOMINAL DIGIT SHAPES */
|
|
636
671
|
,
|
|
637
|
-
/**
|
|
638
|
-
* C.7 Inappropriate for canonical representation
|
|
639
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.7
|
|
672
|
+
/**
|
|
673
|
+
* C.7 Inappropriate for canonical representation
|
|
674
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.7
|
|
640
675
|
*/
|
|
641
676
|
0x2ff0, 0x2ffb
|
|
642
677
|
/* [IDEOGRAPHIC DESCRIPTION CHARACTERS] */
|
|
643
678
|
,
|
|
644
|
-
/**
|
|
645
|
-
* C.5 Surrogate codes
|
|
646
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.5
|
|
679
|
+
/**
|
|
680
|
+
* C.5 Surrogate codes
|
|
681
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.5
|
|
647
682
|
*/
|
|
648
683
|
0xd800, 0xdfff,
|
|
649
|
-
/**
|
|
650
|
-
* C.3 Private use
|
|
651
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.3
|
|
684
|
+
/**
|
|
685
|
+
* C.3 Private use
|
|
686
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.3
|
|
652
687
|
*/
|
|
653
688
|
0xe000, 0xf8ff
|
|
654
689
|
/* [PRIVATE USE, PLANE 0] */
|
|
655
690
|
,
|
|
656
|
-
/**
|
|
657
|
-
* C.6 Inappropriate for plain text
|
|
658
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.6
|
|
691
|
+
/**
|
|
692
|
+
* C.6 Inappropriate for plain text
|
|
693
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.6
|
|
659
694
|
*/
|
|
660
695
|
0xfff9, 0xfff9
|
|
661
696
|
/* INTERLINEAR ANNOTATION ANCHOR */
|
|
@@ -668,61 +703,56 @@ const prohibited_characters = [
|
|
|
668
703
|
, 0xfffd, 0xfffd
|
|
669
704
|
/* REPLACEMENT CHARACTER */
|
|
670
705
|
,
|
|
671
|
-
/**
|
|
672
|
-
* C.9 Tagging characters
|
|
673
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.9
|
|
706
|
+
/**
|
|
707
|
+
* C.9 Tagging characters
|
|
708
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.9
|
|
674
709
|
*/
|
|
675
710
|
0xe0001, 0xe0001
|
|
676
711
|
/* LANGUAGE TAG */
|
|
677
712
|
, 0xe0020, 0xe007f
|
|
678
713
|
/* [TAGGING CHARACTERS] */
|
|
679
714
|
,
|
|
680
|
-
/**
|
|
681
|
-
* C.3 Private use
|
|
682
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.3
|
|
715
|
+
/**
|
|
716
|
+
* C.3 Private use
|
|
717
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.3
|
|
683
718
|
*/
|
|
684
719
|
0xf0000, 0xffffd
|
|
685
720
|
/* [PRIVATE USE, PLANE 15] */
|
|
686
721
|
, 0x100000, 0x10fffd
|
|
687
722
|
/* [PRIVATE USE, PLANE 16] */
|
|
688
|
-
];
|
|
689
|
-
/* eslint-enable */
|
|
723
|
+
]; // prettier-ignore-end
|
|
690
724
|
|
|
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);
|
|
692
|
-
/* eslint-disable prettier/prettier */
|
|
725
|
+
const isProhibitedCharacter = character => inRange(character, non_ASCII_space_characters) || inRange(character, prohibited_characters) || inRange(character, non_ASCII_controls_characters) || inRange(character, non_character_codepoints); // prettier-ignore-start
|
|
693
726
|
|
|
694
|
-
/**
|
|
695
|
-
* D.1 Characters with bidirectional property "R" or "AL"
|
|
696
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-D.1
|
|
727
|
+
/**
|
|
728
|
+
* D.1 Characters with bidirectional property "R" or "AL"
|
|
729
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-D.1
|
|
697
730
|
*/
|
|
698
731
|
|
|
699
732
|
|
|
700
|
-
const bidirectional_r_al = [0x05be, 0x05be, 0x05c0, 0x05c0, 0x05c3, 0x05c3, 0x05d0, 0x05ea, 0x05f0, 0x05f4, 0x061b, 0x061b, 0x061f, 0x061f, 0x0621, 0x063a, 0x0640, 0x064a, 0x066d, 0x066f, 0x0671, 0x06d5, 0x06dd, 0x06dd, 0x06e5, 0x06e6, 0x06fa, 0x06fe, 0x0700, 0x070d, 0x0710, 0x0710, 0x0712, 0x072c, 0x0780, 0x07a5, 0x07b1, 0x07b1, 0x200f, 0x200f, 0xfb1d, 0xfb1d, 0xfb1f, 0xfb28, 0xfb2a, 0xfb36, 0xfb38, 0xfb3c, 0xfb3e, 0xfb3e, 0xfb40, 0xfb41, 0xfb43, 0xfb44, 0xfb46, 0xfbb1, 0xfbd3, 0xfd3d, 0xfd50, 0xfd8f, 0xfd92, 0xfdc7, 0xfdf0, 0xfdfc, 0xfe70, 0xfe74, 0xfe76, 0xfefc];
|
|
701
|
-
/* eslint-enable */
|
|
733
|
+
const bidirectional_r_al = [0x05be, 0x05be, 0x05c0, 0x05c0, 0x05c3, 0x05c3, 0x05d0, 0x05ea, 0x05f0, 0x05f4, 0x061b, 0x061b, 0x061f, 0x061f, 0x0621, 0x063a, 0x0640, 0x064a, 0x066d, 0x066f, 0x0671, 0x06d5, 0x06dd, 0x06dd, 0x06e5, 0x06e6, 0x06fa, 0x06fe, 0x0700, 0x070d, 0x0710, 0x0710, 0x0712, 0x072c, 0x0780, 0x07a5, 0x07b1, 0x07b1, 0x200f, 0x200f, 0xfb1d, 0xfb1d, 0xfb1f, 0xfb28, 0xfb2a, 0xfb36, 0xfb38, 0xfb3c, 0xfb3e, 0xfb3e, 0xfb40, 0xfb41, 0xfb43, 0xfb44, 0xfb46, 0xfbb1, 0xfbd3, 0xfd3d, 0xfd50, 0xfd8f, 0xfd92, 0xfdc7, 0xfdf0, 0xfdfc, 0xfe70, 0xfe74, 0xfe76, 0xfefc]; // prettier-ignore-end
|
|
702
734
|
|
|
703
|
-
const isBidirectionalRAL = character => inRange(character, bidirectional_r_al);
|
|
704
|
-
/* eslint-disable prettier/prettier */
|
|
735
|
+
const isBidirectionalRAL = character => inRange(character, bidirectional_r_al); // prettier-ignore-start
|
|
705
736
|
|
|
706
|
-
/**
|
|
707
|
-
* D.2 Characters with bidirectional property "L"
|
|
708
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-D.2
|
|
737
|
+
/**
|
|
738
|
+
* D.2 Characters with bidirectional property "L"
|
|
739
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-D.2
|
|
709
740
|
*/
|
|
710
741
|
|
|
711
742
|
|
|
712
|
-
const bidirectional_l = [0x0041, 0x005a, 0x0061, 0x007a, 0x00aa, 0x00aa, 0x00b5, 0x00b5, 0x00ba, 0x00ba, 0x00c0, 0x00d6, 0x00d8, 0x00f6, 0x00f8, 0x0220, 0x0222, 0x0233, 0x0250, 0x02ad, 0x02b0, 0x02b8, 0x02bb, 0x02c1, 0x02d0, 0x02d1, 0x02e0, 0x02e4, 0x02ee, 0x02ee, 0x037a, 0x037a, 0x0386, 0x0386, 0x0388, 0x038a, 0x038c, 0x038c, 0x038e, 0x03a1, 0x03a3, 0x03ce, 0x03d0, 0x03f5, 0x0400, 0x0482, 0x048a, 0x04ce, 0x04d0, 0x04f5, 0x04f8, 0x04f9, 0x0500, 0x050f, 0x0531, 0x0556, 0x0559, 0x055f, 0x0561, 0x0587, 0x0589, 0x0589, 0x0903, 0x0903, 0x0905, 0x0939, 0x093d, 0x0940, 0x0949, 0x094c, 0x0950, 0x0950, 0x0958, 0x0961, 0x0964, 0x0970, 0x0982, 0x0983, 0x0985, 0x098c, 0x098f, 0x0990, 0x0993, 0x09a8, 0x09aa, 0x09b0, 0x09b2, 0x09b2, 0x09b6, 0x09b9, 0x09be, 0x09c0, 0x09c7, 0x09c8, 0x09cb, 0x09cc, 0x09d7, 0x09d7, 0x09dc, 0x09dd, 0x09df, 0x09e1, 0x09e6, 0x09f1, 0x09f4, 0x09fa, 0x0a05, 0x0a0a, 0x0a0f, 0x0a10, 0x0a13, 0x0a28, 0x0a2a, 0x0a30, 0x0a32, 0x0a33, 0x0a35, 0x0a36, 0x0a38, 0x0a39, 0x0a3e, 0x0a40, 0x0a59, 0x0a5c, 0x0a5e, 0x0a5e, 0x0a66, 0x0a6f, 0x0a72, 0x0a74, 0x0a83, 0x0a83, 0x0a85, 0x0a8b, 0x0a8d, 0x0a8d, 0x0a8f, 0x0a91, 0x0a93, 0x0aa8, 0x0aaa, 0x0ab0, 0x0ab2, 0x0ab3, 0x0ab5, 0x0ab9, 0x0abd, 0x0ac0, 0x0ac9, 0x0ac9, 0x0acb, 0x0acc, 0x0ad0, 0x0ad0, 0x0ae0, 0x0ae0, 0x0ae6, 0x0aef, 0x0b02, 0x0b03, 0x0b05, 0x0b0c, 0x0b0f, 0x0b10, 0x0b13, 0x0b28, 0x0b2a, 0x0b30, 0x0b32, 0x0b33, 0x0b36, 0x0b39, 0x0b3d, 0x0b3e, 0x0b40, 0x0b40, 0x0b47, 0x0b48, 0x0b4b, 0x0b4c, 0x0b57, 0x0b57, 0x0b5c, 0x0b5d, 0x0b5f, 0x0b61, 0x0b66, 0x0b70, 0x0b83, 0x0b83, 0x0b85, 0x0b8a, 0x0b8e, 0x0b90, 0x0b92, 0x0b95, 0x0b99, 0x0b9a, 0x0b9c, 0x0b9c, 0x0b9e, 0x0b9f, 0x0ba3, 0x0ba4, 0x0ba8, 0x0baa, 0x0bae, 0x0bb5, 0x0bb7, 0x0bb9, 0x0bbe, 0x0bbf, 0x0bc1, 0x0bc2, 0x0bc6, 0x0bc8, 0x0bca, 0x0bcc, 0x0bd7, 0x0bd7, 0x0be7, 0x0bf2, 0x0c01, 0x0c03, 0x0c05, 0x0c0c, 0x0c0e, 0x0c10, 0x0c12, 0x0c28, 0x0c2a, 0x0c33, 0x0c35, 0x0c39, 0x0c41, 0x0c44, 0x0c60, 0x0c61, 0x0c66, 0x0c6f, 0x0c82, 0x0c83, 0x0c85, 0x0c8c, 0x0c8e, 0x0c90, 0x0c92, 0x0ca8, 0x0caa, 0x0cb3, 0x0cb5, 0x0cb9, 0x0cbe, 0x0cbe, 0x0cc0, 0x0cc4, 0x0cc7, 0x0cc8, 0x0cca, 0x0ccb, 0x0cd5, 0x0cd6, 0x0cde, 0x0cde, 0x0ce0, 0x0ce1, 0x0ce6, 0x0cef, 0x0d02, 0x0d03, 0x0d05, 0x0d0c, 0x0d0e, 0x0d10, 0x0d12, 0x0d28, 0x0d2a, 0x0d39, 0x0d3e, 0x0d40, 0x0d46, 0x0d48, 0x0d4a, 0x0d4c, 0x0d57, 0x0d57, 0x0d60, 0x0d61, 0x0d66, 0x0d6f, 0x0d82, 0x0d83, 0x0d85, 0x0d96, 0x0d9a, 0x0db1, 0x0db3, 0x0dbb, 0x0dbd, 0x0dbd, 0x0dc0, 0x0dc6, 0x0dcf, 0x0dd1, 0x0dd8, 0x0ddf, 0x0df2, 0x0df4, 0x0e01, 0x0e30, 0x0e32, 0x0e33, 0x0e40, 0x0e46, 0x0e4f, 0x0e5b, 0x0e81, 0x0e82, 0x0e84, 0x0e84, 0x0e87, 0x0e88, 0x0e8a, 0x0e8a, 0x0e8d, 0x0e8d, 0x0e94, 0x0e97, 0x0e99, 0x0e9f, 0x0ea1, 0x0ea3, 0x0ea5, 0x0ea5, 0x0ea7, 0x0ea7, 0x0eaa, 0x0eab, 0x0ead, 0x0eb0, 0x0eb2, 0x0eb3, 0x0ebd, 0x0ebd, 0x0ec0, 0x0ec4, 0x0ec6, 0x0ec6, 0x0ed0, 0x0ed9, 0x0edc, 0x0edd, 0x0f00, 0x0f17, 0x0f1a, 0x0f34, 0x0f36, 0x0f36, 0x0f38, 0x0f38, 0x0f3e, 0x0f47, 0x0f49, 0x0f6a, 0x0f7f, 0x0f7f, 0x0f85, 0x0f85, 0x0f88, 0x0f8b, 0x0fbe, 0x0fc5, 0x0fc7, 0x0fcc, 0x0fcf, 0x0fcf, 0x1000, 0x1021, 0x1023, 0x1027, 0x1029, 0x102a, 0x102c, 0x102c, 0x1031, 0x1031, 0x1038, 0x1038, 0x1040, 0x1057, 0x10a0, 0x10c5, 0x10d0, 0x10f8, 0x10fb, 0x10fb, 0x1100, 0x1159, 0x115f, 0x11a2, 0x11a8, 0x11f9, 0x1200, 0x1206, 0x1208, 0x1246, 0x1248, 0x1248, 0x124a, 0x124d, 0x1250, 0x1256, 0x1258, 0x1258, 0x125a, 0x125d, 0x1260, 0x1286, 0x1288, 0x1288, 0x128a, 0x128d, 0x1290, 0x12ae, 0x12b0, 0x12b0, 0x12b2, 0x12b5, 0x12b8, 0x12be, 0x12c0, 0x12c0, 0x12c2, 0x12c5, 0x12c8, 0x12ce, 0x12d0, 0x12d6, 0x12d8, 0x12ee, 0x12f0, 0x130e, 0x1310, 0x1310, 0x1312, 0x1315, 0x1318, 0x131e, 0x1320, 0x1346, 0x1348, 0x135a, 0x1361, 0x137c, 0x13a0, 0x13f4, 0x1401, 0x1676, 0x1681, 0x169a, 0x16a0, 0x16f0, 0x1700, 0x170c, 0x170e, 0x1711, 0x1720, 0x1731, 0x1735, 0x1736, 0x1740, 0x1751, 0x1760, 0x176c, 0x176e, 0x1770, 0x1780, 0x17b6, 0x17be, 0x17c5, 0x17c7, 0x17c8, 0x17d4, 0x17da, 0x17dc, 0x17dc, 0x17e0, 0x17e9, 0x1810, 0x1819, 0x1820, 0x1877, 0x1880, 0x18a8, 0x1e00, 0x1e9b, 0x1ea0, 0x1ef9, 0x1f00, 0x1f15, 0x1f18, 0x1f1d, 0x1f20, 0x1f45, 0x1f48, 0x1f4d, 0x1f50, 0x1f57, 0x1f59, 0x1f59, 0x1f5b, 0x1f5b, 0x1f5d, 0x1f5d, 0x1f5f, 0x1f7d, 0x1f80, 0x1fb4, 0x1fb6, 0x1fbc, 0x1fbe, 0x1fbe, 0x1fc2, 0x1fc4, 0x1fc6, 0x1fcc, 0x1fd0, 0x1fd3, 0x1fd6, 0x1fdb, 0x1fe0, 0x1fec, 0x1ff2, 0x1ff4, 0x1ff6, 0x1ffc, 0x200e, 0x200e, 0x2071, 0x2071, 0x207f, 0x207f, 0x2102, 0x2102, 0x2107, 0x2107, 0x210a, 0x2113, 0x2115, 0x2115, 0x2119, 0x211d, 0x2124, 0x2124, 0x2126, 0x2126, 0x2128, 0x2128, 0x212a, 0x212d, 0x212f, 0x2131, 0x2133, 0x2139, 0x213d, 0x213f, 0x2145, 0x2149, 0x2160, 0x2183, 0x2336, 0x237a, 0x2395, 0x2395, 0x249c, 0x24e9, 0x3005, 0x3007, 0x3021, 0x3029, 0x3031, 0x3035, 0x3038, 0x303c, 0x3041, 0x3096, 0x309d, 0x309f, 0x30a1, 0x30fa, 0x30fc, 0x30ff, 0x3105, 0x312c, 0x3131, 0x318e, 0x3190, 0x31b7, 0x31f0, 0x321c, 0x3220, 0x3243, 0x3260, 0x327b, 0x327f, 0x32b0, 0x32c0, 0x32cb, 0x32d0, 0x32fe, 0x3300, 0x3376, 0x337b, 0x33dd, 0x33e0, 0x33fe, 0x3400, 0x4db5, 0x4e00, 0x9fa5, 0xa000, 0xa48c, 0xac00, 0xd7a3, 0xd800, 0xfa2d, 0xfa30, 0xfa6a, 0xfb00, 0xfb06, 0xfb13, 0xfb17, 0xff21, 0xff3a, 0xff41, 0xff5a, 0xff66, 0xffbe, 0xffc2, 0xffc7, 0xffca, 0xffcf, 0xffd2, 0xffd7, 0xffda, 0xffdc, 0x10300, 0x1031e, 0x10320, 0x10323, 0x10330, 0x1034a, 0x10400, 0x10425, 0x10428, 0x1044d, 0x1d000, 0x1d0f5, 0x1d100, 0x1d126, 0x1d12a, 0x1d166, 0x1d16a, 0x1d172, 0x1d183, 0x1d184, 0x1d18c, 0x1d1a9, 0x1d1ae, 0x1d1dd, 0x1d400, 0x1d454, 0x1d456, 0x1d49c, 0x1d49e, 0x1d49f, 0x1d4a2, 0x1d4a2, 0x1d4a5, 0x1d4a6, 0x1d4a9, 0x1d4ac, 0x1d4ae, 0x1d4b9, 0x1d4bb, 0x1d4bb, 0x1d4bd, 0x1d4c0, 0x1d4c2, 0x1d4c3, 0x1d4c5, 0x1d505, 0x1d507, 0x1d50a, 0x1d50d, 0x1d514, 0x1d516, 0x1d51c, 0x1d51e, 0x1d539, 0x1d53b, 0x1d53e, 0x1d540, 0x1d544, 0x1d546, 0x1d546, 0x1d54a, 0x1d550, 0x1d552, 0x1d6a3, 0x1d6a8, 0x1d7c9, 0x20000, 0x2a6d6, 0x2f800, 0x2fa1d, 0xf0000, 0xffffd, 0x100000, 0x10fffd];
|
|
713
|
-
/* eslint-enable */
|
|
743
|
+
const bidirectional_l = [0x0041, 0x005a, 0x0061, 0x007a, 0x00aa, 0x00aa, 0x00b5, 0x00b5, 0x00ba, 0x00ba, 0x00c0, 0x00d6, 0x00d8, 0x00f6, 0x00f8, 0x0220, 0x0222, 0x0233, 0x0250, 0x02ad, 0x02b0, 0x02b8, 0x02bb, 0x02c1, 0x02d0, 0x02d1, 0x02e0, 0x02e4, 0x02ee, 0x02ee, 0x037a, 0x037a, 0x0386, 0x0386, 0x0388, 0x038a, 0x038c, 0x038c, 0x038e, 0x03a1, 0x03a3, 0x03ce, 0x03d0, 0x03f5, 0x0400, 0x0482, 0x048a, 0x04ce, 0x04d0, 0x04f5, 0x04f8, 0x04f9, 0x0500, 0x050f, 0x0531, 0x0556, 0x0559, 0x055f, 0x0561, 0x0587, 0x0589, 0x0589, 0x0903, 0x0903, 0x0905, 0x0939, 0x093d, 0x0940, 0x0949, 0x094c, 0x0950, 0x0950, 0x0958, 0x0961, 0x0964, 0x0970, 0x0982, 0x0983, 0x0985, 0x098c, 0x098f, 0x0990, 0x0993, 0x09a8, 0x09aa, 0x09b0, 0x09b2, 0x09b2, 0x09b6, 0x09b9, 0x09be, 0x09c0, 0x09c7, 0x09c8, 0x09cb, 0x09cc, 0x09d7, 0x09d7, 0x09dc, 0x09dd, 0x09df, 0x09e1, 0x09e6, 0x09f1, 0x09f4, 0x09fa, 0x0a05, 0x0a0a, 0x0a0f, 0x0a10, 0x0a13, 0x0a28, 0x0a2a, 0x0a30, 0x0a32, 0x0a33, 0x0a35, 0x0a36, 0x0a38, 0x0a39, 0x0a3e, 0x0a40, 0x0a59, 0x0a5c, 0x0a5e, 0x0a5e, 0x0a66, 0x0a6f, 0x0a72, 0x0a74, 0x0a83, 0x0a83, 0x0a85, 0x0a8b, 0x0a8d, 0x0a8d, 0x0a8f, 0x0a91, 0x0a93, 0x0aa8, 0x0aaa, 0x0ab0, 0x0ab2, 0x0ab3, 0x0ab5, 0x0ab9, 0x0abd, 0x0ac0, 0x0ac9, 0x0ac9, 0x0acb, 0x0acc, 0x0ad0, 0x0ad0, 0x0ae0, 0x0ae0, 0x0ae6, 0x0aef, 0x0b02, 0x0b03, 0x0b05, 0x0b0c, 0x0b0f, 0x0b10, 0x0b13, 0x0b28, 0x0b2a, 0x0b30, 0x0b32, 0x0b33, 0x0b36, 0x0b39, 0x0b3d, 0x0b3e, 0x0b40, 0x0b40, 0x0b47, 0x0b48, 0x0b4b, 0x0b4c, 0x0b57, 0x0b57, 0x0b5c, 0x0b5d, 0x0b5f, 0x0b61, 0x0b66, 0x0b70, 0x0b83, 0x0b83, 0x0b85, 0x0b8a, 0x0b8e, 0x0b90, 0x0b92, 0x0b95, 0x0b99, 0x0b9a, 0x0b9c, 0x0b9c, 0x0b9e, 0x0b9f, 0x0ba3, 0x0ba4, 0x0ba8, 0x0baa, 0x0bae, 0x0bb5, 0x0bb7, 0x0bb9, 0x0bbe, 0x0bbf, 0x0bc1, 0x0bc2, 0x0bc6, 0x0bc8, 0x0bca, 0x0bcc, 0x0bd7, 0x0bd7, 0x0be7, 0x0bf2, 0x0c01, 0x0c03, 0x0c05, 0x0c0c, 0x0c0e, 0x0c10, 0x0c12, 0x0c28, 0x0c2a, 0x0c33, 0x0c35, 0x0c39, 0x0c41, 0x0c44, 0x0c60, 0x0c61, 0x0c66, 0x0c6f, 0x0c82, 0x0c83, 0x0c85, 0x0c8c, 0x0c8e, 0x0c90, 0x0c92, 0x0ca8, 0x0caa, 0x0cb3, 0x0cb5, 0x0cb9, 0x0cbe, 0x0cbe, 0x0cc0, 0x0cc4, 0x0cc7, 0x0cc8, 0x0cca, 0x0ccb, 0x0cd5, 0x0cd6, 0x0cde, 0x0cde, 0x0ce0, 0x0ce1, 0x0ce6, 0x0cef, 0x0d02, 0x0d03, 0x0d05, 0x0d0c, 0x0d0e, 0x0d10, 0x0d12, 0x0d28, 0x0d2a, 0x0d39, 0x0d3e, 0x0d40, 0x0d46, 0x0d48, 0x0d4a, 0x0d4c, 0x0d57, 0x0d57, 0x0d60, 0x0d61, 0x0d66, 0x0d6f, 0x0d82, 0x0d83, 0x0d85, 0x0d96, 0x0d9a, 0x0db1, 0x0db3, 0x0dbb, 0x0dbd, 0x0dbd, 0x0dc0, 0x0dc6, 0x0dcf, 0x0dd1, 0x0dd8, 0x0ddf, 0x0df2, 0x0df4, 0x0e01, 0x0e30, 0x0e32, 0x0e33, 0x0e40, 0x0e46, 0x0e4f, 0x0e5b, 0x0e81, 0x0e82, 0x0e84, 0x0e84, 0x0e87, 0x0e88, 0x0e8a, 0x0e8a, 0x0e8d, 0x0e8d, 0x0e94, 0x0e97, 0x0e99, 0x0e9f, 0x0ea1, 0x0ea3, 0x0ea5, 0x0ea5, 0x0ea7, 0x0ea7, 0x0eaa, 0x0eab, 0x0ead, 0x0eb0, 0x0eb2, 0x0eb3, 0x0ebd, 0x0ebd, 0x0ec0, 0x0ec4, 0x0ec6, 0x0ec6, 0x0ed0, 0x0ed9, 0x0edc, 0x0edd, 0x0f00, 0x0f17, 0x0f1a, 0x0f34, 0x0f36, 0x0f36, 0x0f38, 0x0f38, 0x0f3e, 0x0f47, 0x0f49, 0x0f6a, 0x0f7f, 0x0f7f, 0x0f85, 0x0f85, 0x0f88, 0x0f8b, 0x0fbe, 0x0fc5, 0x0fc7, 0x0fcc, 0x0fcf, 0x0fcf, 0x1000, 0x1021, 0x1023, 0x1027, 0x1029, 0x102a, 0x102c, 0x102c, 0x1031, 0x1031, 0x1038, 0x1038, 0x1040, 0x1057, 0x10a0, 0x10c5, 0x10d0, 0x10f8, 0x10fb, 0x10fb, 0x1100, 0x1159, 0x115f, 0x11a2, 0x11a8, 0x11f9, 0x1200, 0x1206, 0x1208, 0x1246, 0x1248, 0x1248, 0x124a, 0x124d, 0x1250, 0x1256, 0x1258, 0x1258, 0x125a, 0x125d, 0x1260, 0x1286, 0x1288, 0x1288, 0x128a, 0x128d, 0x1290, 0x12ae, 0x12b0, 0x12b0, 0x12b2, 0x12b5, 0x12b8, 0x12be, 0x12c0, 0x12c0, 0x12c2, 0x12c5, 0x12c8, 0x12ce, 0x12d0, 0x12d6, 0x12d8, 0x12ee, 0x12f0, 0x130e, 0x1310, 0x1310, 0x1312, 0x1315, 0x1318, 0x131e, 0x1320, 0x1346, 0x1348, 0x135a, 0x1361, 0x137c, 0x13a0, 0x13f4, 0x1401, 0x1676, 0x1681, 0x169a, 0x16a0, 0x16f0, 0x1700, 0x170c, 0x170e, 0x1711, 0x1720, 0x1731, 0x1735, 0x1736, 0x1740, 0x1751, 0x1760, 0x176c, 0x176e, 0x1770, 0x1780, 0x17b6, 0x17be, 0x17c5, 0x17c7, 0x17c8, 0x17d4, 0x17da, 0x17dc, 0x17dc, 0x17e0, 0x17e9, 0x1810, 0x1819, 0x1820, 0x1877, 0x1880, 0x18a8, 0x1e00, 0x1e9b, 0x1ea0, 0x1ef9, 0x1f00, 0x1f15, 0x1f18, 0x1f1d, 0x1f20, 0x1f45, 0x1f48, 0x1f4d, 0x1f50, 0x1f57, 0x1f59, 0x1f59, 0x1f5b, 0x1f5b, 0x1f5d, 0x1f5d, 0x1f5f, 0x1f7d, 0x1f80, 0x1fb4, 0x1fb6, 0x1fbc, 0x1fbe, 0x1fbe, 0x1fc2, 0x1fc4, 0x1fc6, 0x1fcc, 0x1fd0, 0x1fd3, 0x1fd6, 0x1fdb, 0x1fe0, 0x1fec, 0x1ff2, 0x1ff4, 0x1ff6, 0x1ffc, 0x200e, 0x200e, 0x2071, 0x2071, 0x207f, 0x207f, 0x2102, 0x2102, 0x2107, 0x2107, 0x210a, 0x2113, 0x2115, 0x2115, 0x2119, 0x211d, 0x2124, 0x2124, 0x2126, 0x2126, 0x2128, 0x2128, 0x212a, 0x212d, 0x212f, 0x2131, 0x2133, 0x2139, 0x213d, 0x213f, 0x2145, 0x2149, 0x2160, 0x2183, 0x2336, 0x237a, 0x2395, 0x2395, 0x249c, 0x24e9, 0x3005, 0x3007, 0x3021, 0x3029, 0x3031, 0x3035, 0x3038, 0x303c, 0x3041, 0x3096, 0x309d, 0x309f, 0x30a1, 0x30fa, 0x30fc, 0x30ff, 0x3105, 0x312c, 0x3131, 0x318e, 0x3190, 0x31b7, 0x31f0, 0x321c, 0x3220, 0x3243, 0x3260, 0x327b, 0x327f, 0x32b0, 0x32c0, 0x32cb, 0x32d0, 0x32fe, 0x3300, 0x3376, 0x337b, 0x33dd, 0x33e0, 0x33fe, 0x3400, 0x4db5, 0x4e00, 0x9fa5, 0xa000, 0xa48c, 0xac00, 0xd7a3, 0xd800, 0xfa2d, 0xfa30, 0xfa6a, 0xfb00, 0xfb06, 0xfb13, 0xfb17, 0xff21, 0xff3a, 0xff41, 0xff5a, 0xff66, 0xffbe, 0xffc2, 0xffc7, 0xffca, 0xffcf, 0xffd2, 0xffd7, 0xffda, 0xffdc, 0x10300, 0x1031e, 0x10320, 0x10323, 0x10330, 0x1034a, 0x10400, 0x10425, 0x10428, 0x1044d, 0x1d000, 0x1d0f5, 0x1d100, 0x1d126, 0x1d12a, 0x1d166, 0x1d16a, 0x1d172, 0x1d183, 0x1d184, 0x1d18c, 0x1d1a9, 0x1d1ae, 0x1d1dd, 0x1d400, 0x1d454, 0x1d456, 0x1d49c, 0x1d49e, 0x1d49f, 0x1d4a2, 0x1d4a2, 0x1d4a5, 0x1d4a6, 0x1d4a9, 0x1d4ac, 0x1d4ae, 0x1d4b9, 0x1d4bb, 0x1d4bb, 0x1d4bd, 0x1d4c0, 0x1d4c2, 0x1d4c3, 0x1d4c5, 0x1d505, 0x1d507, 0x1d50a, 0x1d50d, 0x1d514, 0x1d516, 0x1d51c, 0x1d51e, 0x1d539, 0x1d53b, 0x1d53e, 0x1d540, 0x1d544, 0x1d546, 0x1d546, 0x1d54a, 0x1d550, 0x1d552, 0x1d6a3, 0x1d6a8, 0x1d7c9, 0x20000, 0x2a6d6, 0x2f800, 0x2fa1d, 0xf0000, 0xffffd, 0x100000, 0x10fffd]; // prettier-ignore-end
|
|
714
744
|
|
|
715
745
|
const isBidirectionalL = character => inRange(character, bidirectional_l);
|
|
716
746
|
|
|
717
|
-
/**
|
|
718
|
-
* non-ASCII space characters [StringPrep, C.1.2] that can be
|
|
719
|
-
* mapped to SPACE (U+0020)
|
|
747
|
+
/**
|
|
748
|
+
* non-ASCII space characters [StringPrep, C.1.2] that can be
|
|
749
|
+
* mapped to SPACE (U+0020)
|
|
720
750
|
*/
|
|
721
751
|
|
|
722
752
|
const mapping2space = isNonASCIISpaceCharacter;
|
|
723
|
-
/**
|
|
724
|
-
* the "commonly mapped to nothing" characters [StringPrep, B.1]
|
|
725
|
-
* that can be mapped to nothing.
|
|
753
|
+
/**
|
|
754
|
+
* the "commonly mapped to nothing" characters [StringPrep, B.1]
|
|
755
|
+
* that can be mapped to nothing.
|
|
726
756
|
*/
|
|
727
757
|
|
|
728
758
|
const mapping2nothing = isCommonlyMappedToNothing; // utils
|
|
@@ -732,12 +762,12 @@ const getCodePoint = character => character.codePointAt(0);
|
|
|
732
762
|
const first = x => x[0];
|
|
733
763
|
|
|
734
764
|
const last = x => x[x.length - 1];
|
|
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[]}
|
|
765
|
+
/**
|
|
766
|
+
* Convert provided string into an array of Unicode Code Points.
|
|
767
|
+
* Based on https://stackoverflow.com/a/21409165/1556249
|
|
768
|
+
* and https://www.npmjs.com/package/code-point-at.
|
|
769
|
+
* @param {string} input
|
|
770
|
+
* @returns {number[]}
|
|
741
771
|
*/
|
|
742
772
|
|
|
743
773
|
|
|
@@ -763,12 +793,12 @@ function toCodePoints(input) {
|
|
|
763
793
|
|
|
764
794
|
return codepoints;
|
|
765
795
|
}
|
|
766
|
-
/**
|
|
767
|
-
* SASLprep.
|
|
768
|
-
* @param {string} input
|
|
769
|
-
* @param {Object} opts
|
|
770
|
-
* @param {boolean} opts.allowUnassigned
|
|
771
|
-
* @returns {string}
|
|
796
|
+
/**
|
|
797
|
+
* SASLprep.
|
|
798
|
+
* @param {string} input
|
|
799
|
+
* @param {Object} opts
|
|
800
|
+
* @param {boolean} opts.allowUnassigned
|
|
801
|
+
* @returns {string}
|
|
772
802
|
*/
|
|
773
803
|
|
|
774
804
|
|
|
@@ -812,10 +842,10 @@ function saslprep(input, opts = {}) {
|
|
|
812
842
|
if (hasBidiRAL && hasBidiL) {
|
|
813
843
|
throw new Error('String must not contain RandALCat and LCat at the same time,' + ' see https://tools.ietf.org/html/rfc3454#section-6');
|
|
814
844
|
}
|
|
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.
|
|
845
|
+
/**
|
|
846
|
+
* 4.2 If a string contains any RandALCat character, a RandALCat
|
|
847
|
+
* character MUST be the first character of the string, and a
|
|
848
|
+
* RandALCat character MUST be the last character of the string.
|
|
819
849
|
*/
|
|
820
850
|
|
|
821
851
|
|
|
@@ -829,9 +859,9 @@ function saslprep(input, opts = {}) {
|
|
|
829
859
|
return normalized_input;
|
|
830
860
|
}
|
|
831
861
|
|
|
832
|
-
/*
|
|
833
|
-
PDFSecurity - represents PDF security settings
|
|
834
|
-
By Yang Liu <hi@zesik.com>
|
|
862
|
+
/*
|
|
863
|
+
PDFSecurity - represents PDF security settings
|
|
864
|
+
By Yang Liu <hi@zesik.com>
|
|
835
865
|
*/
|
|
836
866
|
|
|
837
867
|
class PDFSecurity {
|
|
@@ -839,11 +869,12 @@ class PDFSecurity {
|
|
|
839
869
|
let infoStr = `${info.CreationDate.getTime()}\n`;
|
|
840
870
|
|
|
841
871
|
for (let key in info) {
|
|
872
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
842
873
|
if (!info.hasOwnProperty(key)) {
|
|
843
874
|
continue;
|
|
844
875
|
}
|
|
845
876
|
|
|
846
|
-
infoStr += `${key}: ${info[key]}\n`;
|
|
877
|
+
infoStr += `${key}: ${info[key].valueOf()}\n`;
|
|
847
878
|
}
|
|
848
879
|
|
|
849
880
|
return wordArrayToBuffer(CryptoJS.MD5(infoStr));
|
|
@@ -974,7 +1005,7 @@ class PDFSecurity {
|
|
|
974
1005
|
|
|
975
1006
|
_setupEncryptionV5(encDict, options) {
|
|
976
1007
|
this.keyBits = 256;
|
|
977
|
-
const permissions = getPermissionsR3(options);
|
|
1008
|
+
const permissions = getPermissionsR3(options.permissions);
|
|
978
1009
|
const processedUserPassword = processPasswordR5(options.userPassword);
|
|
979
1010
|
const processedOwnerPassword = options.ownerPassword ? processPasswordR5(options.ownerPassword) : processedUserPassword;
|
|
980
1011
|
this.encryptionKey = getEncryptionKeyR5(PDFSecurity.generateRandomWordArray);
|
|
@@ -1206,7 +1237,7 @@ function getEncryptedPermissionsR5(permissions, encryptionKey, generateRandomWor
|
|
|
1206
1237
|
}
|
|
1207
1238
|
|
|
1208
1239
|
function processPasswordR2R3R4(password = '') {
|
|
1209
|
-
const out =
|
|
1240
|
+
const out = Buffer.alloc(32);
|
|
1210
1241
|
const length = password.length;
|
|
1211
1242
|
let index = 0;
|
|
1212
1243
|
|
|
@@ -1232,7 +1263,7 @@ function processPasswordR2R3R4(password = '') {
|
|
|
1232
1263
|
function processPasswordR5(password = '') {
|
|
1233
1264
|
password = unescape(encodeURIComponent(saslprep(password)));
|
|
1234
1265
|
const length = Math.min(127, password.length);
|
|
1235
|
-
const out =
|
|
1266
|
+
const out = Buffer.alloc(length);
|
|
1236
1267
|
|
|
1237
1268
|
for (let i = 0; i < length; i++) {
|
|
1238
1269
|
out[i] = password.charCodeAt(i);
|
|
@@ -3115,10 +3146,10 @@ class EmbeddedFont extends PDFFont {
|
|
|
3115
3146
|
|
|
3116
3147
|
if (this.font.head.macStyle.italic) {
|
|
3117
3148
|
flags |= 1 << 6;
|
|
3118
|
-
} // generate a tag (6 uppercase letters.
|
|
3149
|
+
} // generate a tag (6 uppercase letters. 17 is the char code offset from '0' to 'A'. 73 will map to 'Z')
|
|
3119
3150
|
|
|
3120
3151
|
|
|
3121
|
-
const tag = [1, 2, 3, 4, 5, 6].map(i => String.fromCharCode((this.id.charCodeAt(i) ||
|
|
3152
|
+
const tag = [1, 2, 3, 4, 5, 6].map(i => String.fromCharCode((this.id.charCodeAt(i) || 73) + 17)).join('');
|
|
3122
3153
|
const name = tag + '+' + this.font.postscriptName;
|
|
3123
3154
|
const {
|
|
3124
3155
|
bbox
|
|
@@ -3239,9 +3270,9 @@ class PDFFontFactory {
|
|
|
3239
3270
|
if (Buffer.isBuffer(src)) {
|
|
3240
3271
|
font = fontkit.create(src, family);
|
|
3241
3272
|
} else if (src instanceof Uint8Array) {
|
|
3242
|
-
font = fontkit.create(
|
|
3273
|
+
font = fontkit.create(Buffer.from(src), family);
|
|
3243
3274
|
} else if (src instanceof ArrayBuffer) {
|
|
3244
|
-
font = fontkit.create(
|
|
3275
|
+
font = fontkit.create(Buffer.from(new Uint8Array(src)), family);
|
|
3245
3276
|
}
|
|
3246
3277
|
|
|
3247
3278
|
if (font == null) {
|
|
@@ -3565,7 +3596,7 @@ class LineWrapper extends events.EventEmitter {
|
|
|
3565
3596
|
|
|
3566
3597
|
buffer = buffer.replace(/\s+$/, '');
|
|
3567
3598
|
textWidth = this.wordWidth(buffer + this.ellipsis); // remove characters from the buffer until the ellipsis fits
|
|
3568
|
-
// to avoid
|
|
3599
|
+
// to avoid infinite loop need to stop while-loop if buffer is empty string
|
|
3569
3600
|
|
|
3570
3601
|
while (buffer && textWidth > this.lineWidth) {
|
|
3571
3602
|
buffer = buffer.slice(0, -1).replace(/\s+$/, '');
|
|
@@ -3653,7 +3684,7 @@ class LineWrapper extends events.EventEmitter {
|
|
|
3653
3684
|
return false;
|
|
3654
3685
|
}
|
|
3655
3686
|
|
|
3656
|
-
this.document.
|
|
3687
|
+
this.document.continueOnNewPage();
|
|
3657
3688
|
this.column = 1;
|
|
3658
3689
|
this.startY = this.document.page.margins.top;
|
|
3659
3690
|
this.maxY = this.document.page.maxY();
|
|
@@ -3718,7 +3749,13 @@ var TextMixin = {
|
|
|
3718
3749
|
|
|
3719
3750
|
if (options.wordSpacing) {
|
|
3720
3751
|
text = text.replace(/\s{2,}/g, ' ');
|
|
3721
|
-
}
|
|
3752
|
+
}
|
|
3753
|
+
|
|
3754
|
+
const addStructure = () => {
|
|
3755
|
+
if (options.structParent) {
|
|
3756
|
+
options.structParent.add(this.struct(options.structType || 'P', [this.markStructureContent(options.structType || 'P')]));
|
|
3757
|
+
}
|
|
3758
|
+
}; // word wrapping
|
|
3722
3759
|
|
|
3723
3760
|
|
|
3724
3761
|
if (options.width) {
|
|
@@ -3727,6 +3764,7 @@ var TextMixin = {
|
|
|
3727
3764
|
if (!wrapper) {
|
|
3728
3765
|
wrapper = new LineWrapper(this, options);
|
|
3729
3766
|
wrapper.on('line', lineCallback);
|
|
3767
|
+
wrapper.on('firstLine', addStructure);
|
|
3730
3768
|
}
|
|
3731
3769
|
|
|
3732
3770
|
this._wrapper = options.continued ? wrapper : null;
|
|
@@ -3734,6 +3772,7 @@ var TextMixin = {
|
|
|
3734
3772
|
wrapper.wrap(text, options); // render paragraphs as single lines
|
|
3735
3773
|
} else {
|
|
3736
3774
|
for (let line of text.split('\n')) {
|
|
3775
|
+
addStructure();
|
|
3737
3776
|
lineCallback(line, options);
|
|
3738
3777
|
}
|
|
3739
3778
|
}
|
|
@@ -3823,6 +3862,23 @@ var TextMixin = {
|
|
|
3823
3862
|
level = 1;
|
|
3824
3863
|
let i = 0;
|
|
3825
3864
|
wrapper.on('firstLine', () => {
|
|
3865
|
+
let item, itemType, labelType, bodyType;
|
|
3866
|
+
|
|
3867
|
+
if (options.structParent) {
|
|
3868
|
+
if (options.structTypes) {
|
|
3869
|
+
[itemType, labelType, bodyType] = options.structTypes;
|
|
3870
|
+
} else {
|
|
3871
|
+
[itemType, labelType, bodyType] = ['LI', 'Lbl', 'LBody'];
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3874
|
+
|
|
3875
|
+
if (itemType) {
|
|
3876
|
+
item = this.struct(itemType);
|
|
3877
|
+
options.structParent.add(item);
|
|
3878
|
+
} else if (options.structParent) {
|
|
3879
|
+
item = options.structParent;
|
|
3880
|
+
}
|
|
3881
|
+
|
|
3826
3882
|
let l;
|
|
3827
3883
|
|
|
3828
3884
|
if ((l = levels[i++]) !== level) {
|
|
@@ -3832,15 +3888,31 @@ var TextMixin = {
|
|
|
3832
3888
|
level = l;
|
|
3833
3889
|
}
|
|
3834
3890
|
|
|
3891
|
+
if (item && (labelType || bodyType)) {
|
|
3892
|
+
item.add(this.struct(labelType || bodyType, [this.markStructureContent(labelType || bodyType)]));
|
|
3893
|
+
}
|
|
3894
|
+
|
|
3835
3895
|
switch (listType) {
|
|
3836
3896
|
case 'bullet':
|
|
3837
3897
|
this.circle(this.x - indent + r, this.y + midLine, r);
|
|
3838
|
-
|
|
3898
|
+
this.fill();
|
|
3899
|
+
break;
|
|
3839
3900
|
|
|
3840
3901
|
case 'numbered':
|
|
3841
3902
|
case 'lettered':
|
|
3842
3903
|
var text = label(numbers[i - 1]);
|
|
3843
|
-
|
|
3904
|
+
|
|
3905
|
+
this._fragment(text, this.x - indent, this.y, options);
|
|
3906
|
+
|
|
3907
|
+
break;
|
|
3908
|
+
}
|
|
3909
|
+
|
|
3910
|
+
if (item && labelType && bodyType) {
|
|
3911
|
+
item.add(this.struct(bodyType, [this.markStructureContent(bodyType)]));
|
|
3912
|
+
}
|
|
3913
|
+
|
|
3914
|
+
if (item && item !== options.structParent) {
|
|
3915
|
+
item.end();
|
|
3844
3916
|
}
|
|
3845
3917
|
});
|
|
3846
3918
|
wrapper.on('sectionStart', () => {
|
|
@@ -4009,10 +4081,10 @@ var TextMixin = {
|
|
|
4009
4081
|
|
|
4010
4082
|
if (options.destination != null) {
|
|
4011
4083
|
this.addNamedDestination(options.destination, 'XYZ', x, y, null);
|
|
4012
|
-
} // create underline
|
|
4084
|
+
} // create underline
|
|
4013
4085
|
|
|
4014
4086
|
|
|
4015
|
-
if (options.underline
|
|
4087
|
+
if (options.underline) {
|
|
4016
4088
|
this.save();
|
|
4017
4089
|
|
|
4018
4090
|
if (!options.stroke) {
|
|
@@ -4021,13 +4093,24 @@ var TextMixin = {
|
|
|
4021
4093
|
|
|
4022
4094
|
const lineWidth = this._fontSize < 10 ? 0.5 : Math.floor(this._fontSize / 10);
|
|
4023
4095
|
this.lineWidth(lineWidth);
|
|
4024
|
-
|
|
4025
|
-
|
|
4096
|
+
let lineY = y + this.currentLineHeight() - lineWidth;
|
|
4097
|
+
this.moveTo(x, lineY);
|
|
4098
|
+
this.lineTo(x + renderedWidth, lineY);
|
|
4099
|
+
this.stroke();
|
|
4100
|
+
this.restore();
|
|
4101
|
+
} // create strikethrough line
|
|
4026
4102
|
|
|
4027
|
-
|
|
4028
|
-
|
|
4103
|
+
|
|
4104
|
+
if (options.strike) {
|
|
4105
|
+
this.save();
|
|
4106
|
+
|
|
4107
|
+
if (!options.stroke) {
|
|
4108
|
+
this.strokeColor(...(this._fillColor || []));
|
|
4029
4109
|
}
|
|
4030
4110
|
|
|
4111
|
+
const lineWidth = this._fontSize < 10 ? 0.5 : Math.floor(this._fontSize / 10);
|
|
4112
|
+
this.lineWidth(lineWidth);
|
|
4113
|
+
let lineY = y + this.currentLineHeight() / 2;
|
|
4031
4114
|
this.moveTo(x, lineY);
|
|
4032
4115
|
this.lineTo(x + renderedWidth, lineY);
|
|
4033
4116
|
this.stroke();
|
|
@@ -4290,7 +4373,7 @@ class PNGImage {
|
|
|
4290
4373
|
} else {
|
|
4291
4374
|
// embed the color palette in the PDF as an object stream
|
|
4292
4375
|
const palette = this.document.ref();
|
|
4293
|
-
palette.end(
|
|
4376
|
+
palette.end(Buffer.from(this.image.palette)); // build the color space array for the image
|
|
4294
4377
|
|
|
4295
4378
|
this.obj.data['ColorSpace'] = ['Indexed', 'DeviceRGB', this.image.palette.length / 3 - 1, palette];
|
|
4296
4379
|
} // For PNG color types 0, 2 and 3, the transparency data is stored in
|
|
@@ -4363,8 +4446,8 @@ class PNGImage {
|
|
|
4363
4446
|
let a, p;
|
|
4364
4447
|
const colorCount = this.image.colors;
|
|
4365
4448
|
const pixelCount = this.width * this.height;
|
|
4366
|
-
const imgData =
|
|
4367
|
-
const alphaChannel =
|
|
4449
|
+
const imgData = Buffer.alloc(pixelCount * colorCount);
|
|
4450
|
+
const alphaChannel = Buffer.alloc(pixelCount);
|
|
4368
4451
|
let i = p = a = 0;
|
|
4369
4452
|
const len = pixels.length; // For 16bit images copy only most significant byte (MSB) - PNG data is always stored in network byte order (MSB first)
|
|
4370
4453
|
|
|
@@ -4389,7 +4472,7 @@ class PNGImage {
|
|
|
4389
4472
|
loadIndexedAlphaChannel() {
|
|
4390
4473
|
const transparency = this.image.transparency.indexed;
|
|
4391
4474
|
return this.image.decodePixels(pixels => {
|
|
4392
|
-
const alphaChannel =
|
|
4475
|
+
const alphaChannel = Buffer.alloc(this.width * this.height);
|
|
4393
4476
|
let i = 0;
|
|
4394
4477
|
|
|
4395
4478
|
for (let j = 0, end = pixels.length; j < end; j++) {
|
|
@@ -4410,9 +4493,9 @@ class PNGImage {
|
|
|
4410
4493
|
|
|
4411
4494
|
}
|
|
4412
4495
|
|
|
4413
|
-
/*
|
|
4414
|
-
PDFImage - embeds images in PDF documents
|
|
4415
|
-
By Devon Govett
|
|
4496
|
+
/*
|
|
4497
|
+
PDFImage - embeds images in PDF documents
|
|
4498
|
+
By Devon Govett
|
|
4416
4499
|
*/
|
|
4417
4500
|
|
|
4418
4501
|
class PDFImage {
|
|
@@ -4422,12 +4505,12 @@ class PDFImage {
|
|
|
4422
4505
|
if (Buffer.isBuffer(src)) {
|
|
4423
4506
|
data = src;
|
|
4424
4507
|
} else if (src instanceof ArrayBuffer) {
|
|
4425
|
-
data =
|
|
4508
|
+
data = Buffer.from(new Uint8Array(src));
|
|
4426
4509
|
} else {
|
|
4427
4510
|
let match;
|
|
4428
4511
|
|
|
4429
4512
|
if (match = /^data:.+;base64,(.*)$/.exec(src)) {
|
|
4430
|
-
data =
|
|
4513
|
+
data = Buffer.from(match[1], 'base64');
|
|
4431
4514
|
} else {
|
|
4432
4515
|
data = fs.readFileSync(src);
|
|
4433
4516
|
|
|
@@ -4723,6 +4806,23 @@ var AnnotationsMixin = {
|
|
|
4723
4806
|
return this.annotate(x, y, w, h, options);
|
|
4724
4807
|
},
|
|
4725
4808
|
|
|
4809
|
+
fileAnnotation(x, y, w, h, file = {}, options = {}) {
|
|
4810
|
+
// create hidden file
|
|
4811
|
+
const filespec = this.file(file.src, Object.assign({
|
|
4812
|
+
hidden: true
|
|
4813
|
+
}, file));
|
|
4814
|
+
options.Subtype = 'FileAttachment';
|
|
4815
|
+
options.FS = filespec; // add description from filespec unless description (Contents) has already been set
|
|
4816
|
+
|
|
4817
|
+
if (options.Contents) {
|
|
4818
|
+
options.Contents = new String(options.Contents);
|
|
4819
|
+
} else if (filespec.data.Desc) {
|
|
4820
|
+
options.Contents = filespec.data.Desc;
|
|
4821
|
+
}
|
|
4822
|
+
|
|
4823
|
+
return this.annotate(x, y, w, h, options);
|
|
4824
|
+
},
|
|
4825
|
+
|
|
4726
4826
|
_convertRect(x1, y1, w, h) {
|
|
4727
4827
|
// flip y1 and y2
|
|
4728
4828
|
let y2 = y1;
|
|
@@ -4819,6 +4919,490 @@ var OutlineMixin = {
|
|
|
4819
4919
|
|
|
4820
4920
|
};
|
|
4821
4921
|
|
|
4922
|
+
function _defineProperty(obj, key, value) {
|
|
4923
|
+
if (key in obj) {
|
|
4924
|
+
Object.defineProperty(obj, key, {
|
|
4925
|
+
value: value,
|
|
4926
|
+
enumerable: true,
|
|
4927
|
+
configurable: true,
|
|
4928
|
+
writable: true
|
|
4929
|
+
});
|
|
4930
|
+
} else {
|
|
4931
|
+
obj[key] = value;
|
|
4932
|
+
}
|
|
4933
|
+
|
|
4934
|
+
return obj;
|
|
4935
|
+
}
|
|
4936
|
+
|
|
4937
|
+
function ownKeys(object, enumerableOnly) {
|
|
4938
|
+
var keys = Object.keys(object);
|
|
4939
|
+
|
|
4940
|
+
if (Object.getOwnPropertySymbols) {
|
|
4941
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
4942
|
+
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
4943
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
4944
|
+
});
|
|
4945
|
+
keys.push.apply(keys, symbols);
|
|
4946
|
+
}
|
|
4947
|
+
|
|
4948
|
+
return keys;
|
|
4949
|
+
}
|
|
4950
|
+
|
|
4951
|
+
function _objectSpread2(target) {
|
|
4952
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
4953
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
4954
|
+
|
|
4955
|
+
if (i % 2) {
|
|
4956
|
+
ownKeys(Object(source), true).forEach(function (key) {
|
|
4957
|
+
_defineProperty(target, key, source[key]);
|
|
4958
|
+
});
|
|
4959
|
+
} else if (Object.getOwnPropertyDescriptors) {
|
|
4960
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
4961
|
+
} else {
|
|
4962
|
+
ownKeys(Object(source)).forEach(function (key) {
|
|
4963
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
4964
|
+
});
|
|
4965
|
+
}
|
|
4966
|
+
}
|
|
4967
|
+
|
|
4968
|
+
return target;
|
|
4969
|
+
}
|
|
4970
|
+
|
|
4971
|
+
/*
|
|
4972
|
+
PDFStructureContent - a reference to a marked structure content
|
|
4973
|
+
By Ben Schmidt
|
|
4974
|
+
*/
|
|
4975
|
+
class PDFStructureContent {
|
|
4976
|
+
constructor(pageRef, mcid) {
|
|
4977
|
+
this.refs = [{
|
|
4978
|
+
pageRef,
|
|
4979
|
+
mcid
|
|
4980
|
+
}];
|
|
4981
|
+
}
|
|
4982
|
+
|
|
4983
|
+
push(structContent) {
|
|
4984
|
+
structContent.refs.forEach(ref => this.refs.push(ref));
|
|
4985
|
+
}
|
|
4986
|
+
|
|
4987
|
+
}
|
|
4988
|
+
|
|
4989
|
+
/*
|
|
4990
|
+
PDFStructureElement - represents an element in the PDF logical structure tree
|
|
4991
|
+
By Ben Schmidt
|
|
4992
|
+
*/
|
|
4993
|
+
|
|
4994
|
+
class PDFStructureElement {
|
|
4995
|
+
constructor(document, type, options = {}, children = null) {
|
|
4996
|
+
this.document = document;
|
|
4997
|
+
this._attached = false;
|
|
4998
|
+
this._ended = false;
|
|
4999
|
+
this._flushed = false;
|
|
5000
|
+
this.dictionary = document.ref({
|
|
5001
|
+
// Type: "StructElem",
|
|
5002
|
+
S: type
|
|
5003
|
+
});
|
|
5004
|
+
const data = this.dictionary.data;
|
|
5005
|
+
|
|
5006
|
+
if (Array.isArray(options) || this._isValidChild(options)) {
|
|
5007
|
+
children = options;
|
|
5008
|
+
options = {};
|
|
5009
|
+
}
|
|
5010
|
+
|
|
5011
|
+
if (typeof options.title !== 'undefined') {
|
|
5012
|
+
data.T = new String(options.title);
|
|
5013
|
+
}
|
|
5014
|
+
|
|
5015
|
+
if (typeof options.lang !== 'undefined') {
|
|
5016
|
+
data.Lang = new String(options.lang);
|
|
5017
|
+
}
|
|
5018
|
+
|
|
5019
|
+
if (typeof options.alt !== 'undefined') {
|
|
5020
|
+
data.Alt = new String(options.alt);
|
|
5021
|
+
}
|
|
5022
|
+
|
|
5023
|
+
if (typeof options.expanded !== 'undefined') {
|
|
5024
|
+
data.E = new String(options.expanded);
|
|
5025
|
+
}
|
|
5026
|
+
|
|
5027
|
+
if (typeof options.actual !== 'undefined') {
|
|
5028
|
+
data.ActualText = new String(options.actual);
|
|
5029
|
+
}
|
|
5030
|
+
|
|
5031
|
+
this._children = [];
|
|
5032
|
+
|
|
5033
|
+
if (children) {
|
|
5034
|
+
if (!Array.isArray(children)) {
|
|
5035
|
+
children = [children];
|
|
5036
|
+
}
|
|
5037
|
+
|
|
5038
|
+
children.forEach(child => this.add(child));
|
|
5039
|
+
this.end();
|
|
5040
|
+
}
|
|
5041
|
+
}
|
|
5042
|
+
|
|
5043
|
+
add(child) {
|
|
5044
|
+
if (this._ended) {
|
|
5045
|
+
throw new Error(`Cannot add child to already-ended structure element`);
|
|
5046
|
+
}
|
|
5047
|
+
|
|
5048
|
+
if (!this._isValidChild(child)) {
|
|
5049
|
+
throw new Error(`Invalid structure element child`);
|
|
5050
|
+
}
|
|
5051
|
+
|
|
5052
|
+
if (child instanceof PDFStructureElement) {
|
|
5053
|
+
child.setParent(this.dictionary);
|
|
5054
|
+
|
|
5055
|
+
if (this._attached) {
|
|
5056
|
+
child.setAttached();
|
|
5057
|
+
}
|
|
5058
|
+
}
|
|
5059
|
+
|
|
5060
|
+
if (child instanceof PDFStructureContent) {
|
|
5061
|
+
this._addContentToParentTree(child);
|
|
5062
|
+
}
|
|
5063
|
+
|
|
5064
|
+
if (typeof child === 'function' && this._attached) {
|
|
5065
|
+
// _contentForClosure() adds the content to the parent tree
|
|
5066
|
+
child = this._contentForClosure(child);
|
|
5067
|
+
}
|
|
5068
|
+
|
|
5069
|
+
this._children.push(child);
|
|
5070
|
+
|
|
5071
|
+
return this;
|
|
5072
|
+
}
|
|
5073
|
+
|
|
5074
|
+
_addContentToParentTree(content) {
|
|
5075
|
+
content.refs.forEach(({
|
|
5076
|
+
pageRef,
|
|
5077
|
+
mcid
|
|
5078
|
+
}) => {
|
|
5079
|
+
const pageStructParents = this.document.getStructParentTree().get(pageRef.data.StructParents);
|
|
5080
|
+
pageStructParents[mcid] = this.dictionary;
|
|
5081
|
+
});
|
|
5082
|
+
}
|
|
5083
|
+
|
|
5084
|
+
setParent(parentRef) {
|
|
5085
|
+
if (this.dictionary.data.P) {
|
|
5086
|
+
throw new Error(`Structure element added to more than one parent`);
|
|
5087
|
+
}
|
|
5088
|
+
|
|
5089
|
+
this.dictionary.data.P = parentRef;
|
|
5090
|
+
|
|
5091
|
+
this._flush();
|
|
5092
|
+
}
|
|
5093
|
+
|
|
5094
|
+
setAttached() {
|
|
5095
|
+
if (this._attached) {
|
|
5096
|
+
return;
|
|
5097
|
+
}
|
|
5098
|
+
|
|
5099
|
+
this._children.forEach((child, index) => {
|
|
5100
|
+
if (child instanceof PDFStructureElement) {
|
|
5101
|
+
child.setAttached();
|
|
5102
|
+
}
|
|
5103
|
+
|
|
5104
|
+
if (typeof child === 'function') {
|
|
5105
|
+
this._children[index] = this._contentForClosure(child);
|
|
5106
|
+
}
|
|
5107
|
+
});
|
|
5108
|
+
|
|
5109
|
+
this._attached = true;
|
|
5110
|
+
|
|
5111
|
+
this._flush();
|
|
5112
|
+
}
|
|
5113
|
+
|
|
5114
|
+
end() {
|
|
5115
|
+
if (this._ended) {
|
|
5116
|
+
return;
|
|
5117
|
+
}
|
|
5118
|
+
|
|
5119
|
+
this._children.filter(child => child instanceof PDFStructureElement).forEach(child => child.end());
|
|
5120
|
+
|
|
5121
|
+
this._ended = true;
|
|
5122
|
+
|
|
5123
|
+
this._flush();
|
|
5124
|
+
}
|
|
5125
|
+
|
|
5126
|
+
_isValidChild(child) {
|
|
5127
|
+
return child instanceof PDFStructureElement || child instanceof PDFStructureContent || typeof child === 'function';
|
|
5128
|
+
}
|
|
5129
|
+
|
|
5130
|
+
_contentForClosure(closure) {
|
|
5131
|
+
const content = this.document.markStructureContent(this.dictionary.data.S);
|
|
5132
|
+
closure();
|
|
5133
|
+
this.document.endMarkedContent();
|
|
5134
|
+
|
|
5135
|
+
this._addContentToParentTree(content);
|
|
5136
|
+
|
|
5137
|
+
return content;
|
|
5138
|
+
}
|
|
5139
|
+
|
|
5140
|
+
_isFlushable() {
|
|
5141
|
+
if (!this.dictionary.data.P || !this._ended) {
|
|
5142
|
+
return false;
|
|
5143
|
+
}
|
|
5144
|
+
|
|
5145
|
+
return this._children.every(child => {
|
|
5146
|
+
if (typeof child === 'function') {
|
|
5147
|
+
return false;
|
|
5148
|
+
}
|
|
5149
|
+
|
|
5150
|
+
if (child instanceof PDFStructureElement) {
|
|
5151
|
+
return child._isFlushable();
|
|
5152
|
+
}
|
|
5153
|
+
|
|
5154
|
+
return true;
|
|
5155
|
+
});
|
|
5156
|
+
}
|
|
5157
|
+
|
|
5158
|
+
_flush() {
|
|
5159
|
+
if (this._flushed || !this._isFlushable()) {
|
|
5160
|
+
return;
|
|
5161
|
+
}
|
|
5162
|
+
|
|
5163
|
+
this.dictionary.data.K = [];
|
|
5164
|
+
|
|
5165
|
+
this._children.forEach(child => this._flushChild(child));
|
|
5166
|
+
|
|
5167
|
+
this.dictionary.end(); // free memory used by children; the dictionary itself may still be
|
|
5168
|
+
// referenced by a parent structure element or root, but we can
|
|
5169
|
+
// at least trim the tree here
|
|
5170
|
+
|
|
5171
|
+
this._children = [];
|
|
5172
|
+
this.dictionary.data.K = null;
|
|
5173
|
+
this._flushed = true;
|
|
5174
|
+
}
|
|
5175
|
+
|
|
5176
|
+
_flushChild(child) {
|
|
5177
|
+
if (child instanceof PDFStructureElement) {
|
|
5178
|
+
this.dictionary.data.K.push(child.dictionary);
|
|
5179
|
+
}
|
|
5180
|
+
|
|
5181
|
+
if (child instanceof PDFStructureContent) {
|
|
5182
|
+
child.refs.forEach(({
|
|
5183
|
+
pageRef,
|
|
5184
|
+
mcid
|
|
5185
|
+
}) => {
|
|
5186
|
+
if (!this.dictionary.data.Pg) {
|
|
5187
|
+
this.dictionary.data.Pg = pageRef;
|
|
5188
|
+
}
|
|
5189
|
+
|
|
5190
|
+
if (this.dictionary.data.Pg === pageRef) {
|
|
5191
|
+
this.dictionary.data.K.push(mcid);
|
|
5192
|
+
} else {
|
|
5193
|
+
this.dictionary.data.K.push({
|
|
5194
|
+
Type: "MCR",
|
|
5195
|
+
Pg: pageRef,
|
|
5196
|
+
MCID: mcid
|
|
5197
|
+
});
|
|
5198
|
+
}
|
|
5199
|
+
});
|
|
5200
|
+
}
|
|
5201
|
+
}
|
|
5202
|
+
|
|
5203
|
+
}
|
|
5204
|
+
|
|
5205
|
+
/*
|
|
5206
|
+
PDFNumberTree - represents a number tree object
|
|
5207
|
+
*/
|
|
5208
|
+
|
|
5209
|
+
class PDFNumberTree extends PDFTree {
|
|
5210
|
+
_compareKeys(a, b) {
|
|
5211
|
+
return parseInt(a) - parseInt(b);
|
|
5212
|
+
}
|
|
5213
|
+
|
|
5214
|
+
_keysName() {
|
|
5215
|
+
return "Nums";
|
|
5216
|
+
}
|
|
5217
|
+
|
|
5218
|
+
_dataForKey(k) {
|
|
5219
|
+
return parseInt(k);
|
|
5220
|
+
}
|
|
5221
|
+
|
|
5222
|
+
}
|
|
5223
|
+
|
|
5224
|
+
var MarkingsMixin = {
|
|
5225
|
+
initMarkings(options) {
|
|
5226
|
+
this.structChildren = [];
|
|
5227
|
+
|
|
5228
|
+
if (options.tagged) {
|
|
5229
|
+
this.getMarkInfoDictionary().data.Marked = true;
|
|
5230
|
+
this.getStructTreeRoot();
|
|
5231
|
+
}
|
|
5232
|
+
},
|
|
5233
|
+
|
|
5234
|
+
markContent(tag, options = null) {
|
|
5235
|
+
if (tag === 'Artifact' || options && options.mcid) {
|
|
5236
|
+
let toClose = 0;
|
|
5237
|
+
this.page.markings.forEach(marking => {
|
|
5238
|
+
if (toClose || marking.structContent || marking.tag === 'Artifact') {
|
|
5239
|
+
toClose++;
|
|
5240
|
+
}
|
|
5241
|
+
});
|
|
5242
|
+
|
|
5243
|
+
while (toClose--) {
|
|
5244
|
+
this.endMarkedContent();
|
|
5245
|
+
}
|
|
5246
|
+
}
|
|
5247
|
+
|
|
5248
|
+
if (!options) {
|
|
5249
|
+
this.page.markings.push({
|
|
5250
|
+
tag
|
|
5251
|
+
});
|
|
5252
|
+
this.addContent(`/${tag} BMC`);
|
|
5253
|
+
return this;
|
|
5254
|
+
}
|
|
5255
|
+
|
|
5256
|
+
this.page.markings.push({
|
|
5257
|
+
tag,
|
|
5258
|
+
options
|
|
5259
|
+
});
|
|
5260
|
+
const dictionary = {};
|
|
5261
|
+
|
|
5262
|
+
if (typeof options.mcid !== 'undefined') {
|
|
5263
|
+
dictionary.MCID = options.mcid;
|
|
5264
|
+
}
|
|
5265
|
+
|
|
5266
|
+
if (tag === 'Artifact') {
|
|
5267
|
+
if (typeof options.type === 'string') {
|
|
5268
|
+
dictionary.Type = options.type;
|
|
5269
|
+
}
|
|
5270
|
+
|
|
5271
|
+
if (Array.isArray(options.bbox)) {
|
|
5272
|
+
dictionary.BBox = [options.bbox[0], this.page.height - options.bbox[3], options.bbox[2], this.page.height - options.bbox[1]];
|
|
5273
|
+
}
|
|
5274
|
+
|
|
5275
|
+
if (Array.isArray(options.attached) && options.attached.every(val => typeof val === 'string')) {
|
|
5276
|
+
dictionary.Attached = options.attached;
|
|
5277
|
+
}
|
|
5278
|
+
}
|
|
5279
|
+
|
|
5280
|
+
if (tag === 'Span') {
|
|
5281
|
+
if (options.lang) {
|
|
5282
|
+
dictionary.Lang = new String(options.lang);
|
|
5283
|
+
}
|
|
5284
|
+
|
|
5285
|
+
if (options.alt) {
|
|
5286
|
+
dictionary.Alt = new String(options.alt);
|
|
5287
|
+
}
|
|
5288
|
+
|
|
5289
|
+
if (options.expanded) {
|
|
5290
|
+
dictionary.E = new String(options.expanded);
|
|
5291
|
+
}
|
|
5292
|
+
|
|
5293
|
+
if (options.actual) {
|
|
5294
|
+
dictionary.ActualText = new String(options.actual);
|
|
5295
|
+
}
|
|
5296
|
+
}
|
|
5297
|
+
|
|
5298
|
+
this.addContent(`/${tag} ${PDFObject.convert(dictionary)} BDC`);
|
|
5299
|
+
return this;
|
|
5300
|
+
},
|
|
5301
|
+
|
|
5302
|
+
markStructureContent(tag, options = {}) {
|
|
5303
|
+
const pageStructParents = this.getStructParentTree().get(this.page.structParentTreeKey);
|
|
5304
|
+
const mcid = pageStructParents.length;
|
|
5305
|
+
pageStructParents.push(null);
|
|
5306
|
+
this.markContent(tag, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
5307
|
+
mcid
|
|
5308
|
+
}));
|
|
5309
|
+
const structContent = new PDFStructureContent(this.page.dictionary, mcid);
|
|
5310
|
+
this.page.markings.slice(-1)[0].structContent = structContent;
|
|
5311
|
+
return structContent;
|
|
5312
|
+
},
|
|
5313
|
+
|
|
5314
|
+
endMarkedContent() {
|
|
5315
|
+
this.page.markings.pop();
|
|
5316
|
+
this.addContent('EMC');
|
|
5317
|
+
return this;
|
|
5318
|
+
},
|
|
5319
|
+
|
|
5320
|
+
struct(type, options = {}, children = null) {
|
|
5321
|
+
return new PDFStructureElement(this, type, options, children);
|
|
5322
|
+
},
|
|
5323
|
+
|
|
5324
|
+
addStructure(structElem) {
|
|
5325
|
+
const structTreeRoot = this.getStructTreeRoot();
|
|
5326
|
+
structElem.setParent(structTreeRoot);
|
|
5327
|
+
structElem.setAttached();
|
|
5328
|
+
this.structChildren.push(structElem);
|
|
5329
|
+
|
|
5330
|
+
if (!structTreeRoot.data.K) {
|
|
5331
|
+
structTreeRoot.data.K = [];
|
|
5332
|
+
}
|
|
5333
|
+
|
|
5334
|
+
structTreeRoot.data.K.push(structElem.dictionary);
|
|
5335
|
+
return this;
|
|
5336
|
+
},
|
|
5337
|
+
|
|
5338
|
+
initPageMarkings(pageMarkings) {
|
|
5339
|
+
pageMarkings.forEach(marking => {
|
|
5340
|
+
if (marking.structContent) {
|
|
5341
|
+
const structContent = marking.structContent;
|
|
5342
|
+
const newStructContent = this.markStructureContent(marking.tag, marking.options);
|
|
5343
|
+
structContent.push(newStructContent);
|
|
5344
|
+
this.page.markings.slice(-1)[0].structContent = structContent;
|
|
5345
|
+
} else {
|
|
5346
|
+
this.markContent(marking.tag, marking.options);
|
|
5347
|
+
}
|
|
5348
|
+
});
|
|
5349
|
+
},
|
|
5350
|
+
|
|
5351
|
+
endPageMarkings(page) {
|
|
5352
|
+
const pageMarkings = page.markings;
|
|
5353
|
+
pageMarkings.forEach(() => page.write('EMC'));
|
|
5354
|
+
page.markings = [];
|
|
5355
|
+
return pageMarkings;
|
|
5356
|
+
},
|
|
5357
|
+
|
|
5358
|
+
getMarkInfoDictionary() {
|
|
5359
|
+
if (!this._root.data.MarkInfo) {
|
|
5360
|
+
this._root.data.MarkInfo = this.ref({});
|
|
5361
|
+
}
|
|
5362
|
+
|
|
5363
|
+
return this._root.data.MarkInfo;
|
|
5364
|
+
},
|
|
5365
|
+
|
|
5366
|
+
getStructTreeRoot() {
|
|
5367
|
+
if (!this._root.data.StructTreeRoot) {
|
|
5368
|
+
this._root.data.StructTreeRoot = this.ref({
|
|
5369
|
+
Type: 'StructTreeRoot',
|
|
5370
|
+
ParentTree: new PDFNumberTree(),
|
|
5371
|
+
ParentTreeNextKey: 0
|
|
5372
|
+
});
|
|
5373
|
+
}
|
|
5374
|
+
|
|
5375
|
+
return this._root.data.StructTreeRoot;
|
|
5376
|
+
},
|
|
5377
|
+
|
|
5378
|
+
getStructParentTree() {
|
|
5379
|
+
return this.getStructTreeRoot().data.ParentTree;
|
|
5380
|
+
},
|
|
5381
|
+
|
|
5382
|
+
createStructParentTreeNextKey() {
|
|
5383
|
+
// initialise the MarkInfo dictionary
|
|
5384
|
+
this.getMarkInfoDictionary();
|
|
5385
|
+
const structTreeRoot = this.getStructTreeRoot();
|
|
5386
|
+
const key = structTreeRoot.data.ParentTreeNextKey++;
|
|
5387
|
+
structTreeRoot.data.ParentTree.add(key, []);
|
|
5388
|
+
return key;
|
|
5389
|
+
},
|
|
5390
|
+
|
|
5391
|
+
endMarkings() {
|
|
5392
|
+
const structTreeRoot = this._root.data.StructTreeRoot;
|
|
5393
|
+
|
|
5394
|
+
if (structTreeRoot) {
|
|
5395
|
+
structTreeRoot.end();
|
|
5396
|
+
this.structChildren.forEach(structElem => structElem.end());
|
|
5397
|
+
}
|
|
5398
|
+
|
|
5399
|
+
if (this._root.data.MarkInfo) {
|
|
5400
|
+
this._root.data.MarkInfo.end();
|
|
5401
|
+
}
|
|
5402
|
+
}
|
|
5403
|
+
|
|
5404
|
+
};
|
|
5405
|
+
|
|
4822
5406
|
const FIELD_FLAGS = {
|
|
4823
5407
|
readOnly: 1,
|
|
4824
5408
|
required: 2,
|
|
@@ -4864,9 +5448,9 @@ const FORMAT_DEFAULT = {
|
|
|
4864
5448
|
}
|
|
4865
5449
|
};
|
|
4866
5450
|
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.
|
|
5451
|
+
/**
|
|
5452
|
+
* Must call if adding AcroForms to a document. Must also call font() before
|
|
5453
|
+
* this method to set the default font.
|
|
4870
5454
|
*/
|
|
4871
5455
|
initForm() {
|
|
4872
5456
|
if (!this._font) {
|
|
@@ -4892,8 +5476,8 @@ var AcroFormMixin = {
|
|
|
4892
5476
|
return this;
|
|
4893
5477
|
},
|
|
4894
5478
|
|
|
4895
|
-
/**
|
|
4896
|
-
* Called automatically by document.js
|
|
5479
|
+
/**
|
|
5480
|
+
* Called automatically by document.js
|
|
4897
5481
|
*/
|
|
4898
5482
|
endAcroForm() {
|
|
4899
5483
|
if (this._root.data.AcroForm) {
|
|
@@ -4927,12 +5511,12 @@ var AcroFormMixin = {
|
|
|
4927
5511
|
return this;
|
|
4928
5512
|
},
|
|
4929
5513
|
|
|
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
|
|
5514
|
+
/**
|
|
5515
|
+
* Creates and adds a form field to the document. Form fields are intermediate
|
|
5516
|
+
* nodes in a PDF form that are used to specify form name heirarchy and form
|
|
5517
|
+
* value defaults.
|
|
5518
|
+
* @param {string} name - field name (T attribute in field dictionary)
|
|
5519
|
+
* @param {object} options - other attributes to include in field dictionary
|
|
4936
5520
|
*/
|
|
4937
5521
|
formField(name, options = {}) {
|
|
4938
5522
|
let fieldDict = this._fieldDict(name, null, options);
|
|
@@ -4944,16 +5528,16 @@ var AcroFormMixin = {
|
|
|
4944
5528
|
return fieldRef;
|
|
4945
5529
|
},
|
|
4946
5530
|
|
|
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
|
|
5531
|
+
/**
|
|
5532
|
+
* Creates and adds a Form Annotation to the document. Form annotations are
|
|
5533
|
+
* called Widget annotations internally within a PDF file.
|
|
5534
|
+
* @param {string} name - form field name (T attribute of widget annotation
|
|
5535
|
+
* dictionary)
|
|
5536
|
+
* @param {number} x
|
|
5537
|
+
* @param {number} y
|
|
5538
|
+
* @param {number} w
|
|
5539
|
+
* @param {number} h
|
|
5540
|
+
* @param {object} options
|
|
4957
5541
|
*/
|
|
4958
5542
|
formAnnotation(name, type, x, y, w, h, options = {}) {
|
|
4959
5543
|
let fieldDict = this._fieldDict(name, type, options);
|
|
@@ -5177,9 +5761,11 @@ var AcroFormMixin = {
|
|
|
5177
5761
|
if (this._acroform.defaultFont !== this._font.name) {
|
|
5178
5762
|
options.DR = {
|
|
5179
5763
|
Font: {}
|
|
5180
|
-
};
|
|
5764
|
+
}; // Get the fontSize option. If not set use auto sizing
|
|
5765
|
+
|
|
5766
|
+
const fontSize = options.fontSize || 0;
|
|
5181
5767
|
options.DR.Font[this._font.id] = this._font.ref();
|
|
5182
|
-
options.DA = new String(`/${this._font.id}
|
|
5768
|
+
options.DA = new String(`/${this._font.id} ${fontSize} Tf 0 g`);
|
|
5183
5769
|
}
|
|
5184
5770
|
|
|
5185
5771
|
return options;
|
|
@@ -5211,8 +5797,6 @@ var AcroFormMixin = {
|
|
|
5211
5797
|
options.Opt = select;
|
|
5212
5798
|
}
|
|
5213
5799
|
|
|
5214
|
-
if (options.value || options.defaultValue) ;
|
|
5215
|
-
|
|
5216
5800
|
Object.keys(VALUE_MAP).forEach(key => {
|
|
5217
5801
|
if (options[key] !== undefined) {
|
|
5218
5802
|
options[VALUE_MAP[key]] = options[key];
|
|
@@ -5240,9 +5824,129 @@ var AcroFormMixin = {
|
|
|
5240
5824
|
|
|
5241
5825
|
};
|
|
5242
5826
|
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5827
|
+
var AttachmentsMixin = {
|
|
5828
|
+
/**
|
|
5829
|
+
* Embed contents of `src` in PDF
|
|
5830
|
+
* @param {Buffer | ArrayBuffer | string} src input Buffer, ArrayBuffer, base64 encoded string or path to file
|
|
5831
|
+
* @param {object} options
|
|
5832
|
+
* * options.name: filename to be shown in PDF, will use `src` if none set
|
|
5833
|
+
* * options.type: filetype to be shown in PDF
|
|
5834
|
+
* * options.description: description to be shown in PDF
|
|
5835
|
+
* * options.hidden: if true, do not add attachment to EmbeddedFiles dictionary. Useful for file attachment annotations
|
|
5836
|
+
* * options.creationDate: override creation date
|
|
5837
|
+
* * options.modifiedDate: override modified date
|
|
5838
|
+
* @returns filespec reference
|
|
5839
|
+
*/
|
|
5840
|
+
file(src, options = {}) {
|
|
5841
|
+
options.name = options.name || src;
|
|
5842
|
+
const refBody = {
|
|
5843
|
+
Type: 'EmbeddedFile',
|
|
5844
|
+
Params: {}
|
|
5845
|
+
};
|
|
5846
|
+
let data;
|
|
5847
|
+
|
|
5848
|
+
if (!src) {
|
|
5849
|
+
throw new Error('No src specified');
|
|
5850
|
+
}
|
|
5851
|
+
|
|
5852
|
+
if (Buffer.isBuffer(src)) {
|
|
5853
|
+
data = src;
|
|
5854
|
+
} else if (src instanceof ArrayBuffer) {
|
|
5855
|
+
data = Buffer.from(new Uint8Array(src));
|
|
5856
|
+
} else {
|
|
5857
|
+
let match;
|
|
5858
|
+
|
|
5859
|
+
if (match = /^data:(.*);base64,(.*)$/.exec(src)) {
|
|
5860
|
+
if (match[1]) {
|
|
5861
|
+
refBody.Subtype = match[1].replace('/', '#2F');
|
|
5862
|
+
}
|
|
5863
|
+
|
|
5864
|
+
data = Buffer.from(match[2], 'base64');
|
|
5865
|
+
} else {
|
|
5866
|
+
data = fs.readFileSync(src);
|
|
5867
|
+
|
|
5868
|
+
if (!data) {
|
|
5869
|
+
throw new Error(`Could not read contents of file at filepath ${src}`);
|
|
5870
|
+
} // update CreationDate and ModDate
|
|
5871
|
+
|
|
5872
|
+
|
|
5873
|
+
const {
|
|
5874
|
+
birthtime,
|
|
5875
|
+
ctime
|
|
5876
|
+
} = fs.statSync(src);
|
|
5877
|
+
refBody.Params.CreationDate = birthtime;
|
|
5878
|
+
refBody.Params.ModDate = ctime;
|
|
5879
|
+
}
|
|
5880
|
+
} // override creation date and modified date
|
|
5881
|
+
|
|
5882
|
+
|
|
5883
|
+
if (options.creationDate instanceof Date) {
|
|
5884
|
+
refBody.Params.CreationDate = options.creationDate;
|
|
5885
|
+
}
|
|
5886
|
+
|
|
5887
|
+
if (options.modifiedDate instanceof Date) {
|
|
5888
|
+
refBody.Params.ModDate = options.modifiedDate;
|
|
5889
|
+
} // add optional subtype
|
|
5890
|
+
|
|
5891
|
+
|
|
5892
|
+
if (options.type) {
|
|
5893
|
+
refBody.Subtype = options.type.replace('/', '#2F');
|
|
5894
|
+
} // add checksum and size information
|
|
5895
|
+
|
|
5896
|
+
|
|
5897
|
+
const checksum = CryptoJS.MD5(CryptoJS.lib.WordArray.create(new Uint8Array(data)));
|
|
5898
|
+
refBody.Params.CheckSum = new String(checksum);
|
|
5899
|
+
refBody.Params.Size = data.byteLength; // save some space when embedding the same file again
|
|
5900
|
+
// if a file with the same name and metadata exists, reuse its reference
|
|
5901
|
+
|
|
5902
|
+
let ref;
|
|
5903
|
+
if (!this._fileRegistry) this._fileRegistry = {};
|
|
5904
|
+
let file = this._fileRegistry[options.name];
|
|
5905
|
+
|
|
5906
|
+
if (file && isEqual(refBody, file)) {
|
|
5907
|
+
ref = file.ref;
|
|
5908
|
+
} else {
|
|
5909
|
+
ref = this.ref(refBody);
|
|
5910
|
+
ref.end(data);
|
|
5911
|
+
this._fileRegistry[options.name] = _objectSpread2(_objectSpread2({}, refBody), {}, {
|
|
5912
|
+
ref
|
|
5913
|
+
});
|
|
5914
|
+
} // add filespec for embedded file
|
|
5915
|
+
|
|
5916
|
+
|
|
5917
|
+
const fileSpecBody = {
|
|
5918
|
+
Type: 'Filespec',
|
|
5919
|
+
F: new String(options.name),
|
|
5920
|
+
EF: {
|
|
5921
|
+
F: ref
|
|
5922
|
+
},
|
|
5923
|
+
UF: new String(options.name)
|
|
5924
|
+
};
|
|
5925
|
+
|
|
5926
|
+
if (options.description) {
|
|
5927
|
+
fileSpecBody.Desc = new String(options.description);
|
|
5928
|
+
}
|
|
5929
|
+
|
|
5930
|
+
const filespec = this.ref(fileSpecBody);
|
|
5931
|
+
filespec.end();
|
|
5932
|
+
|
|
5933
|
+
if (!options.hidden) {
|
|
5934
|
+
this.addNamedEmbeddedFile(options.name, filespec);
|
|
5935
|
+
}
|
|
5936
|
+
|
|
5937
|
+
return filespec;
|
|
5938
|
+
}
|
|
5939
|
+
|
|
5940
|
+
};
|
|
5941
|
+
/** check two embedded file metadata objects for equality */
|
|
5942
|
+
|
|
5943
|
+
function isEqual(a, b) {
|
|
5944
|
+
return a.Subtype === b.Subtype && a.Params.CheckSum.toString() === b.Params.CheckSum.toString() && a.Params.Size === b.Params.Size && a.Params.CreationDate === b.Params.CreationDate && a.Params.ModDate === b.Params.ModDate;
|
|
5945
|
+
}
|
|
5946
|
+
|
|
5947
|
+
/*
|
|
5948
|
+
PDFDocument - represents an entire PDF document
|
|
5949
|
+
By Devon Govett
|
|
5246
5950
|
*/
|
|
5247
5951
|
|
|
5248
5952
|
class PDFDocument extends stream.Readable {
|
|
@@ -5294,7 +5998,12 @@ class PDFDocument extends stream.Readable {
|
|
|
5294
5998
|
Type: 'Catalog',
|
|
5295
5999
|
Pages,
|
|
5296
6000
|
Names
|
|
5297
|
-
});
|
|
6001
|
+
});
|
|
6002
|
+
|
|
6003
|
+
if (this.options.lang) {
|
|
6004
|
+
this._root.data.Lang = new String(this.options.lang);
|
|
6005
|
+
} // The current page
|
|
6006
|
+
|
|
5298
6007
|
|
|
5299
6008
|
this.page = null; // Initialize mixins
|
|
5300
6009
|
|
|
@@ -5303,7 +6012,8 @@ class PDFDocument extends stream.Readable {
|
|
|
5303
6012
|
this.initFonts(options.font);
|
|
5304
6013
|
this.initText();
|
|
5305
6014
|
this.initImages();
|
|
5306
|
-
this.initOutline();
|
|
6015
|
+
this.initOutline();
|
|
6016
|
+
this.initMarkings(options); // Initialize the metadata
|
|
5307
6017
|
|
|
5308
6018
|
this.info = {
|
|
5309
6019
|
Producer: 'PDFKit',
|
|
@@ -5316,6 +6026,12 @@ class PDFDocument extends stream.Readable {
|
|
|
5316
6026
|
const val = this.options.info[key];
|
|
5317
6027
|
this.info[key] = val;
|
|
5318
6028
|
}
|
|
6029
|
+
}
|
|
6030
|
+
|
|
6031
|
+
if (this.options.displayTitle) {
|
|
6032
|
+
this._root.data.ViewerPreferences = this.ref({
|
|
6033
|
+
DisplayDocTitle: true
|
|
6034
|
+
});
|
|
5319
6035
|
} // Generate file ID
|
|
5320
6036
|
|
|
5321
6037
|
|
|
@@ -5336,12 +6052,12 @@ class PDFDocument extends stream.Readable {
|
|
|
5336
6052
|
}
|
|
5337
6053
|
|
|
5338
6054
|
addPage(options) {
|
|
5339
|
-
// end the current page if needed
|
|
5340
6055
|
if (options == null) {
|
|
5341
6056
|
({
|
|
5342
6057
|
options
|
|
5343
6058
|
} = this);
|
|
5344
|
-
}
|
|
6059
|
+
} // end the current page if needed
|
|
6060
|
+
|
|
5345
6061
|
|
|
5346
6062
|
if (!this.options.bufferPages) {
|
|
5347
6063
|
this.flushPages();
|
|
@@ -5367,6 +6083,13 @@ class PDFDocument extends stream.Readable {
|
|
|
5367
6083
|
return this;
|
|
5368
6084
|
}
|
|
5369
6085
|
|
|
6086
|
+
continueOnNewPage(options) {
|
|
6087
|
+
const pageMarkings = this.endPageMarkings(this.page);
|
|
6088
|
+
this.addPage(options);
|
|
6089
|
+
this.initPageMarkings(pageMarkings);
|
|
6090
|
+
return this;
|
|
6091
|
+
}
|
|
6092
|
+
|
|
5370
6093
|
bufferedPageRange() {
|
|
5371
6094
|
return {
|
|
5372
6095
|
start: this._pageBufferStart,
|
|
@@ -5392,6 +6115,7 @@ class PDFDocument extends stream.Readable {
|
|
|
5392
6115
|
this._pageBufferStart += pages.length;
|
|
5393
6116
|
|
|
5394
6117
|
for (let page of pages) {
|
|
6118
|
+
this.endPageMarkings(page);
|
|
5395
6119
|
page.end();
|
|
5396
6120
|
}
|
|
5397
6121
|
}
|
|
@@ -5410,6 +6134,18 @@ class PDFDocument extends stream.Readable {
|
|
|
5410
6134
|
this._root.data.Names.data.Dests.add(name, args);
|
|
5411
6135
|
}
|
|
5412
6136
|
|
|
6137
|
+
addNamedEmbeddedFile(name, ref) {
|
|
6138
|
+
if (!this._root.data.Names.data.EmbeddedFiles) {
|
|
6139
|
+
// disabling /Limits for this tree fixes attachments not showing in Adobe Reader
|
|
6140
|
+
this._root.data.Names.data.EmbeddedFiles = new PDFNameTree({
|
|
6141
|
+
limits: false
|
|
6142
|
+
});
|
|
6143
|
+
} // add filespec to EmbeddedFiles
|
|
6144
|
+
|
|
6145
|
+
|
|
6146
|
+
this._root.data.Names.data.EmbeddedFiles.add(name, ref);
|
|
6147
|
+
}
|
|
6148
|
+
|
|
5413
6149
|
addNamedJavaScript(name, js) {
|
|
5414
6150
|
if (!this._root.data.Names.data.JavaScript) {
|
|
5415
6151
|
this._root.data.Names.data.JavaScript = new PDFNameTree();
|
|
@@ -5438,7 +6174,7 @@ class PDFDocument extends stream.Readable {
|
|
|
5438
6174
|
|
|
5439
6175
|
_write(data) {
|
|
5440
6176
|
if (!Buffer.isBuffer(data)) {
|
|
5441
|
-
data =
|
|
6177
|
+
data = Buffer.from(data + '\n', 'binary');
|
|
5442
6178
|
}
|
|
5443
6179
|
|
|
5444
6180
|
this.push(data);
|
|
@@ -5496,6 +6232,7 @@ Please pipe the document into a Node stream.\
|
|
|
5496
6232
|
}
|
|
5497
6233
|
|
|
5498
6234
|
this.endOutline();
|
|
6235
|
+
this.endMarkings();
|
|
5499
6236
|
|
|
5500
6237
|
this._root.end();
|
|
5501
6238
|
|
|
@@ -5505,6 +6242,10 @@ Please pipe the document into a Node stream.\
|
|
|
5505
6242
|
|
|
5506
6243
|
this.endAcroForm();
|
|
5507
6244
|
|
|
6245
|
+
if (this._root.data.ViewerPreferences) {
|
|
6246
|
+
this._root.data.ViewerPreferences.end();
|
|
6247
|
+
}
|
|
6248
|
+
|
|
5508
6249
|
if (this._security) {
|
|
5509
6250
|
this._security.end();
|
|
5510
6251
|
}
|
|
@@ -5516,7 +6257,7 @@ Please pipe the document into a Node stream.\
|
|
|
5516
6257
|
}
|
|
5517
6258
|
}
|
|
5518
6259
|
|
|
5519
|
-
_finalize(
|
|
6260
|
+
_finalize() {
|
|
5520
6261
|
// generate xref
|
|
5521
6262
|
const xRefOffset = this._offset;
|
|
5522
6263
|
|
|
@@ -5575,7 +6316,10 @@ mixin(TextMixin);
|
|
|
5575
6316
|
mixin(ImagesMixin);
|
|
5576
6317
|
mixin(AnnotationsMixin);
|
|
5577
6318
|
mixin(OutlineMixin);
|
|
6319
|
+
mixin(MarkingsMixin);
|
|
5578
6320
|
mixin(AcroFormMixin);
|
|
6321
|
+
mixin(AttachmentsMixin);
|
|
6322
|
+
PDFDocument.LineWrapper = LineWrapper;
|
|
5579
6323
|
|
|
5580
6324
|
module.exports = PDFDocument;
|
|
5581
6325
|
//# sourceMappingURL=pdfkit.js.map
|