Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/jspdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2738,6 +2738,39 @@ var jsPDF = (function (global) {
return this;
};

/**
* Sets the dash pattern for upcoming lines.
*
* To reset the settings simply call the method without any parameters.
* @param {array} dashArray The pattern of the line, expects numbers.
* @param {number} dashPhase The phase at which the dash pattern starts.
* @function
* @instance
* @returns {jsPDF}
* @memberOf jsPDF
* @name setLineDash
*/
var setLineDash = API.__private__.setLineDash = jsPDF.API.setLineDash = function (dashArray, dashPhase) {
dashArray = dashArray || [];
dashPhase = dashPhase || 0;

if (isNaN(dashPhase) || !Array.isArray(dashArray)) {
throw new Error('Invalid arguments passed to jsPDF.setLineDash');
}

dashArray = dashArray.map(function (x) {return (x * k).toFixed(3)}).join(' ');
dashPhase = parseFloat((dashPhase * k).toFixed(3));

out('[' + dashArray + '] ' + dashPhase + ' d');
return this;
};

var lineHeightFactor;

var getLineHeight = API.__private__.getLineHeight = API.getLineHeight = function () {
return activeFontSize * lineHeightFactor;
};

var lineHeightFactor;

var getLineHeight = API.__private__.getLineHeight = API.getLineHeight = function () {
Expand Down
30 changes: 29 additions & 1 deletion tests/init/jspdf.unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,35 @@ describe('jsPDF unit tests', () => {

expect(writeArray).toEqual(['1687.41 w']);
});


it('jsPDF private function setLineDash', () => {
const doc = jsPDF()
var writeArray = [];
doc.__private__.setCustomOutputDestination(writeArray);

expect(function () {doc.__private__.setLineDash('');} ).not.toThrow(new Error('Invalid arguments passed to jsPDF.setLineDash'));

var writeArray = [];
doc.__private__.setCustomOutputDestination(writeArray);
expect(function () {doc.__private__.setLineDash();} ).not.toThrow(new Error('Invalid arguments passed to jsPDF.setLineDash'));

expect(writeArray).toEqual(['[] 0 d']);

var writeArray = [];
doc.__private__.setCustomOutputDestination(writeArray);
expect(function () {doc.__private__.setLineDash('1 1', '1');} ).toThrow(new Error('Invalid arguments passed to jsPDF.setLineDash'));

var writeArray = [];
doc.__private__.setCustomOutputDestination(writeArray);
expect(function () {doc.__private__.setLineDash('1 1', 1);} ).toThrow(new Error('Invalid arguments passed to jsPDF.setLineDash'));

var writeArray = [];
doc.__private__.setCustomOutputDestination(writeArray);
expect(function () {doc.__private__.setLineDash([1,1], 1)} ).not.toThrow(new Error('Invalid arguments passed to jsPDF.setLineDash'));

expect(writeArray).toEqual(['[2.835 2.835] 2.835 d']);
});

it('jsPDF private function getLineHeight', () => {
const doc = jsPDF()

Expand Down