Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix context2d lineWidth scaling #2702

Merged
merged 7 commits into from
Jul 17, 2020

Conversation

tompng
Copy link
Contributor

@tompng tompng commented Mar 21, 2020

context2d.scale(sx, sy) should scale both path-shape and path-lineWidth, but lineWidth was not scaled.
This PR lets lineWidth scale.
スクリーンショット 2020-03-21 16 02 34

スクリーンショット 2020-03-21 16 03 40

canvas = document.createElement('canvas')
canvas.width=canvas.height=200
doc = new jsPDF()
const ctxc = canvas.getContext('2d')
const ctxd = doc.context2d
ctxc.fillStyle = 'white'; ctxc.fillRect(0, 0, 200, 200); ctxc.fillStyle = 'black'
for (ctx of [ctxc, ctxd]) {
  ctx.translate(10, 10)
  ctx.lineWidth = 2
  ctx.font = ctx == ctxc ? '40px times' : '113px times' // see pull #2700
  ctx.beginPath()
  ctx.rect(0, 0, 40, 40)
  ctx.stroke()
  ctx.strokeText('A', 0, 40)
  ctx.scale(2,2)
  ctx.beginPath()
  ctx.rect(0, 30, 40, 40)
  ctx.stroke()
  ctx.strokeText('A', 0, 70)
}
doc.addImage(canvas, 100, 0, 200, 200)

This PR also fixes initial lineWidth. (see #2701)
ctx.stroke() without scaling and without setting ctx.lineWidth will use ctx.lineWidth == 1. (previously, it uses lineWidth = 0.2)
and this is the reason why many context2d tests that doesn't use scale(sx, sy) also fails.

@HackbrettXXX
Copy link
Collaborator

Thanks also for this PR. Could you fix the test cases? You probably need to update the reference PDFs. You can do so with the test-training' and ' test-local npm scripts.

@tompng
Copy link
Contributor Author

tompng commented Mar 24, 2020

I updated reference pdfs and pageoverlap spec.

@HackbrettXXX HackbrettXXX merged commit 91cecee into parallax:master Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants