-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed
Description
When using setDrawColor with CMYK input, the color gets set incorrectly.
Reproduced on the live demo using the following code:
var doc = new jsPDF();
doc.setDrawColor(0.0, 0.0, 0.0, 1.0); // Should set draw color to black
doc.rect(20, 20, 10, 10);
The resulting output on the PDF displays a square with white borders.
The issue revolves around the encodeColorString
function. When the "assume CMYK" branch is reached, the color values passed in are divided by 255 so they're being treated like RGB values. The documentation specifies that if using CMYK, the values passed in should be between 0.0 (0%) to 1.0 (100%) so there is no need to divide the parameters by anything to get the correct CMYK output.
Exact code snippet:
// assume CMYK
if (typeof ch1 === 'string') {
color = [ch1, ch2, ch3, ch4, letterArray[2]].join(" ");
} else {
switch (options.precision) {
case 2:
// ** These should not be divided by 255 **
color = [f2(ch1 / 255), f2(ch2 / 255), f2(ch3 / 255), f2(ch4 / 255), letterArray[2]].join(" ");
break;
case 3:
default:
// ** These should not be divided by 255 **
color = [f3(ch1 / 255), f3(ch2 / 255), f3(ch3 / 255), f3(ch4 / 255), letterArray[2]].join(" ");
}
}