jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

context2d closePath() method adds extra segment

Open andrewcmyers opened this issue 4 years ago • 13 comments

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

andrewcmyers avatar Apr 19 '21 16:04 andrewcmyers

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.

HackbrettXXX avatar Apr 22 '21 08:04 HackbrettXXX

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.

andrewcmyers avatar Apr 22 '21 14:04 andrewcmyers

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 ;)

HackbrettXXX avatar Jul 16 '21 13:07 HackbrettXXX

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.

Uzlopak avatar Sep 28 '21 07:09 Uzlopak

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.

github-actions[bot] avatar Dec 28 '21 01:12 github-actions[bot]

There is a pending fix to this issue.

andrewcmyers avatar Dec 28 '21 04:12 andrewcmyers

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.

github-actions[bot] avatar Mar 29 '22 02:03 github-actions[bot]

The issue is still relevant. There is a fix for it already as a PR.

andrewcmyers avatar Mar 29 '22 03:03 andrewcmyers

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.

github-actions[bot] avatar Jun 28 '22 02:06 github-actions[bot]

The fix is still needed.

andrewcmyers avatar Jun 28 '22 02:06 andrewcmyers

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

andrewcmyers avatar Jun 28 '22 02:06 andrewcmyers

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.

github-actions[bot] avatar Sep 27 '22 02:09 github-actions[bot]

The fix is still needed.

andrewcmyers avatar Sep 27 '22 02:09 andrewcmyers

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.

github-actions[bot] avatar Dec 28 '22 01:12 github-actions[bot]

This should still be fixed by merging the open PR.

andrewcmyers avatar Dec 28 '22 13:12 andrewcmyers

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.

github-actions[bot] avatar Mar 29 '23 02:03 github-actions[bot]

This should still be fixed by merging the open PR.

andrewcmyers avatar Mar 29 '23 02:03 andrewcmyers

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.

github-actions[bot] avatar Jun 28 '23 02:06 github-actions[bot]

Still not fixed

andrewcmyers avatar Jun 28 '23 12:06 andrewcmyers

This is fixed by PR #3273, I believe, but someone else needs to push it across the finish line.

andrewcmyers avatar Aug 09 '23 12:08 andrewcmyers

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.

github-actions[bot] avatar Nov 08 '23 01:11 github-actions[bot]