Hi,On 1/25/10, Peter Hickman wrote:
Thanks, I have tried that and it is an improvement but I think I will need
to get back to it again later.
You are welcome to adapt our BlackOutline() function from tuxmath and
tuxtype if you like - it is GPLv2+. You could simplify it a lot
because it is written to use either SDL_Pango or SDL_ttf, depending on
what is available at build time for a given platform.
The original is at git://git.debian.org/git/tux4kids/tuxtype.git, in
file src/SDL_extras.c
David Bruce
SDL_Surface* BlackOutline(const char* t, int font_size, const SDL_Color* c)
{
SDL_Surface* out = NULL;
SDL_Surface* black_letters = NULL;
SDL_Surface* white_letters = NULL;
SDL_Surface* bg = NULL;
SDL_Rect dstrect;
Uint32 color_key;
/* Make sure everything is sane before we proceed: /
#ifdef HAVE_LIBSDL_PANGO
if (!context)
{
fprintf(stderr, âBlackOutline(): invalid SDL_Pango context - returning.\nâ);
return NULL;
}
#else
TTF_Font font = get_font(font_size);
if (!font)
{
fprintf(stderr, âBlackOutline(): could not load needed font -
returning.\nâ);
return NULL;
}
#endif
if (!t || !c)
{
fprintf(stderr, âBlackOutline(): invalid ptr parameter, returning.\nâ);
return NULL;
}
if (t[0] == â\0â)
{
LOG(âBlackOutline(): empty string, returning\nâ);
return NULL;
}
DEBUGCODE
{
fprintf( stderr, â\nEntering BlackOutline(): \nâ);
fprintf( stderr, âBlackOutline of â%sâ\nâ, t );
}
#ifdef HAVE_LIBSDL_PANGO
Set_SDL_Pango_Font_Size(font_size);
SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_BLACK_LETTER);
SDLPango_SetText(context, t, -1);
black_letters = SDLPango_CreateSurfaceDraw(context);
#else
black_letters = TTF_RenderUTF8_Blended(font, t, black);
#endif
if (!black_letters)
{
fprintf (stderr, âWarning - BlackOutline() could not create image
for %s\nâ, t);
return NULL;
}
bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
(black_letters->w) + 5,
(black_letters->h) + 5,
32,
rmask, gmask, bmask, amask);
/* Use color key for eventual transparency: */
color_key = SDL_MapRGB(bg->format, 01, 01, 01);
SDL_FillRect(bg, NULL, color_key);
/* Now draw black outline/shadow 2 pixels on each side: */
dstrect.w = black_letters->w;
dstrect.h = black_letters->h;
/* NOTE: can make the âshadowâ more or less pronounced by /
/ changing the parameters of these loops. */
for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
SDL_FreeSurface(black_letters);
/* â Put the color version of the text on top! â /
#ifdef HAVE_LIBSDL_PANGO
/ convert color arg: /
SDLPango_Matrix color_matrix = SDL_Colour_to_SDLPango_Matrix©;
if (color_matrix)
{
SDLPango_SetDefaultColor(context, color_matrix);
free(color_matrix);
}
else /* fall back to just using white if conversion fails: */
SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_WHITE_LETTER);
white_letters = SDLPango_CreateSurfaceDraw(context);
#else
white_letters = TTF_RenderUTF8_Blended(font, t, *c);
#endif
if (!white_letters)
{
fprintf (stderr, âWarning - BlackOutline() could not create image
for %s\nâ, t);
return NULL;
}
dstrect.x = 1;
dstrect.y = 1;
SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
SDL_FreeSurface(white_letters);
/* â Convert to the screen format for quicker blits â */
SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
out = SDL_DisplayFormatAlpha(bg);
SDL_FreeSurface(bg);
DEBUGCODE
{ fprintf( stderr, â\nLeaving BlackOutline(): \nâ); }
return out;
}