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

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

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


From: Philippe Plantier
Subject: [Wesnoth-cvs-commits] wesnoth/src unit.cpp sdl_ttf/SDL_ttf.c
Date: Sat, 30 Oct 2004 16:10:58 -0400

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

Modified files:
        src            : unit.cpp 
        src/sdl_ttf    : SDL_ttf.c 

Log message:
        * Fixed memory corruption errors in SDL_ttf
        * Fixed reading unitialized values during unit::write

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

Patches:
Index: wesnoth/src/sdl_ttf/SDL_ttf.c
diff -u wesnoth/src/sdl_ttf/SDL_ttf.c:1.1 wesnoth/src/sdl_ttf/SDL_ttf.c:1.2
--- wesnoth/src/sdl_ttf/SDL_ttf.c:1.1   Tue Oct 26 19:03:55 2004
+++ wesnoth/src/sdl_ttf/SDL_ttf.c       Sat Oct 30 20:05:22 2004
@@ -20,7 +20,7 @@
     address@hidden
 */
 
-/* $Id: SDL_ttf.c,v 1.1 2004/10/26 19:03:55 gruikya Exp $ */
+/* $Id: SDL_ttf.c,v 1.2 2004/10/30 20:05:22 gruikya Exp $ */
 
 #include <math.h>
 #include <stdio.h>
@@ -845,6 +845,8 @@
        int miny, maxy;
        c_glyph *glyph;
        FT_Error error;
+       FT_Long use_kerning;
+       FT_UInt prev_index = 0;
 
        /* Initialize everything to 0 */
        if ( ! TTF_initialized ) {
@@ -856,6 +858,9 @@
        miny = maxy = 0;
        swapped = TTF_byteswapped;
 
+       /* check kerning */
+       use_kerning = FT_HAS_KERNING( font->face );
+
        /* Load each character and sum it's bounding box */
        x= 0;
        for ( ch=text; *ch; ++ch ) {
@@ -884,6 +889,14 @@
                }
                glyph = font->current;
 
+               /* handle kerning */
+               if ( use_kerning && prev_index && glyph->index ) {
+                       FT_Vector delta; 
+                       FT_Get_Kerning( font->face, prev_index, glyph->index, 
ft_kerning_default, &delta ); 
+                       x += delta.x >> 6;
+               }
+
+#if 0
                if ( (ch == text) && (glyph->minx < 0) ) {
                /* Fixes the texture wrapping bug when the first letter
                 * has a negative minx value or horibearing value.  The entire
@@ -901,6 +914,7 @@
                        z -= glyph->minx;
                        
                }
+#endif
                
                z = x + glyph->minx;
                if ( minx > z ) {
@@ -925,6 +939,7 @@
                if ( glyph->maxy > maxy ) {
                        maxy = glyph->maxy;
                }
+               prev_index = glyph->index;
        }
 
        /* Fill the bounds rectangle */
@@ -1508,6 +1523,7 @@
        const Uint16 *ch;
        Uint8 *src;
        Uint32 *dst;
+       Uint32 *dst_check;
        int swapped;
        int row, col;
        c_glyph *glyph;
@@ -1528,6 +1544,10 @@
                return(NULL);
        }
 
+       /* Adding bound checking to avoid all kinds of memory corruption errors
+          that may occur. */
+       dst_check = (Uint32*)textbuf->pixels + textbuf->pitch/4 * textbuf->h;
+
        /* check kerning */
        use_kerning = FT_HAS_KERNING( font->face );
        
@@ -1535,6 +1555,7 @@
        xstart = 0;
        swapped = TTF_byteswapped;
        pixel = (fg.r<<16)|(fg.g<<8)|fg.b;
+
        for ( ch=text; *ch; ++ch ) {
                Uint16 c = *ch;
                if ( c == UNICODE_BOM_NATIVE ) {
@@ -1560,7 +1581,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; 
@@ -1585,11 +1611,12 @@
                        dst = (Uint32*) textbuf->pixels +
                                (row+glyph->yoffset) * textbuf->pitch/4 +
                                xstart + glyph->minx;
+
                        /* Added code to adjust src pointer for pixmaps to
                         * account for pitch.
                         * */
                        src = (Uint8*) (glyph->pixmap.buffer + 
glyph->pixmap.pitch * row);
-                       for ( col = width; col>0; --col) {
+                       for ( col = width; col>0 && dst < dst_check; --col) {
                                alpha = *src++;
                                *dst++ |= pixel | (alpha << 24);
                        }
Index: wesnoth/src/unit.cpp
diff -u wesnoth/src/unit.cpp:1.101 wesnoth/src/unit.cpp:1.102
--- wesnoth/src/unit.cpp:1.101  Sat Oct 23 16:44:24 2004
+++ wesnoth/src/unit.cpp        Sat Oct 30 20:05:21 2004
@@ -1,4 +1,4 @@
-/* $Id: unit.cpp,v 1.101 2004/10/23 16:44:24 silene Exp $ */
+/* $Id: unit.cpp,v 1.102 2004/10/30 20:05:21 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -53,6 +53,7 @@
 //constructor for reading a unit
 unit::unit(const game_data& data, const config& cfg) : state_(STATE_NORMAL),
                                            moves_(0), user_end_turn_(false), 
facingLeft_(true),
+                                          resting_(false),
                                            recruit_(false),
                                            guardian_(false), 
upkeep_(UPKEEP_FREE)
 {




reply via email to

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