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

Font line metrics don't match character metrics #130

Open
nic-hartley opened this issue Nov 28, 2022 · 0 comments
Open

Font line metrics don't match character metrics #130

nic-hartley opened this issue Nov 28, 2022 · 0 comments

Comments

@nic-hartley
Copy link

Heyo!

I'm trying to do some basic font rendering. As part of testing I started iterating over each character in Inconsolata and rendering each one. Just a couple of characters in, I tried to render (index 4), and it failed, seemingly because when rasterized it reaches higher than the ascent reported in the horizontal line metrics (char height=18.04, line ascent=17.18)

I'm not sure if my code is broken because I don't understand fonts, if the font has a slight bug, or if fontdue has an issue, so I've also attached the code I discovered this with and the TTF file (zipped to make GitHub happy). In brief:

  • I'm using line_metrics.ascent.ceil() as usize + line_metrics.descent.floor() as usize to decide how tall each row is.
  • Then, when I rasterize, I'm doing line_metrics.ascent.ceil() as usize - char_metrics.ymin + char_metrics.height (with some casts to ensure the math can be done) to get the number of rows between the top of the rasterized buffer and the top of the line.
  • But that math is failing -- again, as far as I can tell, because ymin == 0, and the character's rasterized height is greater than the line's ascent.

So my questions are: Is my math just wrong? (If so, what's the right way to do this?) Otherwise, is this an issue with this font specifically, and what would be the nicest way to work around it?

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

No branches or pull requests

1 participant