pdfkit 0.8.3 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/README.md +121 -111
- package/js/{font/data → data}/Courier-Bold.afm +0 -0
- package/js/{font/data → data}/Courier-BoldOblique.afm +0 -0
- package/js/{font/data → data}/Courier-Oblique.afm +0 -0
- package/js/{font/data → data}/Courier.afm +0 -0
- package/js/{font/data → data}/Helvetica-Bold.afm +0 -0
- package/js/{font/data → data}/Helvetica-BoldOblique.afm +0 -0
- package/js/{font/data → data}/Helvetica-Oblique.afm +0 -0
- package/js/{font/data → data}/Helvetica.afm +0 -0
- package/js/{font/data → data}/Symbol.afm +0 -0
- package/js/{font/data → data}/Times-Bold.afm +0 -0
- package/js/{font/data → data}/Times-BoldItalic.afm +0 -0
- package/js/{font/data → data}/Times-Italic.afm +0 -0
- package/js/{font/data → data}/Times-Roman.afm +0 -0
- package/js/{font/data → data}/ZapfDingbats.afm +0 -0
- package/js/pdfkit.es5.js +6202 -0
- package/js/pdfkit.es5.js.map +1 -0
- package/js/pdfkit.esnext.js +5549 -0
- package/js/pdfkit.esnext.js.map +1 -0
- package/js/pdfkit.js +5581 -0
- package/js/pdfkit.js.map +1 -0
- package/js/pdfkit.standalone.js +65118 -0
- package/js/virtual-fs.js +70 -0
- package/package.json +52 -22
- package/.npmignore +0 -8
- package/Makefile +0 -30
- package/js/data.js +0 -192
- package/js/document.js +0 -247
- package/js/font/afm.js +0 -170
- package/js/font/data/MustRead.html +0 -19
- package/js/font/embedded.js +0 -234
- package/js/font/standard.js +0 -124
- package/js/font.js +0 -75
- package/js/gradient.js +0 -240
- package/js/image/jpeg.js +0 -78
- package/js/image/png.js +0 -158
- package/js/image.js +0 -53
- package/js/line_wrapper.js +0 -252
- package/js/mixins/annotations.js +0 -133
- package/js/mixins/color.js +0 -298
- package/js/mixins/fonts.js +0 -71
- package/js/mixins/images.js +0 -111
- package/js/mixins/text.js +0 -344
- package/js/mixins/vector.js +0 -302
- package/js/object.js +0 -115
- package/js/page.js +0 -170
- package/js/path.js +0 -366
- package/js/reference.js +0 -109
package/js/line_wrapper.js
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
// Generated by CoffeeScript 1.12.6
|
|
2
|
-
(function() {
|
|
3
|
-
var EventEmitter, LineBreaker, LineWrapper,
|
|
4
|
-
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
5
|
-
hasProp = {}.hasOwnProperty;
|
|
6
|
-
|
|
7
|
-
EventEmitter = require('events').EventEmitter;
|
|
8
|
-
|
|
9
|
-
LineBreaker = require('linebreak');
|
|
10
|
-
|
|
11
|
-
LineWrapper = (function(superClass) {
|
|
12
|
-
extend(LineWrapper, superClass);
|
|
13
|
-
|
|
14
|
-
function LineWrapper(document, options) {
|
|
15
|
-
var ref;
|
|
16
|
-
this.document = document;
|
|
17
|
-
this.indent = options.indent || 0;
|
|
18
|
-
this.characterSpacing = options.characterSpacing || 0;
|
|
19
|
-
this.wordSpacing = options.wordSpacing === 0;
|
|
20
|
-
this.columns = options.columns || 1;
|
|
21
|
-
this.columnGap = (ref = options.columnGap) != null ? ref : 18;
|
|
22
|
-
this.lineWidth = (options.width - (this.columnGap * (this.columns - 1))) / this.columns;
|
|
23
|
-
this.spaceLeft = this.lineWidth;
|
|
24
|
-
this.startX = this.document.x;
|
|
25
|
-
this.startY = this.document.y;
|
|
26
|
-
this.column = 1;
|
|
27
|
-
this.ellipsis = options.ellipsis;
|
|
28
|
-
this.continuedX = 0;
|
|
29
|
-
this.features = options.features;
|
|
30
|
-
if (options.height != null) {
|
|
31
|
-
this.height = options.height;
|
|
32
|
-
this.maxY = this.startY + options.height;
|
|
33
|
-
} else {
|
|
34
|
-
this.maxY = this.document.page.maxY();
|
|
35
|
-
}
|
|
36
|
-
this.on('firstLine', (function(_this) {
|
|
37
|
-
return function(options) {
|
|
38
|
-
var indent;
|
|
39
|
-
indent = _this.continuedX || _this.indent;
|
|
40
|
-
_this.document.x += indent;
|
|
41
|
-
_this.lineWidth -= indent;
|
|
42
|
-
return _this.once('line', function() {
|
|
43
|
-
_this.document.x -= indent;
|
|
44
|
-
_this.lineWidth += indent;
|
|
45
|
-
if (options.continued && !_this.continuedX) {
|
|
46
|
-
_this.continuedX = _this.indent;
|
|
47
|
-
}
|
|
48
|
-
if (!options.continued) {
|
|
49
|
-
return _this.continuedX = 0;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
})(this));
|
|
54
|
-
this.on('lastLine', (function(_this) {
|
|
55
|
-
return function(options) {
|
|
56
|
-
var align;
|
|
57
|
-
align = options.align;
|
|
58
|
-
if (align === 'justify') {
|
|
59
|
-
options.align = 'left';
|
|
60
|
-
}
|
|
61
|
-
_this.lastLine = true;
|
|
62
|
-
return _this.once('line', function() {
|
|
63
|
-
_this.document.y += options.paragraphGap || 0;
|
|
64
|
-
options.align = align;
|
|
65
|
-
return _this.lastLine = false;
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
})(this));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
LineWrapper.prototype.wordWidth = function(word) {
|
|
72
|
-
return this.document.widthOfString(word, this) + this.characterSpacing + this.wordSpacing;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
LineWrapper.prototype.eachWord = function(text, fn) {
|
|
76
|
-
var bk, breaker, fbk, l, last, lbk, shouldContinue, w, word, wordWidths;
|
|
77
|
-
breaker = new LineBreaker(text);
|
|
78
|
-
last = null;
|
|
79
|
-
wordWidths = Object.create(null);
|
|
80
|
-
while (bk = breaker.nextBreak()) {
|
|
81
|
-
word = text.slice((last != null ? last.position : void 0) || 0, bk.position);
|
|
82
|
-
w = wordWidths[word] != null ? wordWidths[word] : wordWidths[word] = this.wordWidth(word);
|
|
83
|
-
if (w > this.lineWidth + this.continuedX) {
|
|
84
|
-
lbk = last;
|
|
85
|
-
fbk = {};
|
|
86
|
-
while (word.length) {
|
|
87
|
-
l = word.length;
|
|
88
|
-
while (w > this.spaceLeft) {
|
|
89
|
-
w = this.wordWidth(word.slice(0, --l));
|
|
90
|
-
}
|
|
91
|
-
fbk.required = l < word.length;
|
|
92
|
-
shouldContinue = fn(word.slice(0, l), w, fbk, lbk);
|
|
93
|
-
lbk = {
|
|
94
|
-
required: false
|
|
95
|
-
};
|
|
96
|
-
word = word.slice(l);
|
|
97
|
-
w = this.wordWidth(word);
|
|
98
|
-
if (shouldContinue === false) {
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
shouldContinue = fn(word, w, bk, last);
|
|
104
|
-
}
|
|
105
|
-
if (shouldContinue === false) {
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
last = bk;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
LineWrapper.prototype.wrap = function(text, options) {
|
|
113
|
-
var buffer, emitLine, lc, nextY, textWidth, wc, y;
|
|
114
|
-
if (options.indent != null) {
|
|
115
|
-
this.indent = options.indent;
|
|
116
|
-
}
|
|
117
|
-
if (options.characterSpacing != null) {
|
|
118
|
-
this.characterSpacing = options.characterSpacing;
|
|
119
|
-
}
|
|
120
|
-
if (options.wordSpacing != null) {
|
|
121
|
-
this.wordSpacing = options.wordSpacing;
|
|
122
|
-
}
|
|
123
|
-
if (options.ellipsis != null) {
|
|
124
|
-
this.ellipsis = options.ellipsis;
|
|
125
|
-
}
|
|
126
|
-
nextY = this.document.y + this.document.currentLineHeight(true);
|
|
127
|
-
if (this.document.y > this.maxY || nextY > this.maxY) {
|
|
128
|
-
this.nextSection();
|
|
129
|
-
}
|
|
130
|
-
buffer = '';
|
|
131
|
-
textWidth = 0;
|
|
132
|
-
wc = 0;
|
|
133
|
-
lc = 0;
|
|
134
|
-
y = this.document.y;
|
|
135
|
-
emitLine = (function(_this) {
|
|
136
|
-
return function() {
|
|
137
|
-
options.textWidth = textWidth + _this.wordSpacing * (wc - 1);
|
|
138
|
-
options.wordCount = wc;
|
|
139
|
-
options.lineWidth = _this.lineWidth;
|
|
140
|
-
y = _this.document.y;
|
|
141
|
-
_this.emit('line', buffer, options, _this);
|
|
142
|
-
return lc++;
|
|
143
|
-
};
|
|
144
|
-
})(this);
|
|
145
|
-
this.emit('sectionStart', options, this);
|
|
146
|
-
this.eachWord(text, (function(_this) {
|
|
147
|
-
return function(word, w, bk, last) {
|
|
148
|
-
var lh, shouldContinue;
|
|
149
|
-
if ((last == null) || last.required) {
|
|
150
|
-
_this.emit('firstLine', options, _this);
|
|
151
|
-
_this.spaceLeft = _this.lineWidth;
|
|
152
|
-
}
|
|
153
|
-
if (w <= _this.spaceLeft) {
|
|
154
|
-
buffer += word;
|
|
155
|
-
textWidth += w;
|
|
156
|
-
wc++;
|
|
157
|
-
}
|
|
158
|
-
if (bk.required || w > _this.spaceLeft) {
|
|
159
|
-
if (bk.required) {
|
|
160
|
-
_this.emit('lastLine', options, _this);
|
|
161
|
-
}
|
|
162
|
-
lh = _this.document.currentLineHeight(true);
|
|
163
|
-
if ((_this.height != null) && _this.ellipsis && _this.document.y + lh * 2 > _this.maxY && _this.column >= _this.columns) {
|
|
164
|
-
if (_this.ellipsis === true) {
|
|
165
|
-
_this.ellipsis = '…';
|
|
166
|
-
}
|
|
167
|
-
buffer = buffer.replace(/\s+$/, '');
|
|
168
|
-
textWidth = _this.wordWidth(buffer + _this.ellipsis);
|
|
169
|
-
while (textWidth > _this.lineWidth) {
|
|
170
|
-
buffer = buffer.slice(0, -1).replace(/\s+$/, '');
|
|
171
|
-
textWidth = _this.wordWidth(buffer + _this.ellipsis);
|
|
172
|
-
}
|
|
173
|
-
buffer = buffer + _this.ellipsis;
|
|
174
|
-
}
|
|
175
|
-
if (bk.required && w > _this.spaceLeft) {
|
|
176
|
-
buffer = word;
|
|
177
|
-
textWidth = w;
|
|
178
|
-
wc = 1;
|
|
179
|
-
}
|
|
180
|
-
emitLine();
|
|
181
|
-
if (_this.document.y + lh > _this.maxY) {
|
|
182
|
-
shouldContinue = _this.nextSection();
|
|
183
|
-
if (!shouldContinue) {
|
|
184
|
-
wc = 0;
|
|
185
|
-
buffer = '';
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
if (bk.required) {
|
|
190
|
-
_this.spaceLeft = _this.lineWidth;
|
|
191
|
-
buffer = '';
|
|
192
|
-
textWidth = 0;
|
|
193
|
-
return wc = 0;
|
|
194
|
-
} else {
|
|
195
|
-
_this.spaceLeft = _this.lineWidth - w;
|
|
196
|
-
buffer = word;
|
|
197
|
-
textWidth = w;
|
|
198
|
-
return wc = 1;
|
|
199
|
-
}
|
|
200
|
-
} else {
|
|
201
|
-
return _this.spaceLeft -= w;
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
})(this));
|
|
205
|
-
if (wc > 0) {
|
|
206
|
-
this.emit('lastLine', options, this);
|
|
207
|
-
emitLine();
|
|
208
|
-
}
|
|
209
|
-
this.emit('sectionEnd', options, this);
|
|
210
|
-
if (options.continued === true) {
|
|
211
|
-
if (lc > 1) {
|
|
212
|
-
this.continuedX = 0;
|
|
213
|
-
}
|
|
214
|
-
this.continuedX += options.textWidth;
|
|
215
|
-
return this.document.y = y;
|
|
216
|
-
} else {
|
|
217
|
-
return this.document.x = this.startX;
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
LineWrapper.prototype.nextSection = function(options) {
|
|
222
|
-
var ref;
|
|
223
|
-
this.emit('sectionEnd', options, this);
|
|
224
|
-
if (++this.column > this.columns) {
|
|
225
|
-
if (this.height != null) {
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
this.document.addPage();
|
|
229
|
-
this.column = 1;
|
|
230
|
-
this.startY = this.document.page.margins.top;
|
|
231
|
-
this.maxY = this.document.page.maxY();
|
|
232
|
-
this.document.x = this.startX;
|
|
233
|
-
if (this.document._fillColor) {
|
|
234
|
-
(ref = this.document).fillColor.apply(ref, this.document._fillColor);
|
|
235
|
-
}
|
|
236
|
-
this.emit('pageBreak', options, this);
|
|
237
|
-
} else {
|
|
238
|
-
this.document.x += this.lineWidth + this.columnGap;
|
|
239
|
-
this.document.y = this.startY;
|
|
240
|
-
this.emit('columnBreak', options, this);
|
|
241
|
-
}
|
|
242
|
-
this.emit('sectionStart', options, this);
|
|
243
|
-
return true;
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
return LineWrapper;
|
|
247
|
-
|
|
248
|
-
})(EventEmitter);
|
|
249
|
-
|
|
250
|
-
module.exports = LineWrapper;
|
|
251
|
-
|
|
252
|
-
}).call(this);
|
package/js/mixins/annotations.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
// Generated by CoffeeScript 1.12.6
|
|
2
|
-
(function() {
|
|
3
|
-
module.exports = {
|
|
4
|
-
annotate: function(x, y, w, h, options) {
|
|
5
|
-
var key, ref, val;
|
|
6
|
-
options.Type = 'Annot';
|
|
7
|
-
options.Rect = this._convertRect(x, y, w, h);
|
|
8
|
-
options.Border = [0, 0, 0];
|
|
9
|
-
if (options.Subtype !== 'Link') {
|
|
10
|
-
if (options.C == null) {
|
|
11
|
-
options.C = this._normalizeColor(options.color || [0, 0, 0]);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
delete options.color;
|
|
15
|
-
if (typeof options.Dest === 'string') {
|
|
16
|
-
options.Dest = new String(options.Dest);
|
|
17
|
-
}
|
|
18
|
-
for (key in options) {
|
|
19
|
-
val = options[key];
|
|
20
|
-
options[key[0].toUpperCase() + key.slice(1)] = val;
|
|
21
|
-
}
|
|
22
|
-
ref = this.ref(options);
|
|
23
|
-
this.page.annotations.push(ref);
|
|
24
|
-
ref.end();
|
|
25
|
-
return this;
|
|
26
|
-
},
|
|
27
|
-
note: function(x, y, w, h, contents, options) {
|
|
28
|
-
if (options == null) {
|
|
29
|
-
options = {};
|
|
30
|
-
}
|
|
31
|
-
options.Subtype = 'Text';
|
|
32
|
-
options.Contents = new String(contents);
|
|
33
|
-
options.Name = 'Comment';
|
|
34
|
-
if (options.color == null) {
|
|
35
|
-
options.color = [243, 223, 92];
|
|
36
|
-
}
|
|
37
|
-
return this.annotate(x, y, w, h, options);
|
|
38
|
-
},
|
|
39
|
-
link: function(x, y, w, h, url, options) {
|
|
40
|
-
if (options == null) {
|
|
41
|
-
options = {};
|
|
42
|
-
}
|
|
43
|
-
options.Subtype = 'Link';
|
|
44
|
-
options.A = this.ref({
|
|
45
|
-
S: 'URI',
|
|
46
|
-
URI: new String(url)
|
|
47
|
-
});
|
|
48
|
-
options.A.end();
|
|
49
|
-
return this.annotate(x, y, w, h, options);
|
|
50
|
-
},
|
|
51
|
-
_markup: function(x, y, w, h, options) {
|
|
52
|
-
var ref1, x1, x2, y1, y2;
|
|
53
|
-
if (options == null) {
|
|
54
|
-
options = {};
|
|
55
|
-
}
|
|
56
|
-
ref1 = this._convertRect(x, y, w, h), x1 = ref1[0], y1 = ref1[1], x2 = ref1[2], y2 = ref1[3];
|
|
57
|
-
options.QuadPoints = [x1, y2, x2, y2, x1, y1, x2, y1];
|
|
58
|
-
options.Contents = new String;
|
|
59
|
-
return this.annotate(x, y, w, h, options);
|
|
60
|
-
},
|
|
61
|
-
highlight: function(x, y, w, h, options) {
|
|
62
|
-
if (options == null) {
|
|
63
|
-
options = {};
|
|
64
|
-
}
|
|
65
|
-
options.Subtype = 'Highlight';
|
|
66
|
-
if (options.color == null) {
|
|
67
|
-
options.color = [241, 238, 148];
|
|
68
|
-
}
|
|
69
|
-
return this._markup(x, y, w, h, options);
|
|
70
|
-
},
|
|
71
|
-
underline: function(x, y, w, h, options) {
|
|
72
|
-
if (options == null) {
|
|
73
|
-
options = {};
|
|
74
|
-
}
|
|
75
|
-
options.Subtype = 'Underline';
|
|
76
|
-
return this._markup(x, y, w, h, options);
|
|
77
|
-
},
|
|
78
|
-
strike: function(x, y, w, h, options) {
|
|
79
|
-
if (options == null) {
|
|
80
|
-
options = {};
|
|
81
|
-
}
|
|
82
|
-
options.Subtype = 'StrikeOut';
|
|
83
|
-
return this._markup(x, y, w, h, options);
|
|
84
|
-
},
|
|
85
|
-
lineAnnotation: function(x1, y1, x2, y2, options) {
|
|
86
|
-
if (options == null) {
|
|
87
|
-
options = {};
|
|
88
|
-
}
|
|
89
|
-
options.Subtype = 'Line';
|
|
90
|
-
options.Contents = new String;
|
|
91
|
-
options.L = [x1, this.page.height - y1, x2, this.page.height - y2];
|
|
92
|
-
return this.annotate(x1, y1, x2, y2, options);
|
|
93
|
-
},
|
|
94
|
-
rectAnnotation: function(x, y, w, h, options) {
|
|
95
|
-
if (options == null) {
|
|
96
|
-
options = {};
|
|
97
|
-
}
|
|
98
|
-
options.Subtype = 'Square';
|
|
99
|
-
options.Contents = new String;
|
|
100
|
-
return this.annotate(x, y, w, h, options);
|
|
101
|
-
},
|
|
102
|
-
ellipseAnnotation: function(x, y, w, h, options) {
|
|
103
|
-
if (options == null) {
|
|
104
|
-
options = {};
|
|
105
|
-
}
|
|
106
|
-
options.Subtype = 'Circle';
|
|
107
|
-
options.Contents = new String;
|
|
108
|
-
return this.annotate(x, y, w, h, options);
|
|
109
|
-
},
|
|
110
|
-
textAnnotation: function(x, y, w, h, text, options) {
|
|
111
|
-
if (options == null) {
|
|
112
|
-
options = {};
|
|
113
|
-
}
|
|
114
|
-
options.Subtype = 'FreeText';
|
|
115
|
-
options.Contents = new String(text);
|
|
116
|
-
options.DA = new String;
|
|
117
|
-
return this.annotate(x, y, w, h, options);
|
|
118
|
-
},
|
|
119
|
-
_convertRect: function(x1, y1, w, h) {
|
|
120
|
-
var m0, m1, m2, m3, m4, m5, ref1, x2, y2;
|
|
121
|
-
y2 = y1;
|
|
122
|
-
y1 += h;
|
|
123
|
-
x2 = x1 + w;
|
|
124
|
-
ref1 = this._ctm, m0 = ref1[0], m1 = ref1[1], m2 = ref1[2], m3 = ref1[3], m4 = ref1[4], m5 = ref1[5];
|
|
125
|
-
x1 = m0 * x1 + m2 * y1 + m4;
|
|
126
|
-
y1 = m1 * x1 + m3 * y1 + m5;
|
|
127
|
-
x2 = m0 * x2 + m2 * y2 + m4;
|
|
128
|
-
y2 = m1 * x2 + m3 * y2 + m5;
|
|
129
|
-
return [x1, y1, x2, y2];
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
}).call(this);
|
package/js/mixins/color.js
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
// Generated by CoffeeScript 1.12.6
|
|
2
|
-
(function() {
|
|
3
|
-
var PDFGradient, PDFLinearGradient, PDFRadialGradient, namedColors, ref;
|
|
4
|
-
|
|
5
|
-
ref = require('../gradient'), PDFGradient = ref.PDFGradient, PDFLinearGradient = ref.PDFLinearGradient, PDFRadialGradient = ref.PDFRadialGradient;
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
initColor: function() {
|
|
9
|
-
this._opacityRegistry = {};
|
|
10
|
-
this._opacityCount = 0;
|
|
11
|
-
return this._gradCount = 0;
|
|
12
|
-
},
|
|
13
|
-
_normalizeColor: function(color) {
|
|
14
|
-
var hex, part;
|
|
15
|
-
if (color instanceof PDFGradient) {
|
|
16
|
-
return color;
|
|
17
|
-
}
|
|
18
|
-
if (typeof color === 'string') {
|
|
19
|
-
if (color.charAt(0) === '#') {
|
|
20
|
-
if (color.length === 4) {
|
|
21
|
-
color = color.replace(/#([0-9A-F])([0-9A-F])([0-9A-F])/i, "#$1$1$2$2$3$3");
|
|
22
|
-
}
|
|
23
|
-
hex = parseInt(color.slice(1), 16);
|
|
24
|
-
color = [hex >> 16, hex >> 8 & 0xff, hex & 0xff];
|
|
25
|
-
} else if (namedColors[color]) {
|
|
26
|
-
color = namedColors[color];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (Array.isArray(color)) {
|
|
30
|
-
if (color.length === 3) {
|
|
31
|
-
color = (function() {
|
|
32
|
-
var i, len, results;
|
|
33
|
-
results = [];
|
|
34
|
-
for (i = 0, len = color.length; i < len; i++) {
|
|
35
|
-
part = color[i];
|
|
36
|
-
results.push(part / 255);
|
|
37
|
-
}
|
|
38
|
-
return results;
|
|
39
|
-
})();
|
|
40
|
-
} else if (color.length === 4) {
|
|
41
|
-
color = (function() {
|
|
42
|
-
var i, len, results;
|
|
43
|
-
results = [];
|
|
44
|
-
for (i = 0, len = color.length; i < len; i++) {
|
|
45
|
-
part = color[i];
|
|
46
|
-
results.push(part / 100);
|
|
47
|
-
}
|
|
48
|
-
return results;
|
|
49
|
-
})();
|
|
50
|
-
}
|
|
51
|
-
return color;
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
},
|
|
55
|
-
_setColor: function(color, stroke) {
|
|
56
|
-
var op, space;
|
|
57
|
-
color = this._normalizeColor(color);
|
|
58
|
-
if (!color) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
op = stroke ? 'SCN' : 'scn';
|
|
62
|
-
if (color instanceof PDFGradient) {
|
|
63
|
-
this._setColorSpace('Pattern', stroke);
|
|
64
|
-
color.apply(op);
|
|
65
|
-
} else {
|
|
66
|
-
space = color.length === 4 ? 'DeviceCMYK' : 'DeviceRGB';
|
|
67
|
-
this._setColorSpace(space, stroke);
|
|
68
|
-
color = color.join(' ');
|
|
69
|
-
this.addContent(color + " " + op);
|
|
70
|
-
}
|
|
71
|
-
return true;
|
|
72
|
-
},
|
|
73
|
-
_setColorSpace: function(space, stroke) {
|
|
74
|
-
var op;
|
|
75
|
-
op = stroke ? 'CS' : 'cs';
|
|
76
|
-
return this.addContent("/" + space + " " + op);
|
|
77
|
-
},
|
|
78
|
-
fillColor: function(color, opacity) {
|
|
79
|
-
var set;
|
|
80
|
-
set = this._setColor(color, false);
|
|
81
|
-
if (set) {
|
|
82
|
-
this.fillOpacity(opacity);
|
|
83
|
-
}
|
|
84
|
-
this._fillColor = [color, opacity];
|
|
85
|
-
return this;
|
|
86
|
-
},
|
|
87
|
-
strokeColor: function(color, opacity) {
|
|
88
|
-
var set;
|
|
89
|
-
set = this._setColor(color, true);
|
|
90
|
-
if (set) {
|
|
91
|
-
this.strokeOpacity(opacity);
|
|
92
|
-
}
|
|
93
|
-
return this;
|
|
94
|
-
},
|
|
95
|
-
opacity: function(opacity) {
|
|
96
|
-
this._doOpacity(opacity, opacity);
|
|
97
|
-
return this;
|
|
98
|
-
},
|
|
99
|
-
fillOpacity: function(opacity) {
|
|
100
|
-
this._doOpacity(opacity, null);
|
|
101
|
-
return this;
|
|
102
|
-
},
|
|
103
|
-
strokeOpacity: function(opacity) {
|
|
104
|
-
this._doOpacity(null, opacity);
|
|
105
|
-
return this;
|
|
106
|
-
},
|
|
107
|
-
_doOpacity: function(fillOpacity, strokeOpacity) {
|
|
108
|
-
var dictionary, id, key, name, ref1;
|
|
109
|
-
if (!((fillOpacity != null) || (strokeOpacity != null))) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (fillOpacity != null) {
|
|
113
|
-
fillOpacity = Math.max(0, Math.min(1, fillOpacity));
|
|
114
|
-
}
|
|
115
|
-
if (strokeOpacity != null) {
|
|
116
|
-
strokeOpacity = Math.max(0, Math.min(1, strokeOpacity));
|
|
117
|
-
}
|
|
118
|
-
key = fillOpacity + "_" + strokeOpacity;
|
|
119
|
-
if (this._opacityRegistry[key]) {
|
|
120
|
-
ref1 = this._opacityRegistry[key], dictionary = ref1[0], name = ref1[1];
|
|
121
|
-
} else {
|
|
122
|
-
dictionary = {
|
|
123
|
-
Type: 'ExtGState'
|
|
124
|
-
};
|
|
125
|
-
if (fillOpacity != null) {
|
|
126
|
-
dictionary.ca = fillOpacity;
|
|
127
|
-
}
|
|
128
|
-
if (strokeOpacity != null) {
|
|
129
|
-
dictionary.CA = strokeOpacity;
|
|
130
|
-
}
|
|
131
|
-
dictionary = this.ref(dictionary);
|
|
132
|
-
dictionary.end();
|
|
133
|
-
id = ++this._opacityCount;
|
|
134
|
-
name = "Gs" + id;
|
|
135
|
-
this._opacityRegistry[key] = [dictionary, name];
|
|
136
|
-
}
|
|
137
|
-
this.page.ext_gstates[name] = dictionary;
|
|
138
|
-
return this.addContent("/" + name + " gs");
|
|
139
|
-
},
|
|
140
|
-
linearGradient: function(x1, y1, x2, y2) {
|
|
141
|
-
return new PDFLinearGradient(this, x1, y1, x2, y2);
|
|
142
|
-
},
|
|
143
|
-
radialGradient: function(x1, y1, r1, x2, y2, r2) {
|
|
144
|
-
return new PDFRadialGradient(this, x1, y1, r1, x2, y2, r2);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
namedColors = {
|
|
149
|
-
aliceblue: [240, 248, 255],
|
|
150
|
-
antiquewhite: [250, 235, 215],
|
|
151
|
-
aqua: [0, 255, 255],
|
|
152
|
-
aquamarine: [127, 255, 212],
|
|
153
|
-
azure: [240, 255, 255],
|
|
154
|
-
beige: [245, 245, 220],
|
|
155
|
-
bisque: [255, 228, 196],
|
|
156
|
-
black: [0, 0, 0],
|
|
157
|
-
blanchedalmond: [255, 235, 205],
|
|
158
|
-
blue: [0, 0, 255],
|
|
159
|
-
blueviolet: [138, 43, 226],
|
|
160
|
-
brown: [165, 42, 42],
|
|
161
|
-
burlywood: [222, 184, 135],
|
|
162
|
-
cadetblue: [95, 158, 160],
|
|
163
|
-
chartreuse: [127, 255, 0],
|
|
164
|
-
chocolate: [210, 105, 30],
|
|
165
|
-
coral: [255, 127, 80],
|
|
166
|
-
cornflowerblue: [100, 149, 237],
|
|
167
|
-
cornsilk: [255, 248, 220],
|
|
168
|
-
crimson: [220, 20, 60],
|
|
169
|
-
cyan: [0, 255, 255],
|
|
170
|
-
darkblue: [0, 0, 139],
|
|
171
|
-
darkcyan: [0, 139, 139],
|
|
172
|
-
darkgoldenrod: [184, 134, 11],
|
|
173
|
-
darkgray: [169, 169, 169],
|
|
174
|
-
darkgreen: [0, 100, 0],
|
|
175
|
-
darkgrey: [169, 169, 169],
|
|
176
|
-
darkkhaki: [189, 183, 107],
|
|
177
|
-
darkmagenta: [139, 0, 139],
|
|
178
|
-
darkolivegreen: [85, 107, 47],
|
|
179
|
-
darkorange: [255, 140, 0],
|
|
180
|
-
darkorchid: [153, 50, 204],
|
|
181
|
-
darkred: [139, 0, 0],
|
|
182
|
-
darksalmon: [233, 150, 122],
|
|
183
|
-
darkseagreen: [143, 188, 143],
|
|
184
|
-
darkslateblue: [72, 61, 139],
|
|
185
|
-
darkslategray: [47, 79, 79],
|
|
186
|
-
darkslategrey: [47, 79, 79],
|
|
187
|
-
darkturquoise: [0, 206, 209],
|
|
188
|
-
darkviolet: [148, 0, 211],
|
|
189
|
-
deeppink: [255, 20, 147],
|
|
190
|
-
deepskyblue: [0, 191, 255],
|
|
191
|
-
dimgray: [105, 105, 105],
|
|
192
|
-
dimgrey: [105, 105, 105],
|
|
193
|
-
dodgerblue: [30, 144, 255],
|
|
194
|
-
firebrick: [178, 34, 34],
|
|
195
|
-
floralwhite: [255, 250, 240],
|
|
196
|
-
forestgreen: [34, 139, 34],
|
|
197
|
-
fuchsia: [255, 0, 255],
|
|
198
|
-
gainsboro: [220, 220, 220],
|
|
199
|
-
ghostwhite: [248, 248, 255],
|
|
200
|
-
gold: [255, 215, 0],
|
|
201
|
-
goldenrod: [218, 165, 32],
|
|
202
|
-
gray: [128, 128, 128],
|
|
203
|
-
grey: [128, 128, 128],
|
|
204
|
-
green: [0, 128, 0],
|
|
205
|
-
greenyellow: [173, 255, 47],
|
|
206
|
-
honeydew: [240, 255, 240],
|
|
207
|
-
hotpink: [255, 105, 180],
|
|
208
|
-
indianred: [205, 92, 92],
|
|
209
|
-
indigo: [75, 0, 130],
|
|
210
|
-
ivory: [255, 255, 240],
|
|
211
|
-
khaki: [240, 230, 140],
|
|
212
|
-
lavender: [230, 230, 250],
|
|
213
|
-
lavenderblush: [255, 240, 245],
|
|
214
|
-
lawngreen: [124, 252, 0],
|
|
215
|
-
lemonchiffon: [255, 250, 205],
|
|
216
|
-
lightblue: [173, 216, 230],
|
|
217
|
-
lightcoral: [240, 128, 128],
|
|
218
|
-
lightcyan: [224, 255, 255],
|
|
219
|
-
lightgoldenrodyellow: [250, 250, 210],
|
|
220
|
-
lightgray: [211, 211, 211],
|
|
221
|
-
lightgreen: [144, 238, 144],
|
|
222
|
-
lightgrey: [211, 211, 211],
|
|
223
|
-
lightpink: [255, 182, 193],
|
|
224
|
-
lightsalmon: [255, 160, 122],
|
|
225
|
-
lightseagreen: [32, 178, 170],
|
|
226
|
-
lightskyblue: [135, 206, 250],
|
|
227
|
-
lightslategray: [119, 136, 153],
|
|
228
|
-
lightslategrey: [119, 136, 153],
|
|
229
|
-
lightsteelblue: [176, 196, 222],
|
|
230
|
-
lightyellow: [255, 255, 224],
|
|
231
|
-
lime: [0, 255, 0],
|
|
232
|
-
limegreen: [50, 205, 50],
|
|
233
|
-
linen: [250, 240, 230],
|
|
234
|
-
magenta: [255, 0, 255],
|
|
235
|
-
maroon: [128, 0, 0],
|
|
236
|
-
mediumaquamarine: [102, 205, 170],
|
|
237
|
-
mediumblue: [0, 0, 205],
|
|
238
|
-
mediumorchid: [186, 85, 211],
|
|
239
|
-
mediumpurple: [147, 112, 219],
|
|
240
|
-
mediumseagreen: [60, 179, 113],
|
|
241
|
-
mediumslateblue: [123, 104, 238],
|
|
242
|
-
mediumspringgreen: [0, 250, 154],
|
|
243
|
-
mediumturquoise: [72, 209, 204],
|
|
244
|
-
mediumvioletred: [199, 21, 133],
|
|
245
|
-
midnightblue: [25, 25, 112],
|
|
246
|
-
mintcream: [245, 255, 250],
|
|
247
|
-
mistyrose: [255, 228, 225],
|
|
248
|
-
moccasin: [255, 228, 181],
|
|
249
|
-
navajowhite: [255, 222, 173],
|
|
250
|
-
navy: [0, 0, 128],
|
|
251
|
-
oldlace: [253, 245, 230],
|
|
252
|
-
olive: [128, 128, 0],
|
|
253
|
-
olivedrab: [107, 142, 35],
|
|
254
|
-
orange: [255, 165, 0],
|
|
255
|
-
orangered: [255, 69, 0],
|
|
256
|
-
orchid: [218, 112, 214],
|
|
257
|
-
palegoldenrod: [238, 232, 170],
|
|
258
|
-
palegreen: [152, 251, 152],
|
|
259
|
-
paleturquoise: [175, 238, 238],
|
|
260
|
-
palevioletred: [219, 112, 147],
|
|
261
|
-
papayawhip: [255, 239, 213],
|
|
262
|
-
peachpuff: [255, 218, 185],
|
|
263
|
-
peru: [205, 133, 63],
|
|
264
|
-
pink: [255, 192, 203],
|
|
265
|
-
plum: [221, 160, 221],
|
|
266
|
-
powderblue: [176, 224, 230],
|
|
267
|
-
purple: [128, 0, 128],
|
|
268
|
-
red: [255, 0, 0],
|
|
269
|
-
rosybrown: [188, 143, 143],
|
|
270
|
-
royalblue: [65, 105, 225],
|
|
271
|
-
saddlebrown: [139, 69, 19],
|
|
272
|
-
salmon: [250, 128, 114],
|
|
273
|
-
sandybrown: [244, 164, 96],
|
|
274
|
-
seagreen: [46, 139, 87],
|
|
275
|
-
seashell: [255, 245, 238],
|
|
276
|
-
sienna: [160, 82, 45],
|
|
277
|
-
silver: [192, 192, 192],
|
|
278
|
-
skyblue: [135, 206, 235],
|
|
279
|
-
slateblue: [106, 90, 205],
|
|
280
|
-
slategray: [112, 128, 144],
|
|
281
|
-
slategrey: [112, 128, 144],
|
|
282
|
-
snow: [255, 250, 250],
|
|
283
|
-
springgreen: [0, 255, 127],
|
|
284
|
-
steelblue: [70, 130, 180],
|
|
285
|
-
tan: [210, 180, 140],
|
|
286
|
-
teal: [0, 128, 128],
|
|
287
|
-
thistle: [216, 191, 216],
|
|
288
|
-
tomato: [255, 99, 71],
|
|
289
|
-
turquoise: [64, 224, 208],
|
|
290
|
-
violet: [238, 130, 238],
|
|
291
|
-
wheat: [245, 222, 179],
|
|
292
|
-
white: [255, 255, 255],
|
|
293
|
-
whitesmoke: [245, 245, 245],
|
|
294
|
-
yellow: [255, 255, 0],
|
|
295
|
-
yellowgreen: [154, 205, 50]
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
}).call(this);
|