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

measureText() is slightly off #581

Closed
nugraizy opened this issue Nov 8, 2022 · 7 comments · Fixed by #606
Closed

measureText() is slightly off #581

nugraizy opened this issue Nov 8, 2022 · 7 comments · Fixed by #606
Assignees
Labels
bug Something isn't working

Comments

@nugraizy
Copy link

nugraizy commented Nov 8, 2022

Hi! I've been using canvas cairo backend / node-canvas created by Automattic. And I'm using packages for wraps big/long texts. When using node-canvas it works fine, everything align to the middle. But after using your canvas, it offset are off. And it might be because of value width on measureText() are different compared to node-canvas.

Here is the result when measuring text 'Hello World' :

node-canvas :

{
  width: 22,
  actualBoundingBoxLeft: 0,
  actualBoundingBoxRight: 22,
  actualBoundingBoxAscent: 8,
  actualBoundingBoxDescent: 0,
  emHeightAscent: 10,
  emHeightDescent: 3,
  alphabeticBaseline: 0.947265625
}

@napi-rs/canvas

{
  actualBoundingBoxAscent: 10,
  actualBoundingBoxDescent: 0,
  actualBoundingBoxLeft: 0,
  actualBoundingBoxRight: 24,
  fontBoundingBoxAscent: 8.056640625,
  fontBoundingBoxDescent: 6.62109375,
  width: 25
}

I'm using 512x512 canvas.

And here I'm using the package canvas-text-wrapper with the options below :

wrap(canvas, 'Hello World', {
	font: '82px chevin',
	textAlign: 'center',
	verticalAlign: 'middle',
	sizeToFill: true,
});

The font I used :
https://fontsgeek.com/fonts/Chevin-Bold

Results :
node-canvas : https://imgur.com/a/gjplLKV
@napi-rs/canvas : https://imgur.com/a/jZ0Rtgi

@Brooooooklyn Brooooooklyn self-assigned this Nov 9, 2022
@Brooooooklyn Brooooooklyn added the bug Something isn't working label Nov 9, 2022
@salsawij
Copy link

salsawij commented Nov 9, 2022

same

@xbal023
Copy link

xbal023 commented Nov 9, 2022

Same as me :(

@twlite
Copy link
Contributor

twlite commented Nov 9, 2022

Same as me :(

Just a suggestion, this issue is already noticed by the maintainer so let's not spam the inbox of the people who are watching this repository by commenting like this unless it is really necessary 😕

image

@Brooooooklyn
Copy link
Owner

@nugraizy this font https://fontsgeek.com/fonts/Chevin-Bold is Chevin not chevin

@nugraizy
Copy link
Author

@nugraizy this font https://fontsgeek.com/fonts/Chevin-Bold is Chevin not chevin

done it. sadly doesn't fix the issue

@Brooooooklyn
Copy link
Owner

@nugraizy could you provide a minimal reproducible repo so I can debug it

@nugraizy
Copy link
Author

@nugraizy could you provide a minimal reproducible repo so I can debug it

sure! here's the repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants