Applied the changes in SDL_ttf to TTF_RenderUNICODE_Solid...

...and to SDL_RenderUNICODE_Shaded too (which are not used in Wesnoth,
but which must be coded in order to produce a valid patch for the
SDL_ttf team.)
This commit is contained in:
Philippe Plantier 2004-10-30 20:50:23 +00:00
parent 25fabbe361
commit f55b696dd6

View file

@ -1021,6 +1021,7 @@ SDL_Surface *TTF_RenderUNICODE_Solid(TTF_Font *font,
const Uint16* ch; const Uint16* ch;
Uint8* src; Uint8* src;
Uint8* dst; Uint8* dst;
Uint8 *dst_check;
int swapped; int swapped;
int row, col; int row, col;
c_glyph *glyph; c_glyph *glyph;
@ -1043,6 +1044,10 @@ SDL_Surface *TTF_RenderUNICODE_Solid(TTF_Font *font,
return NULL; return NULL;
} }
/* Adding bound checking to avoid all kinds of memory corruption errors
that may occur. */
dst_check = (Uint8*)textbuf->pixels + textbuf->pitch * textbuf->h;
/* Fill the palette with the foreground color */ /* Fill the palette with the foreground color */
palette = textbuf->format->palette; palette = textbuf->format->palette;
palette->colors[0].r = 255 - fg.r; palette->colors[0].r = 255 - fg.r;
@ -1086,7 +1091,12 @@ SDL_Surface *TTF_RenderUNICODE_Solid(TTF_Font *font,
} }
glyph = font->current; glyph = font->current;
current = &glyph->bitmap; current = &glyph->bitmap;
/* Ensure the width of the pixmap is correct. On some cases,
* freetype may report a larger pixmap than possible.*/
width = current->width;
if (width > glyph->maxx - glyph->minx) {
width = glyph->maxx - glyph->minx;
}
/* do kerning, if possible AC-Patch */ /* do kerning, if possible AC-Patch */
if ( use_kerning && prev_index && glyph->index ) { if ( use_kerning && prev_index && glyph->index ) {
FT_Vector delta; FT_Vector delta;
@ -1112,7 +1122,7 @@ SDL_Surface *TTF_RenderUNICODE_Solid(TTF_Font *font,
xstart + glyph->minx; xstart + glyph->minx;
src = current->buffer + row * current->pitch; src = current->buffer + row * current->pitch;
for ( col=current->width; col>0; --col ) { for ( col=width; col>0 && dst < dst_check; --col ) {
*dst++ |= *src++; *dst++ |= *src++;
} }
} }
@ -1272,6 +1282,7 @@ SDL_Surface* TTF_RenderUNICODE_Shaded( TTF_Font* font,
const Uint16* ch; const Uint16* ch;
Uint8* src; Uint8* src;
Uint8* dst; Uint8* dst;
Uint8* dst_check;
int swapped; int swapped;
int row, col; int row, col;
FT_Bitmap* current; FT_Bitmap* current;
@ -1293,6 +1304,10 @@ SDL_Surface* TTF_RenderUNICODE_Shaded( TTF_Font* font,
return NULL; return NULL;
} }
/* Adding bound checking to avoid all kinds of memory corruption errors
that may occur. */
dst_check = (Uint8*)textbuf->pixels + textbuf->pitch * textbuf->h;
/* Fill the palette with NUM_GRAYS levels of shading from bg to fg */ /* Fill the palette with NUM_GRAYS levels of shading from bg to fg */
palette = textbuf->format->palette; palette = textbuf->format->palette;
rdiff = fg.r - bg.r; rdiff = fg.r - bg.r;
@ -1337,7 +1352,12 @@ SDL_Surface* TTF_RenderUNICODE_Shaded( TTF_Font* font,
return NULL; return NULL;
} }
glyph = font->current; glyph = font->current;
/* Ensure the width of the pixmap is correct. On some cases,
* freetype may report a larger pixmap than possible.*/
width = glyph->pixmap.width;
if (width > glyph->maxx - glyph->minx) {
width = glyph->maxx - glyph->minx;
}
/* do kerning, if possible AC-Patch */ /* do kerning, if possible AC-Patch */
if ( use_kerning && prev_index && glyph->index ) { if ( use_kerning && prev_index && glyph->index ) {
FT_Vector delta; FT_Vector delta;
@ -1363,7 +1383,7 @@ SDL_Surface* TTF_RenderUNICODE_Shaded( TTF_Font* font,
(row+glyph->yoffset) * textbuf->pitch + (row+glyph->yoffset) * textbuf->pitch +
xstart + glyph->minx; xstart + glyph->minx;
src = current->buffer + row * current->pitch; src = current->buffer + row * current->pitch;
for ( col=current->width; col>0; --col ) { for ( col=width; col>0 && dst < dst_check; --col ) {
*dst++ |= *src++; *dst++ |= *src++;
} }
} }