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

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

Closed
john01dav opened this issue Nov 24, 2021 · 1 comment
Closed

Comments

@john01dav
Copy link

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?

@john01dav
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant