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,69 +0,0 @@
1
- // Generated by CoffeeScript 1.12.1
2
- (function() {
3
- var PDFFont;
4
-
5
- PDFFont = require('../font');
6
-
7
- module.exports = {
8
- initFonts: function() {
9
- this._fontFamilies = {};
10
- this._fontCount = 0;
11
- this._fontSize = 12;
12
- this._font = null;
13
- this._registeredFonts = {};
14
- return this.font('Helvetica');
15
- },
16
- font: function(src, family, size) {
17
- var cacheKey, font, id, ref;
18
- if (typeof family === 'number') {
19
- size = family;
20
- family = null;
21
- }
22
- if (typeof src === 'string' && this._registeredFonts[src]) {
23
- cacheKey = src;
24
- ref = this._registeredFonts[src], src = ref.src, family = ref.family;
25
- } else {
26
- cacheKey = family || src;
27
- if (typeof cacheKey !== 'string') {
28
- cacheKey = null;
29
- }
30
- }
31
- if (size != null) {
32
- this.fontSize(size);
33
- }
34
- if (font = this._fontFamilies[cacheKey]) {
35
- this._font = font;
36
- return this;
37
- }
38
- id = 'F' + (++this._fontCount);
39
- this._font = PDFFont.open(this, src, family, id);
40
- if (font = this._fontFamilies[this._font.name]) {
41
- this._font = font;
42
- return this;
43
- }
44
- if (cacheKey) {
45
- this._fontFamilies[cacheKey] = this._font;
46
- }
47
- this._fontFamilies[this._font.name] = this._font;
48
- return this;
49
- },
50
- fontSize: function(_fontSize) {
51
- this._fontSize = _fontSize;
52
- return this;
53
- },
54
- currentLineHeight: function(includeGap) {
55
- if (includeGap == null) {
56
- includeGap = false;
57
- }
58
- return this._font.lineHeight(this._fontSize, includeGap);
59
- },
60
- registerFont: function(name, src, family) {
61
- this._registeredFonts[name] = {
62
- src: src,
63
- family: family
64
- };
65
- return this;
66
- }
67
- };
68
-
69
- }).call(this);
@@ -1,111 +0,0 @@
1
- // Generated by CoffeeScript 1.12.1
2
- (function() {
3
- var PDFImage;
4
-
5
- PDFImage = require('../image');
6
-
7
- module.exports = {
8
- initImages: function() {
9
- this._imageRegistry = {};
10
- return this._imageCount = 0;
11
- },
12
- image: function(src, x, y, options) {
13
- var base, bh, bp, bw, h, hp, image, ip, name, ref, ref1, ref2, ref3, w, wp;
14
- if (options == null) {
15
- options = {};
16
- }
17
- if (typeof x === 'object') {
18
- options = x;
19
- x = null;
20
- }
21
- x = (ref = x != null ? x : options.x) != null ? ref : this.x;
22
- y = (ref1 = y != null ? y : options.y) != null ? ref1 : this.y;
23
- if (typeof src === 'string') {
24
- image = this._imageRegistry[src];
25
- }
26
- if (!image) {
27
- if (src.width && src.height) {
28
- image = src;
29
- } else {
30
- image = this.openImage(src);
31
- }
32
- }
33
- if (!image.obj) {
34
- image.embed(this);
35
- }
36
- if ((base = this.page.xobjects)[name = image.label] == null) {
37
- base[name] = image.obj;
38
- }
39
- w = options.width || image.width;
40
- h = options.height || image.height;
41
- if (options.width && !options.height) {
42
- wp = w / image.width;
43
- w = image.width * wp;
44
- h = image.height * wp;
45
- } else if (options.height && !options.width) {
46
- hp = h / image.height;
47
- w = image.width * hp;
48
- h = image.height * hp;
49
- } else if (options.scale) {
50
- w = image.width * options.scale;
51
- h = image.height * options.scale;
52
- } else if (options.fit) {
53
- ref2 = options.fit, bw = ref2[0], bh = ref2[1];
54
- bp = bw / bh;
55
- ip = image.width / image.height;
56
- if (ip > bp) {
57
- w = bw;
58
- h = bw / ip;
59
- } else {
60
- h = bh;
61
- w = bh * ip;
62
- }
63
- } else if (options.cover) {
64
- ref3 = options.cover, bw = ref3[0], bh = ref3[1];
65
- bp = bw / bh;
66
- ip = image.width / image.height;
67
- if (ip > bp) {
68
- h = bh;
69
- w = bh * ip;
70
- } else {
71
- w = bw;
72
- h = bw / ip;
73
- }
74
- }
75
- if (options.fit || options.cover) {
76
- if (options.align === 'center') {
77
- x = x + bw / 2 - w / 2;
78
- } else if (options.align === 'right') {
79
- x = x + bw - w;
80
- }
81
- if (options.valign === 'center') {
82
- y = y + bh / 2 - h / 2;
83
- } else if (options.valign === 'bottom') {
84
- y = y + bh - h;
85
- }
86
- }
87
- if (this.y === y) {
88
- this.y += h;
89
- }
90
- this.save();
91
- this.transform(w, 0, 0, -h, x, y + h);
92
- this.addContent("/" + image.label + " Do");
93
- this.restore();
94
- return this;
95
- },
96
- openImage: function(src) {
97
- var image;
98
- if (typeof src === 'string') {
99
- image = this._imageRegistry[src];
100
- }
101
- if (!image) {
102
- image = PDFImage.open(src, 'I' + (++this._imageCount));
103
- if (typeof src === 'string') {
104
- this._imageRegistry[src] = image;
105
- }
106
- }
107
- return image;
108
- }
109
- };
110
-
111
- }).call(this);
package/js/mixins/text.js DELETED
@@ -1,337 +0,0 @@
1
- // Generated by CoffeeScript 1.12.1
2
- (function() {
3
- var LineWrapper, number;
4
-
5
- LineWrapper = require('../line_wrapper');
6
-
7
- number = require('../object').number;
8
-
9
- module.exports = {
10
- initText: function() {
11
- this.x = 0;
12
- this.y = 0;
13
- return this._lineGap = 0;
14
- },
15
- lineGap: function(_lineGap) {
16
- this._lineGap = _lineGap;
17
- return this;
18
- },
19
- moveDown: function(lines) {
20
- if (lines == null) {
21
- lines = 1;
22
- }
23
- this.y += this.currentLineHeight(true) * lines + this._lineGap;
24
- return this;
25
- },
26
- moveUp: function(lines) {
27
- if (lines == null) {
28
- lines = 1;
29
- }
30
- this.y -= this.currentLineHeight(true) * lines + this._lineGap;
31
- return this;
32
- },
33
- _text: function(text, x, y, options, lineCallback) {
34
- var j, len, line, ref, wrapper;
35
- options = this._initOptions(x, y, options);
36
- text = '' + text;
37
- if (options.wordSpacing) {
38
- text = text.replace(/\s{2,}/g, ' ');
39
- }
40
- if (options.width) {
41
- wrapper = this._wrapper;
42
- if (!wrapper) {
43
- wrapper = new LineWrapper(this, options);
44
- wrapper.on('line', lineCallback);
45
- }
46
- this._wrapper = options.continued ? wrapper : null;
47
- this._textOptions = options.continued ? options : null;
48
- wrapper.wrap(text, options);
49
- } else {
50
- ref = text.split('\n');
51
- for (j = 0, len = ref.length; j < len; j++) {
52
- line = ref[j];
53
- lineCallback(line, options);
54
- }
55
- }
56
- return this;
57
- },
58
- text: function(text, x, y, options) {
59
- return this._text(text, x, y, options, this._line.bind(this));
60
- },
61
- widthOfString: function(string, options) {
62
- if (options == null) {
63
- options = {};
64
- }
65
- return this._font.widthOfString(string, this._fontSize, options.features) + (options.characterSpacing || 0) * (string.length - 1);
66
- },
67
- heightOfString: function(text, options) {
68
- var height, lineGap, ref, x, y;
69
- if (options == null) {
70
- options = {};
71
- }
72
- ref = this, x = ref.x, y = ref.y;
73
- options = this._initOptions(options);
74
- options.height = 2e308;
75
- lineGap = options.lineGap || this._lineGap || 0;
76
- this._text(text, this.x, this.y, options, (function(_this) {
77
- return function(line, options) {
78
- return _this.y += _this.currentLineHeight(true) + lineGap;
79
- };
80
- })(this));
81
- height = this.y - y;
82
- this.x = x;
83
- this.y = y;
84
- return height;
85
- },
86
- list: function(list, x, y, options, wrapper) {
87
- var flatten, i, indent, itemIndent, items, level, levels, midLine, r;
88
- options = this._initOptions(x, y, options);
89
- midLine = Math.round((this._font.ascender / 1000 * this._fontSize) / 2);
90
- r = options.bulletRadius || Math.round((this._font.ascender / 1000 * this._fontSize) / 3);
91
- indent = options.textIndent || r * 5;
92
- itemIndent = options.bulletIndent || r * 8;
93
- level = 1;
94
- items = [];
95
- levels = [];
96
- flatten = function(list) {
97
- var i, item, j, len, results;
98
- results = [];
99
- for (i = j = 0, len = list.length; j < len; i = ++j) {
100
- item = list[i];
101
- if (Array.isArray(item)) {
102
- level++;
103
- flatten(item);
104
- results.push(level--);
105
- } else {
106
- items.push(item);
107
- results.push(levels.push(level));
108
- }
109
- }
110
- return results;
111
- };
112
- flatten(list);
113
- wrapper = new LineWrapper(this, options);
114
- wrapper.on('line', this._line.bind(this));
115
- level = 1;
116
- i = 0;
117
- wrapper.on('firstLine', (function(_this) {
118
- return function() {
119
- var diff, l;
120
- if ((l = levels[i++]) !== level) {
121
- diff = itemIndent * (l - level);
122
- _this.x += diff;
123
- wrapper.lineWidth -= diff;
124
- level = l;
125
- }
126
- _this.circle(_this.x - indent + r, _this.y + midLine, r);
127
- return _this.fill();
128
- };
129
- })(this));
130
- wrapper.on('sectionStart', (function(_this) {
131
- return function() {
132
- var pos;
133
- pos = indent + itemIndent * (level - 1);
134
- _this.x += pos;
135
- return wrapper.lineWidth -= pos;
136
- };
137
- })(this));
138
- wrapper.on('sectionEnd', (function(_this) {
139
- return function() {
140
- var pos;
141
- pos = indent + itemIndent * (level - 1);
142
- _this.x -= pos;
143
- return wrapper.lineWidth += pos;
144
- };
145
- })(this));
146
- wrapper.wrap(items.join('\n'), options);
147
- return this;
148
- },
149
- _initOptions: function(x, y, options) {
150
- var key, ref, val;
151
- if (x == null) {
152
- x = {};
153
- }
154
- if (options == null) {
155
- options = {};
156
- }
157
- if (typeof x === 'object') {
158
- options = x;
159
- x = null;
160
- }
161
- options = (function() {
162
- var k, opts, v;
163
- opts = {};
164
- for (k in options) {
165
- v = options[k];
166
- opts[k] = v;
167
- }
168
- return opts;
169
- })();
170
- if (this._textOptions) {
171
- ref = this._textOptions;
172
- for (key in ref) {
173
- val = ref[key];
174
- if (key !== 'continued') {
175
- if (options[key] == null) {
176
- options[key] = val;
177
- }
178
- }
179
- }
180
- }
181
- if (x != null) {
182
- this.x = x;
183
- }
184
- if (y != null) {
185
- this.y = y;
186
- }
187
- if (options.lineBreak !== false) {
188
- if (options.width == null) {
189
- options.width = this.page.width - this.x - this.page.margins.right;
190
- }
191
- }
192
- options.columns || (options.columns = 0);
193
- if (options.columnGap == null) {
194
- options.columnGap = 18;
195
- }
196
- return options;
197
- },
198
- _line: function(text, options, wrapper) {
199
- var lineGap;
200
- if (options == null) {
201
- options = {};
202
- }
203
- this._fragment(text, this.x, this.y, options);
204
- lineGap = options.lineGap || this._lineGap || 0;
205
- if (!wrapper) {
206
- return this.x += this.widthOfString(text);
207
- } else {
208
- return this.y += this.currentLineHeight(true) + lineGap;
209
- }
210
- },
211
- _fragment: function(text, x, y, options) {
212
- var addSegment, align, base, characterSpacing, commands, d, encoded, encodedWord, flush, hadOffset, i, j, last, len, len1, lineWidth, lineY, m, mode, name, pos, positions, positionsWord, ref, ref1, renderedWidth, scale, spaceWidth, textWidth, word, wordSpacing, words;
213
- text = ('' + text).replace(/\n/g, '');
214
- if (text.length === 0) {
215
- return;
216
- }
217
- align = options.align || 'left';
218
- wordSpacing = options.wordSpacing || 0;
219
- characterSpacing = options.characterSpacing || 0;
220
- if (options.width) {
221
- switch (align) {
222
- case 'right':
223
- textWidth = this.widthOfString(text.replace(/\s+$/, ''), options);
224
- x += options.lineWidth - textWidth;
225
- break;
226
- case 'center':
227
- x += options.lineWidth / 2 - options.textWidth / 2;
228
- break;
229
- case 'justify':
230
- words = text.trim().split(/\s+/);
231
- textWidth = this.widthOfString(text.replace(/\s+/g, ''), options);
232
- spaceWidth = this.widthOfString(' ') + characterSpacing;
233
- wordSpacing = Math.max(0, (options.lineWidth - textWidth) / Math.max(1, words.length - 1) - spaceWidth);
234
- }
235
- }
236
- renderedWidth = options.textWidth + (wordSpacing * (options.wordCount - 1)) + (characterSpacing * (text.length - 1));
237
- if (options.link) {
238
- this.link(x, y, renderedWidth, this.currentLineHeight(), options.link);
239
- }
240
- if (options.underline || options.strike) {
241
- this.save();
242
- if (!options.stroke) {
243
- this.strokeColor.apply(this, this._fillColor);
244
- }
245
- lineWidth = this._fontSize < 10 ? 0.5 : Math.floor(this._fontSize / 10);
246
- this.lineWidth(lineWidth);
247
- d = options.underline ? 1 : 2;
248
- lineY = y + this.currentLineHeight() / d;
249
- if (options.underline) {
250
- lineY -= lineWidth;
251
- }
252
- this.moveTo(x, lineY);
253
- this.lineTo(x + renderedWidth, lineY);
254
- this.stroke();
255
- this.restore();
256
- }
257
- this.save();
258
- this.transform(1, 0, 0, -1, 0, this.page.height);
259
- y = this.page.height - y - (this._font.ascender / 1000 * this._fontSize);
260
- if ((base = this.page.fonts)[name = this._font.id] == null) {
261
- base[name] = this._font.ref();
262
- }
263
- this.addContent("BT");
264
- this.addContent("1 0 0 1 " + (number(x)) + " " + (number(y)) + " Tm");
265
- this.addContent("/" + this._font.id + " " + (number(this._fontSize)) + " Tf");
266
- mode = options.fill && options.stroke ? 2 : options.stroke ? 1 : 0;
267
- if (mode) {
268
- this.addContent(mode + " Tr");
269
- }
270
- if (characterSpacing) {
271
- this.addContent((number(characterSpacing)) + " Tc");
272
- }
273
- if (wordSpacing) {
274
- words = text.trim().split(/\s+/);
275
- wordSpacing += this.widthOfString(' ') + characterSpacing;
276
- wordSpacing *= 1000 / this._fontSize;
277
- encoded = [];
278
- positions = [];
279
- for (j = 0, len = words.length; j < len; j++) {
280
- word = words[j];
281
- ref = this._font.encode(word, options.features), encodedWord = ref[0], positionsWord = ref[1];
282
- encoded.push.apply(encoded, encodedWord);
283
- positions.push.apply(positions, positionsWord);
284
- positions[positions.length - 1].xAdvance += wordSpacing;
285
- }
286
- } else {
287
- ref1 = this._font.encode(text, options.features), encoded = ref1[0], positions = ref1[1];
288
- }
289
- scale = this._fontSize / 1000;
290
- commands = [];
291
- last = 0;
292
- hadOffset = false;
293
- addSegment = (function(_this) {
294
- return function(cur) {
295
- var advance, hex;
296
- if (last < cur) {
297
- hex = encoded.slice(last, cur).join('');
298
- advance = positions[cur - 1].xAdvance - positions[cur - 1].advanceWidth;
299
- commands.push("<" + hex + "> " + (number(-advance)));
300
- }
301
- return last = cur;
302
- };
303
- })(this);
304
- flush = (function(_this) {
305
- return function(i) {
306
- addSegment(i);
307
- if (commands.length > 0) {
308
- _this.addContent("[" + (commands.join(' ')) + "] TJ");
309
- return commands.length = 0;
310
- }
311
- };
312
- })(this);
313
- for (i = m = 0, len1 = positions.length; m < len1; i = ++m) {
314
- pos = positions[i];
315
- if (pos.xOffset || pos.yOffset) {
316
- flush(i);
317
- this.addContent("1 0 0 1 " + (number(x + pos.xOffset * scale)) + " " + (number(y + pos.yOffset * scale)) + " Tm");
318
- flush(i + 1);
319
- hadOffset = true;
320
- } else {
321
- if (hadOffset) {
322
- this.addContent("1 0 0 1 " + (number(x)) + " " + (number(y)) + " Tm");
323
- hadOffset = false;
324
- }
325
- if (pos.xAdvance - pos.advanceWidth !== 0) {
326
- addSegment(i + 1);
327
- }
328
- }
329
- x += pos.xAdvance * scale;
330
- }
331
- flush(i);
332
- this.addContent("ET");
333
- return this.restore();
334
- }
335
- };
336
-
337
- }).call(this);