pdfkit 0.8.2 → 0.10.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 (50) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +7 -7
  3. package/README.md +175 -171
  4. package/js/{font/data → data}/Courier-Bold.afm +342 -342
  5. package/js/{font/data → data}/Courier-BoldOblique.afm +342 -342
  6. package/js/{font/data → data}/Courier-Oblique.afm +342 -342
  7. package/js/{font/data → data}/Courier.afm +342 -342
  8. package/js/{font/data → data}/Helvetica-Bold.afm +2827 -2827
  9. package/js/{font/data → data}/Helvetica-BoldOblique.afm +2827 -2827
  10. package/js/{font/data → data}/Helvetica-Oblique.afm +3051 -3051
  11. package/js/{font/data → data}/Helvetica.afm +3051 -3051
  12. package/js/{font/data → data}/Symbol.afm +213 -213
  13. package/js/{font/data → data}/Times-Bold.afm +2588 -2588
  14. package/js/{font/data → data}/Times-BoldItalic.afm +2384 -2384
  15. package/js/{font/data → data}/Times-Italic.afm +2667 -2667
  16. package/js/{font/data → data}/Times-Roman.afm +2419 -2419
  17. package/js/{font/data → data}/ZapfDingbats.afm +225 -225
  18. package/js/pdfkit.es5.js +5724 -0
  19. package/js/pdfkit.es5.js.map +1 -0
  20. package/js/pdfkit.esnext.js +5144 -0
  21. package/js/pdfkit.esnext.js.map +1 -0
  22. package/js/pdfkit.js +5112 -0
  23. package/js/pdfkit.js.map +1 -0
  24. package/js/pdfkit.standalone.js +68105 -0
  25. package/js/virtual-fs.js +70 -0
  26. package/package.json +85 -55
  27. package/.npmignore +0 -8
  28. package/Makefile +0 -30
  29. package/js/data.js +0 -192
  30. package/js/document.js +0 -247
  31. package/js/font/afm.js +0 -170
  32. package/js/font/data/MustRead.html +0 -19
  33. package/js/font/embedded.js +0 -234
  34. package/js/font/standard.js +0 -124
  35. package/js/font.js +0 -75
  36. package/js/gradient.js +0 -240
  37. package/js/image/jpeg.js +0 -78
  38. package/js/image/png.js +0 -158
  39. package/js/image.js +0 -53
  40. package/js/line_wrapper.js +0 -252
  41. package/js/mixins/annotations.js +0 -133
  42. package/js/mixins/color.js +0 -304
  43. package/js/mixins/fonts.js +0 -69
  44. package/js/mixins/images.js +0 -111
  45. package/js/mixins/text.js +0 -337
  46. package/js/mixins/vector.js +0 -265
  47. package/js/object.js +0 -114
  48. package/js/page.js +0 -170
  49. package/js/path.js +0 -366
  50. package/js/reference.js +0 -109
