SDL_ttf bug in solid bold renderings?

I was writing a program that dealt with SDL_ttf, and all my renderings of fonts
using “white” for the color looked horrid. The black ones looked fantastic. I’ve
never given a bug report really, so here goes. :wink: Thanks for any feedback!

First, I’m using the latest (I think) source: 2.0.8. SDL_ttf does not seem to
properly display TTF fonts using the Bold style, with Solid rendering. Normal is
fine, Bold + Blended is fine, only (AFAIK) bold+solid causes issues. The
resulting surface from such a call is 8bit. Pixels within it should be either 0
(transparent) or 1 (the color chosen). Some pixels are turning up as “2”, which
is black. While this isn’t a problem when rendering black (it blends in),
anything else is next to unreadable.

Here’s a showfont to demonstrate the problem:
showfont -solid -b -fgcol 255,255,255 -bgcol 80,80,80 Arial.ttf 12
ABCDEFGHIJKLMNOPQRSTUVWXYZ

In Load_Glyph(), in the code shortly following the comment:
/* The pixmap is a little hard, we have to add and clamp */
Specifically, this line:
pixel = (pixmap[col] + pixmap[col-1]);
Here, the code appears to add two pixels, the current one and the previous one.

From what I’ve seen, ALL of the "2"s in my renderings have a 1 on either side.
This code seems to work both the blended and the solid renderings.

However, if my guesses (I’ve yet to become an expert on the SDL_ttf code) are
correct, the “want” argument, when CACHED_BITMAP, gives back a “solid” (two
color) image. The CACHED_PIXMAP gives a shaded (256 color) one. Adding two
pixels like that needs to be capped at 1, NOT NUM_GRAYS - 1, like the code
shortly after does. So, after the abovementioned line, add:
if(pixel > 1 && (want & CACHED_BITMAP) == CACHED_BITMAP) pixel = 1;
Which corrects the problem for me.

All in all, this is my “proposed” patch, I suppose:
*** SDL_ttf-original.c Wed Jun 6 19:08:34 2007
— SDL_ttf.c Wed Jun 6 19:09:18 2007***************
*** 618,623 ****
— 618,624 ----
for( offset=1; offset <= font->glyph_overhang; ++offset ) {
for( col = dst->width - 1; col > 0; --col ) {
pixel = (pixmap[col] + pixmap[col-1]);

  •   				if(pixel > 1 && (want & CACHED_BITMAP) == CACHED_BITMAP) pixel = 1;
      				if( pixel > NUM_GRAYS - 1 ) {
      					pixel = NUM_GRAYS - 1;
      				}

I was writing a program that dealt with SDL_ttf, and all my renderings of fonts
using “white” for the color looked horrid. The black ones looked fantastic. I’ve
never given a bug report really, so here goes. :wink: Thanks for any feedback!

Thanks for the great description of the problem and patch. I’ve made a
slightly different change that should work more efficiently and also work
for blended modes.

You can check it out in subversion:
http://svn.libsdl.org/trunk/SDL_ttf

Thanks!
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment