[SDN_ttf] incorrect calculation of line spacing?

Not sure this is the right place for SDL_ttf issues, but if so:

Current SDL_ttf (http://www.libsdl.org/cgi/cvsweb.cgi/SDL_ttf2/) seems
to calculate bounding boxes based on the maximum and minimum values that
appear in the font, as opposed to the used glyphs only. This means that
fonts containing some of the Unicode Block Elements will generally cause
SDL_ttf to use very large line spacing, even if the Block Elements are
not actually being used in the application.

From Stepan Roh, project manager for the DejaVu font family:
In version 1.14 Box Elements were added
(created by David Lawrence Ramsey). Those glyphs have bigger descent than
other glyphs which cause the change of yMin value in TTF ‘head’ table from
-492 to -1034 (note that this value comes from Sans Mono and their Box
Drawing glyphs). This may explain your observations, however (I believe)
correct rasterizer should either compute bounding boxes of used glyphs
only (not of the whole font) or use typographic descents (either from
’hhea’ table or from ‘OS/2’ table). I have DejaVuSans 1.14 installed in
KDE as a system font and it clearly uses one of those approaches.

As I look through SDL_ttf sources on a location you provided I see
(function TTF_OpenFontIndexRW):

       font->ascent  = FT_CEIL(FT_MulFix(face->bbox.yMax, scale));
       font->descent = FT_CEIL(FT_MulFix(face->bbox.yMin, scale));

… which looks like what I was talking about. I think you can try to
change it to:

       font->ascent  = FT_CEIL(FT_MulFix(face->ascender, scale));
       font->descent = FT_CEIL(FT_MulFix(face->descender, scale));

I have tested this suggested change with DejaVuSans 2.1 and after
this tweak, SDL_ttf now renders this font correctly in our application
(Battle for Wesnoth, http://www.wesnoth.org/). Please consider this
change for SDL_ttf.

(Stepan also had some other comments, see
for his full message. The change above is the most generally relevant.)

– Andras Salamon @Andras_Salamon

Not sure this is the right place for SDL_ttf issues, but if so:

I’ve entered this bug into Bugzilla:

Can anyone comment on the results of this approach, and whether it will
work in general?

-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment