porting
parent
3f36e2ce2c
commit
328e99db56
@ -1,192 +0,0 @@
|
||||
// Generated by CoffeeScript 1.12.5
|
||||
(function() {
|
||||
var Data;
|
||||
|
||||
Data = (function() {
|
||||
function Data(data) {
|
||||
this.data = data != null ? data : [];
|
||||
this.pos = 0;
|
||||
this.length = this.data.length;
|
||||
}
|
||||
|
||||
Data.prototype.readByte = function() {
|
||||
return this.data[this.pos++];
|
||||
};
|
||||
|
||||
Data.prototype.writeByte = function(byte) {
|
||||
return this.data[this.pos++] = byte;
|
||||
};
|
||||
|
||||
Data.prototype.byteAt = function(index) {
|
||||
return this.data[index];
|
||||
};
|
||||
|
||||
Data.prototype.readBool = function() {
|
||||
return !!this.readByte();
|
||||
};
|
||||
|
||||
Data.prototype.writeBool = function(val) {
|
||||
return this.writeByte(val ? 1 : 0);
|
||||
};
|
||||
|
||||
Data.prototype.readUInt32 = function() {
|
||||
var b1, b2, b3, b4;
|
||||
b1 = this.readByte() * 0x1000000;
|
||||
b2 = this.readByte() << 16;
|
||||
b3 = this.readByte() << 8;
|
||||
b4 = this.readByte();
|
||||
return b1 + b2 + b3 + b4;
|
||||
};
|
||||
|
||||
Data.prototype.writeUInt32 = function(val) {
|
||||
this.writeByte((val >>> 24) & 0xff);
|
||||
this.writeByte((val >> 16) & 0xff);
|
||||
this.writeByte((val >> 8) & 0xff);
|
||||
return this.writeByte(val & 0xff);
|
||||
};
|
||||
|
||||
Data.prototype.readInt32 = function() {
|
||||
var int;
|
||||
int = this.readUInt32();
|
||||
if (int >= 0x80000000) {
|
||||
return int - 0x100000000;
|
||||
} else {
|
||||
return int;
|
||||
}
|
||||
};
|
||||
|
||||
Data.prototype.writeInt32 = function(val) {
|
||||
if (val < 0) {
|
||||
val += 0x100000000;
|
||||
}
|
||||
return this.writeUInt32(val);
|
||||
};
|
||||
|
||||
Data.prototype.readUInt16 = function() {
|
||||
var b1, b2;
|
||||
b1 = this.readByte() << 8;
|
||||
b2 = this.readByte();
|
||||
return b1 | b2;
|
||||
};
|
||||
|
||||
Data.prototype.writeUInt16 = function(val) {
|
||||
this.writeByte((val >> 8) & 0xff);
|
||||
return this.writeByte(val & 0xff);
|
||||
};
|
||||
|
||||
Data.prototype.readInt16 = function() {
|
||||
var int;
|
||||
int = this.readUInt16();
|
||||
if (int >= 0x8000) {
|
||||
return int - 0x10000;
|
||||
} else {
|
||||
return int;
|
||||
}
|
||||
};
|
||||
|
||||
Data.prototype.writeInt16 = function(val) {
|
||||
if (val < 0) {
|
||||
val += 0x10000;
|
||||
}
|
||||
return this.writeUInt16(val);
|
||||
};
|
||||
|
||||
Data.prototype.readString = function(length) {
|
||||
var i, j, ref, ret;
|
||||
ret = [];
|
||||
for (i = j = 0, ref = length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
|
||||
ret[i] = String.fromCharCode(this.readByte());
|
||||
}
|
||||
return ret.join('');
|
||||
};
|
||||
|
||||
Data.prototype.writeString = function(val) {
|
||||
var i, j, ref, results;
|
||||
results = [];
|
||||
for (i = j = 0, ref = val.length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
|
||||
results.push(this.writeByte(val.charCodeAt(i)));
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
Data.prototype.stringAt = function(pos, length) {
|
||||
this.pos = pos;
|
||||
return this.readString(length);
|
||||
};
|
||||
|
||||
Data.prototype.readShort = function() {
|
||||
return this.readInt16();
|
||||
};
|
||||
|
||||
Data.prototype.writeShort = function(val) {
|
||||
return this.writeInt16(val);
|
||||
};
|
||||
|
||||
Data.prototype.readLongLong = function() {
|
||||
var b1, b2, b3, b4, b5, b6, b7, b8;
|
||||
b1 = this.readByte();
|
||||
b2 = this.readByte();
|
||||
b3 = this.readByte();
|
||||
b4 = this.readByte();
|
||||
b5 = this.readByte();
|
||||
b6 = this.readByte();
|
||||
b7 = this.readByte();
|
||||
b8 = this.readByte();
|
||||
if (b1 & 0x80) {
|
||||
return ((b1 ^ 0xff) * 0x100000000000000 + (b2 ^ 0xff) * 0x1000000000000 + (b3 ^ 0xff) * 0x10000000000 + (b4 ^ 0xff) * 0x100000000 + (b5 ^ 0xff) * 0x1000000 + (b6 ^ 0xff) * 0x10000 + (b7 ^ 0xff) * 0x100 + (b8 ^ 0xff) + 1) * -1;
|
||||
}
|
||||
return b1 * 0x100000000000000 + b2 * 0x1000000000000 + b3 * 0x10000000000 + b4 * 0x100000000 + b5 * 0x1000000 + b6 * 0x10000 + b7 * 0x100 + b8;
|
||||
};
|
||||
|
||||
Data.prototype.writeLongLong = function(val) {
|
||||
var high, low;
|
||||
high = Math.floor(val / 0x100000000);
|
||||
low = val & 0xffffffff;
|
||||
this.writeByte((high >> 24) & 0xff);
|
||||
this.writeByte((high >> 16) & 0xff);
|
||||
this.writeByte((high >> 8) & 0xff);
|
||||
this.writeByte(high & 0xff);
|
||||
this.writeByte((low >> 24) & 0xff);
|
||||
this.writeByte((low >> 16) & 0xff);
|
||||
this.writeByte((low >> 8) & 0xff);
|
||||
return this.writeByte(low & 0xff);
|
||||
};
|
||||
|
||||
Data.prototype.readInt = function() {
|
||||
return this.readInt32();
|
||||
};
|
||||
|
||||
Data.prototype.writeInt = function(val) {
|
||||
return this.writeInt32(val);
|
||||
};
|
||||
|
||||
Data.prototype.slice = function(start, end) {
|
||||
return this.data.slice(start, end);
|
||||
};
|
||||
|
||||
Data.prototype.read = function(bytes) {
|
||||
var buf, i, j, ref;
|
||||
buf = [];
|
||||
for (i = j = 0, ref = bytes; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
|
||||
buf.push(this.readByte());
|
||||
}
|
||||
return buf;
|
||||
};
|
||||
|
||||
Data.prototype.write = function(bytes) {
|
||||
var byte, j, len, results;
|
||||
results = [];
|
||||
for (j = 0, len = bytes.length; j < len; j++) {
|
||||
byte = bytes[j];
|
||||
results.push(this.writeByte(byte));
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
return Data;
|
||||
|
||||
})();
|
||||
|
||||
module.exports = Data;
|
||||
|
||||
}).call(this);
|
@ -1,75 +0,0 @@
|
||||
// Generated by CoffeeScript 1.12.5
|
||||
(function() {
|
||||
var EmbeddedFont, PDFFont, StandardFont, fontkit;
|
||||
|
||||
fontkit = require('fontkit');
|
||||
|
||||
PDFFont = (function() {
|
||||
PDFFont.open = function(document, src, family, id) {
|
||||
var font;
|
||||
if (typeof src === 'string') {
|
||||
if (StandardFont.isStandardFont(src)) {
|
||||
return new StandardFont(document, src, id);
|
||||
}
|
||||
font = fontkit.openSync(src, family);
|
||||
} else if (Buffer.isBuffer(src)) {
|
||||
font = fontkit.create(src, family);
|
||||
} else if (src instanceof Uint8Array) {
|
||||
font = fontkit.create(new Buffer(src), family);
|
||||
} else if (src instanceof ArrayBuffer) {
|
||||
font = fontkit.create(new Buffer(new Uint8Array(src)), family);
|
||||
}
|
||||
if (font == null) {
|
||||
throw new Error('Not a supported font format or standard PDF font.');
|
||||
}
|
||||
return new EmbeddedFont(document, font, id);
|
||||
};
|
||||
|
||||
function PDFFont() {
|
||||
throw new Error('Cannot construct a PDFFont directly.');
|
||||
}
|
||||
|
||||
PDFFont.prototype.encode = function(text) {
|
||||
throw new Error('Must be implemented by subclasses');
|
||||
};
|
||||
|
||||
PDFFont.prototype.widthOfString = function(text) {
|
||||
throw new Error('Must be implemented by subclasses');
|
||||
};
|
||||
|
||||
PDFFont.prototype.ref = function() {
|
||||
return this.dictionary != null ? this.dictionary : this.dictionary = this.document.ref();
|
||||
};
|
||||
|
||||
PDFFont.prototype.finalize = function() {
|
||||
if (this.embedded || (this.dictionary == null)) {
|
||||
return;
|
||||
}
|
||||
this.embed();
|
||||
return this.embedded = true;
|
||||
};
|
||||
|
||||
PDFFont.prototype.embed = function() {
|
||||
throw new Error('Must be implemented by subclasses');
|
||||
};
|
||||
|
||||
PDFFont.prototype.lineHeight = function(size, includeGap) {
|
||||
var gap;
|
||||
if (includeGap == null) {
|
||||
includeGap = false;
|
||||
}
|
||||
gap = includeGap ? this.lineGap : 0;
|
||||
return (this.ascender + gap - this.descender) / 1000 * size;
|
||||
};
|
||||
|
||||
return PDFFont;
|
||||
|
||||
})();
|
||||
|
||||
module.exports = PDFFont;
|
||||
|
||||
StandardFont = require('./font/standard');
|
||||
|
||||
EmbeddedFont = require('./font/embedded');
|
||||
|
||||
}).call(this);
|
@ -1,240 +0,0 @@
|
||||
// Generated by CoffeeScript 1.12.5
|
||||
(function() {
|
||||
var PDFGradient, PDFLinearGradient, PDFRadialGradient,
|
||||
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; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
PDFGradient = (function() {
|
||||
function PDFGradient(doc) {
|
||||
this.doc = doc;
|
||||
this.stops = [];
|
||||
this.embedded = false;
|
||||
this.transform = [1, 0, 0, 1, 0, 0];
|
||||
this._colorSpace = 'DeviceRGB';
|
||||
}
|
||||
|
||||
PDFGradient.prototype.stop = function(pos, color, opacity) {
|
||||
if (opacity == null) {
|
||||
opacity = 1;
|
||||
}
|
||||
opacity = Math.max(0, Math.min(1, opacity));
|
||||
this.stops.push([pos, this.doc._normalizeColor(color), opacity]);
|
||||
return this;
|
||||
};
|
||||
|
||||
PDFGradient.prototype.setTransform = function(m11, m12, m21, m22, dx, dy) {
|
||||
this.transform = [m11, m12, m21, m22, dx, dy];
|
||||
return this;
|
||||
};
|
||||
|
||||
PDFGradient.prototype.embed = function(m) {
|
||||
var bounds, encode, fn, form, grad, gstate, i, j, k, last, len, opacityPattern, pageBBox, pattern, ref, ref1, shader, stop, stops, v;
|
||||
if (this.stops.length === 0) {
|
||||
return;
|
||||
}
|
||||
this.embedded = true;
|
||||
this.matrix = m;
|
||||
last = this.stops[this.stops.length - 1];
|
||||
if (last[0] < 1) {
|
||||
this.stops.push([1, last[1], last[2]]);
|
||||
}
|
||||
bounds = [];
|
||||
encode = [];
|
||||
stops = [];
|
||||
for (i = j = 0, ref = this.stops.length - 1; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
|
||||
encode.push(0, 1);
|
||||
if (i + 2 !== this.stops.length) {
|
||||
bounds.push(this.stops[i + 1][0]);
|
||||
}
|
||||
fn = this.doc.ref({
|
||||
FunctionType: 2,
|
||||
Domain: [0, 1],
|
||||
C0: this.stops[i + 0][1],
|
||||
C1: this.stops[i + 1][1],
|
||||
N: 1
|
||||
});
|
||||
stops.push(fn);
|
||||
fn.end();
|
||||
}
|
||||
if (stops.length === 1) {
|
||||
fn = stops[0];
|
||||
} else {
|
||||
fn = this.doc.ref({
|
||||
FunctionType: 3,
|
||||
Domain: [0, 1],
|
||||
Functions: stops,
|
||||
Bounds: bounds,
|
||||
Encode: encode
|
||||
});
|
||||
fn.end();
|
||||
}
|
||||
this.id = 'Sh' + (++this.doc._gradCount);
|
||||
shader = this.shader(fn);
|
||||
shader.end();
|
||||
pattern = this.doc.ref({
|
||||
Type: 'Pattern',
|
||||
PatternType: 2,
|
||||
Shading: shader,
|
||||
Matrix: (function() {
|
||||
var k, len, ref1, results;
|
||||
ref1 = this.matrix;
|
||||
results = [];
|
||||
for (k = 0, len = ref1.length; k < len; k++) {
|
||||
v = ref1[k];
|
||||
results.push(+v.toFixed(5));
|
||||
}
|
||||
return results;
|
||||
}).call(this)
|
||||
});
|
||||
pattern.end();
|
||||
if (this.stops.some(function(stop) {
|
||||
return stop[2] < 1;
|
||||
})) {
|
||||
grad = this.opacityGradient();
|
||||
grad._colorSpace = 'DeviceGray';
|
||||
ref1 = this.stops;
|
||||
for (k = 0, len = ref1.length; k < len; k++) {
|
||||
stop = ref1[k];
|
||||
grad.stop(stop[0], [stop[2]]);
|
||||
}
|
||||
grad = grad.embed(this.matrix);
|
||||
pageBBox = [0, 0, this.doc.page.width, this.doc.page.height];
|
||||
form = this.doc.ref({
|
||||
Type: 'XObject',
|
||||
Subtype: 'Form',
|
||||
FormType: 1,
|
||||
BBox: pageBBox,
|
||||
Group: {
|
||||
Type: 'Group',
|
||||
S: 'Transparency',
|
||||
CS: 'DeviceGray'
|
||||
},
|
||||
Resources: {
|
||||
ProcSet: ['PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'],
|
||||
Pattern: {
|
||||
Sh1: grad
|
||||
}
|
||||
}
|
||||
});
|
||||
form.write("/Pattern cs /Sh1 scn");
|
||||
form.end((pageBBox.join(" ")) + " re f");
|
||||
gstate = this.doc.ref({
|
||||
Type: 'ExtGState',
|
||||
SMask: {
|
||||
Type: 'Mask',
|
||||
S: 'Luminosity',
|
||||
G: form
|
||||
}
|
||||
});
|
||||
gstate.end();
|
||||
opacityPattern = this.doc.ref({
|
||||
Type: 'Pattern',
|
||||
PatternType: 1,
|
||||
PaintType: 1,
|
||||
TilingType: 2,
|
||||
BBox: pageBBox,
|
||||
XStep: pageBBox[2],
|
||||
YStep: pageBBox[3],
|
||||
Resources: {
|
||||
ProcSet: ['PDF', 'Text', 'ImageB', 'ImageC', 'ImageI'],
|
||||
Pattern: {
|
||||
Sh1: pattern
|
||||
},
|
||||
ExtGState: {
|
||||
Gs1: gstate
|
||||
}
|
||||
}
|
||||
});
|
||||
opacityPattern.write("/Gs1 gs /Pattern cs /Sh1 scn");
|
||||
opacityPattern.end((pageBBox.join(" ")) + " re f");
|
||||
this.doc.page.patterns[this.id] = opacityPattern;
|
||||
} else {
|
||||
this.doc.page.patterns[this.id] = pattern;
|
||||
}
|
||||
return pattern;
|
||||
};
|
||||
|
||||
PDFGradient.prototype.apply = function(op) {
|
||||
var dx, dy, m, m0, m1, m11, m12, m2, m21, m22, m3, m4, m5, ref, ref1;
|
||||
ref = this.doc._ctm.slice(), m0 = ref[0], m1 = ref[1], m2 = ref[2], m3 = ref[3], m4 = ref[4], m5 = ref[5];
|
||||
ref1 = this.transform, m11 = ref1[0], m12 = ref1[1], m21 = ref1[2], m22 = ref1[3], dx = ref1[4], dy = ref1[5];
|
||||
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];
|
||||
if (!(this.embedded && m.join(" ") === this.matrix.join(" "))) {
|
||||
this.embed(m);
|
||||
}
|
||||
return this.doc.addContent("/" + this.id + " " + op);
|
||||
};
|
||||
|
||||
return PDFGradient;
|
||||
|
||||
})();
|
||||
|
||||
PDFLinearGradient = (function(superClass) {
|
||||
extend(PDFLinearGradient, superClass);
|
||||
|
||||
function PDFLinearGradient(doc, x1, y1, x2, y2) {
|
||||
this.doc = doc;
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
PDFLinearGradient.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
PDFLinearGradient.prototype.shader = function(fn) {
|
||||
return this.doc.ref({
|
||||
ShadingType: 2,
|
||||
ColorSpace: this._colorSpace,
|
||||
Coords: [this.x1, this.y1, this.x2, this.y2],
|
||||
Function: fn,
|
||||
Extend: [true, true]
|
||||
});
|
||||
};
|
||||
|
||||
PDFLinearGradient.prototype.opacityGradient = function() {
|
||||
return new PDFLinearGradient(this.doc, this.x1, this.y1, this.x2, this.y2);
|
||||
};
|
||||
|
||||
return PDFLinearGradient;
|
||||
|
||||
})(PDFGradient);
|
||||
|
||||
PDFRadialGradient = (function(superClass) {
|
||||
extend(PDFRadialGradient, superClass);
|
||||
|
||||
function PDFRadialGradient(doc, x1, y1, r1, x2, y2, r2) {
|
||||
this.doc = doc;
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
this.r1 = r1;
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
this.r2 = r2;
|
||||
PDFRadialGradient.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
PDFRadialGradient.prototype.shader = function(fn) {
|
||||
return this.doc.ref({
|
||||
ShadingType: 3,
|
||||
ColorSpace: this._colorSpace,
|
||||
Coords: [this.x1, this.y1, this.r1, this.x2, this.y2, this.r2],
|
||||
Function: fn,
|
||||
Extend: [true, true]
|
||||
});
|
||||
};
|
||||
|
||||
PDFRadialGradient.prototype.opacityGradient = function() {
|
||||
return new PDFRadialGradient(this.doc, this.x1, this.y1, this.r1, this.x2, this.y2, this.r2);
|
||||
};
|
||||
|
||||
return PDFRadialGradient;
|
||||
|
||||
})(PDFGradient);
|
||||
|
||||
module.exports = {
|
||||
PDFGradient: PDFGradient,
|
||||
PDFLinearGradient: PDFLinearGradient,
|
||||
PDFRadialGradient: PDFRadialGradient
|
||||
};
|
||||
|
||||
}).call(this);
|
@ -1,53 +0,0 @@
|
||||
// Generated by CoffeeScript 1.12.5
|
||||
|
||||
/*
|
||||
PDFImage - embeds images in PDF documents
|
||||
By Devon Govett
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var Data, JPEG, PDFImage, PNG, fs;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
Data = require('./data');
|
||||
|
||||
JPEG = require('./image/jpeg');
|
||||
|
||||
PNG = require('./image/png');
|
||||
|
||||
PDFImage = (function() {
|
||||
function PDFImage() {}
|
||||
|
||||
PDFImage.open = function(src, label) {
|
||||
var data, match;
|
||||
if (Buffer.isBuffer(src)) {
|
||||
data = src;
|
||||
} else if (src instanceof ArrayBuffer) {
|
||||
data = new Buffer(new Uint8Array(src));
|
||||
} else {
|
||||
if (match = /^data:.+;base64,(.*)$/.exec(src)) {
|
||||
data = new Buffer(match[1], 'base64');
|
||||
} else {
|
||||
data = fs.readFileSync(src);
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data[0] === 0xff && data[1] === 0xd8) {
|
||||
return new JPEG(data, label);
|
||||
} else if (data[0] === 0x89 && data.toString('ascii', 1, 4) === 'PNG') {
|
||||
return new PNG(data, label);
|
||||
} else {
|
||||
throw new Error('Unknown image format.');
|
||||
}
|
||||
};
|
||||
|
||||
return PDFImage;
|
||||
|
||||
})();
|
||||
|
||||
module.exports = PDFImage;
|
||||
|
||||
}).call(this);
|
@ -1,252 +0,0 @@
|
||||
// Generated by CoffeeScript 1.12.5
|
||||
(function() {
|
||||
var EventEmitter, LineBreaker, LineWrapper,
|
||||
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; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
EventEmitter = require('events').EventEmitter;
|
||||
|
||||
LineBreaker = require('linebreak');
|
||||
|
||||
LineWrapper = (function(superClass) {
|
||||
extend(LineWrapper, superClass);
|
||||
|
||||
function LineWrapper(document, options) {
|
||||
var ref;
|
||||
this.document = document;
|
||||
this.indent = options.indent || 0;
|
||||
this.characterSpacing = options.characterSpacing || 0;
|
||||
this.wordSpacing = options.wordSpacing === 0;
|
||||
this.columns = options.columns || 1;
|
||||
this.columnGap = (ref = options.columnGap) != null ? ref : 18;
|
||||
this.lineWidth = (options.width - (this.columnGap * (this.columns - 1))) / this.columns;
|
||||
this.spaceLeft = this.lineWidth;
|
||||
this.startX = this.document.x;
|
||||
this.startY = this.document.y;
|
||||
this.column = 1;
|
||||
this.ellipsis = options.ellipsis;
|
||||
this.continuedX = 0;
|
||||
this.features = options.features;
|
||||
if (options.height != null) {
|
||||
this.height = options.height;
|
||||
this.maxY = this.startY + options.height;
|
||||
} else {
|
||||
this.maxY = this.document.page.maxY();
|
||||
}
|
||||
this.on('firstLine', (function(_this) {
|
||||
return function(options) {
|
||||
var indent;
|
||||
indent = _this.continuedX || _this.indent;
|
||||
_this.document.x += indent;
|
||||
_this.lineWidth -= indent;
|
||||
return _this.once('line', function() {
|
||||
_this.document.x -= indent;
|
||||
_this.lineWidth += indent;
|
||||
if (options.continued && !_this.continuedX) {
|
||||
_this.continuedX = _this.indent;
|
||||
}
|
||||
if (!options.continued) {
|
||||
return _this.continuedX = 0;
|
||||
}
|
||||
});
|
||||
};
|
||||
})(this));
|
||||
this.on('lastLine', (function(_this) {
|
||||
return function(options) {
|
||||
var align;
|
||||
align = options.align;
|
||||
if (align === 'justify') {
|
||||
options.align = 'left';
|
||||
}
|
||||
_this.lastLine = true;
|
||||
return _this.once('line', function() {
|
||||
_this.document.y += options.paragraphGap || 0;
|
||||
options.align = align;
|
||||
return _this.lastLine = false;
|
||||
});
|
||||
};
|
||||
})(this));
|
||||
}
|
||||
|
||||
LineWrapper.prototype.wordWidth = function(word) {
|
||||
return this.document.widthOfString(word, this) + this.characterSpacing + this.wordSpacing;
|
||||
};
|
||||
|
||||
LineWrapper.prototype.eachWord = function(text, fn) {
|
||||
var bk, breaker, fbk, l, last, lbk, shouldContinue, w, word, wordWidths;
|
||||
breaker = new LineBreaker(text);
|
||||
last = null;
|
||||
wordWidths = Object.create(null);
|
||||
while (bk = breaker.nextBreak()) {
|
||||
word = text.slice((last != null ? last.position : void 0) || 0, bk.position);
|
||||
w = wordWidths[word] != null ? wordWidths[word] : wordWidths[word] = this.wordWidth(word);
|
||||
if (w > this.lineWidth + this.continuedX) {
|
||||
lbk = last;
|
||||
fbk = {};
|
||||
while (word.length) {
|
||||
l = word.length;
|
||||
while (w > this.spaceLeft) {
|
||||
w = this.wordWidth(word.slice(0, --l));
|
||||
}
|
||||
fbk.required = l < word.length;
|
||||
shouldContinue = fn(word.slice(0, l), w, fbk, lbk);
|
||||
lbk = {
|
||||
required: false
|
||||
};
|
||||
word = word.slice(l);
|
||||
w = this.wordWidth(word);
|
||||
if (shouldContinue === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
shouldContinue = fn(word, w, bk, last);
|
||||
}
|
||||
if (shouldContinue === false) {
|
||||
break;
|
||||
}
|
||||
last = bk;
|
||||
}
|
||||
};
|
||||
|
||||
LineWrapper.prototype.wrap = function(text, options) {
|
||||
var buffer, emitLine, lc, nextY, textWidth, wc, y;
|
||||
if (options.indent != null) {
|
||||
this.indent = options.indent;
|
||||
}
|
||||
if (options.characterSpacing != null) {
|
||||
this.characterSpacing = options.characterSpacing;
|
||||
}
|
||||
if (options.wordSpacing != null) {
|
||||
this.wordSpacing = options.wordSpacing;
|
||||
}
|
||||
if (options.ellipsis != null) {
|
||||
this.ellipsis = options.ellipsis;
|
||||
}
|
||||
nextY = this.document.y + this.document.currentLineHeight(true);
|
||||
if (this.document.y > this.maxY || nextY > this.maxY) {
|
||||
this.nextSection();
|
||||
}
|
||||
buffer = '';
|
||||
textWidth = 0;
|
||||
wc = 0;
|
||||
lc = 0;
|
||||
y = this.document.y;
|
||||
emitLine = (function(_this) {
|
||||
return function() {
|
||||
options.textWidth = textWidth + _this.wordSpacing * (wc - 1);
|
||||
options.wordCount = wc;
|
||||
options.lineWidth = _this.lineWidth;
|
||||
y = _this.document.y;
|
||||
_this.emit('line', buffer, options, _this);
|
||||
return lc++;
|
||||
};
|
||||
})(this);
|
||||
this.emit('sectionStart', options, this);
|
||||
this.eachWord(text, (function(_this) {
|
||||
return function(word, w, bk, last) {
|
||||
var lh, shouldContinue;
|
||||
if ((last == null) || last.required) {
|
||||
_this.emit('firstLine', options, _this);
|
||||
_this.spaceLeft = _this.lineWidth;
|
||||
}
|
||||
if (w <= _this.spaceLeft) {
|
||||
buffer += word;
|
||||
textWidth += w;
|
||||
wc++;
|
||||
}
|
||||
if (bk.required || w > _this.spaceLeft) {
|
||||
if (bk.required) {
|
||||
_this.emit('lastLine', options, _this);
|
||||
}
|
||||
lh = _this.document.currentLineHeight(true);
|
||||
if ((_this.height != null) && _this.ellipsis && _this.document.y + lh * 2 > _this.maxY && _this.column >= _this.columns) {
|
||||
if (_this.ellipsis === true) {
|
||||
_this.ellipsis = '…';
|
||||
}
|
||||
buffer = buffer.replace(/\s+$/, '');
|
||||
textWidth = _this.wordWidth(buffer + _this.ellipsis);
|
||||
while (textWidth > _this.lineWidth) {
|
||||
buffer = buffer.slice(0, -1).replace(/\s+$/, '');
|
||||
textWidth = _this.wordWidth(buffer + _this.ellipsis);
|
||||
}
|
||||
buffer = buffer + _this.ellipsis;
|
||||
}
|
||||
if (bk.required && w > _this.spaceLeft) {
|
||||
buffer = word;
|
||||
textWidth = w;
|
||||
wc = 1;
|
||||
}
|
||||
emitLine();
|
||||
if (_this.document.y + lh > _this.maxY) {
|
||||
shouldContinue = _this.nextSection();
|
||||
if (!shouldContinue) {
|
||||
wc = 0;
|
||||
buffer = '';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (bk.required) {
|
||||
_this.spaceLeft = _this.lineWidth;
|
||||
buffer = '';
|
||||
textWidth = 0;
|
||||
return wc = 0;
|
||||
} else {
|
||||
_this.spaceLeft = _this.lineWidth - w;
|
||||
buffer = word;
|
||||
textWidth = w;
|
||||
return wc = 1;
|
||||
}
|
||||
} else {
|
||||
return _this.spaceLeft -= w;
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
if (wc > 0) {
|
||||
this.emit('lastLine', options, this);
|
||||
emitLine();
|
||||
}
|
||||
this.emit('sectionEnd', options, this);
|
||||
if (options.continued === true) {
|
||||
if (lc > 1) {
|
||||
this.continuedX = 0;
|
||||
}
|
||||
this.continuedX += options.textWidth;
|
||||
return this.document.y = y;
|
||||
} else {
|
||||
return this.document.x = this.startX;
|
||||
}
|
||||
};
|
||||
|
||||
LineWrapper.prototype.nextSection = function(options) {
|
||||
var ref;
|
||||
this.emit('sectionEnd', options, this);
|
||||
if (++this.column > this.columns) {
|
||||
if (this.height != null) {
|
||||
return false;
|
||||
}
|
||||
this.document.addPage();
|
||||
this.column = 1;
|
||||
this.startY = this.document.page.margins.top;
|
||||
this.maxY = this.document.page.maxY();
|
||||
this.document.x = this.startX;
|
||||
if (this.document._fillColor) {
|
||||
(ref = this.document).fillColor.apply(ref, this.document._fillColor);
|
||||
}
|
||||
this.emit('pageBreak', options, this);
|
||||
} else {
|
||||
this.document.x += this.lineWidth + this.columnGap;
|
||||
this.document.y = this.startY;
|
||||
this.emit('columnBreak', options, this);
|
||||
}
|
||||
this.emit('sectionStart', options, this);
|
||||
return true;
|
||||
};
|
||||
|
||||
return LineWrapper;
|
||||
|
||||
})(EventEmitter);
|
||||
|
||||
module.exports = LineWrapper;
|
||||
|
||||
}).call(this);
|
@ -1,421 +0,0 @@
|
||||
0 info it worked if it ends with ok
|
||||
1 verbose cli [ '/usr/local/bin/node',
|
||||
1 verbose cli '/usr/local/bin/npm',
|
||||
1 verbose cli 'unlink',
|
||||
1 verbose cli 'pdfkit' ]
|
||||
2 info using npm@3.10.10
|
||||
3 info using node@v6.10.3
|
||||
4 silly loadCurrentTree Starting
|
||||
5 silly install loadCurrentTree
|
||||
6 silly install readLocalPackageData
|
||||
7 silly install normalizeTree
|
||||
8 silly loadCurrentTree Finishing
|
||||
9 silly loadIdealTree Starting
|
||||
10 silly install loadIdealTree
|
||||
11 silly cloneCurrentTree Starting
|
||||
12 silly install cloneCurrentTreeToIdealTree
|
||||
13 silly cloneCurrentTree Finishing
|
||||
14 silly loadShrinkwrap Starting
|
||||
15 silly install loadShrinkwrap
|
||||
16 silly loadShrinkwrap Finishing
|
||||
17 silly loadAllDepsIntoIdealTree Starting
|
||||
18 silly uninstall loadAllDepsIntoIdealtree
|
||||
19 silly loadAllDepsIntoIdealTree Finishing
|
||||
20 silly loadIdealTree Finishing
|
||||
21 silly currentTree pdfkit@0.8.0
|
||||
21 silly currentTree ├── abbrev@1.1.0
|
||||
21 silly currentTree ├── acorn@4.0.11
|
||||
21 silly currentTree ├── amdefine@1.0.1
|
||||
21 silly currentTree ├── assert@1.1.2
|
||||
21 silly currentTree ├─┬ ast-transform@0.0.0
|
||||
21 silly currentTree │ ├── escodegen@1.2.0
|
||||
21 silly currentTree │ └── esprima@1.0.4
|
||||
21 silly currentTree ├── ast-types@0.7.8
|
||||
21 silly currentTree ├── astw@2.2.0
|
||||
21 silly currentTree ├── async@0.2.10
|
||||
21 silly currentTree ├── babel-runtime@6.23.0
|
||||
21 silly currentTree ├── base64-js@1.2.0
|
||||
21 silly currentTree ├── Base64@0.2.1
|
||||
21 silly currentTree ├── blob-stream@0.1.3
|
||||
21 silly currentTree ├── blob@0.0.4
|
||||
21 silly currentTree ├── brace@0.2.1
|
||||
21 silly currentTree ├─┬ brfs@1.0.2
|
||||
21 silly currentTree │ └── through@2.2.7
|
||||
21 silly currentTree ├── brotli@1.3.2
|
||||
21 silly currentTree ├─┬ browser-pack@2.0.1
|
||||
21 silly currentTree │ └─┬ JSONStream@0.6.4
|
||||
21 silly currentTree │ └── through@2.2.7
|
||||
21 silly currentTree ├─┬ browser-resolve@1.11.2
|
||||
21 silly currentTree │ └── resolve@1.1.7
|
||||
21 silly currentTree ├── browserify-optional@1.0.0
|
||||
21 silly currentTree ├── browserify-zlib@0.1.4
|
||||
21 silly currentTree ├─┬ browserify@3.46.1
|
||||
21 silly currentTree │ ├── browser-resolve@1.2.4
|
||||
21 silly currentTree │ └── deep-equal@0.1.2
|
||||
21 silly currentTree ├─┬ buffer@2.1.13
|
||||
21 silly currentTree │ └── base64-js@0.0.8
|
||||
21 silly currentTree ├── builtins@0.0.7
|
||||
21 silly currentTree ├── callsite@1.0.0
|
||||
21 silly currentTree ├── camelcase@1.2.1
|
||||
21 silly currentTree ├── character-parser@1.2.0
|
||||
21 silly currentTree ├── clone@1.0.2
|
||||
21 silly currentTree ├── codemirror@3.20.0
|
||||
21 silly currentTree ├── coffee-script@1.12.5
|
||||
21 silly currentTree ├─┬ coffeeify@0.6.0
|
||||
21 silly currentTree │ └── coffee-script@1.7.1
|
||||
21 silly currentTree ├── combine-source-map@0.3.0
|
||||
21 silly currentTree ├── commander@2.1.0
|
||||
21 silly currentTree ├── commondir@0.0.1
|
||||
21 silly currentTree ├── concat-stream@1.4.10
|
||||
21 silly currentTree ├── console-browserify@1.0.3
|
||||
21 silly currentTree ├── constantinople@1.0.2
|
||||
21 silly currentTree ├── constants-browserify@0.0.1
|
||||
21 silly currentTree ├── convert-source-map@0.3.5
|
||||
21 silly currentTree ├── core-js@2.4.1
|
||||
21 silly currentTree ├── core-util-is@1.0.2
|
||||
21 silly currentTree ├── crypto-browserify@1.0.9
|
||||
21 silly currentTree ├── css-parse@1.0.4
|
||||
21 silly currentTree ├── css-stringify@1.0.5
|
||||
21 silly currentTree ├── css@1.0.8
|
||||
21 silly currentTree ├── decamelize@1.2.0
|
||||
21 silly currentTree ├── deep-equal@1.0.1
|
||||
21 silly currentTree ├── defined@0.0.0
|
||||
21 silly currentTree ├─┬ deps-sort@0.1.2
|
||||
21 silly currentTree │ └─┬ JSONStream@0.6.4
|
||||
21 silly currentTree │ └── through@2.2.7
|
||||
21 silly currentTree ├─┬ derequire@0.8.0
|
||||
21 silly currentTree │ └── esprima-fb@3001.1.0-dev-harmony-fb
|
||||
21 silly currentTree ├─┬ detective@3.1.0
|
||||
21 silly currentTree │ ├── escodegen@1.1.0
|
||||
21 silly currentTree │ └── esprima-fb@3001.1.0-dev-harmony-fb
|
||||
21 silly currentTree ├── dfa@1.0.0
|
||||
21 silly currentTree ├── domain-browser@1.1.7
|
||||
21 silly currentTree ├── duplexer@0.1.1
|
||||
21 silly currentTree ├── duplexer2@0.0.2
|
||||
21 silly currentTree ├─┬ escodegen@0.0.17
|
||||
21 silly currentTree │ └── estraverse@0.0.4
|
||||
21 silly currentTree ├── escope@0.0.16
|
||||
21 silly currentTree ├── esprima@1.0.4
|
||||
21 silly currentTree ├─┬ esrefactor@0.1.0
|
||||
21 silly currentTree │ └── estraverse@0.0.4
|
||||
21 silly currentTree ├── estraverse@1.5.1
|
||||
21 silly currentTree ├── esutils@1.0.0
|
||||
21 silly currentTree ├── events@1.0.2
|
||||
21 silly currentTree ├─┬ exorcist@0.1.6
|
||||
21 silly currentTree │ └── minimist@0.0.5
|
||||
21 silly currentTree ├── falafel@0.1.6
|
||||
21 silly currentTree ├── fontkit@1.6.0
|
||||
21 silly currentTree ├── glob@3.2.11
|
||||
21 silly currentTree ├── http-browserify@1.3.2
|
||||
21 silly currentTree ├── https-browserify@0.0.1
|
||||
21 silly currentTree ├── iconv-lite@0.4.17
|
||||
21 silly currentTree ├── ieee754@1.1.8
|
||||
21 silly currentTree ├── indexof@0.0.1
|
||||
21 silly currentTree ├── inherits@2.0.3
|
||||
21 silly currentTree ├─┬ inline-source-map@0.3.1
|
||||
21 silly currentTree │ └── source-map@0.3.0
|
||||
21 silly currentTree ├─┬ insert-module-globals@6.0.0
|
||||
21 silly currentTree │ └── process@0.6.0
|
||||
21 silly currentTree ├── is-promise@1.0.1
|
||||
21 silly currentTree ├── isarray@0.0.1
|
||||
21 silly currentTree ├── jade@1.1.5
|
||||
21 silly currentTree ├── jsonparse@0.0.5
|
||||
21 silly currentTree ├── JSONStream@0.7.4
|
||||
21 silly currentTree ├── lexical-scope@1.1.1
|
||||
21 silly currentTree ├─┬ linebreak@0.1.2
|
||||
21 silly currentTree │ └── unicode-trie@0.1.2
|
||||
21 silly currentTree ├── lru-cache@2.7.3
|
||||
21 silly currentTree ├── markdown@0.5.0
|
||||
21 silly currentTree ├── minimatch@0.3.0
|
||||
21 silly currentTree ├── minimist@0.0.10
|
||||
21 silly currentTree ├── mkdirp@0.3.5
|
||||
21 silly currentTree ├─┬ module-deps@2.0.6
|
||||
21 silly currentTree │ ├── browser-resolve@1.2.4
|
||||
21 silly currentTree │ ├── parents@0.0.2
|
||||
21 silly currentTree │ └── stream-combiner@0.1.0
|
||||
21 silly currentTree ├── monocle@1.1.51
|
||||
21 silly currentTree ├── nopt@2.1.2
|
||||
21 silly currentTree ├── object-keys@0.4.0
|
||||
21 silly currentTree ├── optimist@0.3.7
|
||||
21 silly currentTree ├── os-browserify@0.1.2
|
||||
21 silly currentTree ├── pako@0.2.9
|
||||
21 silly currentTree ├── parents@0.0.3
|
||||
21 silly currentTree ├── path-browserify@0.0.0
|
||||
21 silly currentTree ├── path-platform@0.0.1
|
||||
21 silly currentTree ├── png-js@0.1.1
|
||||
21 silly currentTree ├── process@0.7.0
|
||||
21 silly currentTree ├── promise@2.0.0
|
||||
21 silly currentTree ├── punycode@1.2.4
|
||||
21 silly currentTree ├── querystring-es3@0.2.0
|
||||
21 silly currentTree ├── querystring@0.2.0
|
||||
21 silly currentTree ├─┬ readable-stream@1.1.14
|
||||
21 silly currentTree │ └── string_decoder@0.10.31
|
||||
21 silly currentTree ├── readdirp@0.2.5
|
||||
21 silly currentTree ├── regenerator-runtime@0.10.5
|
||||
21 silly currentTree ├── resolve@0.6.3
|
||||
21 silly currentTree ├── restructure@0.5.4
|
||||
21 silly currentTree ├─┬ rfile@1.0.0
|
||||
21 silly currentTree │ └── resolve@0.3.1
|
||||
21 silly currentTree ├─┬ ruglify@1.0.0
|
||||
21 silly currentTree │ └── uglify-js@2.2.5
|
||||
21 silly currentTree ├── shallow-copy@0.0.1
|
||||
21 silly currentTree ├── shell-quote@0.0.1
|
||||
21 silly currentTree ├── sigmund@1.0.1
|
||||
21 silly currentTree ├── source-map@0.1.43
|
||||
21 silly currentTree ├─┬ stream-browserify@0.1.3
|
||||
21 silly currentTree │ └── process@0.5.2
|
||||
21 silly currentTree ├── stream-combiner@0.0.4
|
||||
21 silly currentTree ├── string_decoder@0.0.1
|
||||
21 silly currentTree ├── subarg@0.0.1
|
||||
21 silly currentTree ├─┬ syntax-error@1.1.6
|
||||
21 silly currentTree │ └── acorn@2.7.0
|
||||
21 silly currentTree ├── through@2.3.8
|
||||
21 silly currentTree ├─┬ through2@0.4.2
|
||||
21 silly currentTree │ ├── readable-stream@1.0.34
|
||||
21 silly currentTree │ ├── string_decoder@0.10.31
|
||||
21 silly currentTree │ └── xtend@2.1.2
|
||||
21 silly currentTree ├─┬ timers-browserify@1.0.3
|
||||
21 silly currentTree │ └── process@0.5.2
|
||||
21 silly currentTree ├── tiny-inflate@1.0.2
|
||||
21 silly currentTree ├─┬ transformers@2.1.0
|
||||
21 silly currentTree │ └── uglify-js@2.2.5
|
||||
21 silly currentTree ├── tty-browserify@0.0.0
|
||||
21 silly currentTree ├── typedarray@0.0.6
|
||||
21 silly currentTree ├─┬ uglify-js@2.4.24
|
||||
21 silly currentTree │ └── source-map@0.1.34
|
||||
21 silly currentTree ├── uglify-to-browserify@1.0.2
|
||||
21 silly currentTree ├── umd@2.0.0
|
||||
21 silly currentTree ├── unicode-properties@1.1.0
|
||||
21 silly currentTree ├── unicode-trie@0.3.1
|
||||
21 silly currentTree ├─┬ url@0.10.3
|
||||
21 silly currentTree │ └── punycode@1.3.2
|
||||
21 silly currentTree ├─┬ util@0.10.3
|
||||
21 silly currentTree │ └── inherits@2.0.1
|
||||
21 silly currentTree ├── vm-browserify@0.0.4
|
||||
21 silly currentTree ├── w3c-blob@0.0.1
|
||||
21 silly currentTree ├── window-size@0.1.0
|
||||
21 silly currentTree ├─┬ with@2.0.0
|
||||
21 silly currentTree │ └── uglify-js@2.4.0
|
||||
21 silly currentTree ├── wordwrap@0.0.3
|
||||
21 silly currentTree ├── xtend@3.0.0
|
||||
21 silly currentTree └─┬ yargs@3.5.4
|
||||
21 silly currentTree └── wordwrap@0.0.2
|
||||
22 silly idealTree pdfkit@0.8.0
|
||||
22 silly idealTree ├── abbrev@1.1.0
|
||||
22 silly idealTree ├── acorn@4.0.11
|
||||
22 silly idealTree ├── amdefine@1.0.1
|
||||
22 silly idealTree ├── assert@1.1.2
|
||||
22 silly idealTree ├─┬ ast-transform@0.0.0
|
||||
22 silly idealTree │ ├── escodegen@1.2.0
|
||||
22 silly idealTree │ └── esprima@1.0.4
|
||||
22 silly idealTree ├── ast-types@0.7.8
|
||||
22 silly idealTree ├── astw@2.2.0
|
||||
22 silly idealTree ├── async@0.2.10
|
||||
22 silly idealTree ├── babel-runtime@6.23.0
|
||||
22 silly idealTree ├── base64-js@1.2.0
|
||||
22 silly idealTree ├── Base64@0.2.1
|
||||
22 silly idealTree ├── blob-stream@0.1.3
|
||||
22 silly idealTree ├── blob@0.0.4
|
||||
22 silly idealTree ├── brace@0.2.1
|
||||
22 silly idealTree ├─┬ brfs@1.0.2
|
||||
22 silly idealTree │ └── through@2.2.7
|
||||
22 silly idealTree ├── brotli@1.3.2
|
||||
22 silly idealTree ├─┬ browser-pack@2.0.1
|
||||
22 silly idealTree │ └─┬ JSONStream@0.6.4
|
||||
22 silly idealTree │ └── through@2.2.7
|
||||
22 silly idealTree ├─┬ browser-resolve@1.11.2
|
||||
22 silly idealTree │ └── resolve@1.1.7
|
||||
22 silly idealTree ├── browserify-optional@1.0.0
|
||||
22 silly idealTree ├── browserify-zlib@0.1.4
|
||||
22 silly idealTree ├─┬ browserify@3.46.1
|
||||
22 silly idealTree │ ├── browser-resolve@1.2.4
|
||||
22 silly idealTree │ └── deep-equal@0.1.2
|
||||
22 silly idealTree ├─┬ buffer@2.1.13
|
||||
22 silly idealTree │ └── base64-js@0.0.8
|
||||
22 silly idealTree ├── builtins@0.0.7
|
||||
22 silly idealTree ├── callsite@1.0.0
|
||||
22 silly idealTree ├── camelcase@1.2.1
|
||||
22 silly idealTree ├── character-parser@1.2.0
|
||||
22 silly idealTree ├── clone@1.0.2
|
||||
22 silly idealTree ├── codemirror@3.20.0
|
||||
22 silly idealTree ├── coffee-script@1.12.5
|
||||
22 silly idealTree ├─┬ coffeeify@0.6.0
|
||||
22 silly idealTree │ └── coffee-script@1.7.1
|
||||
22 silly idealTree ├── combine-source-map@0.3.0
|
||||
22 silly idealTree ├── commander@2.1.0
|
||||
22 silly idealTree ├── commondir@0.0.1
|
||||
22 silly idealTree ├── concat-stream@1.4.10
|
||||
22 silly idealTree ├── console-browserify@1.0.3
|
||||
22 silly idealTree ├── constantinople@1.0.2
|
||||
22 silly idealTree ├── constants-browserify@0.0.1
|
||||
22 silly idealTree ├── convert-source-map@0.3.5
|
||||
22 silly idealTree ├── core-js@2.4.1
|
||||
22 silly idealTree ├── core-util-is@1.0.2
|
||||
22 silly idealTree ├── crypto-browserify@1.0.9
|
||||
22 silly idealTree ├── css-parse@1.0.4
|
||||
22 silly idealTree ├── css-stringify@1.0.5
|
||||
22 silly idealTree ├── css@1.0.8
|
||||
22 silly idealTree ├── decamelize@1.2.0
|
||||
22 silly idealTree ├── deep-equal@1.0.1
|
||||
22 silly idealTree ├── defined@0.0.0
|
||||
22 silly idealTree ├─┬ deps-sort@0.1.2
|
||||
22 silly idealTree │ └─┬ JSONStream@0.6.4
|
||||
22 silly idealTree │ └── through@2.2.7
|
||||
22 silly idealTree ├─┬ derequire@0.8.0
|
||||
22 silly idealTree │ └── esprima-fb@3001.1.0-dev-harmony-fb
|
||||
22 silly idealTree ├─┬ detective@3.1.0
|
||||
22 silly idealTree │ ├── escodegen@1.1.0
|
||||
22 silly idealTree │ └── esprima-fb@3001.1.0-dev-harmony-fb
|
||||
22 silly idealTree ├── dfa@1.0.0
|
||||
22 silly idealTree ├── domain-browser@1.1.7
|
||||
22 silly idealTree ├── duplexer@0.1.1
|
||||
22 silly idealTree ├── duplexer2@0.0.2
|
||||
22 silly idealTree ├─┬ escodegen@0.0.17
|
||||
22 silly idealTree │ └── estraverse@0.0.4
|
||||
22 silly idealTree ├── escope@0.0.16
|
||||
22 silly idealTree ├── esprima@1.0.4
|
||||
22 silly idealTree ├─┬ esrefactor@0.1.0
|
||||
22 silly idealTree │ └── estraverse@0.0.4
|
||||
22 silly idealTree ├── estraverse@1.5.1
|
||||
22 silly idealTree ├── esutils@1.0.0
|
||||
22 silly idealTree ├── events@1.0.2
|
||||
22 silly idealTree ├─┬ exorcist@0.1.6
|
||||
22 silly idealTree │ └── minimist@0.0.5
|
||||
22 silly idealTree ├── falafel@0.1.6
|
||||
22 silly idealTree ├── fontkit@1.6.0
|
||||
22 silly idealTree ├── glob@3.2.11
|
||||
22 silly idealTree ├── http-browserify@1.3.2
|
||||
22 silly idealTree ├── https-browserify@0.0.1
|
||||
22 silly idealTree ├── iconv-lite@0.4.17
|
||||
22 silly idealTree ├── ieee754@1.1.8
|
||||
22 silly idealTree ├── indexof@0.0.1
|
||||
22 silly idealTree ├── inherits@2.0.3
|
||||
22 silly idealTree ├─┬ inline-source-map@0.3.1
|
||||
22 silly idealTree │ └── source-map@0.3.0
|
||||
22 silly idealTree ├─┬ insert-module-globals@6.0.0
|
||||
22 silly idealTree │ └── process@0.6.0
|
||||
22 silly idealTree ├── is-promise@1.0.1
|
||||
22 silly idealTree ├── isarray@0.0.1
|
||||
22 silly idealTree ├── jade@1.1.5
|
||||
22 silly idealTree ├── jsonparse@0.0.5
|
||||
22 silly idealTree ├── JSONStream@0.7.4
|
||||
22 silly idealTree ├── lexical-scope@1.1.1
|
||||
22 silly idealTree ├─┬ linebreak@0.1.2
|
||||
22 silly idealTree │ └── unicode-trie@0.1.2
|
||||
22 silly idealTree ├── lru-cache@2.7.3
|
||||
22 silly idealTree ├── markdown@0.5.0
|
||||
22 silly idealTree ├── minimatch@0.3.0
|
||||
22 silly idealTree ├── minimist@0.0.10
|
||||
22 silly idealTree ├── mkdirp@0.3.5
|
||||
22 silly idealTree ├─┬ module-deps@2.0.6
|
||||
22 silly idealTree │ ├── browser-resolve@1.2.4
|
||||
22 silly idealTree │ ├── parents@0.0.2
|
||||
22 silly idealTree │ └── stream-combiner@0.1.0
|
||||
22 silly idealTree ├── monocle@1.1.51
|
||||
22 silly idealTree ├── nopt@2.1.2
|
||||
22 silly idealTree ├── object-keys@0.4.0
|
||||
22 silly idealTree ├── optimist@0.3.7
|
||||
22 silly idealTree ├── os-browserify@0.1.2
|
||||
22 silly idealTree ├── pako@0.2.9
|
||||
22 silly idealTree ├── parents@0.0.3
|
||||
22 silly idealTree ├── path-browserify@0.0.0
|
||||
22 silly idealTree ├── path-platform@0.0.1
|
||||
22 silly idealTree ├── png-js@0.1.1
|
||||
22 silly idealTree ├── process@0.7.0
|
||||
22 silly idealTree ├── promise@2.0.0
|
||||
22 silly idealTree ├── punycode@1.2.4
|
||||
22 silly idealTree ├── querystring-es3@0.2.0
|
||||
22 silly idealTree ├── querystring@0.2.0
|
||||
22 silly idealTree ├─┬ readable-stream@1.1.14
|
||||
22 silly idealTree │ └── string_decoder@0.10.31
|
||||
22 silly idealTree ├── readdirp@0.2.5
|
||||
22 silly idealTree ├── regenerator-runtime@0.10.5
|
||||
22 silly idealTree ├── resolve@0.6.3
|
||||
22 silly idealTree ├── restructure@0.5.4
|
||||
22 silly idealTree ├─┬ rfile@1.0.0
|
||||
22 silly idealTree │ └── resolve@0.3.1
|
||||
22 silly idealTree ├─┬ ruglify@1.0.0
|
||||
22 silly idealTree │ └── uglify-js@2.2.5
|
||||
22 silly idealTree ├── shallow-copy@0.0.1
|
||||
22 silly idealTree ├── shell-quote@0.0.1
|
||||
22 silly idealTree ├── sigmund@1.0.1
|
||||
22 silly idealTree ├── source-map@0.1.43
|
||||
22 silly idealTree ├─┬ stream-browserify@0.1.3
|
||||
22 silly idealTree │ └── process@0.5.2
|
||||
22 silly idealTree ├── stream-combiner@0.0.4
|
||||
22 silly idealTree ├── string_decoder@0.0.1
|
||||
22 silly idealTree ├── subarg@0.0.1
|
||||
22 silly idealTree ├─┬ syntax-error@1.1.6
|
||||
22 silly idealTree │ └── acorn@2.7.0
|
||||
22 silly idealTree ├── through@2.3.8
|
||||
22 silly idealTree ├─┬ through2@0.4.2
|
||||
22 silly idealTree │ ├── readable-stream@1.0.34
|
||||
22 silly idealTree │ ├── string_decoder@0.10.31
|
||||
22 silly idealTree │ └── xtend@2.1.2
|
||||
22 silly idealTree ├─┬ timers-browserify@1.0.3
|
||||
22 silly idealTree │ └── process@0.5.2
|
||||
22 silly idealTree ├── tiny-inflate@1.0.2
|
||||
22 silly idealTree ├─┬ transformers@2.1.0
|
||||
22 silly idealTree │ └── uglify-js@2.2.5
|
||||
22 silly idealTree ├── tty-browserify@0.0.0
|
||||
22 silly idealTree ├── typedarray@0.0.6
|
||||
22 silly idealTree ├─┬ uglify-js@2.4.24
|
||||
22 silly idealTree │ └── source-map@0.1.34
|
||||
22 silly idealTree ├── uglify-to-browserify@1.0.2
|
||||
22 silly idealTree ├── umd@2.0.0
|
||||
22 silly idealTree ├── unicode-properties@1.1.0
|
||||
22 silly idealTree ├── unicode-trie@0.3.1
|
||||
22 silly idealTree ├─┬ url@0.10.3
|
||||
22 silly idealTree │ └── punycode@1.3.2
|
||||
22 silly idealTree ├─┬ util@0.10.3
|
||||
22 silly idealTree │ └── inherits@2.0.1
|
||||
22 silly idealTree ├── vm-browserify@0.0.4
|
||||
22 silly idealTree ├── w3c-blob@0.0.1
|
||||
22 silly idealTree ├── window-size@0.1.0
|
||||
22 silly idealTree ├─┬ with@2.0.0
|
||||
22 silly idealTree │ └── uglify-js@2.4.0
|
||||
22 silly idealTree ├── wordwrap@0.0.3
|
||||
22 silly idealTree ├── xtend@3.0.0
|
||||
22 silly idealTree └─┬ yargs@3.5.4
|
||||
22 silly idealTree └── wordwrap@0.0.2
|
||||
23 silly generateActionsToTake Starting
|
||||
24 silly install generateActionsToTake
|
||||
25 silly generateActionsToTake Finishing
|
||||
26 silly diffTrees action count 0
|
||||
27 silly decomposeActions action count 0
|
||||
28 silly runTopLevelLifecycles Starting
|
||||
29 silly executeActions Starting
|
||||
30 silly install executeActions
|
||||
31 silly doSerial global-install 0
|
||||
32 silly doParallel fetch 0
|
||||
33 verbose correctMkdir /Users/MB/.npm/_locks correctMkdir not in flight; initializing
|
||||
34 verbose lock using /Users/MB/.npm/_locks/staging-73efde40ed96aa4a.lock for /Users/MB/git/pitfall/pdfkit/node_modules/.staging
|
||||
35 verbose unlock done using /Users/MB/.npm/_locks/staging-73efde40ed96aa4a.lock for /Users/MB/git/pitfall/pdfkit/node_modules/.staging
|
||||
36 silly rollbackFailedOptional Starting
|
||||
37 silly rollbackFailedOptional Finishing
|
||||
38 silly runTopLevelLifecycles Finishing
|
||||
39 silly install printInstalled
|
||||
40 warn pdfkit@0.8.0 No license field.
|
||||
41 verbose If you need help, you may report this error at:
|
||||
41 verbose <https://github.com/npm/npm/issues>
|
||||
42 verbose stack Error: EACCES: permission denied, mkdir '/Users/MB/git/pitfall/pdfkit/node_modules/.staging'
|
||||
42 verbose stack at Error (native)
|
||||
43 verbose cwd /Users/MB/git/pitfall/pdfkit/lib
|
||||
44 error Darwin 16.5.0
|
||||
45 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "unlink" "pdfkit"
|
||||
46 error node v6.10.3
|
||||
47 error npm v3.10.10
|
||||
48 error path /Users/MB/git/pitfall/pdfkit/node_modules/.staging
|
||||
49 error code EACCES
|
||||
50 error errno -13
|
||||
51 error syscall mkdir
|
||||
52 error Error: EACCES: permission denied, mkdir '/Users/MB/git/pitfall/pdfkit/node_modules/.staging'
|
||||
52 error at Error (native)
|
||||
52 error { Error: EACCES: permission denied, mkdir '/Users/MB/git/pitfall/pdfkit/node_modules/.staging'
|
||||
52 error at Error (native)
|
||||
52 error errno: -13,
|
||||
52 error code: 'EACCES',
|
||||
52 error syscall: 'mkdir',
|
||||
52 error path: '/Users/MB/git/pitfall/pdfkit/node_modules/.staging' }
|
||||
53 error Please try running this command again as root/Administrator.
|
||||
54 verbose exit [ -13, true ]
|
@ -1,114 +0,0 @@
|
||||
// Generated by CoffeeScript 1.12.5
|
||||
|
||||
/*
|
||||
PDFObject - converts JavaScript types into their corrisponding PDF types.
|
||||
By Devon Govett
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var PDFObject, PDFReference;
|
||||
|
||||
PDFObject = (function() {
|
||||
var escapable, escapableRe, pad, swapBytes;
|
||||
|
||||
function PDFObject() {}
|
||||
|
||||
pad = function(str, length) {
|
||||
return (Array(length + 1).join('0') + str).slice(-length);
|
||||
};
|
||||
|
||||
escapableRe = /[\n\r\t\b\f\(\)\\]/g;
|
||||
|
||||
escapable = {
|
||||
'\n': '\\n',
|
||||
'\r': '\\r',
|
||||
'\t': '\\t',
|
||||
'\b': '\\b',
|
||||
'\f': '\\f',
|
||||
'\\': '\\\\',
|
||||
'(': '\\(',
|
||||
')': '\\)'
|
||||
};
|
||||
|
||||
swapBytes = function(buff) {
|
||||
var a, i, j, l, ref;
|
||||
l = buff.length;
|
||||
if (l & 0x01) {
|
||||
throw new Error("Buffer length must be even");
|
||||
} else {
|
||||
for (i = j = 0, ref = l - 1; j < ref; i = j += 2) {
|
||||
a = buff[i];
|
||||
buff[i] = buff[i + 1];
|
||||
buff[i + 1] = a;
|
||||
}
|
||||
}
|
||||
return buff;
|
||||
};
|
||||
|
||||
PDFObject.convert = function(object) {
|
||||
var e, i, isUnicode, items, j, key, out, ref, string, val;
|
||||
if (typeof object === 'string') {
|
||||
return '/' + object;
|
||||
} else if (object instanceof String) {
|
||||
string = object.replace(escapableRe, function(c) {
|
||||
return escapable[c];
|
||||
});
|
||||
isUnicode = false;
|
||||
for (i = j = 0, ref = string.length; j < ref; i = j += 1) {
|
||||
if (string.charCodeAt(i) > 0x7f) {
|
||||
isUnicode = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isUnicode) {
|
||||
string = swapBytes(new Buffer('\ufeff' + string, 'utf16le')).toString('binary');
|
||||
}
|
||||
return '(' + string + ')';
|
||||
} else if (Buffer.isBuffer(object)) {
|
||||
return '<' + object.toString('hex') + '>';
|
||||
} else if (object instanceof PDFReference) {
|
||||
return object.toString();
|
||||
} else if (object instanceof Date) {
|
||||
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)';
|
||||
} else if (Array.isArray(object)) {
|
||||
items = ((function() {
|
||||
var k, len, results;
|
||||
results = [];
|
||||
for (k = 0, len = object.length; k < len; k++) {
|
||||
e = object[k];
|
||||
results.push(PDFObject.convert(e));
|
||||
}
|
||||
return results;
|
||||
})()).join(' ');
|
||||
return '[' + items + ']';
|
||||
} else if ({}.toString.call(object) === '[object Object]') {
|
||||
out = ['<<'];
|
||||
for (key in object) {
|
||||
val = object[key];
|
||||
out.push('/' + key + ' ' + PDFObject.convert(val));
|
||||
}
|
||||
out.push('>>');
|
||||
return out.join('\n');
|
||||
} else if (typeof object === 'number') {
|
||||
return PDFObject.number(object);
|
||||
} else {
|
||||
return '' + object;
|
||||
}
|
||||
};
|
||||
|
||||
PDFObject.number = function(n) {
|
||||
if (n > -1e21 && n < 1e21) {
|
||||
return Math.round(n * 1e6) / 1e6;
|
||||
}
|
||||
throw new Error("unsupported number: " + n);
|
||||
};
|
||||
|
||||
return PDFObject;
|
||||
|
||||
})();
|
||||
|
||||
module.exports = PDFObject;
|
||||
|
||||
PDFReference = require('./reference');
|
||||
|
||||
}).call(this);
|
@ -1,170 +0,0 @@
|
||||
// Generated by CoffeeScript 1.12.5
|
||||
|
||||
/*
|
||||
PDFPage - represents a single page in the PDF document
|
||||
By Devon Govett
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var PDFPage;
|
||||
|
||||
PDFPage = (function() {
|
||||
var DEFAULT_MARGINS, SIZES;
|
||||
|
||||
function PDFPage(document, options) {
|
||||
var dimensions;
|
||||
this.document = document;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
this.size = options.size || 'letter';
|
||||
this.layout = options.layout || 'portrait';
|
||||
if (typeof options.margin === 'number') {
|
||||
this.margins = {
|
||||
top: options.margin,
|
||||
left: options.margin,
|
||||
bottom: options.margin,
|
||||
right: options.margin
|
||||
};
|
||||
} else {
|
||||
this.margins = options.margins || DEFAULT_MARGINS;
|
||||
}
|
||||
dimensions = Array.isArray(this.size) ? this.size : SIZES[this.size.toUpperCase()];
|
||||
this.width = dimensions[this.layout === 'portrait' ? 0 : 1];
|
||||
this.height = dimensions[this.layout === 'portrait' ? 1 : 0];
|
||||
this.content = this.document.ref();
|
||||
this.resources = this.document.ref({
|
||||
ProcSet: ['PDF', 'Text', 'ImageB', 'ImageC', 'ImageI']
|
||||
});
|
||||
Object.defineProperties(this, {
|
||||
fonts: {
|
||||
get: (function(_this) {
|
||||
return function() {
|
||||
var base;
|
||||
return (base = _this.resources.data).Font != null ? base.Font : base.Font = {};
|
||||
};
|
||||
})(this)
|
||||
},
|
||||
xobjects: {
|
||||
get: (function(_this) {
|
||||
return function() {
|
||||
var base;
|
||||
return (base = _this.resources.data).XObject != null ? base.XObject : base.XObject = {};
|
||||
};
|
||||
})(this)
|
||||
},
|
||||
ext_gstates: {
|
||||
get: (function(_this) {
|
||||
return function() {
|
||||
var base;
|
||||
return (base = _this.resources.data).ExtGState != null ? base.ExtGState : base.ExtGState = {};
|
||||
};
|
||||
})(this)
|
||||
},
|
||||
patterns: {
|
||||
get: (function(_this) {
|
||||
return function() {
|
||||
var base;
|
||||
return (base = _this.resources.data).Pattern != null ? base.Pattern : base.Pattern = {};
|
||||
};
|
||||
})(this)
|
||||
},
|
||||
annotations: {
|
||||
get: (function(_this) {
|
||||
return function() {
|
||||
var base;
|
||||
return (base = _this.dictionary.data).Annots != null ? base.Annots : base.Annots = [];
|
||||
};
|
||||
})(this)
|
||||
}
|
||||
});
|
||||
this.dictionary = this.document.ref({
|
||||
Type: 'Page',
|
||||
Parent: this.document._root.data.Pages,
|
||||
MediaBox: [0, 0, this.width, this.height],
|
||||
Contents: this.content,
|
||||
Resources: this.resources
|
||||
});
|
||||
}
|
||||
|
||||
PDFPage.prototype.maxY = function() {
|
||||
return this.height - this.margins.bottom;
|
||||
};
|
||||
|
||||
PDFPage.prototype.write = function(chunk) {
|
||||
return this.content.write(chunk);
|
||||
};
|
||||
|
||||
PDFPage.prototype.end = function() {
|
||||
this.dictionary.end();
|
||||
this.resources.end();
|
||||
return this.content.end();
|
||||
};
|
||||
|
||||
DEFAULT_MARGINS = {
|
||||
top: 72,
|
||||
left: 72,
|
||||
bottom: 72,
|
||||
right: 72
|
||||
};
|
||||
|
||||
SIZES = {
|
||||
'4A0': [4767.87, 6740.79],
|
||||
'2A0': [3370.39, 4767.87],
|
||||
A0: [2383.94, 3370.39],
|
||||
A1: [1683.78, 2383.94],
|
||||
A2: [1190.55, 1683.78],
|
||||
A3: [841.89, 1190.55],
|
||||
A4: [595.28, 841.89],
|
||||
A5: [419.53, 595.28],
|
||||
A6: [297.64, 419.53],
|
||||
A7: [209.76, 297.64],
|
||||
A8: [147.40, 209.76],
|
||||
A9: [104.88, 147.40],
|
||||
A10: [73.70, 104.88],
|
||||
B0: [2834.65, 4008.19],
|
||||
B1: [2004.09, 2834.65],
|
||||
B2: [1417.32, 2004.09],
|
||||
B3: [1000.63, 1417.32],
|
||||
B4: [708.66, 1000.63],
|
||||
B5: [498.90, 708.66],
|
||||
B6: [354.33, 498.90],
|
||||
B7: [249.45, 354.33],
|
||||
B8: [175.75, 249.45],
|
||||
B9: [124.72, 175.75],
|
||||
B10: [87.87, 124.72],
|
||||
C0: [2599.37, 3676.54],
|
||||
C1: [1836.85, 2599.37],
|
||||
C2: [1298.27, 1836.85],
|
||||
C3: [918.43, 1298.27],
|
||||
C4: [649.13, 918.43],
|
||||
C5: [459.21, 649.13],
|
||||
C6: [323.15, 459.21],
|
||||
C7: [229.61, 323.15],
|
||||
C8: [161.57, 229.61],
|
||||
C9: [113.39, 161.57],
|
||||
C10: [79.37, 113.39],
|
||||
RA0: [2437.80, 3458.27],
|
||||
RA1: [1729.13, 2437.80],
|
||||
RA2: [1218.90, 1729.13],
|
||||
RA3: [864.57, 1218.90],
|
||||
RA4: [609.45, 864.57],
|
||||
SRA0: [2551.18, 3628.35],
|
||||
SRA1: [1814.17, 2551.18],
|
||||
SRA2: [1275.59, 1814.17],
|
||||
SRA3: [907.09, 1275.59],
|
||||
SRA4: [637.80, 907.09],
|
||||
EXECUTIVE: [521.86, 756.00],
|
||||
FOLIO: [612.00, 936.00],
|
||||
LEGAL: [612.00, 1008.00],
|
||||
LETTER: [612.00, 792.00],
|
||||
TABLOID: [792.00, 1224.00]
|
||||
};
|
||||
|
||||
return PDFPage;
|
||||
|
||||
})();
|
||||
|
||||
module.exports = PDFPage;
|
||||
|
||||
}).call(this);
|
@ -1,366 +0,0 @@
|
||||
// Generated by CoffeeScript 1.12.5
|
||||
(function() {
|
||||
var SVGPath;
|
||||
|
||||
SVGPath = (function() {
|
||||
var apply, arcToSegments, cx, cy, parameters, parse, px, py, runners, segmentToBezier, solveArc, sx, sy;
|
||||
|
||||
function SVGPath() {}
|
||||
|
||||
SVGPath.apply = function(doc, path) {
|
||||
var commands;
|
||||
commands = parse(path);
|
||||
return apply(commands, doc);
|
||||
};
|
||||
|
||||
parameters = {
|
||||
A: 7,
|
||||
a: 7,
|
||||
C: 6,
|
||||
c: 6,
|
||||
H: 1,
|
||||
h: 1,
|
||||
L: 2,
|
||||
l: 2,
|
||||
M: 2,
|
||||
m: 2,
|
||||
Q: 4,
|
||||
q: 4,
|
||||
S: 4,
|
||||
s: 4,
|
||||
T: 2,
|
||||
t: 2,
|
||||
V: 1,
|
||||
v: 1,
|
||||
Z: 0,
|
||||
z: 0
|
||||
};
|
||||
|
||||
parse = function(path) {
|
||||
var args, c, cmd, curArg, foundDecimal, j, len, params, ret;
|
||||
ret = [];
|
||||
args = [];
|
||||
curArg = "";
|
||||
foundDecimal = false;
|
||||
params = 0;
|
||||
for (j = 0, len = path.length; j < len; j++) {
|
||||
c = path[j];
|
||||
if (parameters[c] != null) {
|
||||
params = parameters[c];
|
||||
if (cmd) {
|
||||
if (curArg.length > 0) {
|
||||
args[args.length] = +curArg;
|
||||
}
|
||||
ret[ret.length] = {
|
||||
cmd: cmd,
|
||||
args: args
|
||||
};
|
||||
args = [];
|
||||
curArg = "";
|
||||
foundDecimal = false;
|
||||
}
|
||||
cmd = c;
|
||||
} else if ((c === " " || c === ",") || (c === "-" && curArg.length > 0 && curArg[curArg.length - 1] !== 'e') || (c === "." && foundDecimal)) {
|
||||
if (curArg.length === 0) {
|
||||
continue;
|
||||
}
|
||||
if (args.length === params) {
|
||||
ret[ret.length] = {
|
||||
cmd: cmd,
|
||||
args: args
|
||||
};
|
||||
args = [+curArg];
|
||||
if (cmd === "M") {
|
||||
cmd = "L";
|
||||
}
|
||||
if (cmd === "m") {
|
||||
cmd = "l";
|
||||
}
|
||||
} else {
|
||||
args[args.length] = +curArg;
|
||||
}
|
||||
foundDecimal = c === ".";
|
||||
curArg = c === '-' || c === '.' ? c : '';
|
||||
} else {
|
||||
curArg += c;
|
||||
if (c === '.') {
|
||||
foundDecimal = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (curArg.length > 0) {
|
||||
if (args.length === params) {
|
||||
ret[ret.length] = {
|
||||
cmd: cmd,
|
||||
args: args
|
||||
};
|
||||
args = [+curArg];
|
||||
if (cmd === "M") {
|
||||
cmd = "L";
|
||||
}
|
||||
if (cmd === "m") {
|
||||
cmd = "l";
|
||||
}
|
||||
} else {
|
||||
args[args.length] = +curArg;
|
||||
}
|
||||
}
|
||||
ret[ret.length] = {
|
||||
cmd: cmd,
|
||||
args: args
|
||||
};
|
||||
return ret;
|
||||
};
|
||||
|
||||
cx = cy = px = py = sx = sy = 0;
|
||||
|
||||
apply = function(commands, doc) {
|
||||
var c, i, j, len, name;
|
||||
cx = cy = px = py = sx = sy = 0;
|
||||
for (i = j = 0, len = commands.length; j < len; i = ++j) {
|
||||
c = commands[i];
|
||||
if (typeof runners[name = c.cmd] === "function") {
|
||||
runners[name](doc, c.args);
|
||||
}
|
||||
}
|
||||
return cx = cy = px = py = 0;
|
||||
};
|
||||
|
||||
runners = {
|
||||
M: function(doc, a) {
|
||||
cx = a[0];
|
||||
cy = a[1];
|
||||
px = py = null;
|
||||
sx = cx;
|
||||
sy = cy;
|
||||
return doc.moveTo(cx, cy);
|
||||
},
|
||||
m: function(doc, a) {
|
||||
cx += a[0];
|
||||
cy += a[1];
|
||||
px = py = null;
|
||||
sx = cx;
|
||||
sy = cy;
|
||||
return doc.moveTo(cx, cy);
|
||||
},
|
||||
C: function(doc, a) {
|
||||
cx = a[4];
|
||||
cy = a[5];
|
||||
px = a[2];
|
||||
py = a[3];
|
||||
return doc.bezierCurveTo.apply(doc, a);
|
||||
},
|
||||
c: function(doc, a) {
|
||||
doc.bezierCurveTo(a[0] + cx, a[1] + cy, a[2] + cx, a[3] + cy, a[4] + cx, a[5] + cy);
|
||||
px = cx + a[2];
|
||||
py = cy + a[3];
|
||||
cx += a[4];
|
||||
return cy += a[5];
|
||||
},
|
||||
S: function(doc, a) {
|
||||
if (px === null) {
|
||||
px = cx;
|
||||
py = cy;
|
||||
}
|
||||
doc.bezierCurveTo(cx - (px - cx), cy - (py - cy), a[0], a[1], a[2], a[3]);
|
||||
px = a[0];
|
||||
py = a[1];
|
||||
cx = a[2];
|
||||
return cy = a[3];
|
||||
},
|
||||
s: function(doc, a) {
|
||||
if (px === null) {
|
||||
px = cx;
|
||||
py = cy;
|
||||
}
|
||||
doc.bezierCurveTo(cx - (px - cx), cy - (py - cy), cx + a[0], cy + a[1], cx + a[2], cy + a[3]);
|
||||
px = cx + a[0];
|
||||
py = cy + a[1];
|
||||
cx += a[2];
|
||||
return cy += a[3];
|
||||
},
|
||||
Q: function(doc, a) {
|
||||
px = a[0];
|
||||
py = a[1];
|
||||
cx = a[2];
|
||||
cy = a[3];
|
||||
return doc.quadraticCurveTo(a[0], a[1], cx, cy);
|
||||
},
|
||||
q: function(doc, a) {
|
||||
doc.quadraticCurveTo(a[0] + cx, a[1] + cy, a[2] + cx, a[3] + cy);
|
||||
px = cx + a[0];
|
||||
py = cy + a[1];
|
||||
cx += a[2];
|
||||
return cy += a[3];
|
||||
},
|
||||
T: function(doc, a) {
|
||||
if (px === null) {
|
||||
px = cx;
|
||||
py = cy;
|
||||
} else {
|
||||
px = cx - (px - cx);
|
||||
py = cy - (py - cy);
|
||||
}
|
||||
doc.quadraticCurveTo(px, py, a[0], a[1]);
|
||||
px = cx - (px - cx);
|
||||
py = cy - (py - cy);
|
||||
cx = a[0];
|
||||
return cy = a[1];
|
||||
},
|
||||
t: function(doc, a) {
|
||||
if (px === null) {
|
||||
px = cx;
|
||||
py = cy;
|
||||
} else {
|
||||
px = cx - (px - cx);
|
||||
py = cy - (py - cy);
|
||||
}
|
||||
doc.quadraticCurveTo(px, py, cx + a[0], cy + a[1]);
|
||||
cx += a[0];
|
||||
return cy += a[1];
|
||||
},
|
||||
A: function(doc, a) {
|
||||
solveArc(doc, cx, cy, a);
|
||||
cx = a[5];
|
||||
return cy = a[6];
|
||||
},
|
||||
a: function(doc, a) {
|
||||
a[5] += cx;
|
||||
a[6] += cy;
|
||||
solveArc(doc, cx, cy, a);
|
||||
cx = a[5];
|
||||
return cy = a[6];
|
||||
},
|
||||
L: function(doc, a) {
|
||||
cx = a[0];
|
||||
cy = a[1];
|
||||
px = py = null;
|
||||
return doc.lineTo(cx, cy);
|
||||
},
|
||||
l: function(doc, a) {
|
||||
cx += a[0];
|
||||
cy += a[1];
|
||||
px = py = null;
|
||||
return doc.lineTo(cx, cy);
|
||||
},
|
||||
H: function(doc, a) {
|
||||
cx = a[0];
|
||||
px = py = null;
|
||||
return doc.lineTo(cx, cy);
|
||||
},
|
||||
h: function(doc, a) {
|
||||
cx += a[0];
|
||||
px = py = null;
|
||||
return doc.lineTo(cx, cy);
|
||||
},
|
||||
V: function(doc, a) {
|
||||
cy = a[0];
|
||||
px = py = null;
|
||||
return doc.lineTo(cx, cy);
|
||||
},
|
||||
v: function(doc, a) {
|
||||
cy += a[0];
|
||||
px = py = null;
|
||||
return doc.lineTo(cx, cy);
|
||||
},
|
||||
Z: function(doc) {
|
||||
doc.closePath();
|
||||
cx = sx;
|
||||
return cy = sy;
|
||||
},
|
||||
z: function(doc) {
|
||||
doc.closePath();
|
||||
cx = sx;
|
||||
return cy = sy;
|
||||
}
|
||||
};
|
||||
|
||||
solveArc = function(doc, x, y, coords) {
|
||||
var bez, ex, ey, j, large, len, results, rot, rx, ry, seg, segs, sweep;
|
||||
rx = coords[0], ry = coords[1], rot = coords[2], large = coords[3], sweep = coords[4], ex = coords[5], ey = coords[6];
|
||||
segs = arcToSegments(ex, ey, rx, ry, large, sweep, rot, x, y);
|
||||
results = [];
|
||||
for (j = 0, len = segs.length; j < len; j++) {
|
||||
seg = segs[j];
|
||||
bez = segmentToBezier.apply(null, seg);
|
||||
results.push(doc.bezierCurveTo.apply(doc, bez));
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
arcToSegments = function(x, y, rx, ry, large, sweep, rotateX, ox, oy) {
|
||||
var a00, a01, a10, a11, cos_th, d, i, j, pl, ref, result, segments, sfactor, sfactor_sq, sin_th, th, th0, th1, th2, th3, th_arc, x0, x1, xc, y0, y1, yc;
|
||||
th = rotateX * (Math.PI / 180);
|
||||
sin_th = Math.sin(th);
|
||||
cos_th = Math.cos(th);
|
||||
rx = Math.abs(rx);
|
||||
ry = Math.abs(ry);
|
||||
px = cos_th * (ox - x) * 0.5 + sin_th * (oy - y) * 0.5;
|
||||
py = cos_th * (oy - y) * 0.5 - sin_th * (ox - x) * 0.5;
|
||||
pl = (px * px) / (rx * rx) + (py * py) / (ry * ry);
|
||||
if (pl > 1) {
|
||||
pl = Math.sqrt(pl);
|
||||
rx *= pl;
|
||||
ry *= pl;
|
||||
}
|
||||
a00 = cos_th / rx;
|
||||
a01 = sin_th / rx;
|
||||
a10 = (-sin_th) / ry;
|
||||
a11 = cos_th / ry;
|
||||
x0 = a00 * ox + a01 * oy;
|
||||
y0 = a10 * ox + a11 * oy;
|
||||
x1 = a00 * x + a01 * y;
|
||||
y1 = a10 * x + a11 * y;
|
||||
d = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0);
|
||||
sfactor_sq = 1 / d - 0.25;
|
||||
if (sfactor_sq < 0) {
|
||||
sfactor_sq = 0;
|
||||
}
|
||||
sfactor = Math.sqrt(sfactor_sq);
|
||||
if (sweep === large) {
|
||||
sfactor = -sfactor;
|
||||
}
|
||||
xc = 0.5 * (x0 + x1) - sfactor * (y1 - y0);
|
||||
yc = 0.5 * (y0 + y1) + sfactor * (x1 - x0);
|
||||
th0 = Math.atan2(y0 - yc, x0 - xc);
|
||||
th1 = Math.atan2(y1 - yc, x1 - xc);
|
||||
th_arc = th1 - th0;
|
||||
if (th_arc < 0 && sweep === 1) {
|
||||
th_arc += 2 * Math.PI;
|
||||
} else if (th_arc > 0 && sweep === 0) {
|
||||
th_arc -= 2 * Math.PI;
|
||||
}
|
||||
segments = Math.ceil(Math.abs(th_arc / (Math.PI * 0.5 + 0.001)));
|
||||
result = [];
|
||||
for (i = j = 0, ref = segments; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
|
||||
th2 = th0 + i * th_arc / segments;
|
||||
th3 = th0 + (i + 1) * th_arc / segments;
|
||||
result[i] = [xc, yc, th2, th3, rx, ry, sin_th, cos_th];
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
segmentToBezier = function(cx, cy, th0, th1, rx, ry, sin_th, cos_th) {
|
||||
var a00, a01, a10, a11, t, th_half, x1, x2, x3, y1, y2, y3;
|
||||
a00 = cos_th * rx;
|
||||
a01 = -sin_th * ry;
|
||||
a10 = sin_th * rx;
|
||||
a11 = cos_th * ry;
|
||||
th_half = 0.5 * (th1 - th0);
|
||||
t = (8 / 3) * Math.sin(th_half * 0.5) * Math.sin(th_half * 0.5) / Math.sin(th_half);
|
||||
x1 = cx + Math.cos(th0) - t * Math.sin(th0);
|
||||
y1 = cy + Math.sin(th0) + t * Math.cos(th0);
|
||||
x3 = cx + Math.cos(th1);
|
||||
y3 = cy + Math.sin(th1);
|
||||
x2 = x3 + t * Math.sin(th1);
|
||||
y2 = y3 - t * Math.cos(th1);
|
||||
return [a00 * x1 + a01 * y1, a10 * x1 + a11 * y1, a00 * x2 + a01 * y2, a10 * x2 + a11 * y2, a00 * x3 + a01 * y3, a10 * x3 + a11 * y3];
|
||||
};
|
||||
|
||||
return SVGPath;
|
||||
|
||||
})();
|
||||
|
||||
module.exports = SVGPath;
|
||||
|
||||
}).call(this);
|
@ -1,109 +0,0 @@
|
||||
// Generated by CoffeeScript 1.12.5
|
||||
|
||||
/*
|
||||
PDFReference - represents a reference to another object in the PDF object heirarchy
|
||||
By Devon Govett
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var PDFObject, PDFReference, stream, zlib,
|
||||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
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; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
zlib = require('zlib');
|
||||
|
||||
stream = require('stream');
|
||||
|
||||
PDFReference = (function(superClass) {
|
||||
extend(PDFReference, superClass);
|
||||
|
||||
function PDFReference(document, id, data) {
|
||||
this.document = document;
|
||||
this.id = id;
|
||||
this.data = data != null ? data : {};
|
||||
this.finalize = bind(this.finalize, this);
|
||||
PDFReference.__super__.constructor.call(this, {
|
||||
decodeStrings: false
|
||||
});
|
||||
this.gen = 0;
|
||||
this.deflate = null;
|
||||
this.compress = this.document.compress && !this.data.Filter;
|
||||
this.uncompressedLength = 0;
|
||||
this.chunks = [];
|
||||
}
|
||||
|
||||
PDFReference.prototype.initDeflate = function() {
|
||||
this.data.Filter = 'FlateDecode';
|
||||
this.deflate = zlib.createDeflate();
|
||||
this.deflate.on('data', (function(_this) {
|
||||
return function(chunk) {
|
||||
_this.chunks.push(chunk);
|
||||
return _this.data.Length += chunk.length;
|
||||
};
|
||||
})(this));
|
||||
return this.deflate.on('end', this.finalize);
|
||||
};
|
||||
|
||||
PDFReference.prototype._write = function(chunk, encoding, callback) {
|
||||
var base;
|
||||
if (!Buffer.isBuffer(chunk)) {
|
||||
chunk = new Buffer(chunk + '\n', 'binary');
|
||||
}
|
||||
this.uncompressedLength += chunk.length;
|
||||
if ((base = this.data).Length == null) {
|
||||
base.Length = 0;
|
||||
}
|
||||
if (this.compress) {
|
||||
if (!this.deflate) {
|
||||
this.initDeflate();
|
||||
}
|
||||
this.deflate.write(chunk);
|
||||
} else {
|
||||
this.chunks.push(chunk);
|
||||
this.data.Length += chunk.length;
|
||||
}
|
||||
return callback();
|
||||
};
|
||||
|
||||
PDFReference.prototype.end = function(chunk) {
|
||||
PDFReference.__super__.end.apply(this, arguments);
|
||||
if (this.deflate) {
|
||||
return this.deflate.end();
|
||||
} else {
|
||||
return this.finalize();
|
||||
}
|
||||
};
|
||||
|
||||
PDFReference.prototype.finalize = function() {
|
||||
var chunk, i, len, ref;
|
||||
this.offset = this.document._offset;
|
||||
this.document._write(this.id + " " + this.gen + " obj");
|
||||
this.document._write(PDFObject.convert(this.data));
|
||||
if (this.chunks.length) {
|
||||
this.document._write('stream');
|
||||
ref = this.chunks;
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
chunk = ref[i];
|
||||
this.document._write(chunk);
|
||||
}
|
||||
this.chunks.length = 0;
|
||||
this.document._write('\nendstream');
|
||||
}
|
||||
this.document._write('endobj');
|
||||
return this.document._refEnd(this);
|
||||
};
|
||||
|
||||
PDFReference.prototype.toString = function() {
|
||||
return this.id + " " + this.gen + " R";
|
||||
};
|
||||
|
||||
return PDFReference;
|
||||
|
||||
})(stream.Writable);
|
||||
|
||||
module.exports = PDFReference;
|
||||
|
||||
PDFObject = require('./object');
|
||||
|
||||
}).call(this);
|
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 340 KiB After Width: | Height: | Size: 340 KiB |
Binary file not shown.
@ -1,73 +0,0 @@
|
||||
// Generated by CoffeeScript 1.12.5
|
||||
(function() {
|
||||
var PDFDocument, doc, fs, i, len, loremIpsum, part, tiger;
|
||||
|
||||
PDFDocument = require('pdfkit/document');
|
||||
|
||||
tiger = require('./tiger');
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
doc = new PDFDocument;
|
||||
|
||||
doc.pipe(fs.createWriteStream('out.pdf'));
|
||||
|
||||
doc.info['Title'] = 'Test Document';
|
||||
|
||||
doc.info['Author'] = 'Devon Govett';
|
||||
|
||||
doc.registerFont('Charter', 'charter.ttf');
|
||||
|
||||
doc.font('Charter').fontSize(25).text('Some text with an embedded font!', 100, 100).fontSize(18).text('PNG and JPEG images:').image('test.png', 100, 160, {
|
||||
width: 412
|
||||
}).image('test.jpeg', 190, 400, {
|
||||
height: 300
|
||||
});
|
||||
|
||||
doc.addPage().fontSize(25).text('Here is some vector graphics...', 100, 100);
|
||||
|
||||
doc.save().moveTo(100, 150).lineTo(100, 250).lineTo(200, 250).fill("#FF3300");
|
||||
|
||||
doc.circle(280, 200, 50).fill("#6600FF");
|
||||
|
||||
doc.scale(0.6).translate(470, -380).path('M 250,75 L 323,301 131,161 369,161 177,301 z').fill('red', 'even-odd').restore();
|
||||
|
||||
loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in suscipit purus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus nec hendrerit felis. Morbi aliquam facilisis risus eu lacinia. Sed eu leo in turpis fringilla hendrerit. Ut nec accumsan nisl. Suspendisse rhoncus nisl posuere tortor tempus et dapibus elit porta. Cras leo neque, elementum a rhoncus ut, vestibulum non nibh. Phasellus pretium justo turpis. Etiam vulputate, odio vitae tincidunt ultricies, eros odio dapibus nisi, ut tincidunt lacus arcu eu elit. Aenean velit erat, vehicula eget lacinia ut, dignissim non tellus. Aliquam nec lacus mi, sed vestibulum nunc. Suspendisse potenti. Curabitur vitae sem turpis. Vestibulum sed neque eget dolor dapibus porttitor at sit amet sem. Fusce a turpis lorem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;\nMauris at ante tellus. Vestibulum a metus lectus. Praesent tempor purus a lacus blandit eget gravida ante hendrerit. Cras et eros metus. Sed commodo malesuada eros, vitae interdum augue semper quis. Fusce id magna nunc. Curabitur sollicitudin placerat semper. Cras et mi neque, a dignissim risus. Nulla venenatis porta lacus, vel rhoncus lectus tempor vitae. Duis sagittis venenatis rutrum. Curabitur tempor massa tortor.';
|
||||
|
||||
doc.text('And here is some wrapped text...', 100, 300).font('Charter', 13).moveDown().text(loremIpsum, {
|
||||
width: 412,
|
||||
align: 'justify',
|
||||
indent: 30,
|
||||
paragraphGap: 5
|
||||
});
|
||||
|
||||
doc.addPage().font('Charter', 25).text('Rendering some SVG paths...', 100, 100).translate(220, 300);
|
||||
|
||||
for (i = 0, len = tiger.length; i < len; i++) {
|
||||
part = tiger[i];
|
||||
doc.save();
|
||||
doc.path(part.path);
|
||||
if (part['stroke-width']) {
|
||||
doc.lineWidth(part['stroke-width']);
|
||||
}
|
||||
if (part.fill !== 'none' && part.stroke !== 'none') {
|
||||
doc.fillAndStroke(part.fill, part.stroke);
|
||||
} else {
|
||||
if (part.fill !== 'none') {
|
||||
doc.fill(part.fill);
|
||||
}
|
||||
if (part.stroke !== 'none') {
|
||||
doc.stroke(part.stroke);
|
||||
}
|
||||
}
|
||||
doc.restore();
|
||||
}
|
||||
|
||||
doc.addPage().fillColor("blue").text('Here is a link!', 100, 100, {
|
||||
link: 'http://google.com/',
|
||||
underline: true
|
||||
});
|
||||
|
||||
doc.end();
|
||||
|
||||
}).call(this);
|
Binary file not shown.
@ -1,15 +0,0 @@
|
||||
// Generated by CoffeeScript 1.12.5
|
||||
(function() {
|
||||
var PDFDocument, doc, fs;
|
||||
|
||||
PDFDocument = require('pdfkit');
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
doc = new PDFDocument;
|
||||
|
||||
doc.pipe(fs.createWriteStream('out.pdf'));
|
||||
|
||||
doc.end();
|
||||
|
||||
}).call(this);
|
Binary file not shown.
Loading…
Reference in New Issue