We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
actualBoundingBoxRight
when I set ctx.textAlign = 'center', then call measureText, will get wrong actualBoundingBoxRight result.
ctx.textAlign = 'center'
measureText
const Canvas = require('canvas'); const canvas = Canvas.createCanvas(); const ctx = canvas.getContext('2d'); console.log(ctx.measureText('aaaa')); /*** { width: 24, actualBoundingBoxLeft: -0.400390625, actualBoundingBoxRight: 23.3466796875, actualBoundingBoxAscent: 5.3564453125, actualBoundingBoxDescent: 0.17578125, emHeightAscent: 7.7001953125, emHeightDescent: 2.2998046875, alphabeticBaseline: -2.8994140625 } ***/ // then set textAlign center ctx.textAlign = 'center'; console.log(ctx.measureText('aaaa')); /*** { width: 24, actualBoundingBoxLeft: 11.599609375, actualBoundingBoxRight: 35.3466796875, // <--- should be 23.3466796875 - 12 actualBoundingBoxAscent: 5.3564453125, actualBoundingBoxDescent: 0.17578125, emHeightAscent: 7.7001953125, emHeightDescent: 2.2998046875, alphabeticBaseline: -2.8994140625 } ***/
Here is the result screenshot when using node-canvas:
And here is the screenshot when run on Chrome:
It seem that, the correct way to get actualBoundingBoxRight is
actualBoundingBoxRight @ center align = actualBoundingBoxRight @ left align - width / 2
actualBoundingBoxRight @ center align
actualBoundingBoxRight @ left align
width / 2
but now use
actualBoundingBoxRight @ center align = actualBoundingBoxRight @ left align + width / 2
The text was updated successfully, but these errors were encountered:
Fix actualBoundingBoxLeft/Right with center/right alignment
167aade
This bug goes back 10 years to the original implementation. Fixes #1909
b2e8ca7
bbce6a4
c52bc7d
a0a78ab
Fix actualBoundingBoxLeft/Right with center/right alignment (#2109)
6862532
zbjornson
Successfully merging a pull request may close this issue.
when I set
ctx.textAlign = 'center'
, then callmeasureText
, will get wrongactualBoundingBoxRight
result.Steps to Reproduce
Here is the result screenshot when using node-canvas:
And here is the screenshot when run on Chrome:
It seem that, the correct way to get
actualBoundingBoxRight
isactualBoundingBoxRight @ center align
=actualBoundingBoxRight @ left align
-width / 2
but now use
actualBoundingBoxRight @ center align
=actualBoundingBoxRight @ left align
+width / 2
Your Environment
The text was updated successfully, but these errors were encountered: