pdfkit 0.8.3 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +121 -111
  3. package/js/{font/data → data}/Courier-Bold.afm +0 -0
  4. package/js/{font/data → data}/Courier-BoldOblique.afm +0 -0
  5. package/js/{font/data → data}/Courier-Oblique.afm +0 -0
  6. package/js/{font/data → data}/Courier.afm +0 -0
  7. package/js/{font/data → data}/Helvetica-Bold.afm +0 -0
  8. package/js/{font/data → data}/Helvetica-BoldOblique.afm +0 -0
  9. package/js/{font/data → data}/Helvetica-Oblique.afm +0 -0
  10. package/js/{font/data → data}/Helvetica.afm +0 -0
  11. package/js/{font/data → data}/Symbol.afm +0 -0
  12. package/js/{font/data → data}/Times-Bold.afm +0 -0
  13. package/js/{font/data → data}/Times-BoldItalic.afm +0 -0
  14. package/js/{font/data → data}/Times-Italic.afm +0 -0
  15. package/js/{font/data → data}/Times-Roman.afm +0 -0
  16. package/js/{font/data → data}/ZapfDingbats.afm +0 -0
  17. package/js/pdfkit.es5.js +6202 -0
  18. package/js/pdfkit.es5.js.map +1 -0
  19. package/js/pdfkit.esnext.js +5549 -0
  20. package/js/pdfkit.esnext.js.map +1 -0
  21. package/js/pdfkit.js +5581 -0
  22. package/js/pdfkit.js.map +1 -0
  23. package/js/pdfkit.standalone.js +65118 -0
  24. package/js/virtual-fs.js +70 -0
  25. package/package.json +52 -22
  26. package/.npmignore +0 -8
  27. package/Makefile +0 -30
  28. package/js/data.js +0 -192
  29. package/js/document.js +0 -247
  30. package/js/font/afm.js +0 -170
  31. package/js/font/data/MustRead.html +0 -19
  32. package/js/font/embedded.js +0 -234
  33. package/js/font/standard.js +0 -124
  34. package/js/font.js +0 -75
  35. package/js/gradient.js +0 -240
  36. package/js/image/jpeg.js +0 -78
  37. package/js/image/png.js +0 -158
  38. package/js/image.js +0 -53
  39. package/js/line_wrapper.js +0 -252
  40. package/js/mixins/annotations.js +0 -133
  41. package/js/mixins/color.js +0 -298
  42. package/js/mixins/fonts.js +0 -71
  43. package/js/mixins/images.js +0 -111
  44. package/js/mixins/text.js +0 -344
  45. package/js/mixins/vector.js +0 -302
  46. package/js/object.js +0 -115
  47. package/js/page.js +0 -170
  48. package/js/path.js +0 -366
  49. package/js/reference.js +0 -109
