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::getVerticalSize computes incorrect ascenders and descenders for TTF fonts #1287

Open
rubenlg opened this issue Dec 18, 2023 · 2 comments

Comments

@rubenlg
Copy link

rubenlg commented Dec 18, 2023

FreeTypeFont::getVerticalSize relies on FreeTypeFont::getCoordScale instead of unitsPerEm to compute the ascender and descender.

FreeTypeFont::getCoordScale uses _currentRes.second * 64 where _currentRes.second is initialized to 32 and then changes arbitrarily whenever a glyph is computed. So if a font happens to have 2048 unitsPerEm, and nothing ever called getGlyph yet, the font will return the correct ascender and descender. Otherwise you get an arbitrary number that can't be used.

I wanted to use that to compute a stable height for my text that won't jump up and down as the text contents change dynamically (see #1269).

I see that there was initially code scaling the ascender and descender correctly with unitsPerEm but that is currently disabled with #if 0. Any idea why that is? It seems to come from here, but that's a very old commit with very little context.

@robertosfield
Copy link
Collaborator

I'm afraid I can't recall stuff from 12 years ago. The change must have been made to address an issue experience some some user at some point, perhaps archive of osg-users mailing list.

@rubenlg
Copy link
Author

rubenlg commented Dec 19, 2023

Understandable. I worked around this by using Freetype directly.

Fixing this properly would be a breaking change, as users might be relying on the current implementation. Giving OSG's state, I'm guessing it's not worth it. Should I leave this open as documentation that it's a known bug?

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

2 participants