Skip to content

Commit

Permalink
add SetMiterLimit functionality to pdf and context2d (#2162)
Browse files Browse the repository at this point in the history
* Update jspdf.js

* Update context2d.js

* Update jspdf.unit.spec.js

* Add files via upload

* Add files via upload
  • Loading branch information
Uzlopak committed Dec 20, 2018
1 parent 7e03e14 commit 68b41fb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/jspdf.js
Expand Up @@ -3155,6 +3155,28 @@ var jsPDF = (function (global) {
return this;
};

var miterLimit;
/**
* Sets the miterLimit property, which effects the maximum miter length.
*
* @param {number} length The length of the miter
* @function
* @instance
* @returns {jsPDF}
* @memberOf jsPDF
* @name setMiterLimit
*/
var setMiterLimit = API.__private__.setMiterLimit = API.setMiterLimit = function (length) {
length = length || 0;
if (isNaN(length)) {
throw new Error('Invalid argument passed to jsPDF.setMiterLimit');
}
miterLimit = parseFloat(f2(length * k));
out(miterLimit + ' M');

return this;
};

/**
* Saves as PDF document. An alias of jsPDF.output('save', 'filename.pdf').
* Uses FileSaver.js-method saveAs.
Expand Down
1 change: 1 addition & 0 deletions src/modules/context2d.js
Expand Up @@ -352,6 +352,7 @@
set: function (value) {
if (!isNaN(value)) {
this.ctx.miterLimit = value;
this.pdf.setMiterLimit(value);
}
}
});
Expand Down
Binary file modified tests/context2d/reference/bar_graph_with_text_and_lines.pdf
Binary file not shown.
13 changes: 13 additions & 0 deletions tests/init/jspdf.unit.spec.js
Expand Up @@ -1171,6 +1171,19 @@ break`, 10, 10, {scope: doc});

})

it('jsPDF private function setMiterLimit', () => {
var doc = jsPDF();

var writeArray;

//miter/butt
doc = jsPDF();
writeArray = [];
doc.__private__.setCustomOutputDestination(writeArray);
doc.__private__.setMiterLimit(1);
expect(writeArray).toEqual(['2.83 M']);
expect(function() {doc.__private__.setMiterLimit('invalid');}).toThrow(new Error('Invalid argument passed to jsPDF.setMiterLimit'));
})
it('jsPDF private function putHeader', () => {
var doc = jsPDF();

Expand Down

0 comments on commit 68b41fb

Please sign in to comment.