openscenegraph / OpenSceneGraph

OpenSceneGraph git repository
http://www.openscenegraph.org
Other
3.21k stars 1.42k forks source link

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

Open rubenlg opened 9 months ago

rubenlg commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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?