@@ -1,265 +0,0 @@
1
- // Generated by CoffeeScript 1.12.1
2
- (function() {
3
- var KAPPA, SVGPath, number,
4
- slice = [].slice;
5
-
6
- SVGPath = require('../path');
7
-
8
- number = require('../object').number;
9
-
10
- KAPPA = 4.0 * ((Math.sqrt(2) - 1.0) / 3.0);
11
-
12
- module.exports = {
13
- initVector: function() {
14
- this._ctm = [1, 0, 0, 1, 0, 0];
15
- return this._ctmStack = [];
16
- },
17
- save: function() {
18
- this._ctmStack.push(this._ctm.slice());
19
- return this.addContent('q');
20
- },
21
- restore: function() {
22
- this._ctm = this._ctmStack.pop() || [1, 0, 0, 1, 0, 0];
23
- return this.addContent('Q');
24
- },
25
- closePath: function() {
26
- return this.addContent('h');
27
- },
28
- lineWidth: function(w) {
29
- return this.addContent((number(w)) + " w");
30
- },
31
- _CAP_STYLES: {
32
- BUTT: 0,
33
- ROUND: 1,
34
- SQUARE: 2
35
- },
36
- lineCap: function(c) {
37
- if (typeof c === 'string') {
38
- c = this._CAP_STYLES[c.toUpperCase()];
39
- }
40
- return this.addContent(c + " J");
41
- },
42
- _JOIN_STYLES: {
43
- MITER: 0,
44
- ROUND: 1,
45
- BEVEL: 2
46
- },
47
- lineJoin: function(j) {
48
- if (typeof j === 'string') {
49
- j = this._JOIN_STYLES[j.toUpperCase()];
50
- }
51
- return this.addContent(j + " j");
52
- },
53
- miterLimit: function(m) {
54
- return this.addContent((number(m)) + " M");
55
- },
56
- dash: function(length, options) {
57
- var phase, ref, space, v;
58
- if (options == null) {
59
- options = {};
60
- }
61
- if (length == null) {
62
- return this;
63
- }
64
- if (Array.isArray(length)) {
65
- length = ((function() {
66
- var i, len, results;
67
- results = [];
68
- for (i = 0, len = length.length; i < len; i++) {
69
- v = length[i];
70
- results.push(number(v));
71
- }
72
- return results;
73
- })()).join(' ');
74
- phase = options.phase || 0;
75
- return this.addContent("[" + length + "] " + (number(phase)) + " d");
76
- } else {
77
- space = (ref = options.space) != null ? ref : length;
78
- phase = options.phase || 0;
79
- return this.addContent("[" + (number(length)) + " " + (number(space)) + "] " + (number(phase)) + " d");
80
- }
81
- },
82
- undash: function() {
83
- return this.addContent("[] 0 d");
84
- },
85
- moveTo: function(x, y) {
86
- return this.addContent((number(x)) + " " + (number(y)) + " m");
87
- },
88
- lineTo: function(x, y) {
89
- return this.addContent((number(x)) + " " + (number(y)) + " l");
90
- },
91
- bezierCurveTo: function(cp1x, cp1y, cp2x, cp2y, x, y) {
92
- return this.addContent((number(cp1x)) + " " + (number(cp1y)) + " " + (number(cp2x)) + " " + (number(cp2y)) + " " + (number(x)) + " " + (number(y)) + " c");
93
- },
94
- quadraticCurveTo: function(cpx, cpy, x, y) {
95
- return this.addContent((number(cpx)) + " " + (number(cpy)) + " " + (number(x)) + " " + (number(y)) + " v");
96
- },
97
- rect: function(x, y, w, h) {
98
- return this.addContent((number(x)) + " " + (number(y)) + " " + (number(w)) + " " + (number(h)) + " re");
99
- },
100
- roundedRect: function(x, y, w, h, r) {
101
- var c;
102
- if (r == null) {
103
- r = 0;
104
- }
105
- r = Math.min(r, 0.5 * w, 0.5 * h);
106
- c = r * (1.0 - KAPPA);
107
- this.moveTo(x + r, y);
108
- this.lineTo(x + w - r, y);
109
- this.bezierCurveTo(x + w - c, y, x + w, y + c, x + w, y + r);
110
- this.lineTo(x + w, y + h - r);
111
- this.bezierCurveTo(x + w, y + h - c, x + w - c, y + h, x + w - r, y + h);
112
- this.lineTo(x + r, y + h);
113
- this.bezierCurveTo(x + c, y + h, x, y + h - c, x, y + h - r);
114
- this.lineTo(x, y + r);
115
- this.bezierCurveTo(x, y + c, x + c, y, x + r, y);
116
- return this.closePath();
117
- },
118
- ellipse: function(x, y, r1, r2) {
119
- var ox, oy, xe, xm, ye, ym;
120
- if (r2 == null) {
121
- r2 = r1;
122
- }
123
- x -= r1;
124
- y -= r2;
125
- ox = r1 * KAPPA;
126
- oy = r2 * KAPPA;
127
- xe = x + r1 * 2;
128
- ye = y + r2 * 2;
129
- xm = x + r1;
130
- ym = y + r2;
131
- this.moveTo(x, ym);
132
- this.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
133
- this.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
134
- this.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
135
- this.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
136
- return this.closePath();
137
- },
138
- circle: function(x, y, radius) {
139
- return this.ellipse(x, y, radius);
140
- },
141
- polygon: function() {
142
- var i, len, point, points;
143
- points = 1 <= arguments.length ? slice.call(arguments, 0) : [];
144
- this.moveTo.apply(this, points.shift());
145
- for (i = 0, len = points.length; i < len; i++) {
146
- point = points[i];
147
- this.lineTo.apply(this, point);
148
- }
149
- return this.closePath();
150
- },
151
- path: function(path) {
152
- SVGPath.apply(this, path);
153
- return this;
154
- },
155
- _windingRule: function(rule) {
156
- if (/even-?odd/.test(rule)) {
157
- return '*';
158
- }
159
- return '';
160
- },
161
- fill: function(color, rule) {
162
- if (/(even-?odd)|(non-?zero)/.test(color)) {
163
- rule = color;
164
- color = null;
165
- }
166
- if (color) {
167
- this.fillColor(color);
168
- }
169
- return this.addContent('f' + this._windingRule(rule));
170
- },
171
- stroke: function(color) {
172
- if (color) {
173
- this.strokeColor(color);
174
- }
175
- return this.addContent('S');
176
- },
177
- fillAndStroke: function(fillColor, strokeColor, rule) {
178
- var isFillRule;
179
- if (strokeColor == null) {
180
- strokeColor = fillColor;
181
- }
182
- isFillRule = /(even-?odd)|(non-?zero)/;
183
- if (isFillRule.test(fillColor)) {
184
- rule = fillColor;
185
- fillColor = null;
186
- }
187
- if (isFillRule.test(strokeColor)) {
188
- rule = strokeColor;
189
- strokeColor = fillColor;
190
- }
191
- if (fillColor) {
192
- this.fillColor(fillColor);
193
- this.strokeColor(strokeColor);
194
- }
195
- return this.addContent('B' + this._windingRule(rule));
196
- },
197
- clip: function(rule) {
198
- return this.addContent('W' + this._windingRule(rule) + ' n');
199
- },
200
- transform: function(m11, m12, m21, m22, dx, dy) {
201
- var m, m0, m1, m2, m3, m4, m5, v, values;
202
- m = this._ctm;
203
- m0 = m[0], m1 = m[1], m2 = m[2], m3 = m[3], m4 = m[4], m5 = m[5];
204
- m[0] = m0 * m11 + m2 * m12;
205
- m[1] = m1 * m11 + m3 * m12;
206
- m[2] = m0 * m21 + m2 * m22;
207
- m[3] = m1 * m21 + m3 * m22;
208
- m[4] = m0 * dx + m2 * dy + m4;
209
- m[5] = m1 * dx + m3 * dy + m5;
210
- values = ((function() {
211
- var i, len, ref, results;
212
- ref = [m11, m12, m21, m22, dx, dy];
213
- results = [];
214
- for (i = 0, len = ref.length; i < len; i++) {
215
- v = ref[i];
216
- results.push(number(v));
217
- }
218
- return results;
219
- })()).join(' ');
220
- return this.addContent(values + " cm");
221
- },
222
- translate: function(x, y) {
223
- return this.transform(1, 0, 0, 1, x, y);
224
- },
225
- rotate: function(angle, options) {
226
- var cos, rad, ref, sin, x, x1, y, y1;
227
- if (options == null) {
228
- options = {};
229
- }
230
- rad = angle * Math.PI / 180;
231
- cos = Math.cos(rad);
232
- sin = Math.sin(rad);
233
- x = y = 0;
234
- if (options.origin != null) {
235
- ref = options.origin, x = ref[0], y = ref[1];
236
- x1 = x * cos - y * sin;
237
- y1 = x * sin + y * cos;
238
- x -= x1;
239
- y -= y1;
240
- }
241
- return this.transform(cos, sin, -sin, cos, x, y);
242
- },
243
- scale: function(xFactor, yFactor, options) {
244
- var ref, x, y;
245
- if (yFactor == null) {
246
- yFactor = xFactor;
247
- }
248
- if (options == null) {
249
- options = {};
250
- }
251
- if (arguments.length === 2) {
252
- yFactor = xFactor;
253
- options = yFactor;
254
- }
255
- x = y = 0;
256
- if (options.origin != null) {
257
- ref = options.origin, x = ref[0], y = ref[1];
258
- x -= xFactor * x;
259
- y -= yFactor * y;
260
- }
261
- return this.transform(xFactor, 0, 0, yFactor, x, y);
262
- }
263
- };
264
-
265
- }).call(this);
package/js/object.js DELETED
@@ -1,114 +0,0 @@
1
- // Generated by CoffeeScript 1.12.1
2
-
3
- /*
4
- PDFObject - converts JavaScript types into their corrisponding PDF types.
5
- By Devon Govett
6
- */
7
-
8
- (function() {
9
- var PDFObject, PDFReference;
10
-
11
- PDFObject = (function() {
12
- var escapable, escapableRe, pad, swapBytes;
13
-
14
- function PDFObject() {}
15
-
16
- pad = function(str, length) {
17
- return (Array(length + 1).join('0') + str).slice(-length);
18
- };
19
-
20
- escapableRe = /[\n\r\t\b\f\(\)\\]/g;
21
-
22
- escapable = {
23
- '\n': '\\n',
24
- '\r': '\\r',
25
- '\t': '\\t',
26
- '\b': '\\b',
27
- '\f': '\\f',
28
- '\\': '\\\\',
29
- '(': '\\(',
30
- ')': '\\)'
31
- };
32
-
33
- swapBytes = function(buff) {
34
- var a, i, j, l, ref;
35
- l = buff.length;
36
- if (l & 0x01) {
37
- throw new Error("Buffer length must be even");
38
- } else {
39
- for (i = j = 0, ref = l - 1; j < ref; i = j += 2) {
40
- a = buff[i];
41
- buff[i] = buff[i + 1];
42
- buff[i + 1] = a;
43
- }
44
- }
45
- return buff;
46
- };
47
-
48
- PDFObject.convert = function(object) {
49
- var e, i, isUnicode, items, j, key, out, ref, string, val;
50
- if (typeof object === 'string') {
51
- return '/' + object;
52
- } else if (object instanceof String) {
53
- string = object.replace(escapableRe, function(c) {
54
- return escapable[c];
55
- });
56
- isUnicode = false;
57
- for (i = j = 0, ref = string.length; j < ref; i = j += 1) {
58
- if (string.charCodeAt(i) > 0x7f) {
59
- isUnicode = true;
60
- break;
61
- }
62
- }
63
- if (isUnicode) {
64
- string = swapBytes(new Buffer('\ufeff' + string, 'utf16le')).toString('binary');
65
- }
66
- return '(' + string + ')';
67
- } else if (Buffer.isBuffer(object)) {
68
- return '<' + object.toString('hex') + '>';
69
- } else if (object instanceof PDFReference) {
70
- return object.toString();
71
- } else if (object instanceof Date) {
72
- return '(D:' + pad(object.getUTCFullYear(), 4) + pad(object.getUTCMonth() + 1, 2) + pad(object.getUTCDate(), 2) + pad(object.getUTCHours(), 2) + pad(object.getUTCMinutes(), 2) + pad(object.getUTCSeconds(), 2) + 'Z)';
73
- } else if (Array.isArray(object)) {
74
- items = ((function() {
75
- var k, len, results;
76
- results = [];
77
- for (k = 0, len = object.length; k < len; k++) {
78
- e = object[k];
79
- results.push(PDFObject.convert(e));
80
- }
81
- return results;
82
- })()).join(' ');
83
- return '[' + items + ']';
84
- } else if ({}.toString.call(object) === '[object Object]') {
85
- out = ['<<'];
86
- for (key in object) {
87
- val = object[key];
88
- out.push('/' + key + ' ' + PDFObject.convert(val));
89
- }
90
- out.push('>>');
91
- return out.join('\n');
92
- } else if (typeof object === 'number') {
93
- return PDFObject.number(object);
94
- } else {
95
- return '' + object;
96
- }
97
- };
98
-
99
- PDFObject.number = function(n) {
100
- if (n > -1e21 && n < 1e21) {
101
- return Math.round(n * 1e6) / 1e6;
102
- }
103
- throw new Error("unsupported number: " + n);
104
- };
105
-
106
- return PDFObject;
107
-
108
- })();
109
-
110
- module.exports = PDFObject;
111
-
112
- PDFReference = require('./reference');
113
-
114
- }).call(this);
package/js/page.js DELETED
@@ -1,170 +0,0 @@
1
- // Generated by CoffeeScript 1.12.1
2
-
3
- /*
4
- PDFPage - represents a single page in the PDF document
5
- By Devon Govett
6
- */
7
-
8
- (function() {
9
- var PDFPage;
10
-
11
- PDFPage = (function() {
12
- var DEFAULT_MARGINS, SIZES;
13
-
14
- function PDFPage(document, options) {
15
- var dimensions;
16
- this.document = document;
17
- if (options == null) {
18
- options = {};
19
- }
20
- this.size = options.size || 'letter';
21
- this.layout = options.layout || 'portrait';
22
- if (typeof options.margin === 'number') {
23
- this.margins = {
24
- top: options.margin,
25
- left: options.margin,
26
- bottom: options.margin,
27
- right: options.margin
28
- };
29
- } else {
30
- this.margins = options.margins || DEFAULT_MARGINS;
31
- }
32
- dimensions = Array.isArray(this.size) ? this.size : SIZES[this.size.toUpperCase()];
33
- this.width = dimensions[this.layout === 'portrait' ? 0 : 1];
34
- this.height = dimensions[this.layout === 'portrait' ? 1 : 0];
35
- this.content = this.document.ref();
36
- this.resources = this.document.ref({
37
- ProcSet: ['PDF', 'Text', 'ImageB', 'ImageC', 'ImageI']
38
- });
39
- Object.defineProperties(this, {
40
- fonts: {
41
- get: (function(_this) {
42
- return function() {
43
- var base;
44
- return (base = _this.resources.data).Font != null ? base.Font : base.Font = {};
45
- };
46
- })(this)
47
- },
48
- xobjects: {
49
- get: (function(_this) {
50
- return function() {
51
- var base;
52
- return (base = _this.resources.data).XObject != null ? base.XObject : base.XObject = {};
53
- };
54
- })(this)
55
- },
56
- ext_gstates: {
57
- get: (function(_this) {
58
- return function() {
59
- var base;
60
- return (base = _this.resources.data).ExtGState != null ? base.ExtGState : base.ExtGState = {};
61
- };
62
- })(this)
63
- },
64
- patterns: {
65
- get: (function(_this) {
66
- return function() {
67
- var base;
68
- return (base = _this.resources.data).Pattern != null ? base.Pattern : base.Pattern = {};
69
- };
70
- })(this)
71
- },
72
- annotations: {
73
- get: (function(_this) {
74
- return function() {
75
- var base;
76
- return (base = _this.dictionary.data).Annots != null ? base.Annots : base.Annots = [];
77
- };
78
- })(this)
79
- }
80
- });
81
- this.dictionary = this.document.ref({
82
- Type: 'Page',
83
- Parent: this.document._root.data.Pages,
84
- MediaBox: [0, 0, this.width, this.height],
85
- Contents: this.content,
86
- Resources: this.resources
87
- });
88
- }
89
-
90
- PDFPage.prototype.maxY = function() {
91
- return this.height - this.margins.bottom;
92
- };
93
-
94
- PDFPage.prototype.write = function(chunk) {
95
- return this.content.write(chunk);
96
- };
97
-
98
- PDFPage.prototype.end = function() {
99
- this.dictionary.end();
100
- this.resources.end();
101
- return this.content.end();
102
- };
103
-
104
- DEFAULT_MARGINS = {
105
- top: 72,
106
- left: 72,
107
- bottom: 72,
108
- right: 72
109
- };
110
-
111
- SIZES = {
112
- '4A0': [4767.87, 6740.79],
113
- '2A0': [3370.39, 4767.87],
114
- A0: [2383.94, 3370.39],
115
- A1: [1683.78, 2383.94],
116
- A2: [1190.55, 1683.78],
117
- A3: [841.89, 1190.55],
118
- A4: [595.28, 841.89],
119
- A5: [419.53, 595.28],
120
- A6: [297.64, 419.53],
121
- A7: [209.76, 297.64],
122
- A8: [147.40, 209.76],
123
- A9: [104.88, 147.40],
124
- A10: [73.70, 104.88],
125
- B0: [2834.65, 4008.19],
126
- B1: [2004.09, 2834.65],
127
- B2: [1417.32, 2004.09],
128
- B3: [1000.63, 1417.32],
129
- B4: [708.66, 1000.63],
130
- B5: [498.90, 708.66],
131
- B6: [354.33, 498.90],
132
- B7: [249.45, 354.33],
133
- B8: [175.75, 249.45],
134
- B9: [124.72, 175.75],
135
- B10: [87.87, 124.72],
136
- C0: [2599.37, 3676.54],
137
- C1: [1836.85, 2599.37],
138
- C2: [1298.27, 1836.85],
139
- C3: [918.43, 1298.27],
140
- C4: [649.13, 918.43],
141
- C5: [459.21, 649.13],
142
- C6: [323.15, 459.21],
143
- C7: [229.61, 323.15],
144
- C8: [161.57, 229.61],
145
- C9: [113.39, 161.57],
146
- C10: [79.37, 113.39],
147
- RA0: [2437.80, 3458.27],
148
- RA1: [1729.13, 2437.80],
149
- RA2: [1218.90, 1729.13],
150
- RA3: [864.57, 1218.90],
151
- RA4: [609.45, 864.57],
152
- SRA0: [2551.18, 3628.35],
153
- SRA1: [1814.17, 2551.18],
154
- SRA2: [1275.59, 1814.17],
155
- SRA3: [907.09, 1275.59],
156
- SRA4: [637.80, 907.09],
157
- EXECUTIVE: [521.86, 756.00],
158
- FOLIO: [612.00, 936.00],
159
- LEGAL: [612.00, 1008.00],
160
- LETTER: [612.00, 792.00],
161
- TABLOID: [792.00, 1224.00]
162
- };
163
-
164
- return PDFPage;
165
-
166
- })();
167
-
168
- module.exports = PDFPage;
169
-
170
- }).call(this);