context2d closePath() method adds extra segment
The current implementation of closePath in context2d.js very deliberately adds not just the beginning of the path but the next point as well, causing one path segment to be drawn twice:
if (
typeof this.path[i + 2] === "object" &&
typeof this.path[i + 2].x === "number"
) {
this.path.push(JSON.parse(JSON.stringify(this.path[i + 2])));
}
This is quite noticeably wrong if one turns on line dashing, since the segment drawn twice is not aligned the same way with respect to dashes. I'm sure these lines of code were added for a reason, but it seems to work more correctly without them. So whatever problem was being addressed by this code probably should have been fixed some other way...
You are right, this looks very fishy. I can't explain why it's there, but I agree with you that these lines are probably there for a reason. Unfortunately the lines are quite hard to track in the git history because of prettier commits and bad "merge" commits. Maybe we can find the respective commit in the commits before the merge of yWorks/jsPDF. Could you maybe dig into that? Although I'm quite sure we can remove these lines, I would be better to know for sure.
I'm probably not the right person to do that detective work. My random guess is that it has to do with drawing corners with appropriate mitering, though I would not expect the extra line segment to be necessary for that.
The line seems to originate from this commit with the very expressive commit message "modify context2d" :D https://github.com/MrRio/jsPDF/commit/7d2695c75405e62a80bf63a1a933e1286d637b16
I would suggest, let's remove these lines and wait until someone complains ;)
I remember. That was pain to implement context2d better. Invested multiple hours to get it run as compliant to the html5 interface. Just be careful.
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
There is a pending fix to this issue.
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
The issue is still relevant. There is a fix for it already as a PR.
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
The fix is still needed.
I get around this bug by monkey-patching jsPDF, so I don't have much incentive to put more effort into it. I wrote the PR and someone else needs to pick it up
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
The fix is still needed.
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
This should still be fixed by merging the open PR.
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
This should still be fixed by merging the open PR.
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
Still not fixed
This is fixed by PR #3273, I believe, but someone else needs to push it across the finish line.
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.