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.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,13 +17,16 @@ class PDFAbstractReference {
|
|
|
17
17
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
/*
|
|
21
|
-
|
|
20
|
+
/*
|
|
21
|
+
PDFTree - abstract base class for name and number tree objects
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
class
|
|
24
|
+
class PDFTree {
|
|
25
25
|
constructor() {
|
|
26
|
-
|
|
26
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
27
|
+
this._items = {}; // disable /Limits output for this tree
|
|
28
|
+
|
|
29
|
+
this.limits = typeof options.limits === 'boolean' ? options.limits : true;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
add(key, val) {
|
|
@@ -36,19 +39,19 @@ class PDFNameTree {
|
|
|
36
39
|
|
|
37
40
|
toString() {
|
|
38
41
|
// Needs to be sorted by key
|
|
39
|
-
var sortedKeys = Object.keys(this._items).sort((a, b) =>
|
|
42
|
+
var sortedKeys = Object.keys(this._items).sort((a, b) => this._compareKeys(a, b));
|
|
40
43
|
var out = ['<<'];
|
|
41
44
|
|
|
42
|
-
if (sortedKeys.length > 1) {
|
|
45
|
+
if (this.limits && sortedKeys.length > 1) {
|
|
43
46
|
var first = sortedKeys[0],
|
|
44
47
|
last = sortedKeys[sortedKeys.length - 1];
|
|
45
|
-
out.push(" /Limits ".concat(PDFObject.convert([
|
|
48
|
+
out.push(" /Limits ".concat(PDFObject.convert([this._dataForKey(first), this._dataForKey(last)])));
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
out.push(
|
|
51
|
+
out.push(" /".concat(this._keysName(), " ["));
|
|
49
52
|
|
|
50
53
|
for (var key of sortedKeys) {
|
|
51
|
-
out.push(" ".concat(PDFObject.convert(
|
|
54
|
+
out.push(" ".concat(PDFObject.convert(this._dataForKey(key)), " ").concat(PDFObject.convert(this._items[key])));
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
out.push(']');
|
|
@@ -56,16 +59,32 @@ class PDFNameTree {
|
|
|
56
59
|
return out.join('\n');
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
_compareKeys()
|
|
63
|
+
/*a, b*/
|
|
64
|
+
{
|
|
65
|
+
throw new Error('Must be implemented by subclasses');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
_keysName() {
|
|
69
|
+
throw new Error('Must be implemented by subclasses');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
_dataForKey()
|
|
73
|
+
/*k*/
|
|
74
|
+
{
|
|
75
|
+
throw new Error('Must be implemented by subclasses');
|
|
76
|
+
}
|
|
77
|
+
|
|
59
78
|
}
|
|
60
79
|
|
|
61
|
-
/*
|
|
62
|
-
PDFObject - converts JavaScript types into their corresponding PDF types.
|
|
63
|
-
By Devon Govett
|
|
80
|
+
/*
|
|
81
|
+
PDFObject - converts JavaScript types into their corresponding PDF types.
|
|
82
|
+
By Devon Govett
|
|
64
83
|
*/
|
|
65
84
|
|
|
66
85
|
var pad = (str, length) => (Array(length + 1).join('0') + str).slice(-length);
|
|
67
86
|
|
|
68
|
-
var escapableRe = /[\n\r\t\b\f
|
|
87
|
+
var escapableRe = /[\n\r\t\b\f()\\]/g;
|
|
69
88
|
var escapable = {
|
|
70
89
|
'\n': '\\n',
|
|
71
90
|
'\r': '\\r',
|
|
@@ -133,14 +152,14 @@ class PDFObject {
|
|
|
133
152
|
return "(".concat(string, ")"); // Buffers are converted to PDF hex strings
|
|
134
153
|
} else if (Buffer.isBuffer(object)) {
|
|
135
154
|
return "<".concat(object.toString('hex'), ">");
|
|
136
|
-
} else if (object instanceof PDFAbstractReference || object instanceof
|
|
155
|
+
} else if (object instanceof PDFAbstractReference || object instanceof PDFTree) {
|
|
137
156
|
return object.toString();
|
|
138
157
|
} else if (object instanceof Date) {
|
|
139
158
|
var _string = "D:".concat(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
159
|
|
|
141
160
|
|
|
142
161
|
if (encryptFn) {
|
|
143
|
-
_string = encryptFn(
|
|
162
|
+
_string = encryptFn(Buffer.from(_string, 'ascii')).toString('binary'); // Escape characters as required by the spec
|
|
144
163
|
|
|
145
164
|
_string = _string.replace(escapableRe, c => escapable[c]);
|
|
146
165
|
}
|
|
@@ -176,9 +195,9 @@ class PDFObject {
|
|
|
176
195
|
|
|
177
196
|
}
|
|
178
197
|
|
|
179
|
-
/*
|
|
180
|
-
PDFReference - represents a reference to another object in the PDF object heirarchy
|
|
181
|
-
By Devon Govett
|
|
198
|
+
/*
|
|
199
|
+
PDFReference - represents a reference to another object in the PDF object heirarchy
|
|
200
|
+
By Devon Govett
|
|
182
201
|
*/
|
|
183
202
|
|
|
184
203
|
class PDFReference extends PDFAbstractReference {
|
|
@@ -196,7 +215,7 @@ class PDFReference extends PDFAbstractReference {
|
|
|
196
215
|
|
|
197
216
|
write(chunk) {
|
|
198
217
|
if (!Buffer.isBuffer(chunk)) {
|
|
199
|
-
chunk =
|
|
218
|
+
chunk = Buffer.from(chunk + '\n', 'binary');
|
|
200
219
|
}
|
|
201
220
|
|
|
202
221
|
this.uncompressedLength += chunk.length;
|
|
@@ -264,9 +283,9 @@ class PDFReference extends PDFAbstractReference {
|
|
|
264
283
|
|
|
265
284
|
}
|
|
266
285
|
|
|
267
|
-
/*
|
|
268
|
-
PDFPage - represents a single page in the PDF document
|
|
269
|
-
By Devon Govett
|
|
286
|
+
/*
|
|
287
|
+
PDFPage - represents a single page in the PDF document
|
|
288
|
+
By Devon Govett
|
|
270
289
|
*/
|
|
271
290
|
var DEFAULT_MARGINS = {
|
|
272
291
|
top: 72,
|
|
@@ -362,7 +381,8 @@ class PDFPage {
|
|
|
362
381
|
Contents: this.content,
|
|
363
382
|
Resources: this.resources
|
|
364
383
|
});
|
|
365
|
-
|
|
384
|
+
this.markings = [];
|
|
385
|
+
} // Lazily create these objects
|
|
366
386
|
|
|
367
387
|
|
|
368
388
|
get fonts() {
|
|
@@ -390,6 +410,11 @@ class PDFPage {
|
|
|
390
410
|
return data.Annots != null ? data.Annots : data.Annots = [];
|
|
391
411
|
}
|
|
392
412
|
|
|
413
|
+
get structParentTreeKey() {
|
|
414
|
+
var data = this.dictionary.data;
|
|
415
|
+
return data.StructParents != null ? data.StructParents : data.StructParents = this.document.createStructParentTreeNextKey();
|
|
416
|
+
}
|
|
417
|
+
|
|
393
418
|
maxY() {
|
|
394
419
|
return this.height - this.margins.bottom;
|
|
395
420
|
}
|
|
@@ -406,11 +431,30 @@ class PDFPage {
|
|
|
406
431
|
|
|
407
432
|
}
|
|
408
433
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
434
|
+
/*
|
|
435
|
+
PDFNameTree - represents a name tree object
|
|
436
|
+
*/
|
|
437
|
+
|
|
438
|
+
class PDFNameTree extends PDFTree {
|
|
439
|
+
_compareKeys(a, b) {
|
|
440
|
+
return a.localeCompare(b);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
_keysName() {
|
|
444
|
+
return "Names";
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
_dataForKey(k) {
|
|
448
|
+
return new String(k);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Check if value is in a range group.
|
|
455
|
+
* @param {number} value
|
|
456
|
+
* @param {number[]} rangeGroup
|
|
457
|
+
* @returns {boolean}
|
|
414
458
|
*/
|
|
415
459
|
function inRange(value, rangeGroup) {
|
|
416
460
|
if (value < rangeGroup[0]) return false;
|
|
@@ -438,34 +482,28 @@ function inRange(value, rangeGroup) {
|
|
|
438
482
|
return false;
|
|
439
483
|
}
|
|
440
484
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
* A.1 Unassigned code points in Unicode 3.2
|
|
445
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-A.1
|
|
485
|
+
/**
|
|
486
|
+
* A.1 Unassigned code points in Unicode 3.2
|
|
487
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-A.1
|
|
446
488
|
*/
|
|
447
489
|
|
|
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];
|
|
449
|
-
/* eslint-enable */
|
|
490
|
+
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]; // prettier-ignore-end
|
|
450
491
|
|
|
451
|
-
var isUnassignedCodePoint = character => inRange(character, unassigned_code_points);
|
|
452
|
-
/* eslint-disable prettier/prettier */
|
|
492
|
+
var isUnassignedCodePoint = character => inRange(character, unassigned_code_points); // prettier-ignore-start
|
|
453
493
|
|
|
454
|
-
/**
|
|
455
|
-
* B.1 Commonly mapped to nothing
|
|
456
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-B.1
|
|
494
|
+
/**
|
|
495
|
+
* B.1 Commonly mapped to nothing
|
|
496
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-B.1
|
|
457
497
|
*/
|
|
458
498
|
|
|
459
499
|
|
|
460
|
-
var 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];
|
|
461
|
-
/* eslint-enable */
|
|
500
|
+
var 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
|
|
462
501
|
|
|
463
|
-
var isCommonlyMappedToNothing = character => inRange(character, commonly_mapped_to_nothing);
|
|
464
|
-
/* eslint-disable prettier/prettier */
|
|
502
|
+
var isCommonlyMappedToNothing = character => inRange(character, commonly_mapped_to_nothing); // prettier-ignore-start
|
|
465
503
|
|
|
466
|
-
/**
|
|
467
|
-
* C.1.2 Non-ASCII space characters
|
|
468
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.1.2
|
|
504
|
+
/**
|
|
505
|
+
* C.1.2 Non-ASCII space characters
|
|
506
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.1.2
|
|
469
507
|
*/
|
|
470
508
|
|
|
471
509
|
|
|
@@ -503,17 +541,15 @@ var non_ASCII_space_characters = [0x00a0, 0x00a0
|
|
|
503
541
|
/* MEDIUM MATHEMATICAL SPACE */
|
|
504
542
|
, 0x3000, 0x3000
|
|
505
543
|
/* IDEOGRAPHIC SPACE */
|
|
506
|
-
];
|
|
507
|
-
/* eslint-enable */
|
|
544
|
+
]; // prettier-ignore-end
|
|
508
545
|
|
|
509
|
-
var isNonASCIISpaceCharacter = character => inRange(character, non_ASCII_space_characters);
|
|
510
|
-
/* eslint-disable prettier/prettier */
|
|
546
|
+
var isNonASCIISpaceCharacter = character => inRange(character, non_ASCII_space_characters); // prettier-ignore-start
|
|
511
547
|
|
|
512
548
|
|
|
513
549
|
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
|
|
550
|
+
/**
|
|
551
|
+
* C.2.2 Non-ASCII control characters
|
|
552
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.2.2
|
|
517
553
|
*/
|
|
518
554
|
0x0080, 0x009f
|
|
519
555
|
/* [CONTROL CHARACTERS] */
|
|
@@ -549,9 +585,9 @@ var non_ASCII_controls_characters = [
|
|
|
549
585
|
/* [MUSICAL CONTROL CHARACTERS] */
|
|
550
586
|
];
|
|
551
587
|
var non_character_codepoints = [
|
|
552
|
-
/**
|
|
553
|
-
* C.4 Non-character code points
|
|
554
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.4
|
|
588
|
+
/**
|
|
589
|
+
* C.4 Non-character code points
|
|
590
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.4
|
|
555
591
|
*/
|
|
556
592
|
0xfdd0, 0xfdef
|
|
557
593
|
/* [NONCHARACTER CODE POINTS] */
|
|
@@ -588,23 +624,23 @@ var non_character_codepoints = [
|
|
|
588
624
|
, 0x10fffe, 0x10ffff
|
|
589
625
|
/* [NONCHARACTER CODE POINTS] */
|
|
590
626
|
];
|
|
591
|
-
/**
|
|
592
|
-
* 2.3. Prohibited Output
|
|
627
|
+
/**
|
|
628
|
+
* 2.3. Prohibited Output
|
|
593
629
|
*/
|
|
594
630
|
|
|
595
631
|
var prohibited_characters = [
|
|
596
|
-
/**
|
|
597
|
-
* C.2.1 ASCII control characters
|
|
598
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.2.1
|
|
632
|
+
/**
|
|
633
|
+
* C.2.1 ASCII control characters
|
|
634
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.2.1
|
|
599
635
|
*/
|
|
600
636
|
0, 0x001f
|
|
601
637
|
/* [CONTROL CHARACTERS] */
|
|
602
638
|
, 0x007f, 0x007f
|
|
603
639
|
/* DELETE */
|
|
604
640
|
,
|
|
605
|
-
/**
|
|
606
|
-
* C.8 Change display properties or are deprecated
|
|
607
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.8
|
|
641
|
+
/**
|
|
642
|
+
* C.8 Change display properties or are deprecated
|
|
643
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.8
|
|
608
644
|
*/
|
|
609
645
|
0x0340, 0x0340
|
|
610
646
|
/* COMBINING GRAVE TONE MARK */
|
|
@@ -637,28 +673,28 @@ var prohibited_characters = [
|
|
|
637
673
|
, 0x206f, 0x206f
|
|
638
674
|
/* NOMINAL DIGIT SHAPES */
|
|
639
675
|
,
|
|
640
|
-
/**
|
|
641
|
-
* C.7 Inappropriate for canonical representation
|
|
642
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.7
|
|
676
|
+
/**
|
|
677
|
+
* C.7 Inappropriate for canonical representation
|
|
678
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.7
|
|
643
679
|
*/
|
|
644
680
|
0x2ff0, 0x2ffb
|
|
645
681
|
/* [IDEOGRAPHIC DESCRIPTION CHARACTERS] */
|
|
646
682
|
,
|
|
647
|
-
/**
|
|
648
|
-
* C.5 Surrogate codes
|
|
649
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.5
|
|
683
|
+
/**
|
|
684
|
+
* C.5 Surrogate codes
|
|
685
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.5
|
|
650
686
|
*/
|
|
651
687
|
0xd800, 0xdfff,
|
|
652
|
-
/**
|
|
653
|
-
* C.3 Private use
|
|
654
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.3
|
|
688
|
+
/**
|
|
689
|
+
* C.3 Private use
|
|
690
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.3
|
|
655
691
|
*/
|
|
656
692
|
0xe000, 0xf8ff
|
|
657
693
|
/* [PRIVATE USE, PLANE 0] */
|
|
658
694
|
,
|
|
659
|
-
/**
|
|
660
|
-
* C.6 Inappropriate for plain text
|
|
661
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.6
|
|
695
|
+
/**
|
|
696
|
+
* C.6 Inappropriate for plain text
|
|
697
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.6
|
|
662
698
|
*/
|
|
663
699
|
0xfff9, 0xfff9
|
|
664
700
|
/* INTERLINEAR ANNOTATION ANCHOR */
|
|
@@ -671,61 +707,56 @@ var prohibited_characters = [
|
|
|
671
707
|
, 0xfffd, 0xfffd
|
|
672
708
|
/* REPLACEMENT CHARACTER */
|
|
673
709
|
,
|
|
674
|
-
/**
|
|
675
|
-
* C.9 Tagging characters
|
|
676
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.9
|
|
710
|
+
/**
|
|
711
|
+
* C.9 Tagging characters
|
|
712
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.9
|
|
677
713
|
*/
|
|
678
714
|
0xe0001, 0xe0001
|
|
679
715
|
/* LANGUAGE TAG */
|
|
680
716
|
, 0xe0020, 0xe007f
|
|
681
717
|
/* [TAGGING CHARACTERS] */
|
|
682
718
|
,
|
|
683
|
-
/**
|
|
684
|
-
* C.3 Private use
|
|
685
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-C.3
|
|
719
|
+
/**
|
|
720
|
+
* C.3 Private use
|
|
721
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-C.3
|
|
686
722
|
*/
|
|
687
723
|
0xf0000, 0xffffd
|
|
688
724
|
/* [PRIVATE USE, PLANE 15] */
|
|
689
725
|
, 0x100000, 0x10fffd
|
|
690
726
|
/* [PRIVATE USE, PLANE 16] */
|
|
691
|
-
];
|
|
692
|
-
/* eslint-enable */
|
|
727
|
+
]; // prettier-ignore-end
|
|
693
728
|
|
|
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
|
-
/* eslint-disable prettier/prettier */
|
|
729
|
+
var 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
|
|
696
730
|
|
|
697
|
-
/**
|
|
698
|
-
* D.1 Characters with bidirectional property "R" or "AL"
|
|
699
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-D.1
|
|
731
|
+
/**
|
|
732
|
+
* D.1 Characters with bidirectional property "R" or "AL"
|
|
733
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-D.1
|
|
700
734
|
*/
|
|
701
735
|
|
|
702
736
|
|
|
703
|
-
var 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];
|
|
704
|
-
/* eslint-enable */
|
|
737
|
+
var 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
|
|
705
738
|
|
|
706
|
-
var isBidirectionalRAL = character => inRange(character, bidirectional_r_al);
|
|
707
|
-
/* eslint-disable prettier/prettier */
|
|
739
|
+
var isBidirectionalRAL = character => inRange(character, bidirectional_r_al); // prettier-ignore-start
|
|
708
740
|
|
|
709
|
-
/**
|
|
710
|
-
* D.2 Characters with bidirectional property "L"
|
|
711
|
-
* @link https://tools.ietf.org/html/rfc3454#appendix-D.2
|
|
741
|
+
/**
|
|
742
|
+
* D.2 Characters with bidirectional property "L"
|
|
743
|
+
* @link https://tools.ietf.org/html/rfc3454#appendix-D.2
|
|
712
744
|
*/
|
|
713
745
|
|
|
714
746
|
|
|
715
|
-
var 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];
|
|
716
|
-
/* eslint-enable */
|
|
747
|
+
var 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
|
|
717
748
|
|
|
718
749
|
var isBidirectionalL = character => inRange(character, bidirectional_l);
|
|
719
750
|
|
|
720
|
-
/**
|
|
721
|
-
* non-ASCII space characters [StringPrep, C.1.2] that can be
|
|
722
|
-
* mapped to SPACE (U+0020)
|
|
751
|
+
/**
|
|
752
|
+
* non-ASCII space characters [StringPrep, C.1.2] that can be
|
|
753
|
+
* mapped to SPACE (U+0020)
|
|
723
754
|
*/
|
|
724
755
|
|
|
725
756
|
var mapping2space = isNonASCIISpaceCharacter;
|
|
726
|
-
/**
|
|
727
|
-
* the "commonly mapped to nothing" characters [StringPrep, B.1]
|
|
728
|
-
* that can be mapped to nothing.
|
|
757
|
+
/**
|
|
758
|
+
* the "commonly mapped to nothing" characters [StringPrep, B.1]
|
|
759
|
+
* that can be mapped to nothing.
|
|
729
760
|
*/
|
|
730
761
|
|
|
731
762
|
var mapping2nothing = isCommonlyMappedToNothing; // utils
|
|
@@ -735,12 +766,12 @@ var getCodePoint = character => character.codePointAt(0);
|
|
|
735
766
|
var first = x => x[0];
|
|
736
767
|
|
|
737
768
|
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[]}
|
|
769
|
+
/**
|
|
770
|
+
* Convert provided string into an array of Unicode Code Points.
|
|
771
|
+
* Based on https://stackoverflow.com/a/21409165/1556249
|
|
772
|
+
* and https://www.npmjs.com/package/code-point-at.
|
|
773
|
+
* @param {string} input
|
|
774
|
+
* @returns {number[]}
|
|
744
775
|
*/
|
|
745
776
|
|
|
746
777
|
|
|
@@ -766,12 +797,12 @@ function toCodePoints(input) {
|
|
|
766
797
|
|
|
767
798
|
return codepoints;
|
|
768
799
|
}
|
|
769
|
-
/**
|
|
770
|
-
* SASLprep.
|
|
771
|
-
* @param {string} input
|
|
772
|
-
* @param {Object} opts
|
|
773
|
-
* @param {boolean} opts.allowUnassigned
|
|
774
|
-
* @returns {string}
|
|
800
|
+
/**
|
|
801
|
+
* SASLprep.
|
|
802
|
+
* @param {string} input
|
|
803
|
+
* @param {Object} opts
|
|
804
|
+
* @param {boolean} opts.allowUnassigned
|
|
805
|
+
* @returns {string}
|
|
775
806
|
*/
|
|
776
807
|
|
|
777
808
|
|
|
@@ -817,10 +848,10 @@ function saslprep(input) {
|
|
|
817
848
|
if (hasBidiRAL && hasBidiL) {
|
|
818
849
|
throw new Error('String must not contain RandALCat and LCat at the same time,' + ' see https://tools.ietf.org/html/rfc3454#section-6');
|
|
819
850
|
}
|
|
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.
|
|
851
|
+
/**
|
|
852
|
+
* 4.2 If a string contains any RandALCat character, a RandALCat
|
|
853
|
+
* character MUST be the first character of the string, and a
|
|
854
|
+
* RandALCat character MUST be the last character of the string.
|
|
824
855
|
*/
|
|
825
856
|
|
|
826
857
|
|
|
@@ -834,9 +865,9 @@ function saslprep(input) {
|
|
|
834
865
|
return normalized_input;
|
|
835
866
|
}
|
|
836
867
|
|
|
837
|
-
/*
|
|
838
|
-
PDFSecurity - represents PDF security settings
|
|
839
|
-
By Yang Liu <hi@zesik.com>
|
|
868
|
+
/*
|
|
869
|
+
PDFSecurity - represents PDF security settings
|
|
870
|
+
By Yang Liu <hi@zesik.com>
|
|
840
871
|
*/
|
|
841
872
|
|
|
842
873
|
class PDFSecurity {
|
|
@@ -845,11 +876,12 @@ class PDFSecurity {
|
|
|
845
876
|
var infoStr = "".concat(info.CreationDate.getTime(), "\n");
|
|
846
877
|
|
|
847
878
|
for (var key in info) {
|
|
879
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
848
880
|
if (!info.hasOwnProperty(key)) {
|
|
849
881
|
continue;
|
|
850
882
|
}
|
|
851
883
|
|
|
852
|
-
infoStr += "".concat(key, ": ").concat(info[key], "\n");
|
|
884
|
+
infoStr += "".concat(key, ": ").concat(info[key].valueOf(), "\n");
|
|
853
885
|
}
|
|
854
886
|
|
|
855
887
|
return wordArrayToBuffer(CryptoJS.MD5(infoStr));
|
|
@@ -984,7 +1016,7 @@ class PDFSecurity {
|
|
|
984
1016
|
|
|
985
1017
|
_setupEncryptionV5(encDict, options) {
|
|
986
1018
|
this.keyBits = 256;
|
|
987
|
-
var permissions = getPermissionsR3(options);
|
|
1019
|
+
var permissions = getPermissionsR3(options.permissions);
|
|
988
1020
|
var processedUserPassword = processPasswordR5(options.userPassword);
|
|
989
1021
|
var processedOwnerPassword = options.ownerPassword ? processPasswordR5(options.ownerPassword) : processedUserPassword;
|
|
990
1022
|
this.encryptionKey = getEncryptionKeyR5(PDFSecurity.generateRandomWordArray);
|
|
@@ -1220,7 +1252,7 @@ function getEncryptedPermissionsR5(permissions, encryptionKey, generateRandomWor
|
|
|
1220
1252
|
|
|
1221
1253
|
function processPasswordR2R3R4() {
|
|
1222
1254
|
var password = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
1223
|
-
var out =
|
|
1255
|
+
var out = Buffer.alloc(32);
|
|
1224
1256
|
var length = password.length;
|
|
1225
1257
|
var index = 0;
|
|
1226
1258
|
|
|
@@ -1247,7 +1279,7 @@ function processPasswordR5() {
|
|
|
1247
1279
|
var password = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
1248
1280
|
password = unescape(encodeURIComponent(saslprep(password)));
|
|
1249
1281
|
var length = Math.min(127, password.length);
|
|
1250
|
-
var out =
|
|
1282
|
+
var out = Buffer.alloc(length);
|
|
1251
1283
|
|
|
1252
1284
|
for (var i = 0; i < length; i++) {
|
|
1253
1285
|
out[i] = password.charCodeAt(i);
|
|
@@ -3065,10 +3097,10 @@ class EmbeddedFont extends PDFFont {
|
|
|
3065
3097
|
|
|
3066
3098
|
if (this.font.head.macStyle.italic) {
|
|
3067
3099
|
flags |= 1 << 6;
|
|
3068
|
-
} // generate a tag (6 uppercase letters.
|
|
3100
|
+
} // generate a tag (6 uppercase letters. 17 is the char code offset from '0' to 'A'. 73 will map to 'Z')
|
|
3069
3101
|
|
|
3070
3102
|
|
|
3071
|
-
var tag = [1, 2, 3, 4, 5, 6].map(i => String.fromCharCode((this.id.charCodeAt(i) ||
|
|
3103
|
+
var tag = [1, 2, 3, 4, 5, 6].map(i => String.fromCharCode((this.id.charCodeAt(i) || 73) + 17)).join('');
|
|
3072
3104
|
var name = tag + '+' + this.font.postscriptName;
|
|
3073
3105
|
var {
|
|
3074
3106
|
bbox
|
|
@@ -3168,9 +3200,9 @@ class PDFFontFactory {
|
|
|
3168
3200
|
if (Buffer.isBuffer(src)) {
|
|
3169
3201
|
font = fontkit.create(src, family);
|
|
3170
3202
|
} else if (src instanceof Uint8Array) {
|
|
3171
|
-
font = fontkit.create(
|
|
3203
|
+
font = fontkit.create(Buffer.from(src), family);
|
|
3172
3204
|
} else if (src instanceof ArrayBuffer) {
|
|
3173
|
-
font = fontkit.create(
|
|
3205
|
+
font = fontkit.create(Buffer.from(new Uint8Array(src)), family);
|
|
3174
3206
|
}
|
|
3175
3207
|
|
|
3176
3208
|
if (font == null) {
|
|
@@ -3495,7 +3527,7 @@ class LineWrapper extends EventEmitter {
|
|
|
3495
3527
|
|
|
3496
3528
|
buffer = buffer.replace(/\s+$/, '');
|
|
3497
3529
|
textWidth = this.wordWidth(buffer + this.ellipsis); // remove characters from the buffer until the ellipsis fits
|
|
3498
|
-
// to avoid
|
|
3530
|
+
// to avoid infinite loop need to stop while-loop if buffer is empty string
|
|
3499
3531
|
|
|
3500
3532
|
while (buffer && textWidth > this.lineWidth) {
|
|
3501
3533
|
buffer = buffer.slice(0, -1).replace(/\s+$/, '');
|
|
@@ -3583,7 +3615,7 @@ class LineWrapper extends EventEmitter {
|
|
|
3583
3615
|
return false;
|
|
3584
3616
|
}
|
|
3585
3617
|
|
|
3586
|
-
this.document.
|
|
3618
|
+
this.document.continueOnNewPage();
|
|
3587
3619
|
this.column = 1;
|
|
3588
3620
|
this.startY = this.document.page.margins.top;
|
|
3589
3621
|
this.maxY = this.document.page.maxY();
|
|
@@ -3648,7 +3680,13 @@ var TextMixin = {
|
|
|
3648
3680
|
|
|
3649
3681
|
if (options.wordSpacing) {
|
|
3650
3682
|
text = text.replace(/\s{2,}/g, ' ');
|
|
3651
|
-
}
|
|
3683
|
+
}
|
|
3684
|
+
|
|
3685
|
+
var addStructure = () => {
|
|
3686
|
+
if (options.structParent) {
|
|
3687
|
+
options.structParent.add(this.struct(options.structType || 'P', [this.markStructureContent(options.structType || 'P')]));
|
|
3688
|
+
}
|
|
3689
|
+
}; // word wrapping
|
|
3652
3690
|
|
|
3653
3691
|
|
|
3654
3692
|
if (options.width) {
|
|
@@ -3657,6 +3695,7 @@ var TextMixin = {
|
|
|
3657
3695
|
if (!wrapper) {
|
|
3658
3696
|
wrapper = new LineWrapper(this, options);
|
|
3659
3697
|
wrapper.on('line', lineCallback);
|
|
3698
|
+
wrapper.on('firstLine', addStructure);
|
|
3660
3699
|
}
|
|
3661
3700
|
|
|
3662
3701
|
this._wrapper = options.continued ? wrapper : null;
|
|
@@ -3664,6 +3703,7 @@ var TextMixin = {
|
|
|
3664
3703
|
wrapper.wrap(text, options); // render paragraphs as single lines
|
|
3665
3704
|
} else {
|
|
3666
3705
|
for (var line of text.split('\n')) {
|
|
3706
|
+
addStructure();
|
|
3667
3707
|
lineCallback(line, options);
|
|
3668
3708
|
}
|
|
3669
3709
|
}
|
|
@@ -3754,6 +3794,23 @@ var TextMixin = {
|
|
|
3754
3794
|
level = 1;
|
|
3755
3795
|
var i = 0;
|
|
3756
3796
|
wrapper.on('firstLine', () => {
|
|
3797
|
+
var item, itemType, labelType, bodyType;
|
|
3798
|
+
|
|
3799
|
+
if (options.structParent) {
|
|
3800
|
+
if (options.structTypes) {
|
|
3801
|
+
[itemType, labelType, bodyType] = options.structTypes;
|
|
3802
|
+
} else {
|
|
3803
|
+
[itemType, labelType, bodyType] = ['LI', 'Lbl', 'LBody'];
|
|
3804
|
+
}
|
|
3805
|
+
}
|
|
3806
|
+
|
|
3807
|
+
if (itemType) {
|
|
3808
|
+
item = this.struct(itemType);
|
|
3809
|
+
options.structParent.add(item);
|
|
3810
|
+
} else if (options.structParent) {
|
|
3811
|
+
item = options.structParent;
|
|
3812
|
+
}
|
|
3813
|
+
|
|
3757
3814
|
var l;
|
|
3758
3815
|
|
|
3759
3816
|
if ((l = levels[i++]) !== level) {
|
|
@@ -3763,15 +3820,31 @@ var TextMixin = {
|
|
|
3763
3820
|
level = l;
|
|
3764
3821
|
}
|
|
3765
3822
|
|
|
3823
|
+
if (item && (labelType || bodyType)) {
|
|
3824
|
+
item.add(this.struct(labelType || bodyType, [this.markStructureContent(labelType || bodyType)]));
|
|
3825
|
+
}
|
|
3826
|
+
|
|
3766
3827
|
switch (listType) {
|
|
3767
3828
|
case 'bullet':
|
|
3768
3829
|
this.circle(this.x - indent + r, this.y + midLine, r);
|
|
3769
|
-
|
|
3830
|
+
this.fill();
|
|
3831
|
+
break;
|
|
3770
3832
|
|
|
3771
3833
|
case 'numbered':
|
|
3772
3834
|
case 'lettered':
|
|
3773
3835
|
var text = label(numbers[i - 1]);
|
|
3774
|
-
|
|
3836
|
+
|
|
3837
|
+
this._fragment(text, this.x - indent, this.y, options);
|
|
3838
|
+
|
|
3839
|
+
break;
|
|
3840
|
+
}
|
|
3841
|
+
|
|
3842
|
+
if (item && labelType && bodyType) {
|
|
3843
|
+
item.add(this.struct(bodyType, [this.markStructureContent(bodyType)]));
|
|
3844
|
+
}
|
|
3845
|
+
|
|
3846
|
+
if (item && item !== options.structParent) {
|
|
3847
|
+
item.end();
|
|
3775
3848
|
}
|
|
3776
3849
|
});
|
|
3777
3850
|
wrapper.on('sectionStart', () => {
|
|
@@ -3947,10 +4020,10 @@ var TextMixin = {
|
|
|
3947
4020
|
|
|
3948
4021
|
if (options.destination != null) {
|
|
3949
4022
|
this.addNamedDestination(options.destination, 'XYZ', x, y, null);
|
|
3950
|
-
} // create underline
|
|
4023
|
+
} // create underline
|
|
3951
4024
|
|
|
3952
4025
|
|
|
3953
|
-
if (options.underline
|
|
4026
|
+
if (options.underline) {
|
|
3954
4027
|
this.save();
|
|
3955
4028
|
|
|
3956
4029
|
if (!options.stroke) {
|
|
@@ -3959,15 +4032,29 @@ var TextMixin = {
|
|
|
3959
4032
|
|
|
3960
4033
|
var lineWidth = this._fontSize < 10 ? 0.5 : Math.floor(this._fontSize / 10);
|
|
3961
4034
|
this.lineWidth(lineWidth);
|
|
3962
|
-
var
|
|
3963
|
-
|
|
4035
|
+
var lineY = y + this.currentLineHeight() - lineWidth;
|
|
4036
|
+
this.moveTo(x, lineY);
|
|
4037
|
+
this.lineTo(x + renderedWidth, lineY);
|
|
4038
|
+
this.stroke();
|
|
4039
|
+
this.restore();
|
|
4040
|
+
} // create strikethrough line
|
|
4041
|
+
|
|
3964
4042
|
|
|
3965
|
-
|
|
3966
|
-
|
|
4043
|
+
if (options.strike) {
|
|
4044
|
+
this.save();
|
|
4045
|
+
|
|
4046
|
+
if (!options.stroke) {
|
|
4047
|
+
this.strokeColor(...(this._fillColor || []));
|
|
3967
4048
|
}
|
|
3968
4049
|
|
|
3969
|
-
this.
|
|
3970
|
-
|
|
4050
|
+
var _lineWidth = this._fontSize < 10 ? 0.5 : Math.floor(this._fontSize / 10);
|
|
4051
|
+
|
|
4052
|
+
this.lineWidth(_lineWidth);
|
|
4053
|
+
|
|
4054
|
+
var _lineY = y + this.currentLineHeight() / 2;
|
|
4055
|
+
|
|
4056
|
+
this.moveTo(x, _lineY);
|
|
4057
|
+
this.lineTo(x + renderedWidth, _lineY);
|
|
3971
4058
|
this.stroke();
|
|
3972
4059
|
this.restore();
|
|
3973
4060
|
}
|
|
@@ -4228,7 +4315,7 @@ class PNGImage {
|
|
|
4228
4315
|
} else {
|
|
4229
4316
|
// embed the color palette in the PDF as an object stream
|
|
4230
4317
|
var palette = this.document.ref();
|
|
4231
|
-
palette.end(
|
|
4318
|
+
palette.end(Buffer.from(this.image.palette)); // build the color space array for the image
|
|
4232
4319
|
|
|
4233
4320
|
this.obj.data['ColorSpace'] = ['Indexed', 'DeviceRGB', this.image.palette.length / 3 - 1, palette];
|
|
4234
4321
|
} // For PNG color types 0, 2 and 3, the transparency data is stored in
|
|
@@ -4301,8 +4388,8 @@ class PNGImage {
|
|
|
4301
4388
|
var a, p;
|
|
4302
4389
|
var colorCount = this.image.colors;
|
|
4303
4390
|
var pixelCount = this.width * this.height;
|
|
4304
|
-
var imgData =
|
|
4305
|
-
var alphaChannel =
|
|
4391
|
+
var imgData = Buffer.alloc(pixelCount * colorCount);
|
|
4392
|
+
var alphaChannel = Buffer.alloc(pixelCount);
|
|
4306
4393
|
var i = p = a = 0;
|
|
4307
4394
|
var len = pixels.length; // For 16bit images copy only most significant byte (MSB) - PNG data is always stored in network byte order (MSB first)
|
|
4308
4395
|
|
|
@@ -4327,7 +4414,7 @@ class PNGImage {
|
|
|
4327
4414
|
loadIndexedAlphaChannel() {
|
|
4328
4415
|
var transparency = this.image.transparency.indexed;
|
|
4329
4416
|
return this.image.decodePixels(pixels => {
|
|
4330
|
-
var alphaChannel =
|
|
4417
|
+
var alphaChannel = Buffer.alloc(this.width * this.height);
|
|
4331
4418
|
var i = 0;
|
|
4332
4419
|
|
|
4333
4420
|
for (var j = 0, end = pixels.length; j < end; j++) {
|
|
@@ -4348,9 +4435,9 @@ class PNGImage {
|
|
|
4348
4435
|
|
|
4349
4436
|
}
|
|
4350
4437
|
|
|
4351
|
-
/*
|
|
4352
|
-
PDFImage - embeds images in PDF documents
|
|
4353
|
-
By Devon Govett
|
|
4438
|
+
/*
|
|
4439
|
+
PDFImage - embeds images in PDF documents
|
|
4440
|
+
By Devon Govett
|
|
4354
4441
|
*/
|
|
4355
4442
|
|
|
4356
4443
|
class PDFImage {
|
|
@@ -4360,12 +4447,12 @@ class PDFImage {
|
|
|
4360
4447
|
if (Buffer.isBuffer(src)) {
|
|
4361
4448
|
data = src;
|
|
4362
4449
|
} else if (src instanceof ArrayBuffer) {
|
|
4363
|
-
data =
|
|
4450
|
+
data = Buffer.from(new Uint8Array(src));
|
|
4364
4451
|
} else {
|
|
4365
4452
|
var match;
|
|
4366
4453
|
|
|
4367
4454
|
if (match = /^data:.+;base64,(.*)$/.exec(src)) {
|
|
4368
|
-
data =
|
|
4455
|
+
data = Buffer.from(match[1], 'base64');
|
|
4369
4456
|
} else {
|
|
4370
4457
|
data = fs.readFileSync(src);
|
|
4371
4458
|
|
|
@@ -4674,6 +4761,25 @@ var AnnotationsMixin = {
|
|
|
4674
4761
|
return this.annotate(x, y, w, h, options);
|
|
4675
4762
|
},
|
|
4676
4763
|
|
|
4764
|
+
fileAnnotation(x, y, w, h) {
|
|
4765
|
+
var file = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
4766
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
4767
|
+
// create hidden file
|
|
4768
|
+
var filespec = this.file(file.src, Object.assign({
|
|
4769
|
+
hidden: true
|
|
4770
|
+
}, file));
|
|
4771
|
+
options.Subtype = 'FileAttachment';
|
|
4772
|
+
options.FS = filespec; // add description from filespec unless description (Contents) has already been set
|
|
4773
|
+
|
|
4774
|
+
if (options.Contents) {
|
|
4775
|
+
options.Contents = new String(options.Contents);
|
|
4776
|
+
} else if (filespec.data.Desc) {
|
|
4777
|
+
options.Contents = filespec.data.Desc;
|
|
4778
|
+
}
|
|
4779
|
+
|
|
4780
|
+
return this.annotate(x, y, w, h, options);
|
|
4781
|
+
},
|
|
4782
|
+
|
|
4677
4783
|
_convertRect(x1, y1, w, h) {
|
|
4678
4784
|
// flip y1 and y2
|
|
4679
4785
|
var y2 = y1;
|
|
@@ -4772,6 +4878,500 @@ var OutlineMixin = {
|
|
|
4772
4878
|
|
|
4773
4879
|
};
|
|
4774
4880
|
|
|
4881
|
+
function _defineProperty(obj, key, value) {
|
|
4882
|
+
if (key in obj) {
|
|
4883
|
+
Object.defineProperty(obj, key, {
|
|
4884
|
+
value: value,
|
|
4885
|
+
enumerable: true,
|
|
4886
|
+
configurable: true,
|
|
4887
|
+
writable: true
|
|
4888
|
+
});
|
|
4889
|
+
} else {
|
|
4890
|
+
obj[key] = value;
|
|
4891
|
+
}
|
|
4892
|
+
|
|
4893
|
+
return obj;
|
|
4894
|
+
}
|
|
4895
|
+
|
|
4896
|
+
function ownKeys(object, enumerableOnly) {
|
|
4897
|
+
var keys = Object.keys(object);
|
|
4898
|
+
|
|
4899
|
+
if (Object.getOwnPropertySymbols) {
|
|
4900
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
4901
|
+
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
4902
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
4903
|
+
});
|
|
4904
|
+
keys.push.apply(keys, symbols);
|
|
4905
|
+
}
|
|
4906
|
+
|
|
4907
|
+
return keys;
|
|
4908
|
+
}
|
|
4909
|
+
|
|
4910
|
+
function _objectSpread2(target) {
|
|
4911
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
4912
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
4913
|
+
|
|
4914
|
+
if (i % 2) {
|
|
4915
|
+
ownKeys(Object(source), true).forEach(function (key) {
|
|
4916
|
+
_defineProperty(target, key, source[key]);
|
|
4917
|
+
});
|
|
4918
|
+
} else if (Object.getOwnPropertyDescriptors) {
|
|
4919
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
4920
|
+
} else {
|
|
4921
|
+
ownKeys(Object(source)).forEach(function (key) {
|
|
4922
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
4923
|
+
});
|
|
4924
|
+
}
|
|
4925
|
+
}
|
|
4926
|
+
|
|
4927
|
+
return target;
|
|
4928
|
+
}
|
|
4929
|
+
|
|
4930
|
+
/*
|
|
4931
|
+
PDFStructureContent - a reference to a marked structure content
|
|
4932
|
+
By Ben Schmidt
|
|
4933
|
+
*/
|
|
4934
|
+
class PDFStructureContent {
|
|
4935
|
+
constructor(pageRef, mcid) {
|
|
4936
|
+
this.refs = [{
|
|
4937
|
+
pageRef,
|
|
4938
|
+
mcid
|
|
4939
|
+
}];
|
|
4940
|
+
}
|
|
4941
|
+
|
|
4942
|
+
push(structContent) {
|
|
4943
|
+
structContent.refs.forEach(ref => this.refs.push(ref));
|
|
4944
|
+
}
|
|
4945
|
+
|
|
4946
|
+
}
|
|
4947
|
+
|
|
4948
|
+
/*
|
|
4949
|
+
PDFStructureElement - represents an element in the PDF logical structure tree
|
|
4950
|
+
By Ben Schmidt
|
|
4951
|
+
*/
|
|
4952
|
+
|
|
4953
|
+
class PDFStructureElement {
|
|
4954
|
+
constructor(document, type) {
|
|
4955
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
4956
|
+
var children = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
4957
|
+
this.document = document;
|
|
4958
|
+
this._attached = false;
|
|
4959
|
+
this._ended = false;
|
|
4960
|
+
this._flushed = false;
|
|
4961
|
+
this.dictionary = document.ref({
|
|
4962
|
+
// Type: "StructElem",
|
|
4963
|
+
S: type
|
|
4964
|
+
});
|
|
4965
|
+
var data = this.dictionary.data;
|
|
4966
|
+
|
|
4967
|
+
if (Array.isArray(options) || this._isValidChild(options)) {
|
|
4968
|
+
children = options;
|
|
4969
|
+
options = {};
|
|
4970
|
+
}
|
|
4971
|
+
|
|
4972
|
+
if (typeof options.title !== 'undefined') {
|
|
4973
|
+
data.T = new String(options.title);
|
|
4974
|
+
}
|
|
4975
|
+
|
|
4976
|
+
if (typeof options.lang !== 'undefined') {
|
|
4977
|
+
data.Lang = new String(options.lang);
|
|
4978
|
+
}
|
|
4979
|
+
|
|
4980
|
+
if (typeof options.alt !== 'undefined') {
|
|
4981
|
+
data.Alt = new String(options.alt);
|
|
4982
|
+
}
|
|
4983
|
+
|
|
4984
|
+
if (typeof options.expanded !== 'undefined') {
|
|
4985
|
+
data.E = new String(options.expanded);
|
|
4986
|
+
}
|
|
4987
|
+
|
|
4988
|
+
if (typeof options.actual !== 'undefined') {
|
|
4989
|
+
data.ActualText = new String(options.actual);
|
|
4990
|
+
}
|
|
4991
|
+
|
|
4992
|
+
this._children = [];
|
|
4993
|
+
|
|
4994
|
+
if (children) {
|
|
4995
|
+
if (!Array.isArray(children)) {
|
|
4996
|
+
children = [children];
|
|
4997
|
+
}
|
|
4998
|
+
|
|
4999
|
+
children.forEach(child => this.add(child));
|
|
5000
|
+
this.end();
|
|
5001
|
+
}
|
|
5002
|
+
}
|
|
5003
|
+
|
|
5004
|
+
add(child) {
|
|
5005
|
+
if (this._ended) {
|
|
5006
|
+
throw new Error("Cannot add child to already-ended structure element");
|
|
5007
|
+
}
|
|
5008
|
+
|
|
5009
|
+
if (!this._isValidChild(child)) {
|
|
5010
|
+
throw new Error("Invalid structure element child");
|
|
5011
|
+
}
|
|
5012
|
+
|
|
5013
|
+
if (child instanceof PDFStructureElement) {
|
|
5014
|
+
child.setParent(this.dictionary);
|
|
5015
|
+
|
|
5016
|
+
if (this._attached) {
|
|
5017
|
+
child.setAttached();
|
|
5018
|
+
}
|
|
5019
|
+
}
|
|
5020
|
+
|
|
5021
|
+
if (child instanceof PDFStructureContent) {
|
|
5022
|
+
this._addContentToParentTree(child);
|
|
5023
|
+
}
|
|
5024
|
+
|
|
5025
|
+
if (typeof child === 'function' && this._attached) {
|
|
5026
|
+
// _contentForClosure() adds the content to the parent tree
|
|
5027
|
+
child = this._contentForClosure(child);
|
|
5028
|
+
}
|
|
5029
|
+
|
|
5030
|
+
this._children.push(child);
|
|
5031
|
+
|
|
5032
|
+
return this;
|
|
5033
|
+
}
|
|
5034
|
+
|
|
5035
|
+
_addContentToParentTree(content) {
|
|
5036
|
+
content.refs.forEach((_ref) => {
|
|
5037
|
+
var {
|
|
5038
|
+
pageRef,
|
|
5039
|
+
mcid
|
|
5040
|
+
} = _ref;
|
|
5041
|
+
var pageStructParents = this.document.getStructParentTree().get(pageRef.data.StructParents);
|
|
5042
|
+
pageStructParents[mcid] = this.dictionary;
|
|
5043
|
+
});
|
|
5044
|
+
}
|
|
5045
|
+
|
|
5046
|
+
setParent(parentRef) {
|
|
5047
|
+
if (this.dictionary.data.P) {
|
|
5048
|
+
throw new Error("Structure element added to more than one parent");
|
|
5049
|
+
}
|
|
5050
|
+
|
|
5051
|
+
this.dictionary.data.P = parentRef;
|
|
5052
|
+
|
|
5053
|
+
this._flush();
|
|
5054
|
+
}
|
|
5055
|
+
|
|
5056
|
+
setAttached() {
|
|
5057
|
+
if (this._attached) {
|
|
5058
|
+
return;
|
|
5059
|
+
}
|
|
5060
|
+
|
|
5061
|
+
this._children.forEach((child, index) => {
|
|
5062
|
+
if (child instanceof PDFStructureElement) {
|
|
5063
|
+
child.setAttached();
|
|
5064
|
+
}
|
|
5065
|
+
|
|
5066
|
+
if (typeof child === 'function') {
|
|
5067
|
+
this._children[index] = this._contentForClosure(child);
|
|
5068
|
+
}
|
|
5069
|
+
});
|
|
5070
|
+
|
|
5071
|
+
this._attached = true;
|
|
5072
|
+
|
|
5073
|
+
this._flush();
|
|
5074
|
+
}
|
|
5075
|
+
|
|
5076
|
+
end() {
|
|
5077
|
+
if (this._ended) {
|
|
5078
|
+
return;
|
|
5079
|
+
}
|
|
5080
|
+
|
|
5081
|
+
this._children.filter(child => child instanceof PDFStructureElement).forEach(child => child.end());
|
|
5082
|
+
|
|
5083
|
+
this._ended = true;
|
|
5084
|
+
|
|
5085
|
+
this._flush();
|
|
5086
|
+
}
|
|
5087
|
+
|
|
5088
|
+
_isValidChild(child) {
|
|
5089
|
+
return child instanceof PDFStructureElement || child instanceof PDFStructureContent || typeof child === 'function';
|
|
5090
|
+
}
|
|
5091
|
+
|
|
5092
|
+
_contentForClosure(closure) {
|
|
5093
|
+
var content = this.document.markStructureContent(this.dictionary.data.S);
|
|
5094
|
+
closure();
|
|
5095
|
+
this.document.endMarkedContent();
|
|
5096
|
+
|
|
5097
|
+
this._addContentToParentTree(content);
|
|
5098
|
+
|
|
5099
|
+
return content;
|
|
5100
|
+
}
|
|
5101
|
+
|
|
5102
|
+
_isFlushable() {
|
|
5103
|
+
if (!this.dictionary.data.P || !this._ended) {
|
|
5104
|
+
return false;
|
|
5105
|
+
}
|
|
5106
|
+
|
|
5107
|
+
return this._children.every(child => {
|
|
5108
|
+
if (typeof child === 'function') {
|
|
5109
|
+
return false;
|
|
5110
|
+
}
|
|
5111
|
+
|
|
5112
|
+
if (child instanceof PDFStructureElement) {
|
|
5113
|
+
return child._isFlushable();
|
|
5114
|
+
}
|
|
5115
|
+
|
|
5116
|
+
return true;
|
|
5117
|
+
});
|
|
5118
|
+
}
|
|
5119
|
+
|
|
5120
|
+
_flush() {
|
|
5121
|
+
if (this._flushed || !this._isFlushable()) {
|
|
5122
|
+
return;
|
|
5123
|
+
}
|
|
5124
|
+
|
|
5125
|
+
this.dictionary.data.K = [];
|
|
5126
|
+
|
|
5127
|
+
this._children.forEach(child => this._flushChild(child));
|
|
5128
|
+
|
|
5129
|
+
this.dictionary.end(); // free memory used by children; the dictionary itself may still be
|
|
5130
|
+
// referenced by a parent structure element or root, but we can
|
|
5131
|
+
// at least trim the tree here
|
|
5132
|
+
|
|
5133
|
+
this._children = [];
|
|
5134
|
+
this.dictionary.data.K = null;
|
|
5135
|
+
this._flushed = true;
|
|
5136
|
+
}
|
|
5137
|
+
|
|
5138
|
+
_flushChild(child) {
|
|
5139
|
+
if (child instanceof PDFStructureElement) {
|
|
5140
|
+
this.dictionary.data.K.push(child.dictionary);
|
|
5141
|
+
}
|
|
5142
|
+
|
|
5143
|
+
if (child instanceof PDFStructureContent) {
|
|
5144
|
+
child.refs.forEach((_ref2) => {
|
|
5145
|
+
var {
|
|
5146
|
+
pageRef,
|
|
5147
|
+
mcid
|
|
5148
|
+
} = _ref2;
|
|
5149
|
+
|
|
5150
|
+
if (!this.dictionary.data.Pg) {
|
|
5151
|
+
this.dictionary.data.Pg = pageRef;
|
|
5152
|
+
}
|
|
5153
|
+
|
|
5154
|
+
if (this.dictionary.data.Pg === pageRef) {
|
|
5155
|
+
this.dictionary.data.K.push(mcid);
|
|
5156
|
+
} else {
|
|
5157
|
+
this.dictionary.data.K.push({
|
|
5158
|
+
Type: "MCR",
|
|
5159
|
+
Pg: pageRef,
|
|
5160
|
+
MCID: mcid
|
|
5161
|
+
});
|
|
5162
|
+
}
|
|
5163
|
+
});
|
|
5164
|
+
}
|
|
5165
|
+
}
|
|
5166
|
+
|
|
5167
|
+
}
|
|
5168
|
+
|
|
5169
|
+
/*
|
|
5170
|
+
PDFNumberTree - represents a number tree object
|
|
5171
|
+
*/
|
|
5172
|
+
|
|
5173
|
+
class PDFNumberTree extends PDFTree {
|
|
5174
|
+
_compareKeys(a, b) {
|
|
5175
|
+
return parseInt(a) - parseInt(b);
|
|
5176
|
+
}
|
|
5177
|
+
|
|
5178
|
+
_keysName() {
|
|
5179
|
+
return "Nums";
|
|
5180
|
+
}
|
|
5181
|
+
|
|
5182
|
+
_dataForKey(k) {
|
|
5183
|
+
return parseInt(k);
|
|
5184
|
+
}
|
|
5185
|
+
|
|
5186
|
+
}
|
|
5187
|
+
|
|
5188
|
+
var MarkingsMixin = {
|
|
5189
|
+
initMarkings(options) {
|
|
5190
|
+
this.structChildren = [];
|
|
5191
|
+
|
|
5192
|
+
if (options.tagged) {
|
|
5193
|
+
this.getMarkInfoDictionary().data.Marked = true;
|
|
5194
|
+
this.getStructTreeRoot();
|
|
5195
|
+
}
|
|
5196
|
+
},
|
|
5197
|
+
|
|
5198
|
+
markContent(tag) {
|
|
5199
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
5200
|
+
|
|
5201
|
+
if (tag === 'Artifact' || options && options.mcid) {
|
|
5202
|
+
var toClose = 0;
|
|
5203
|
+
this.page.markings.forEach(marking => {
|
|
5204
|
+
if (toClose || marking.structContent || marking.tag === 'Artifact') {
|
|
5205
|
+
toClose++;
|
|
5206
|
+
}
|
|
5207
|
+
});
|
|
5208
|
+
|
|
5209
|
+
while (toClose--) {
|
|
5210
|
+
this.endMarkedContent();
|
|
5211
|
+
}
|
|
5212
|
+
}
|
|
5213
|
+
|
|
5214
|
+
if (!options) {
|
|
5215
|
+
this.page.markings.push({
|
|
5216
|
+
tag
|
|
5217
|
+
});
|
|
5218
|
+
this.addContent("/".concat(tag, " BMC"));
|
|
5219
|
+
return this;
|
|
5220
|
+
}
|
|
5221
|
+
|
|
5222
|
+
this.page.markings.push({
|
|
5223
|
+
tag,
|
|
5224
|
+
options
|
|
5225
|
+
});
|
|
5226
|
+
var dictionary = {};
|
|
5227
|
+
|
|
5228
|
+
if (typeof options.mcid !== 'undefined') {
|
|
5229
|
+
dictionary.MCID = options.mcid;
|
|
5230
|
+
}
|
|
5231
|
+
|
|
5232
|
+
if (tag === 'Artifact') {
|
|
5233
|
+
if (typeof options.type === 'string') {
|
|
5234
|
+
dictionary.Type = options.type;
|
|
5235
|
+
}
|
|
5236
|
+
|
|
5237
|
+
if (Array.isArray(options.bbox)) {
|
|
5238
|
+
dictionary.BBox = [options.bbox[0], this.page.height - options.bbox[3], options.bbox[2], this.page.height - options.bbox[1]];
|
|
5239
|
+
}
|
|
5240
|
+
|
|
5241
|
+
if (Array.isArray(options.attached) && options.attached.every(val => typeof val === 'string')) {
|
|
5242
|
+
dictionary.Attached = options.attached;
|
|
5243
|
+
}
|
|
5244
|
+
}
|
|
5245
|
+
|
|
5246
|
+
if (tag === 'Span') {
|
|
5247
|
+
if (options.lang) {
|
|
5248
|
+
dictionary.Lang = new String(options.lang);
|
|
5249
|
+
}
|
|
5250
|
+
|
|
5251
|
+
if (options.alt) {
|
|
5252
|
+
dictionary.Alt = new String(options.alt);
|
|
5253
|
+
}
|
|
5254
|
+
|
|
5255
|
+
if (options.expanded) {
|
|
5256
|
+
dictionary.E = new String(options.expanded);
|
|
5257
|
+
}
|
|
5258
|
+
|
|
5259
|
+
if (options.actual) {
|
|
5260
|
+
dictionary.ActualText = new String(options.actual);
|
|
5261
|
+
}
|
|
5262
|
+
}
|
|
5263
|
+
|
|
5264
|
+
this.addContent("/".concat(tag, " ").concat(PDFObject.convert(dictionary), " BDC"));
|
|
5265
|
+
return this;
|
|
5266
|
+
},
|
|
5267
|
+
|
|
5268
|
+
markStructureContent(tag) {
|
|
5269
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
5270
|
+
var pageStructParents = this.getStructParentTree().get(this.page.structParentTreeKey);
|
|
5271
|
+
var mcid = pageStructParents.length;
|
|
5272
|
+
pageStructParents.push(null);
|
|
5273
|
+
this.markContent(tag, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
5274
|
+
mcid
|
|
5275
|
+
}));
|
|
5276
|
+
var structContent = new PDFStructureContent(this.page.dictionary, mcid);
|
|
5277
|
+
this.page.markings.slice(-1)[0].structContent = structContent;
|
|
5278
|
+
return structContent;
|
|
5279
|
+
},
|
|
5280
|
+
|
|
5281
|
+
endMarkedContent() {
|
|
5282
|
+
this.page.markings.pop();
|
|
5283
|
+
this.addContent('EMC');
|
|
5284
|
+
return this;
|
|
5285
|
+
},
|
|
5286
|
+
|
|
5287
|
+
struct(type) {
|
|
5288
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
5289
|
+
var children = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
5290
|
+
return new PDFStructureElement(this, type, options, children);
|
|
5291
|
+
},
|
|
5292
|
+
|
|
5293
|
+
addStructure(structElem) {
|
|
5294
|
+
var structTreeRoot = this.getStructTreeRoot();
|
|
5295
|
+
structElem.setParent(structTreeRoot);
|
|
5296
|
+
structElem.setAttached();
|
|
5297
|
+
this.structChildren.push(structElem);
|
|
5298
|
+
|
|
5299
|
+
if (!structTreeRoot.data.K) {
|
|
5300
|
+
structTreeRoot.data.K = [];
|
|
5301
|
+
}
|
|
5302
|
+
|
|
5303
|
+
structTreeRoot.data.K.push(structElem.dictionary);
|
|
5304
|
+
return this;
|
|
5305
|
+
},
|
|
5306
|
+
|
|
5307
|
+
initPageMarkings(pageMarkings) {
|
|
5308
|
+
pageMarkings.forEach(marking => {
|
|
5309
|
+
if (marking.structContent) {
|
|
5310
|
+
var structContent = marking.structContent;
|
|
5311
|
+
var newStructContent = this.markStructureContent(marking.tag, marking.options);
|
|
5312
|
+
structContent.push(newStructContent);
|
|
5313
|
+
this.page.markings.slice(-1)[0].structContent = structContent;
|
|
5314
|
+
} else {
|
|
5315
|
+
this.markContent(marking.tag, marking.options);
|
|
5316
|
+
}
|
|
5317
|
+
});
|
|
5318
|
+
},
|
|
5319
|
+
|
|
5320
|
+
endPageMarkings(page) {
|
|
5321
|
+
var pageMarkings = page.markings;
|
|
5322
|
+
pageMarkings.forEach(() => page.write('EMC'));
|
|
5323
|
+
page.markings = [];
|
|
5324
|
+
return pageMarkings;
|
|
5325
|
+
},
|
|
5326
|
+
|
|
5327
|
+
getMarkInfoDictionary() {
|
|
5328
|
+
if (!this._root.data.MarkInfo) {
|
|
5329
|
+
this._root.data.MarkInfo = this.ref({});
|
|
5330
|
+
}
|
|
5331
|
+
|
|
5332
|
+
return this._root.data.MarkInfo;
|
|
5333
|
+
},
|
|
5334
|
+
|
|
5335
|
+
getStructTreeRoot() {
|
|
5336
|
+
if (!this._root.data.StructTreeRoot) {
|
|
5337
|
+
this._root.data.StructTreeRoot = this.ref({
|
|
5338
|
+
Type: 'StructTreeRoot',
|
|
5339
|
+
ParentTree: new PDFNumberTree(),
|
|
5340
|
+
ParentTreeNextKey: 0
|
|
5341
|
+
});
|
|
5342
|
+
}
|
|
5343
|
+
|
|
5344
|
+
return this._root.data.StructTreeRoot;
|
|
5345
|
+
},
|
|
5346
|
+
|
|
5347
|
+
getStructParentTree() {
|
|
5348
|
+
return this.getStructTreeRoot().data.ParentTree;
|
|
5349
|
+
},
|
|
5350
|
+
|
|
5351
|
+
createStructParentTreeNextKey() {
|
|
5352
|
+
// initialise the MarkInfo dictionary
|
|
5353
|
+
this.getMarkInfoDictionary();
|
|
5354
|
+
var structTreeRoot = this.getStructTreeRoot();
|
|
5355
|
+
var key = structTreeRoot.data.ParentTreeNextKey++;
|
|
5356
|
+
structTreeRoot.data.ParentTree.add(key, []);
|
|
5357
|
+
return key;
|
|
5358
|
+
},
|
|
5359
|
+
|
|
5360
|
+
endMarkings() {
|
|
5361
|
+
var structTreeRoot = this._root.data.StructTreeRoot;
|
|
5362
|
+
|
|
5363
|
+
if (structTreeRoot) {
|
|
5364
|
+
structTreeRoot.end();
|
|
5365
|
+
this.structChildren.forEach(structElem => structElem.end());
|
|
5366
|
+
}
|
|
5367
|
+
|
|
5368
|
+
if (this._root.data.MarkInfo) {
|
|
5369
|
+
this._root.data.MarkInfo.end();
|
|
5370
|
+
}
|
|
5371
|
+
}
|
|
5372
|
+
|
|
5373
|
+
};
|
|
5374
|
+
|
|
4775
5375
|
var FIELD_FLAGS = {
|
|
4776
5376
|
readOnly: 1,
|
|
4777
5377
|
required: 2,
|
|
@@ -4817,9 +5417,9 @@ var FORMAT_DEFAULT = {
|
|
|
4817
5417
|
}
|
|
4818
5418
|
};
|
|
4819
5419
|
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.
|
|
5420
|
+
/**
|
|
5421
|
+
* Must call if adding AcroForms to a document. Must also call font() before
|
|
5422
|
+
* this method to set the default font.
|
|
4823
5423
|
*/
|
|
4824
5424
|
initForm() {
|
|
4825
5425
|
if (!this._font) {
|
|
@@ -4845,8 +5445,8 @@ var AcroFormMixin = {
|
|
|
4845
5445
|
return this;
|
|
4846
5446
|
},
|
|
4847
5447
|
|
|
4848
|
-
/**
|
|
4849
|
-
* Called automatically by document.js
|
|
5448
|
+
/**
|
|
5449
|
+
* Called automatically by document.js
|
|
4850
5450
|
*/
|
|
4851
5451
|
endAcroForm() {
|
|
4852
5452
|
if (this._root.data.AcroForm) {
|
|
@@ -4880,12 +5480,12 @@ var AcroFormMixin = {
|
|
|
4880
5480
|
return this;
|
|
4881
5481
|
},
|
|
4882
5482
|
|
|
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
|
|
5483
|
+
/**
|
|
5484
|
+
* Creates and adds a form field to the document. Form fields are intermediate
|
|
5485
|
+
* nodes in a PDF form that are used to specify form name heirarchy and form
|
|
5486
|
+
* value defaults.
|
|
5487
|
+
* @param {string} name - field name (T attribute in field dictionary)
|
|
5488
|
+
* @param {object} options - other attributes to include in field dictionary
|
|
4889
5489
|
*/
|
|
4890
5490
|
formField(name) {
|
|
4891
5491
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -4899,16 +5499,16 @@ var AcroFormMixin = {
|
|
|
4899
5499
|
return fieldRef;
|
|
4900
5500
|
},
|
|
4901
5501
|
|
|
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
|
|
5502
|
+
/**
|
|
5503
|
+
* Creates and adds a Form Annotation to the document. Form annotations are
|
|
5504
|
+
* called Widget annotations internally within a PDF file.
|
|
5505
|
+
* @param {string} name - form field name (T attribute of widget annotation
|
|
5506
|
+
* dictionary)
|
|
5507
|
+
* @param {number} x
|
|
5508
|
+
* @param {number} y
|
|
5509
|
+
* @param {number} w
|
|
5510
|
+
* @param {number} h
|
|
5511
|
+
* @param {object} options
|
|
4912
5512
|
*/
|
|
4913
5513
|
formAnnotation(name, type, x, y, w, h) {
|
|
4914
5514
|
var options = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
|
|
@@ -5143,9 +5743,11 @@ var AcroFormMixin = {
|
|
|
5143
5743
|
if (this._acroform.defaultFont !== this._font.name) {
|
|
5144
5744
|
options.DR = {
|
|
5145
5745
|
Font: {}
|
|
5146
|
-
};
|
|
5746
|
+
}; // Get the fontSize option. If not set use auto sizing
|
|
5747
|
+
|
|
5748
|
+
var fontSize = options.fontSize || 0;
|
|
5147
5749
|
options.DR.Font[this._font.id] = this._font.ref();
|
|
5148
|
-
options.DA = new String("/".concat(this._font.id, "
|
|
5750
|
+
options.DA = new String("/".concat(this._font.id, " ").concat(fontSize, " Tf 0 g"));
|
|
5149
5751
|
}
|
|
5150
5752
|
|
|
5151
5753
|
return options;
|
|
@@ -5177,8 +5779,6 @@ var AcroFormMixin = {
|
|
|
5177
5779
|
options.Opt = select;
|
|
5178
5780
|
}
|
|
5179
5781
|
|
|
5180
|
-
if (options.value || options.defaultValue) ;
|
|
5181
|
-
|
|
5182
5782
|
Object.keys(VALUE_MAP).forEach(key => {
|
|
5183
5783
|
if (options[key] !== undefined) {
|
|
5184
5784
|
options[VALUE_MAP[key]] = options[key];
|
|
@@ -5206,9 +5806,130 @@ var AcroFormMixin = {
|
|
|
5206
5806
|
|
|
5207
5807
|
};
|
|
5208
5808
|
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5809
|
+
var AttachmentsMixin = {
|
|
5810
|
+
/**
|
|
5811
|
+
* Embed contents of `src` in PDF
|
|
5812
|
+
* @param {Buffer | ArrayBuffer | string} src input Buffer, ArrayBuffer, base64 encoded string or path to file
|
|
5813
|
+
* @param {object} options
|
|
5814
|
+
* * options.name: filename to be shown in PDF, will use `src` if none set
|
|
5815
|
+
* * options.type: filetype to be shown in PDF
|
|
5816
|
+
* * options.description: description to be shown in PDF
|
|
5817
|
+
* * options.hidden: if true, do not add attachment to EmbeddedFiles dictionary. Useful for file attachment annotations
|
|
5818
|
+
* * options.creationDate: override creation date
|
|
5819
|
+
* * options.modifiedDate: override modified date
|
|
5820
|
+
* @returns filespec reference
|
|
5821
|
+
*/
|
|
5822
|
+
file(src) {
|
|
5823
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
5824
|
+
options.name = options.name || src;
|
|
5825
|
+
var refBody = {
|
|
5826
|
+
Type: 'EmbeddedFile',
|
|
5827
|
+
Params: {}
|
|
5828
|
+
};
|
|
5829
|
+
var data;
|
|
5830
|
+
|
|
5831
|
+
if (!src) {
|
|
5832
|
+
throw new Error('No src specified');
|
|
5833
|
+
}
|
|
5834
|
+
|
|
5835
|
+
if (Buffer.isBuffer(src)) {
|
|
5836
|
+
data = src;
|
|
5837
|
+
} else if (src instanceof ArrayBuffer) {
|
|
5838
|
+
data = Buffer.from(new Uint8Array(src));
|
|
5839
|
+
} else {
|
|
5840
|
+
var match;
|
|
5841
|
+
|
|
5842
|
+
if (match = /^data:(.*);base64,(.*)$/.exec(src)) {
|
|
5843
|
+
if (match[1]) {
|
|
5844
|
+
refBody.Subtype = match[1].replace('/', '#2F');
|
|
5845
|
+
}
|
|
5846
|
+
|
|
5847
|
+
data = Buffer.from(match[2], 'base64');
|
|
5848
|
+
} else {
|
|
5849
|
+
data = fs.readFileSync(src);
|
|
5850
|
+
|
|
5851
|
+
if (!data) {
|
|
5852
|
+
throw new Error("Could not read contents of file at filepath ".concat(src));
|
|
5853
|
+
} // update CreationDate and ModDate
|
|
5854
|
+
|
|
5855
|
+
|
|
5856
|
+
var {
|
|
5857
|
+
birthtime,
|
|
5858
|
+
ctime
|
|
5859
|
+
} = fs.statSync(src);
|
|
5860
|
+
refBody.Params.CreationDate = birthtime;
|
|
5861
|
+
refBody.Params.ModDate = ctime;
|
|
5862
|
+
}
|
|
5863
|
+
} // override creation date and modified date
|
|
5864
|
+
|
|
5865
|
+
|
|
5866
|
+
if (options.creationDate instanceof Date) {
|
|
5867
|
+
refBody.Params.CreationDate = options.creationDate;
|
|
5868
|
+
}
|
|
5869
|
+
|
|
5870
|
+
if (options.modifiedDate instanceof Date) {
|
|
5871
|
+
refBody.Params.ModDate = options.modifiedDate;
|
|
5872
|
+
} // add optional subtype
|
|
5873
|
+
|
|
5874
|
+
|
|
5875
|
+
if (options.type) {
|
|
5876
|
+
refBody.Subtype = options.type.replace('/', '#2F');
|
|
5877
|
+
} // add checksum and size information
|
|
5878
|
+
|
|
5879
|
+
|
|
5880
|
+
var checksum = CryptoJS.MD5(CryptoJS.lib.WordArray.create(new Uint8Array(data)));
|
|
5881
|
+
refBody.Params.CheckSum = new String(checksum);
|
|
5882
|
+
refBody.Params.Size = data.byteLength; // save some space when embedding the same file again
|
|
5883
|
+
// if a file with the same name and metadata exists, reuse its reference
|
|
5884
|
+
|
|
5885
|
+
var ref;
|
|
5886
|
+
if (!this._fileRegistry) this._fileRegistry = {};
|
|
5887
|
+
var file = this._fileRegistry[options.name];
|
|
5888
|
+
|
|
5889
|
+
if (file && isEqual(refBody, file)) {
|
|
5890
|
+
ref = file.ref;
|
|
5891
|
+
} else {
|
|
5892
|
+
ref = this.ref(refBody);
|
|
5893
|
+
ref.end(data);
|
|
5894
|
+
this._fileRegistry[options.name] = _objectSpread2(_objectSpread2({}, refBody), {}, {
|
|
5895
|
+
ref
|
|
5896
|
+
});
|
|
5897
|
+
} // add filespec for embedded file
|
|
5898
|
+
|
|
5899
|
+
|
|
5900
|
+
var fileSpecBody = {
|
|
5901
|
+
Type: 'Filespec',
|
|
5902
|
+
F: new String(options.name),
|
|
5903
|
+
EF: {
|
|
5904
|
+
F: ref
|
|
5905
|
+
},
|
|
5906
|
+
UF: new String(options.name)
|
|
5907
|
+
};
|
|
5908
|
+
|
|
5909
|
+
if (options.description) {
|
|
5910
|
+
fileSpecBody.Desc = new String(options.description);
|
|
5911
|
+
}
|
|
5912
|
+
|
|
5913
|
+
var filespec = this.ref(fileSpecBody);
|
|
5914
|
+
filespec.end();
|
|
5915
|
+
|
|
5916
|
+
if (!options.hidden) {
|
|
5917
|
+
this.addNamedEmbeddedFile(options.name, filespec);
|
|
5918
|
+
}
|
|
5919
|
+
|
|
5920
|
+
return filespec;
|
|
5921
|
+
}
|
|
5922
|
+
|
|
5923
|
+
};
|
|
5924
|
+
/** check two embedded file metadata objects for equality */
|
|
5925
|
+
|
|
5926
|
+
function isEqual(a, b) {
|
|
5927
|
+
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;
|
|
5928
|
+
}
|
|
5929
|
+
|
|
5930
|
+
/*
|
|
5931
|
+
PDFDocument - represents an entire PDF document
|
|
5932
|
+
By Devon Govett
|
|
5212
5933
|
*/
|
|
5213
5934
|
|
|
5214
5935
|
class PDFDocument extends stream.Readable {
|
|
@@ -5261,7 +5982,12 @@ class PDFDocument extends stream.Readable {
|
|
|
5261
5982
|
Type: 'Catalog',
|
|
5262
5983
|
Pages,
|
|
5263
5984
|
Names
|
|
5264
|
-
});
|
|
5985
|
+
});
|
|
5986
|
+
|
|
5987
|
+
if (this.options.lang) {
|
|
5988
|
+
this._root.data.Lang = new String(this.options.lang);
|
|
5989
|
+
} // The current page
|
|
5990
|
+
|
|
5265
5991
|
|
|
5266
5992
|
this.page = null; // Initialize mixins
|
|
5267
5993
|
|
|
@@ -5270,7 +5996,8 @@ class PDFDocument extends stream.Readable {
|
|
|
5270
5996
|
this.initFonts(options.font);
|
|
5271
5997
|
this.initText();
|
|
5272
5998
|
this.initImages();
|
|
5273
|
-
this.initOutline();
|
|
5999
|
+
this.initOutline();
|
|
6000
|
+
this.initMarkings(options); // Initialize the metadata
|
|
5274
6001
|
|
|
5275
6002
|
this.info = {
|
|
5276
6003
|
Producer: 'PDFKit',
|
|
@@ -5283,6 +6010,12 @@ class PDFDocument extends stream.Readable {
|
|
|
5283
6010
|
var val = this.options.info[key];
|
|
5284
6011
|
this.info[key] = val;
|
|
5285
6012
|
}
|
|
6013
|
+
}
|
|
6014
|
+
|
|
6015
|
+
if (this.options.displayTitle) {
|
|
6016
|
+
this._root.data.ViewerPreferences = this.ref({
|
|
6017
|
+
DisplayDocTitle: true
|
|
6018
|
+
});
|
|
5286
6019
|
} // Generate file ID
|
|
5287
6020
|
|
|
5288
6021
|
|
|
@@ -5303,12 +6036,12 @@ class PDFDocument extends stream.Readable {
|
|
|
5303
6036
|
}
|
|
5304
6037
|
|
|
5305
6038
|
addPage(options) {
|
|
5306
|
-
// end the current page if needed
|
|
5307
6039
|
if (options == null) {
|
|
5308
6040
|
({
|
|
5309
6041
|
options
|
|
5310
6042
|
} = this);
|
|
5311
|
-
}
|
|
6043
|
+
} // end the current page if needed
|
|
6044
|
+
|
|
5312
6045
|
|
|
5313
6046
|
if (!this.options.bufferPages) {
|
|
5314
6047
|
this.flushPages();
|
|
@@ -5334,6 +6067,13 @@ class PDFDocument extends stream.Readable {
|
|
|
5334
6067
|
return this;
|
|
5335
6068
|
}
|
|
5336
6069
|
|
|
6070
|
+
continueOnNewPage(options) {
|
|
6071
|
+
var pageMarkings = this.endPageMarkings(this.page);
|
|
6072
|
+
this.addPage(options);
|
|
6073
|
+
this.initPageMarkings(pageMarkings);
|
|
6074
|
+
return this;
|
|
6075
|
+
}
|
|
6076
|
+
|
|
5337
6077
|
bufferedPageRange() {
|
|
5338
6078
|
return {
|
|
5339
6079
|
start: this._pageBufferStart,
|
|
@@ -5359,6 +6099,7 @@ class PDFDocument extends stream.Readable {
|
|
|
5359
6099
|
this._pageBufferStart += pages.length;
|
|
5360
6100
|
|
|
5361
6101
|
for (var page of pages) {
|
|
6102
|
+
this.endPageMarkings(page);
|
|
5362
6103
|
page.end();
|
|
5363
6104
|
}
|
|
5364
6105
|
}
|
|
@@ -5381,6 +6122,18 @@ class PDFDocument extends stream.Readable {
|
|
|
5381
6122
|
this._root.data.Names.data.Dests.add(name, args);
|
|
5382
6123
|
}
|
|
5383
6124
|
|
|
6125
|
+
addNamedEmbeddedFile(name, ref) {
|
|
6126
|
+
if (!this._root.data.Names.data.EmbeddedFiles) {
|
|
6127
|
+
// disabling /Limits for this tree fixes attachments not showing in Adobe Reader
|
|
6128
|
+
this._root.data.Names.data.EmbeddedFiles = new PDFNameTree({
|
|
6129
|
+
limits: false
|
|
6130
|
+
});
|
|
6131
|
+
} // add filespec to EmbeddedFiles
|
|
6132
|
+
|
|
6133
|
+
|
|
6134
|
+
this._root.data.Names.data.EmbeddedFiles.add(name, ref);
|
|
6135
|
+
}
|
|
6136
|
+
|
|
5384
6137
|
addNamedJavaScript(name, js) {
|
|
5385
6138
|
if (!this._root.data.Names.data.JavaScript) {
|
|
5386
6139
|
this._root.data.Names.data.JavaScript = new PDFNameTree();
|
|
@@ -5409,7 +6162,7 @@ class PDFDocument extends stream.Readable {
|
|
|
5409
6162
|
|
|
5410
6163
|
_write(data) {
|
|
5411
6164
|
if (!Buffer.isBuffer(data)) {
|
|
5412
|
-
data =
|
|
6165
|
+
data = Buffer.from(data + '\n', 'binary');
|
|
5413
6166
|
}
|
|
5414
6167
|
|
|
5415
6168
|
this.push(data);
|
|
@@ -5464,6 +6217,7 @@ class PDFDocument extends stream.Readable {
|
|
|
5464
6217
|
}
|
|
5465
6218
|
|
|
5466
6219
|
this.endOutline();
|
|
6220
|
+
this.endMarkings();
|
|
5467
6221
|
|
|
5468
6222
|
this._root.end();
|
|
5469
6223
|
|
|
@@ -5473,6 +6227,10 @@ class PDFDocument extends stream.Readable {
|
|
|
5473
6227
|
|
|
5474
6228
|
this.endAcroForm();
|
|
5475
6229
|
|
|
6230
|
+
if (this._root.data.ViewerPreferences) {
|
|
6231
|
+
this._root.data.ViewerPreferences.end();
|
|
6232
|
+
}
|
|
6233
|
+
|
|
5476
6234
|
if (this._security) {
|
|
5477
6235
|
this._security.end();
|
|
5478
6236
|
}
|
|
@@ -5484,7 +6242,7 @@ class PDFDocument extends stream.Readable {
|
|
|
5484
6242
|
}
|
|
5485
6243
|
}
|
|
5486
6244
|
|
|
5487
|
-
_finalize(
|
|
6245
|
+
_finalize() {
|
|
5488
6246
|
// generate xref
|
|
5489
6247
|
var xRefOffset = this._offset;
|
|
5490
6248
|
|
|
@@ -5543,7 +6301,10 @@ mixin(TextMixin);
|
|
|
5543
6301
|
mixin(ImagesMixin);
|
|
5544
6302
|
mixin(AnnotationsMixin);
|
|
5545
6303
|
mixin(OutlineMixin);
|
|
6304
|
+
mixin(MarkingsMixin);
|
|
5546
6305
|
mixin(AcroFormMixin);
|
|
6306
|
+
mixin(AttachmentsMixin);
|
|
6307
|
+
PDFDocument.LineWrapper = LineWrapper;
|
|
5547
6308
|
|
|
5548
6309
|
export default PDFDocument;
|
|
5549
6310
|
//# sourceMappingURL=pdfkit.esnext.js.map
|