pdfkit 0.12.3 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +1 -1
- package/js/pdfkit.es5.js +264 -123
- package/js/pdfkit.es5.js.map +1 -1
- package/js/pdfkit.esnext.js +159 -42
- package/js/pdfkit.esnext.js.map +1 -1
- package/js/pdfkit.js +157 -40
- package/js/pdfkit.js.map +1 -1
- package/js/pdfkit.standalone.js +1914 -615
- package/package.json +1 -1
- package/js/font/data/Courier-Bold.afm +0 -342
- package/js/font/data/Courier-BoldOblique.afm +0 -342
- package/js/font/data/Courier-Oblique.afm +0 -342
- package/js/font/data/Courier.afm +0 -342
- package/js/font/data/Helvetica-Bold.afm +0 -2827
- package/js/font/data/Helvetica-BoldOblique.afm +0 -2827
- package/js/font/data/Helvetica-Oblique.afm +0 -3051
- package/js/font/data/Helvetica.afm +0 -3051
- package/js/font/data/Symbol.afm +0 -213
- package/js/font/data/Times-Bold.afm +0 -2588
- package/js/font/data/Times-BoldItalic.afm +0 -2384
- package/js/font/data/Times-Italic.afm +0 -2667
- package/js/font/data/Times-Roman.afm +0 -2419
- package/js/font/data/ZapfDingbats.afm +0 -225
- package/js/pdfkit.standalone.orig.js +0 -68494
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -154,7 +154,7 @@ const stream = doc.pipe(blobStream());
|
|
|
154
154
|
|
|
155
155
|
// add your content to the document here, as usual
|
|
156
156
|
|
|
157
|
-
// get a blob when you
|
|
157
|
+
// get a blob when you are done
|
|
158
158
|
doc.end();
|
|
159
159
|
stream.on('finish', function() {
|
|
160
160
|
// get a blob you can do whatever you like with
|
package/js/pdfkit.es5.js
CHANGED
|
@@ -7,6 +7,44 @@ import { EventEmitter } from 'events';
|
|
|
7
7
|
import LineBreaker from 'linebreak';
|
|
8
8
|
import PNG from 'png-js';
|
|
9
9
|
|
|
10
|
+
function ownKeys(object, enumerableOnly) {
|
|
11
|
+
var keys = Object.keys(object);
|
|
12
|
+
|
|
13
|
+
if (Object.getOwnPropertySymbols) {
|
|
14
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
15
|
+
|
|
16
|
+
if (enumerableOnly) {
|
|
17
|
+
symbols = symbols.filter(function (sym) {
|
|
18
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
keys.push.apply(keys, symbols);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return keys;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _objectSpread2(target) {
|
|
29
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
30
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
31
|
+
|
|
32
|
+
if (i % 2) {
|
|
33
|
+
ownKeys(Object(source), true).forEach(function (key) {
|
|
34
|
+
_defineProperty(target, key, source[key]);
|
|
35
|
+
});
|
|
36
|
+
} else if (Object.getOwnPropertyDescriptors) {
|
|
37
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
38
|
+
} else {
|
|
39
|
+
ownKeys(Object(source)).forEach(function (key) {
|
|
40
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return target;
|
|
46
|
+
}
|
|
47
|
+
|
|
10
48
|
function _classCallCheck(instance, Constructor) {
|
|
11
49
|
if (!(instance instanceof Constructor)) {
|
|
12
50
|
throw new TypeError("Cannot call a class as a function");
|
|
@@ -44,40 +82,6 @@ function _defineProperty(obj, key, value) {
|
|
|
44
82
|
return obj;
|
|
45
83
|
}
|
|
46
84
|
|
|
47
|
-
function ownKeys(object, enumerableOnly) {
|
|
48
|
-
var keys = Object.keys(object);
|
|
49
|
-
|
|
50
|
-
if (Object.getOwnPropertySymbols) {
|
|
51
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
52
|
-
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
53
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
54
|
-
});
|
|
55
|
-
keys.push.apply(keys, symbols);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return keys;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function _objectSpread2(target) {
|
|
62
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
63
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
64
|
-
|
|
65
|
-
if (i % 2) {
|
|
66
|
-
ownKeys(Object(source), true).forEach(function (key) {
|
|
67
|
-
_defineProperty(target, key, source[key]);
|
|
68
|
-
});
|
|
69
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
70
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
71
|
-
} else {
|
|
72
|
-
ownKeys(Object(source)).forEach(function (key) {
|
|
73
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return target;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
85
|
function _inherits(subClass, superClass) {
|
|
82
86
|
if (typeof superClass !== "function" && superClass !== null) {
|
|
83
87
|
throw new TypeError("Super expression must either be null or a function");
|
|
@@ -115,7 +119,7 @@ function _isNativeReflectConstruct() {
|
|
|
115
119
|
if (typeof Proxy === "function") return true;
|
|
116
120
|
|
|
117
121
|
try {
|
|
118
|
-
|
|
122
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
119
123
|
return true;
|
|
120
124
|
} catch (e) {
|
|
121
125
|
return false;
|
|
@@ -174,18 +178,21 @@ function _arrayWithHoles(arr) {
|
|
|
174
178
|
}
|
|
175
179
|
|
|
176
180
|
function _iterableToArray(iter) {
|
|
177
|
-
if (typeof Symbol !== "undefined" && Symbol.iterator
|
|
181
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
178
182
|
}
|
|
179
183
|
|
|
180
184
|
function _iterableToArrayLimit(arr, i) {
|
|
181
|
-
|
|
185
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
186
|
+
|
|
187
|
+
if (_i == null) return;
|
|
182
188
|
var _arr = [];
|
|
183
189
|
var _n = true;
|
|
184
190
|
var _d = false;
|
|
185
|
-
|
|
191
|
+
|
|
192
|
+
var _s, _e;
|
|
186
193
|
|
|
187
194
|
try {
|
|
188
|
-
for (
|
|
195
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
189
196
|
_arr.push(_s.value);
|
|
190
197
|
|
|
191
198
|
if (i && _arr.length === i) break;
|
|
@@ -230,9 +237,9 @@ function _nonIterableRest() {
|
|
|
230
237
|
}
|
|
231
238
|
|
|
232
239
|
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
233
|
-
var it;
|
|
240
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
234
241
|
|
|
235
|
-
if (
|
|
242
|
+
if (!it) {
|
|
236
243
|
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
237
244
|
if (it) o = it;
|
|
238
245
|
var i = 0;
|
|
@@ -265,7 +272,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
|
265
272
|
err;
|
|
266
273
|
return {
|
|
267
274
|
s: function () {
|
|
268
|
-
it =
|
|
275
|
+
it = it.call(o);
|
|
269
276
|
},
|
|
270
277
|
n: function () {
|
|
271
278
|
var step = it.next();
|
|
@@ -364,9 +371,7 @@ var PDFTree = /*#__PURE__*/function () {
|
|
|
364
371
|
}
|
|
365
372
|
}, {
|
|
366
373
|
key: "_compareKeys",
|
|
367
|
-
value: function _compareKeys()
|
|
368
|
-
/*a, b*/
|
|
369
|
-
{
|
|
374
|
+
value: function _compareKeys() {
|
|
370
375
|
throw new Error('Must be implemented by subclasses');
|
|
371
376
|
}
|
|
372
377
|
}, {
|
|
@@ -376,9 +381,7 @@ var PDFTree = /*#__PURE__*/function () {
|
|
|
376
381
|
}
|
|
377
382
|
}, {
|
|
378
383
|
key: "_dataForKey",
|
|
379
|
-
value: function _dataForKey()
|
|
380
|
-
/*k*/
|
|
381
|
-
{
|
|
384
|
+
value: function _dataForKey() {
|
|
382
385
|
throw new Error('Must be implemented by subclasses');
|
|
383
386
|
}
|
|
384
387
|
}]);
|
|
@@ -722,23 +725,6 @@ var PDFPage = /*#__PURE__*/function () {
|
|
|
722
725
|
|
|
723
726
|
|
|
724
727
|
_createClass(PDFPage, [{
|
|
725
|
-
key: "maxY",
|
|
726
|
-
value: function maxY() {
|
|
727
|
-
return this.height - this.margins.bottom;
|
|
728
|
-
}
|
|
729
|
-
}, {
|
|
730
|
-
key: "write",
|
|
731
|
-
value: function write(chunk) {
|
|
732
|
-
return this.content.write(chunk);
|
|
733
|
-
}
|
|
734
|
-
}, {
|
|
735
|
-
key: "end",
|
|
736
|
-
value: function end() {
|
|
737
|
-
this.dictionary.end();
|
|
738
|
-
this.resources.end();
|
|
739
|
-
return this.content.end();
|
|
740
|
-
}
|
|
741
|
-
}, {
|
|
742
728
|
key: "fonts",
|
|
743
729
|
get: function get() {
|
|
744
730
|
var data = this.resources.data;
|
|
@@ -762,6 +748,12 @@ var PDFPage = /*#__PURE__*/function () {
|
|
|
762
748
|
var data = this.resources.data;
|
|
763
749
|
return data.Pattern != null ? data.Pattern : data.Pattern = {};
|
|
764
750
|
}
|
|
751
|
+
}, {
|
|
752
|
+
key: "colorSpaces",
|
|
753
|
+
get: function get() {
|
|
754
|
+
var data = this.resources.data;
|
|
755
|
+
return data.ColorSpace || (data.ColorSpace = {});
|
|
756
|
+
}
|
|
765
757
|
}, {
|
|
766
758
|
key: "annotations",
|
|
767
759
|
get: function get() {
|
|
@@ -774,6 +766,23 @@ var PDFPage = /*#__PURE__*/function () {
|
|
|
774
766
|
var data = this.dictionary.data;
|
|
775
767
|
return data.StructParents != null ? data.StructParents : data.StructParents = this.document.createStructParentTreeNextKey();
|
|
776
768
|
}
|
|
769
|
+
}, {
|
|
770
|
+
key: "maxY",
|
|
771
|
+
value: function maxY() {
|
|
772
|
+
return this.height - this.margins.bottom;
|
|
773
|
+
}
|
|
774
|
+
}, {
|
|
775
|
+
key: "write",
|
|
776
|
+
value: function write(chunk) {
|
|
777
|
+
return this.content.write(chunk);
|
|
778
|
+
}
|
|
779
|
+
}, {
|
|
780
|
+
key: "end",
|
|
781
|
+
value: function end() {
|
|
782
|
+
this.dictionary.end();
|
|
783
|
+
this.resources.end();
|
|
784
|
+
return this.content.end();
|
|
785
|
+
}
|
|
777
786
|
}]);
|
|
778
787
|
|
|
779
788
|
return PDFPage;
|
|
@@ -1248,41 +1257,6 @@ function saslprep(input) {
|
|
|
1248
1257
|
}
|
|
1249
1258
|
|
|
1250
1259
|
var PDFSecurity = /*#__PURE__*/function () {
|
|
1251
|
-
_createClass(PDFSecurity, null, [{
|
|
1252
|
-
key: "generateFileID",
|
|
1253
|
-
value: function generateFileID() {
|
|
1254
|
-
var info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1255
|
-
var infoStr = "".concat(info.CreationDate.getTime(), "\n");
|
|
1256
|
-
|
|
1257
|
-
for (var key in info) {
|
|
1258
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
1259
|
-
if (!info.hasOwnProperty(key)) {
|
|
1260
|
-
continue;
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
infoStr += "".concat(key, ": ").concat(info[key].valueOf(), "\n");
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
return wordArrayToBuffer(CryptoJS.MD5(infoStr));
|
|
1267
|
-
}
|
|
1268
|
-
}, {
|
|
1269
|
-
key: "generateRandomWordArray",
|
|
1270
|
-
value: function generateRandomWordArray(bytes) {
|
|
1271
|
-
return CryptoJS.lib.WordArray.random(bytes);
|
|
1272
|
-
}
|
|
1273
|
-
}, {
|
|
1274
|
-
key: "create",
|
|
1275
|
-
value: function create(document) {
|
|
1276
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1277
|
-
|
|
1278
|
-
if (!options.ownerPassword && !options.userPassword) {
|
|
1279
|
-
return null;
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
return new PDFSecurity(document, options);
|
|
1283
|
-
}
|
|
1284
|
-
}]);
|
|
1285
|
-
|
|
1286
1260
|
function PDFSecurity(document) {
|
|
1287
1261
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1288
1262
|
|
|
@@ -1475,6 +1449,39 @@ var PDFSecurity = /*#__PURE__*/function () {
|
|
|
1475
1449
|
value: function end() {
|
|
1476
1450
|
this.dictionary.end();
|
|
1477
1451
|
}
|
|
1452
|
+
}], [{
|
|
1453
|
+
key: "generateFileID",
|
|
1454
|
+
value: function generateFileID() {
|
|
1455
|
+
var info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1456
|
+
var infoStr = "".concat(info.CreationDate.getTime(), "\n");
|
|
1457
|
+
|
|
1458
|
+
for (var key in info) {
|
|
1459
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
1460
|
+
if (!info.hasOwnProperty(key)) {
|
|
1461
|
+
continue;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
infoStr += "".concat(key, ": ").concat(info[key].valueOf(), "\n");
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
return wordArrayToBuffer(CryptoJS.MD5(infoStr));
|
|
1468
|
+
}
|
|
1469
|
+
}, {
|
|
1470
|
+
key: "generateRandomWordArray",
|
|
1471
|
+
value: function generateRandomWordArray(bytes) {
|
|
1472
|
+
return CryptoJS.lib.WordArray.random(bytes);
|
|
1473
|
+
}
|
|
1474
|
+
}, {
|
|
1475
|
+
key: "create",
|
|
1476
|
+
value: function create(document) {
|
|
1477
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1478
|
+
|
|
1479
|
+
if (!options.ownerPassword && !options.userPassword) {
|
|
1480
|
+
return null;
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
return new PDFSecurity(document, options);
|
|
1484
|
+
}
|
|
1478
1485
|
}]);
|
|
1479
1486
|
|
|
1480
1487
|
return PDFSecurity;
|
|
@@ -1891,7 +1898,7 @@ var PDFGradient = /*#__PURE__*/function () {
|
|
|
1891
1898
|
}
|
|
1892
1899
|
}, {
|
|
1893
1900
|
key: "apply",
|
|
1894
|
-
value: function apply(
|
|
1901
|
+
value: function apply(stroke) {
|
|
1895
1902
|
// apply gradient transform to existing document ctm
|
|
1896
1903
|
var _this$doc$_ctm = _slicedToArray(this.doc._ctm, 6),
|
|
1897
1904
|
m0 = _this$doc$_ctm[0],
|
|
@@ -1915,6 +1922,9 @@ var PDFGradient = /*#__PURE__*/function () {
|
|
|
1915
1922
|
this.embed(m);
|
|
1916
1923
|
}
|
|
1917
1924
|
|
|
1925
|
+
this.doc._setColorSpace('Pattern', stroke);
|
|
1926
|
+
|
|
1927
|
+
var op = stroke ? 'SCN' : 'scn';
|
|
1918
1928
|
return this.doc.addContent("/".concat(this.id, " ").concat(op));
|
|
1919
1929
|
}
|
|
1920
1930
|
}]);
|
|
@@ -2009,21 +2019,143 @@ var Gradient = {
|
|
|
2009
2019
|
PDFRadialGradient: PDFRadialGradient
|
|
2010
2020
|
};
|
|
2011
2021
|
|
|
2022
|
+
/*
|
|
2023
|
+
PDF tiling pattern support. Uncolored only.
|
|
2024
|
+
*/
|
|
2025
|
+
var underlyingColorSpaces = ['DeviceCMYK', 'DeviceRGB'];
|
|
2026
|
+
|
|
2027
|
+
var PDFTilingPattern = /*#__PURE__*/function () {
|
|
2028
|
+
function PDFTilingPattern(doc, bBox, xStep, yStep, stream) {
|
|
2029
|
+
_classCallCheck(this, PDFTilingPattern);
|
|
2030
|
+
|
|
2031
|
+
this.doc = doc;
|
|
2032
|
+
this.bBox = bBox;
|
|
2033
|
+
this.xStep = xStep;
|
|
2034
|
+
this.yStep = yStep;
|
|
2035
|
+
this.stream = stream;
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
_createClass(PDFTilingPattern, [{
|
|
2039
|
+
key: "createPattern",
|
|
2040
|
+
value: function createPattern() {
|
|
2041
|
+
// no resources needed for our current usage
|
|
2042
|
+
// required entry
|
|
2043
|
+
var resources = this.doc.ref();
|
|
2044
|
+
resources.end(); // apply default transform matrix (flipped in the default doc._ctm)
|
|
2045
|
+
// see document.js & gradient.js
|
|
2046
|
+
|
|
2047
|
+
var _this$doc$_ctm = _slicedToArray(this.doc._ctm, 6),
|
|
2048
|
+
m0 = _this$doc$_ctm[0],
|
|
2049
|
+
m1 = _this$doc$_ctm[1],
|
|
2050
|
+
m2 = _this$doc$_ctm[2],
|
|
2051
|
+
m3 = _this$doc$_ctm[3],
|
|
2052
|
+
m4 = _this$doc$_ctm[4],
|
|
2053
|
+
m5 = _this$doc$_ctm[5];
|
|
2054
|
+
|
|
2055
|
+
var m11 = 1,
|
|
2056
|
+
m12 = 0,
|
|
2057
|
+
m21 = 0,
|
|
2058
|
+
m22 = 1,
|
|
2059
|
+
dx = 0,
|
|
2060
|
+
dy = 0;
|
|
2061
|
+
var m = [m0 * m11 + m2 * m12, m1 * m11 + m3 * m12, m0 * m21 + m2 * m22, m1 * m21 + m3 * m22, m0 * dx + m2 * dy + m4, m1 * dx + m3 * dy + m5];
|
|
2062
|
+
var pattern = this.doc.ref({
|
|
2063
|
+
Type: 'Pattern',
|
|
2064
|
+
PatternType: 1,
|
|
2065
|
+
// tiling
|
|
2066
|
+
PaintType: 2,
|
|
2067
|
+
// 1-colored, 2-uncolored
|
|
2068
|
+
TilingType: 2,
|
|
2069
|
+
// 2-no distortion
|
|
2070
|
+
BBox: this.bBox,
|
|
2071
|
+
XStep: this.xStep,
|
|
2072
|
+
YStep: this.yStep,
|
|
2073
|
+
Matrix: m.map(function (v) {
|
|
2074
|
+
return +v.toFixed(5);
|
|
2075
|
+
}),
|
|
2076
|
+
Resources: resources
|
|
2077
|
+
});
|
|
2078
|
+
pattern.end(this.stream);
|
|
2079
|
+
return pattern;
|
|
2080
|
+
}
|
|
2081
|
+
}, {
|
|
2082
|
+
key: "embedPatternColorSpaces",
|
|
2083
|
+
value: function embedPatternColorSpaces() {
|
|
2084
|
+
var _this = this;
|
|
2085
|
+
|
|
2086
|
+
// map each pattern to an underlying color space
|
|
2087
|
+
// and embed on each page
|
|
2088
|
+
underlyingColorSpaces.forEach(function (csName) {
|
|
2089
|
+
var csId = _this.getPatternColorSpaceId(csName);
|
|
2090
|
+
|
|
2091
|
+
if (_this.doc.page.colorSpaces[csId]) return;
|
|
2092
|
+
|
|
2093
|
+
var cs = _this.doc.ref(['Pattern', csName]);
|
|
2094
|
+
|
|
2095
|
+
cs.end();
|
|
2096
|
+
_this.doc.page.colorSpaces[csId] = cs;
|
|
2097
|
+
});
|
|
2098
|
+
}
|
|
2099
|
+
}, {
|
|
2100
|
+
key: "getPatternColorSpaceId",
|
|
2101
|
+
value: function getPatternColorSpaceId(underlyingColorspace) {
|
|
2102
|
+
return "CsP".concat(underlyingColorspace);
|
|
2103
|
+
}
|
|
2104
|
+
}, {
|
|
2105
|
+
key: "embed",
|
|
2106
|
+
value: function embed() {
|
|
2107
|
+
if (!this.id) {
|
|
2108
|
+
this.doc._patternCount = this.doc._patternCount + 1;
|
|
2109
|
+
this.id = 'P' + this.doc._patternCount;
|
|
2110
|
+
this.pattern = this.createPattern();
|
|
2111
|
+
} // patterns are embedded in each page
|
|
2112
|
+
|
|
2113
|
+
|
|
2114
|
+
if (!this.doc.page.patterns[this.id]) {
|
|
2115
|
+
this.doc.page.patterns[this.id] = this.pattern;
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
}, {
|
|
2119
|
+
key: "apply",
|
|
2120
|
+
value: function apply(stroke, patternColor) {
|
|
2121
|
+
// do any embedding/creating that might be needed
|
|
2122
|
+
this.embedPatternColorSpaces();
|
|
2123
|
+
this.embed();
|
|
2124
|
+
|
|
2125
|
+
var normalizedColor = this.doc._normalizeColor(patternColor);
|
|
2126
|
+
|
|
2127
|
+
if (!normalizedColor) throw Error("invalid pattern color. (value: ".concat(patternColor, ")")); // select one of the pattern color spaces
|
|
2128
|
+
|
|
2129
|
+
var csId = this.getPatternColorSpaceId(this.doc._getColorSpace(normalizedColor));
|
|
2130
|
+
|
|
2131
|
+
this.doc._setColorSpace(csId, stroke); // stroke/fill using the pattern and color (in the above underlying color space)
|
|
2132
|
+
|
|
2133
|
+
|
|
2134
|
+
var op = stroke ? 'SCN' : 'scn';
|
|
2135
|
+
return this.doc.addContent("".concat(normalizedColor.join(' '), " /").concat(this.id, " ").concat(op));
|
|
2136
|
+
}
|
|
2137
|
+
}]);
|
|
2138
|
+
|
|
2139
|
+
return PDFTilingPattern;
|
|
2140
|
+
}();
|
|
2141
|
+
|
|
2142
|
+
var pattern = {
|
|
2143
|
+
PDFTilingPattern: PDFTilingPattern
|
|
2144
|
+
};
|
|
2145
|
+
|
|
2012
2146
|
var PDFGradient$1 = Gradient.PDFGradient,
|
|
2013
2147
|
PDFLinearGradient$1 = Gradient.PDFLinearGradient,
|
|
2014
2148
|
PDFRadialGradient$1 = Gradient.PDFRadialGradient;
|
|
2149
|
+
var PDFTilingPattern$1 = pattern.PDFTilingPattern;
|
|
2015
2150
|
var ColorMixin = {
|
|
2016
2151
|
initColor: function initColor() {
|
|
2017
2152
|
// The opacity dictionaries
|
|
2018
2153
|
this._opacityRegistry = {};
|
|
2019
2154
|
this._opacityCount = 0;
|
|
2155
|
+
this._patternCount = 0;
|
|
2020
2156
|
return this._gradCount = 0;
|
|
2021
2157
|
},
|
|
2022
2158
|
_normalizeColor: function _normalizeColor(color) {
|
|
2023
|
-
if (color instanceof PDFGradient$1) {
|
|
2024
|
-
return color;
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
2159
|
if (typeof color === 'string') {
|
|
2028
2160
|
if (color.charAt(0) === '#') {
|
|
2029
2161
|
if (color.length === 4) {
|
|
@@ -2055,6 +2187,18 @@ var ColorMixin = {
|
|
|
2055
2187
|
return null;
|
|
2056
2188
|
},
|
|
2057
2189
|
_setColor: function _setColor(color, stroke) {
|
|
2190
|
+
if (color instanceof PDFGradient$1) {
|
|
2191
|
+
color.apply(stroke);
|
|
2192
|
+
return true; // see if tiling pattern, decode & apply it it
|
|
2193
|
+
} else if (Array.isArray(color) && color[0] instanceof PDFTilingPattern$1) {
|
|
2194
|
+
color[0].apply(stroke, color[1]);
|
|
2195
|
+
return true;
|
|
2196
|
+
} // any other case should be a normal color and not a pattern
|
|
2197
|
+
|
|
2198
|
+
|
|
2199
|
+
return this._setColorCore(color, stroke);
|
|
2200
|
+
},
|
|
2201
|
+
_setColorCore: function _setColorCore(color, stroke) {
|
|
2058
2202
|
color = this._normalizeColor(color);
|
|
2059
2203
|
|
|
2060
2204
|
if (!color) {
|
|
@@ -2063,25 +2207,21 @@ var ColorMixin = {
|
|
|
2063
2207
|
|
|
2064
2208
|
var op = stroke ? 'SCN' : 'scn';
|
|
2065
2209
|
|
|
2066
|
-
|
|
2067
|
-
this._setColorSpace('Pattern', stroke);
|
|
2068
|
-
|
|
2069
|
-
color.apply(op);
|
|
2070
|
-
} else {
|
|
2071
|
-
var space = color.length === 4 ? 'DeviceCMYK' : 'DeviceRGB';
|
|
2072
|
-
|
|
2073
|
-
this._setColorSpace(space, stroke);
|
|
2210
|
+
var space = this._getColorSpace(color);
|
|
2074
2211
|
|
|
2075
|
-
|
|
2076
|
-
this.addContent("".concat(color, " ").concat(op));
|
|
2077
|
-
}
|
|
2212
|
+
this._setColorSpace(space, stroke);
|
|
2078
2213
|
|
|
2214
|
+
color = color.join(' ');
|
|
2215
|
+
this.addContent("".concat(color, " ").concat(op));
|
|
2079
2216
|
return true;
|
|
2080
2217
|
},
|
|
2081
2218
|
_setColorSpace: function _setColorSpace(space, stroke) {
|
|
2082
2219
|
var op = stroke ? 'CS' : 'cs';
|
|
2083
2220
|
return this.addContent("/".concat(space, " ").concat(op));
|
|
2084
2221
|
},
|
|
2222
|
+
_getColorSpace: function _getColorSpace(color) {
|
|
2223
|
+
return color.length === 4 ? 'DeviceCMYK' : 'DeviceRGB';
|
|
2224
|
+
},
|
|
2085
2225
|
fillColor: function fillColor(color, opacity) {
|
|
2086
2226
|
var set = this._setColor(color, false);
|
|
2087
2227
|
|
|
@@ -2168,6 +2308,9 @@ var ColorMixin = {
|
|
|
2168
2308
|
},
|
|
2169
2309
|
radialGradient: function radialGradient(x1, y1, r1, x2, y2, r2) {
|
|
2170
2310
|
return new PDFRadialGradient$1(this, x1, y1, r1, x2, y2, r2);
|
|
2311
|
+
},
|
|
2312
|
+
pattern: function pattern(bbox, xStep, yStep, stream) {
|
|
2313
|
+
return new PDFTilingPattern$1(this, bbox, xStep, yStep, stream);
|
|
2171
2314
|
}
|
|
2172
2315
|
};
|
|
2173
2316
|
var namedColors = {
|
|
@@ -3101,13 +3244,6 @@ var WIN_ANSI_MAP = {
|
|
|
3101
3244
|
var characters = ".notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n \nspace exclam quotedbl numbersign\ndollar percent ampersand quotesingle\nparenleft parenright asterisk plus\ncomma hyphen period slash\nzero one two three\nfour five six seven\neight nine colon semicolon\nless equal greater question\n \nat A B C\nD E F G\nH I J K\nL M N O\nP Q R S\nT U V W\nX Y Z bracketleft\nbackslash bracketright asciicircum underscore\n \ngrave a b c\nd e f g\nh i j k\nl m n o\np q r s\nt u v w\nx y z braceleft\nbar braceright asciitilde .notdef\n \nEuro .notdef quotesinglbase florin\nquotedblbase ellipsis dagger daggerdbl\ncircumflex perthousand Scaron guilsinglleft\nOE .notdef Zcaron .notdef\n.notdef quoteleft quoteright quotedblleft\nquotedblright bullet endash emdash\ntilde trademark scaron guilsinglright\noe .notdef zcaron ydieresis\n \nspace exclamdown cent sterling\ncurrency yen brokenbar section\ndieresis copyright ordfeminine guillemotleft\nlogicalnot hyphen registered macron\ndegree plusminus twosuperior threesuperior\nacute mu paragraph periodcentered\ncedilla onesuperior ordmasculine guillemotright\nonequarter onehalf threequarters questiondown\n \nAgrave Aacute Acircumflex Atilde\nAdieresis Aring AE Ccedilla\nEgrave Eacute Ecircumflex Edieresis\nIgrave Iacute Icircumflex Idieresis\nEth Ntilde Ograve Oacute\nOcircumflex Otilde Odieresis multiply\nOslash Ugrave Uacute Ucircumflex\nUdieresis Yacute Thorn germandbls\n \nagrave aacute acircumflex atilde\nadieresis aring ae ccedilla\negrave eacute ecircumflex edieresis\nigrave iacute icircumflex idieresis\neth ntilde ograve oacute\nocircumflex otilde odieresis divide\noslash ugrave uacute ucircumflex\nudieresis yacute thorn ydieresis".split(/\s+/);
|
|
3102
3245
|
|
|
3103
3246
|
var AFMFont = /*#__PURE__*/function () {
|
|
3104
|
-
_createClass(AFMFont, null, [{
|
|
3105
|
-
key: "open",
|
|
3106
|
-
value: function open(filename) {
|
|
3107
|
-
return new AFMFont(fs.readFileSync(filename, 'utf8'));
|
|
3108
|
-
}
|
|
3109
|
-
}]);
|
|
3110
|
-
|
|
3111
3247
|
function AFMFont(contents) {
|
|
3112
3248
|
_classCallCheck(this, AFMFont);
|
|
3113
3249
|
|
|
@@ -3252,6 +3388,11 @@ var AFMFont = /*#__PURE__*/function () {
|
|
|
3252
3388
|
|
|
3253
3389
|
return advances;
|
|
3254
3390
|
}
|
|
3391
|
+
}], [{
|
|
3392
|
+
key: "open",
|
|
3393
|
+
value: function open(filename) {
|
|
3394
|
+
return new AFMFont(fs.readFileSync(filename, 'utf8'));
|
|
3395
|
+
}
|
|
3255
3396
|
}]);
|
|
3256
3397
|
|
|
3257
3398
|
return AFMFont;
|