[SDL] SDL_ttf pixel wrapping bug?

Huib-Jan Imbens hj at imbens.nl
Thu Sep 26 01:04:01 PDT 2002

> > If anybody has a solution, please post it as I'm still
> > dying to know.

Here is a solution. The problem is that the left bearing of the italic 'j'
is negative, meaning that it should be placed before the end of the previous
character. The code in SDL_ttf.c recognizes this when calculating the size
of the temp bitmap where it renders the font, but it forgets it when it
actually renders the text.
The last six lines of the snippet below should be pasted at three locations
(all three locations can be found by searching for /* Load and render each
character */).
Of course this is a dirty hack. Besides it is not completely correct because
the entire text will now be offset a few pixels to the right (the same
number of pixels that you saw on the right side of the text).

 /* Load and render each character */
 xstart = 0;
 for( ch = text; *ch; ++ch ) {
  FT_Bitmap* current;

  error = Find_Glyph(font, *ch, CACHED_METRICS|CACHED_PIXMAP);
  if( error ) {
   SDL_FreeSurface( textbuf );
   return NULL;
  glyph = font->current;

  if (ch == text) { // first char
   if (glyph->minx < 0) { // first character has negative bearing
    xstart -= glyph->minx; // fixup xstart


More information about the SDL mailing list