Skip to content

Commit 3c8cf42

Browse files
committed
allow method chaining
1 parent 44d6831 commit 3c8cf42

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

jspdf.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,10 @@ var jsPDF = function(orientation, unit, format){
296296
return text.replace(/\\/g, '\\\\').replace(/\(/g, '\\(').replace(/\)/g, '\\)');
297297
}
298298

299-
return {
299+
var _jsPDF = {
300300
addPage: function() {
301301
_addPage();
302+
return _jsPDF;
302303
},
303304
text: function(x, y, text) {
304305
// need page height
@@ -308,16 +309,19 @@ var jsPDF = function(orientation, unit, format){
308309
}
309310
var str = sprintf('BT %.2f %.2f Td (%s) Tj ET', x * k, (pageHeight - y) * k, pdfEscape(text));
310311
out(str);
312+
return _jsPDF;
311313
},
312314
line: function(x1, y1, x2, y2) {
313315
var str = sprintf('%.2f %.2f m %.2f %.2f l S',x1 * k, (pageHeight - y1) * k, x2 * k, (pageHeight - y2) * k);
314316
out(str);
317+
return _jsPDF;
315318
},
316319
setProperties: function(properties) {
317320
documentProperties = properties;
321+
return _jsPDF;
318322
},
319323
addImage: function(imageData, format, x, y, w, h) {
320-
324+
return _jsPDF;
321325
},
322326
output: function(type, options) {
323327
endDocument();
@@ -331,9 +335,11 @@ var jsPDF = function(orientation, unit, format){
331335
},
332336
setFontSize: function(size) {
333337
fontSize = size;
338+
return _jsPDF;
334339
},
335340
setLineWidth: function(width) {
336341
out(sprintf('%.2f w', (width * k)));
342+
return _jsPDF;
337343
},
338344
setDrawColor: function(r,g,b) {
339345
var color;
@@ -343,7 +349,9 @@ var jsPDF = function(orientation, unit, format){
343349
color = sprintf('%.3f %.3f %.3f RG', r/255, g/255, b/255);
344350
}
345351
out(color);
352+
return _jsPDF;
346353
}
347-
}
354+
};
355+
return _jsPDF;
348356

349357
};

0 commit comments

Comments
 (0)