question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setDrawColor sets incorrect color with CMYK input

See original GitHub issue

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(" ");
	}
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SmythConorcommented, Feb 13, 2019

I expect to see a black square.

0reactions
SmythConorcommented, Feb 19, 2019

@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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found