fontdue icon indicating copy to clipboard operation
fontdue copied to clipboard

Font line metrics don't match character metrics

Open nic-hartley opened this issue 1 year ago • 0 comments

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?

nic-hartley avatar Nov 28 '22 04:11 nic-hartley