mooman219/fontdue

How can I align a line with the maximum height of the characters?

john01dav opened this issue · 1 comments

I'm trying to write a text field control based on this (excellent) library, and I'm running into some trouble. I'm using LineMetrics::ascent.abs() + LineMetrics::descent.abs() to calculate the maximum size of a character (e.g. distance from top of tallest character to bottom of lowest-reaching character), and then drawing a vertical line to represent the cursor or a blue rectangle to represent selection of this height down from the y coordinate that I'm setting as the origin for font rendering (glyphs are rendered at <some location> + (GlyphPosition.x, GlyphPosition.y) in my current code), but this produces incorrect results where the blue rectangle or line are shifted higher than the range of heights that the characters can take up (although the height seems to be correct):

image

For comparison, here's what it looks like when Firefox renders this same string (note how the selection color covers the exact range from highest ascent to lowest descent, and the cursor does the same):
image

Upon closer inspection, it looks like fontdue is never returning any characters that start at the top of the line (e.g. GlyphPosition::y is never 0 on any of the characters that I tested with), making me think that there's some constant offset here. I saw LineMetrics::line_gap and thought that this might be relevant, but this is set to zero so it can't be this. The font that I'm using is Roboto semi bold. Could I please get some clarification on what the best way to do this is?

I have resolved the issue. It turned out to be a small error in my code (missing a / 2 when I forgot what one of my variables was). Sorry for any trouble this issue caused.