OpenSceneGraph icon indicating copy to clipboard operation
OpenSceneGraph copied to clipboard

Font::getVerticalSize computes incorrect ascenders and descenders for TTF fonts

Open rubenlg opened this issue 2 years ago • 2 comments

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.

rubenlg avatar Dec 18 '23 22:12 rubenlg

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.

robertosfield avatar Dec 19 '23 09:12 robertosfield

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?

rubenlg avatar Dec 19 '23 14:12 rubenlg