setDrawColor sets incorrect color with CMYK input
See original GitHub issueWhen 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(" ");
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
setDrawColor sets incorrect color with CMYK input #2274
When using setDrawColor with CMYK input, the color gets set incorrectly. Reproduced on the live demo using the following code: var doc =...
Read more >Colour values change on their own! Very frustrating
I will enter an exact CMYK or RGB value to match our brands colours, then these values will change slightly all on their...
Read more >RGB to CMYK conversion problem
You can not translate an RGB color to CMYK if you do not define a set of profiles and some methods of conversion....
Read more >CMYK colours – What Else Can I Do – mPDF Manual
Functions - SetDrawColor() , SetTextColor() and SetFillColor() all take an optional 4th parameter. If defined this will interpret the input as ...
Read more >CMYK Printing vs. RGB: How to Print the Right Colors
Wondering why your printed document doesn't match the colors on your screen? Learn about RGB vs. CMYK printing and ways to ensure the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I expect to see a black square.
@arasabbasi just wondering if you could take a look at the pull request, maybe let me know why the build fails if the tests look like they’re all green. Thanks!