package/js/gradient.js DELETED
@@ -1,240 +0,0 @@
1
- // Generated by CoffeeScript 1.12.6
2
- (function() {
3
- var PDFGradient, PDFLinearGradient, PDFRadialGradient,
4
- extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
5
- hasProp = {}.hasOwnProperty;
6
-
7
- PDFGradient = (function() {
8
- function PDFGradient(doc) {
9
- this.doc = doc;
10
- this.stops = [];
11
- this.embedded = false;
12
- this.transform = [1, 0, 0, 1, 0, 0];
13
- this._colorSpace = 'DeviceRGB';
14
- }
15
-
16
- PDFGradient.prototype.stop = function(pos, color, opacity) {
17
- if (opacity == null) {
18
- opacity = 1;
19
- }
20
- opacity = Math.max(0, Math.min(1, opacity));
21
- this.stops.push([pos, this.doc._normalizeColor(color), opacity]);
22
- return this;
23
- };
24
-
25
- PDFGradient.prototype.setTransform = function(m11, m12, m21, m22, dx, dy) {
26
- this.transform = [m11, m12, m21, m22, dx, dy];
27
- return this;
28
- };
29
-
30
- PDFGradient.prototype.embed = function(m) {
31
- var bounds, encode, fn, form, grad, gstate, i, j, k, last, len, opacityPattern, pageBBox, pattern, ref, ref1, shader, stop, stops, v;
32
- if (this.stops.length === 0) {
33
- return;
34
- }
35
- this.embedded = true;
36
- this.matrix = m;
37
- last = this.stops[this.stops.length - 1];
38
- if (last[0] < 1) {
39
- this.stops.push([1, last[1], last[2]]);
40
- }
41
- bounds = [];
42
- encode = [];
43
- stops = [];
44
- for (i = j = 0, ref = this.stops.length - 1; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
45
- encode.push(0, 1);
46
- if (i + 2 !== this.stops.length) {
47
- bounds.push(this.stops[i + 1][0]);
48
- }
49
- fn = this.doc.ref({
50
- FunctionType: 2,
51
- Domain: [0, 1],
52
- C0: this.stops[i + 0][1],
53
- C1: this.stops[i + 1][1],
54
- N: 1
55
- });
56
- stops.push(fn);
57
- fn.end();
58
- }
59
- if (stops.length === 1) {
60
- fn = stops[0];
61
- } else {
62
- fn = this.doc.ref({
63
- FunctionType: 3,
64
- Domain: [0, 1],
65
- Functions: stops,
66
- Bounds: bounds,
67
- Encode: encode
68
- });
69
- fn.end();
70
- }
71
- this.id = 'Sh' + (++this.doc._gradCount);
72
- shader = this.shader(fn);
73
- shader.end();
74
- pattern = this.doc.ref({
75
- Type: 'Pattern',
76
- PatternType: 2,
77
- Shading: shader,
78
- Matrix: (function() {
79
- var k, len, ref1, results;
80
- ref1 = this.matrix;
81
- results = [];
82
- for (k = 0, len = ref1.length; k < len; k++) {
83
- v = ref1[k];
84
- results.push(+v.toFixed(5));
85
- }
86
- return results;
87
- }).call(this)
88
- });
89
- pattern.end();
90
- if (this.stops.some(function(stop) {
91
- return stop[2] < 1;
92
- })) {
93
- grad = this.opacityGradient();
94
- grad._colorSpace = 'DeviceGray';
95
- ref1 = this.stops;
96
- for (k = 0, len = ref1.length; k < len; k++) {
97
- stop = ref1[k];
98
- grad.stop(stop[0], [stop[2]]);
99
- }
100
- grad = grad.embed(this.matrix);
101
- pageBBox = [0, 0, this.doc.page.width, this.doc.page.height];
102
- form = this.doc.ref({
103
- Type: 'XObject',
104
- Subtype: 'Form',
105
- FormType: 1,
106
- BBox: pageBBox,
107
- Group: {
108
- Type: 'Group',
109
- S: 'Transparency',
110
- CS: 'DeviceGray'
111
- },
112
- Resources: {
113
- ProcSet: ['PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'],
114
- Pattern: {
115
- Sh1: grad
116
- }
117
- }
118
- });
119
- form.write("/Pattern cs /Sh1 scn");
120
- form.end((pageBBox.join(" ")) + " re f");
121
- gstate = this.doc.ref({
122
- Type: 'ExtGState',
123
- SMask: {
124
- Type: 'Mask',
125
- S: 'Luminosity',
126
- G: form
127
- }
128
- });
129
- gstate.end();
130
- opacityPattern = this.doc.ref({
131
- Type: 'Pattern',
132
- PatternType: 1,
133
- PaintType: 1,
134
- TilingType: 2,
135
- BBox: pageBBox,
136
- XStep: pageBBox[2],
137
- YStep: pageBBox[3],
138
- Resources: {
139
- ProcSet: ['PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'],
140
- Pattern: {
141
- Sh1: pattern
142
- },
143
- ExtGState: {
144
- Gs1: gstate
145
- }
146
- }
147
- });
148
- opacityPattern.write("/Gs1 gs /Pattern cs /Sh1 scn");
149
- opacityPattern.end((pageBBox.join(" ")) + " re f");
150
- this.doc.page.patterns[this.id] = opacityPattern;
151
- } else {
152
- this.doc.page.patterns[this.id] = pattern;
153
- }
154
- return pattern;
155
- };
156
-
157
- PDFGradient.prototype.apply = function(op) {
158
- var dx, dy, m, m0, m1, m11, m12, m2, m21, m22, m3, m4, m5, ref, ref1;
159
- ref = this.doc._ctm.slice(), m0 = ref[0], m1 = ref[1], m2 = ref[2], m3 = ref[3], m4 = ref[4], m5 = ref[5];
160
- ref1 = this.transform, m11 = ref1[0], m12 = ref1[1], m21 = ref1[2], m22 = ref1[3], dx = ref1[4], dy = ref1[5];
161
- 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];
162
- if (!(this.embedded && m.join(" ") === this.matrix.join(" "))) {
163
- this.embed(m);
164
- }
165
- return this.doc.addContent("/" + this.id + " " + op);
166
- };
167
-
168
- return PDFGradient;
169
-
170
- })();
171
-
172
- PDFLinearGradient = (function(superClass) {
173
- extend(PDFLinearGradient, superClass);
174
-
175
- function PDFLinearGradient(doc, x1, y1, x2, y2) {
176
- this.doc = doc;
177
- this.x1 = x1;
178
- this.y1 = y1;
179
- this.x2 = x2;
180
- this.y2 = y2;
181
- PDFLinearGradient.__super__.constructor.apply(this, arguments);
182
- }
183
-
184
- PDFLinearGradient.prototype.shader = function(fn) {
185
- return this.doc.ref({
186
- ShadingType: 2,
187
- ColorSpace: this._colorSpace,
188
- Coords: [this.x1, this.y1, this.x2, this.y2],
189
- Function: fn,
190
- Extend: [true, true]
191
- });
192
- };
193
-
194
- PDFLinearGradient.prototype.opacityGradient = function() {
195
- return new PDFLinearGradient(this.doc, this.x1, this.y1, this.x2, this.y2);
196
- };
197
-
198
- return PDFLinearGradient;
199
-
200
- })(PDFGradient);
201
-
202
- PDFRadialGradient = (function(superClass) {
203
- extend(PDFRadialGradient, superClass);
204
-
205
- function PDFRadialGradient(doc, x1, y1, r1, x2, y2, r2) {
206
- this.doc = doc;
207
- this.x1 = x1;
208
- this.y1 = y1;
209
- this.r1 = r1;
210
- this.x2 = x2;
211
- this.y2 = y2;
212
- this.r2 = r2;
213
- PDFRadialGradient.__super__.constructor.apply(this, arguments);
214
- }
215
-
216
- PDFRadialGradient.prototype.shader = function(fn) {
217
- return this.doc.ref({
218
- ShadingType: 3,
219
- ColorSpace: this._colorSpace,
220
- Coords: [this.x1, this.y1, this.r1, this.x2, this.y2, this.r2],
221
- Function: fn,
222
- Extend: [true, true]
223
- });
224
- };
225
-
226
- PDFRadialGradient.prototype.opacityGradient = function() {
227
- return new PDFRadialGradient(this.doc, this.x1, this.y1, this.r1, this.x2, this.y2, this.r2);
228
- };
229
-
230
- return PDFRadialGradient;
231
-
232
- })(PDFGradient);
233
-
234
- module.exports = {
235
- PDFGradient: PDFGradient,
236
- PDFLinearGradient: PDFLinearGradient,
237
- PDFRadialGradient: PDFRadialGradient
238
- };
239
-
240
- }).call(this);
package/js/image/jpeg.js DELETED
@@ -1,78 +0,0 @@
1
- // Generated by CoffeeScript 1.12.6
2
- (function() {
3
- var JPEG, fs,
4
- indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
5
-
6
- fs = require('fs');
7
-
8
- JPEG = (function() {
9
- var MARKERS;
10
-
11
- MARKERS = [0xFFC0, 0xFFC1, 0xFFC2, 0xFFC3, 0xFFC5, 0xFFC6, 0xFFC7, 0xFFC8, 0xFFC9, 0xFFCA, 0xFFCB, 0xFFCC, 0xFFCD, 0xFFCE, 0xFFCF];
12
-
13
- function JPEG(data, label) {
14
- var channels, marker, pos;
15
- this.data = data;
16
- this.label = label;
17
- if (this.data.readUInt16BE(0) !== 0xFFD8) {
18
- throw "SOI not found in JPEG";
19
- }
20
- pos = 2;
21
- while (pos < this.data.length) {
22
- marker = this.data.readUInt16BE(pos);
23
- pos += 2;
24
- if (indexOf.call(MARKERS, marker) >= 0) {
25
- break;
26
- }
27
- pos += this.data.readUInt16BE(pos);
28
- }
29
- if (indexOf.call(MARKERS, marker) < 0) {
30
- throw "Invalid JPEG.";
31
- }
32
- pos += 2;
33
- this.bits = this.data[pos++];
34
- this.height = this.data.readUInt16BE(pos);
35
- pos += 2;
36
- this.width = this.data.readUInt16BE(pos);
37
- pos += 2;
38
- channels = this.data[pos++];
39
- this.colorSpace = (function() {
40
- switch (channels) {
41
- case 1:
42
- return 'DeviceGray';
43
- case 3:
44
- return 'DeviceRGB';
45
- case 4:
46
- return 'DeviceCMYK';
47
- }
48
- })();
49
- this.obj = null;
50
- }
51
-
52
- JPEG.prototype.embed = function(document) {
53
- if (this.obj) {
54
- return;
55
- }
56
- this.obj = document.ref({
57
- Type: 'XObject',
58
- Subtype: 'Image',
59
- BitsPerComponent: this.bits,
60
- Width: this.width,
61
- Height: this.height,
62
- ColorSpace: this.colorSpace,
63
- Filter: 'DCTDecode'
64
- });
65
- if (this.colorSpace === 'DeviceCMYK') {
66
- this.obj.data['Decode'] = [1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0];
67
- }
68
- this.obj.end(this.data);
69
- return this.data = null;
70
- };
71
-
72
- return JPEG;
73
-
74
- })();
75
-
76
- module.exports = JPEG;
77
-
78
- }).call(this);
package/js/image/png.js DELETED
@@ -1,158 +0,0 @@
1
- // Generated by CoffeeScript 1.12.6
2
- (function() {
3
- var PNG, PNGImage, zlib;
4
-
5
- zlib = require('zlib');
6
-
7
- PNG = require('png-js');
8
-
9
- PNGImage = (function() {
10
- function PNGImage(data, label) {
11
- this.label = label;
12
- this.image = new PNG(data);
13
- this.width = this.image.width;
14
- this.height = this.image.height;
15
- this.imgData = this.image.imgData;
16
- this.obj = null;
17
- }
18
-
19
- PNGImage.prototype.embed = function(document) {
20
- var k, len1, mask, palette, params, rgb, val, x;
21
- this.document = document;
22
- if (this.obj) {
23
- return;
24
- }
25
- this.obj = this.document.ref({
26
- Type: 'XObject',
27
- Subtype: 'Image',
28
- BitsPerComponent: this.image.bits,
29
- Width: this.width,
30
- Height: this.height,
31
- Filter: 'FlateDecode'
32
- });
33
- if (!this.image.hasAlphaChannel) {
34
- params = this.document.ref({
35
- Predictor: 15,
36
- Colors: this.image.colors,
37
- BitsPerComponent: this.image.bits,
38
- Columns: this.width
39
- });
40
- this.obj.data['DecodeParms'] = params;
41
- params.end();
42
- }
43
- if (this.image.palette.length === 0) {
44
- this.obj.data['ColorSpace'] = this.image.colorSpace;
45
- } else {
46
- palette = this.document.ref();
47
- palette.end(new Buffer(this.image.palette));
48
- this.obj.data['ColorSpace'] = ['Indexed', 'DeviceRGB', (this.image.palette.length / 3) - 1, palette];
49
- }
50
- if (this.image.transparency.grayscale) {
51
- val = this.image.transparency.greyscale;
52
- return this.obj.data['Mask'] = [val, val];
53
- } else if (this.image.transparency.rgb) {
54
- rgb = this.image.transparency.rgb;
55
- mask = [];
56
- for (k = 0, len1 = rgb.length; k < len1; k++) {
57
- x = rgb[k];
58
- mask.push(x, x);
59
- }
60
- return this.obj.data['Mask'] = mask;
61
- } else if (this.image.transparency.indexed) {
62
- return this.loadIndexedAlphaChannel();
63
- } else if (this.image.hasAlphaChannel) {
64
- return this.splitAlphaChannel();
65
- } else {
66
- return this.finalize();
67
- }
68
- };
69
-
70
- PNGImage.prototype.finalize = function() {
71
- var sMask;
72
- if (this.alphaChannel) {
73
- sMask = this.document.ref({
74
- Type: 'XObject',
75
- Subtype: 'Image',
76
- Height: this.height,
77
- Width: this.width,
78
- BitsPerComponent: 8,
79
- Filter: 'FlateDecode',
80
- ColorSpace: 'DeviceGray',
81
- Decode: [0, 1]
82
- });
83
- sMask.end(this.alphaChannel);
84
- this.obj.data['SMask'] = sMask;
85
- }
86
- this.obj.end(this.imgData);
87
- this.image = null;
88
- return this.imgData = null;
89
- };
90
-
91
- PNGImage.prototype.splitAlphaChannel = function() {
92
- return this.image.decodePixels((function(_this) {
93
- return function(pixels) {
94
- var a, alphaChannel, colorByteSize, done, i, imgData, len, p, pixelCount;
95
- colorByteSize = _this.image.colors * _this.image.bits / 8;
96
- pixelCount = _this.width * _this.height;
97
- imgData = new Buffer(pixelCount * colorByteSize);
98
- alphaChannel = new Buffer(pixelCount);
99
- i = p = a = 0;
100
- len = pixels.length;
101
- while (i < len) {
102
- imgData[p++] = pixels[i++];
103
- imgData[p++] = pixels[i++];
104
- imgData[p++] = pixels[i++];
105
- alphaChannel[a++] = pixels[i++];
106
- }
107
- done = 0;
108
- zlib.deflate(imgData, function(err, imgData1) {
109
- _this.imgData = imgData1;
110
- if (err) {
111
- throw err;
112
- }
113
- if (++done === 2) {
114
- return _this.finalize();
115
- }
116
- });
117
- return zlib.deflate(alphaChannel, function(err, alphaChannel1) {
118
- _this.alphaChannel = alphaChannel1;
119
- if (err) {
120
- throw err;
121
- }
122
- if (++done === 2) {
123
- return _this.finalize();
124
- }
125
- });
126
- };
127
- })(this));
128
- };
129
-
130
- PNGImage.prototype.loadIndexedAlphaChannel = function(fn) {
131
- var transparency;
132
- transparency = this.image.transparency.indexed;
133
- return this.image.decodePixels((function(_this) {
134
- return function(pixels) {
135
- var alphaChannel, i, j, k, ref;
136
- alphaChannel = new Buffer(_this.width * _this.height);
137
- i = 0;
138
- for (j = k = 0, ref = pixels.length; k < ref; j = k += 1) {
139
- alphaChannel[i++] = transparency[pixels[j]];
140
- }
141
- return zlib.deflate(alphaChannel, function(err, alphaChannel1) {
142
- _this.alphaChannel = alphaChannel1;
143
- if (err) {
144
- throw err;
145
- }
146
- return _this.finalize();
147
- });
148
- };
149
- })(this));
150
- };
151
-
152
- return PNGImage;
153
-
154
- })();
155
-
156
- module.exports = PNGImage;
157
-
158
- }).call(this);
package/js/image.js DELETED
@@ -1,53 +0,0 @@
1
- // Generated by CoffeeScript 1.12.6
2
-
3
- /*
4
- PDFImage - embeds images in PDF documents
5
- By Devon Govett
6
- */
7
-
8
- (function() {
9
- var Data, JPEG, PDFImage, PNG, fs;
10
-
11
- fs = require('fs');
12
-
13
- Data = require('./data');
14
-
15
- JPEG = require('./image/jpeg');
16
-
17
- PNG = require('./image/png');
18
-
19
- PDFImage = (function() {
20
- function PDFImage() {}
21
-
22
- PDFImage.open = function(src, label) {
23
- var data, match;
24
- if (Buffer.isBuffer(src)) {
25
- data = src;
26
- } else if (src instanceof ArrayBuffer) {
27
- data = new Buffer(new Uint8Array(src));
28
- } else {
29
- if (match = /^data:.+;base64,(.*)$/.exec(src)) {
30
- data = new Buffer(match[1], 'base64');
31
- } else {
32
- data = fs.readFileSync(src);
33
- if (!data) {
34
- return;
35
- }
36
- }
37
- }
38
- if (data[0] === 0xff && data[1] === 0xd8) {
39
- return new JPEG(data, label);
40
- } else if (data[0] === 0x89 && data.toString('ascii', 1, 4) === 'PNG') {
41
- return new PNG(data, label);
42
- } else {
43
- throw new Error('Unknown image format.');
44
- }
45
- };
46
-
47
- return PDFImage;
48
-
49
- })();
50
-
51
- module.exports = PDFImage;
52
-
53
- }).call(this);