-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Refactor helpers.canvas.drawPoint() #5623
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nagix Do you think we can also move ctx.fill()
calls to the end, just before ctx.stroke
? I don't know if it makes a difference to fill all paths, even cross
, dash
, line
, etc. I'm asking because it could be interesting to move the path creation in a separate method (e.g. helpers.canvas.symbol()
) and only fill
and stroke
when needed. It would fix #5180 without relying on a transparent stroke but simply skip ctx.stroke()
if borderWidth
is 0.
@@ -41,6 +41,7 @@ var exports = module.exports = { | |||
ctx.arcTo(x, y + height, x, y + height - r, r); | |||
ctx.lineTo(x, y + r); | |||
ctx.arcTo(x, y, x + r, y, r); | |||
ctx.closePath(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is preferable that
helpers.canvas.roundedRect()
includectx.closePath()
at the end becauseCanvasRenderingContext2D.rect()
closes the subpath [link]
It's also written that rect()
"must then create a new subpath with the point (x, y) as the only point in the subpath". Shoud we add ctx.move(x, y)
right after closePath()
or do you think it's not application to a rounded rectangle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx.move(x, y)
after closePath()
makes sense. I will update the code.
@@ -65,17 +66,16 @@ var exports = module.exports = { | |||
ctx.save(); | |||
ctx.translate(x, y); | |||
ctx.rotate(rotation * Math.PI / 180); | |||
ctx.beginPath(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need closePath()
before stroke()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can move |
Confirmed that there is no problem with the changes above. It's ready to merge. |
break; | ||
} | ||
|
||
ctx.fill(); | ||
ctx.stroke(); | ||
ctx.restore(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any impact (in the calling code) to not call ctx.closePath();
anymore before returning?
A path itself doesn't have an open/close state, but a subpath does. What
The last subpath is always open regardless of whether |
If we make sure that the path has the last subpath with the point (x, y) like |
Bring ctx.beginPath() before switch and replace ctx.fillRect()/ctx.strokeRect() with ctx.rect()/ctx.fill() to make it consistent with the other styles. It is also preferable that helpers.canvas.roundedRect() include ctx.closePath() at the end because CanvasRenderingContext2D.rect() closes the subpath. Get rid of ctx.closePath() for cross, crossRot, star, line and dash because these have no closed path shape, and it should be avoided that ctx.closePath() makes a round-trip path.
This PR makes the following changes:
ctx.beginPath()
before switchctx.fillRect()
/ctx.strokeRect()
withctx.rect()
/ctx.fill()
to make it consistent with the other styleshelpers.canvas.roundedRect()
includectx.closePath()
at the end becauseCanvasRenderingContext2D.rect()
closes the subpath [link]ctx.closePath()
for cross, crossRot, star, line and dash because these have no closed path shape, and it should be avoided thatctx.closePath()
makes a round-trip path [link]