wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src/sdl_ttf SDL_ttf.c


From: Philippe Plantier
Subject: [Wesnoth-cvs-commits] wesnoth/src/sdl_ttf SDL_ttf.c
Date: Sat, 30 Oct 2004 17:07:57 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Philippe Plantier <address@hidden>      04/10/30 20:50:24

Modified files:
        src/sdl_ttf    : SDL_ttf.c 

Log message:
        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.)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/sdl_ttf/SDL_ttf.c.diff?tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: wesnoth/src/sdl_ttf/SDL_ttf.c
diff -u wesnoth/src/sdl_ttf/SDL_ttf.c:1.2 wesnoth/src/sdl_ttf/SDL_ttf.c:1.3
--- wesnoth/src/sdl_ttf/SDL_ttf.c:1.2   Sat Oct 30 20:05:22 2004
+++ wesnoth/src/sdl_ttf/SDL_ttf.c       Sat Oct 30 20:50:23 2004
@@ -20,7 +20,7 @@
     address@hidden
 */
 
-/* $Id: SDL_ttf.c,v 1.2 2004/10/30 20:05:22 gruikya Exp $ */
+/* $Id: SDL_ttf.c,v 1.3 2004/10/30 20:50:23 gruikya Exp $ */
 
 #include <math.h>
 #include <stdio.h>
@@ -1021,6 +1021,7 @@
        const Uint16* ch;
        Uint8* src;
        Uint8* dst;
+       Uint8 *dst_check;
        int swapped;
        int row, col;
        c_glyph *glyph;
@@ -1043,6 +1044,10 @@
                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 */
        palette = textbuf->format->palette;
        palette->colors[0].r = 255 - fg.r;
@@ -1086,7 +1091,12 @@
                }
                glyph = font->current;
                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 */
                if ( use_kerning && prev_index && glyph->index ) {
                        FT_Vector delta; 
@@ -1112,7 +1122,7 @@
                                xstart + glyph->minx;
                        src = current->buffer + row * current->pitch;
 
-                       for ( col=current->width; col>0; --col ) {
+                       for ( col=width; col>0 && dst < dst_check; --col ) {
                                *dst++ |= *src++;
                        }
                }
@@ -1272,6 +1282,7 @@
        const Uint16* ch;
        Uint8* src;
        Uint8* dst;
+       Uint8* dst_check;
        int swapped;
        int row, col;
        FT_Bitmap* current;
@@ -1293,6 +1304,10 @@
                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 */
        palette = textbuf->format->palette;
        rdiff = fg.r - bg.r;
@@ -1337,7 +1352,12 @@
                        return NULL;
                }
                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 */
                if ( use_kerning && prev_index && glyph->index ) {
                        FT_Vector delta; 
@@ -1363,7 +1383,7 @@
                                (row+glyph->yoffset) * textbuf->pitch +
                                xstart + glyph->minx;
                        src = current->buffer + row * current->pitch;
-                       for ( col=current->width; col>0; --col ) {
+                       for ( col=width; col>0 && dst < dst_check; --col ) {
                                *dst++ |= *src++;
                        }
                }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]