Index: SDL_ttf.c
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL_ttf2/SDL_ttf.c,v
retrieving revision 1.16
diff -u -r1.16 SDL_ttf.c
--- SDL_ttf.c	3 May 2003 20:07:53 -0000	1.16
+++ SDL_ttf.c	13 Jun 2003 22:37:53 -0000
@@ -830,6 +830,8 @@
 	int x, z;
 	int minx, maxx;
 	int miny, maxy;
+        int max_height;
+        int rows;
 	c_glyph *glyph;
 	FT_Error error;
 
@@ -841,6 +843,7 @@
 	status = 0;
 	minx = maxx = 0;
 	miny = maxy = 0;
+	max_height = 0;
 	swapped = TTF_byteswapped;
 
 	/* Load each character and sum it's bounding box */
@@ -871,6 +874,12 @@
 		}
 		glyph = font->current;
 
+                rows = glyph->maxy - glyph->miny;
+                if ( max_height < (rows + glyph->yoffset) ) {
+                        max_height = (rows + glyph->yoffset);
+                }
+
+
 		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
@@ -922,7 +931,14 @@
 #if 0 /* This is correct, but breaks many applications */
 		*h = (maxy - miny);
 #else
-		*h = font->height;
+                if (font->height >= max_height) {
+                  *h = font->height;
+                } else {
+                  *h = max_height;
+                }
+                  
+		/*  *h = font->height; XXX This doesn't take into account
+                 * the bearingY, leading to memory access errors */
 #endif
 	}
 	return status;
@@ -1000,11 +1016,10 @@
 	FT_Error error;
 
 	/* Get the dimensions of the text surface */
-	if( ( TTF_SizeUNICODE(font, text, &width, NULL) < 0 ) || !width ) {
+	if( ( TTF_SizeUNICODE(font, text, &width, &height) < 0 ) || !width ) {
 		TTF_SetError( "Text has zero width" );
 		return NULL;
 	}
-	height = font->height;
 
 	/* Create the target surface */
 	textbuf = SDL_AllocSurface(SDL_SWSURFACE, width, height, 8, 0, 0, 0, 0);
@@ -1233,11 +1248,10 @@
 	FT_Error error;
 
 	/* Get the dimensions of the text surface */
-	if( ( TTF_SizeUNICODE(font, text, &width, NULL) < 0 ) || !width ) {
+	if( ( TTF_SizeUNICODE(font, text, &width, &height) < 0 ) || !width ) {
 		TTF_SetError("Text has zero width");
 		return NULL;
 	}
-	height = font->height;
 
 	/* Create the target surface */
 	textbuf = SDL_AllocSurface(SDL_SWSURFACE, width, height, 8, 0, 0, 0, 0);
@@ -1466,11 +1480,10 @@
 	FT_Error error;
 
 	/* Get the dimensions of the text surface */
-	if ( (TTF_SizeUNICODE(font, text, &width, NULL) < 0) || !width ) {
+	if ( (TTF_SizeUNICODE(font, text, &width, &height) < 0) || !width ) {
 		TTF_SetError("Text has zero width");
 		return(NULL);
 	}
-	height = font->height;
 
 	textbuf = SDL_AllocSurface(SDL_SWSURFACE, width, height, 32,
                   0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
