Commit 3a0d7bf548b75036ac8e2e81d3a21be3bdd6a275

henry 2002-01-09T20:54:12

Added a check for zero dimension bitmaps

diff --git a/src/FTBitmapGlyph.cpp b/src/FTBitmapGlyph.cpp
index bb3cd6c..948f78e 100755
--- a/src/FTBitmapGlyph.cpp
+++ b/src/FTBitmapGlyph.cpp
@@ -29,19 +29,22 @@ FTBitmapGlyph::FTBitmapGlyph( FT_Glyph glyph)
     destWidth = srcWidth;
     destHeight = srcHeight;
     
-    data = new unsigned char[srcPitch * destHeight];
-    
-    for(int y = 0; y < srcHeight; ++y)
+	if( destWidth && destHeight)
     {
-    	--destHeight;
-    	for(int x = 0; x < srcPitch; ++x)
-    	{
-			*( data + ( destHeight * srcPitch + x)) = *( source->buffer + ( y * srcPitch) + x);
-    	}    	
-    }
-
-    destHeight = srcHeight;
+		data = new unsigned char[srcPitch * destHeight];
+	    
+	    for(int y = 0; y < srcHeight; ++y)
+	    {
+	    	--destHeight;
+	    	for(int x = 0; x < srcPitch; ++x)
+	    	{
+				*( data + ( destHeight * srcPitch + x)) = *( source->buffer + ( y * srcPitch) + x);
+	    	}    	
+	    }
 
+	    destHeight = srcHeight;
+	}
+	
 	bBox = FTBBox( glyph);
 	advance = static_cast<float>(glyph->advance.x >> 16);
  	pos.x = bitmap->left;
@@ -55,13 +58,14 @@ FTBitmapGlyph::FTBitmapGlyph( FT_Glyph glyph)
 
 FTBitmapGlyph::~FTBitmapGlyph()
 {
-	delete[] data;
+	if( data)
+		delete [] data;
 }
 
 
 float FTBitmapGlyph::Render( const FT_Vector& pen)
 {
-	if( data != 0 )
+	if( data)
 	{
 		// Move the glyph origin
 		glBitmap( 0, 0, 0.0, 0.0, pen.x + pos.x, pen.y - pos.y, (const GLubyte *)0 );
diff --git a/src/FTPixmapGlyph.cpp b/src/FTPixmapGlyph.cpp
index 897fc54..d378aa9 100755
--- a/src/FTPixmapGlyph.cpp
+++ b/src/FTPixmapGlyph.cpp
@@ -32,26 +32,29 @@ FTPixmapGlyph::FTPixmapGlyph( FT_Glyph glyph)
     destWidth = srcWidth;
     destHeight = srcHeight;
     
-    data = new unsigned char[destWidth * destHeight * 4];
-    
-    // Get the current glColor.
-    float ftglColour[4];
-    glGetFloatv( GL_CURRENT_COLOR, ftglColour);
-    
-    for(int y = 0; y < srcHeight; ++y)
+    if( destWidth && destHeight)
     {
-    	--destHeight;
-    	for(int x = 0; x < srcWidth; ++x)
-    	{
-			*( data + ( destHeight * destWidth  + x) * 4 + 0) = static_cast<unsigned char>( ftglColour[0] * 255.0f);
-			*( data + ( destHeight * destWidth  + x) * 4 + 1) = static_cast<unsigned char>( ftglColour[1] * 255.0f);
-			*( data + ( destHeight * destWidth  + x) * 4 + 2) = static_cast<unsigned char>( ftglColour[2] * 255.0f);
-			*( data + ( destHeight * destWidth  + x) * 4 + 3) = static_cast<unsigned char>( ftglColour[3] * (*( source->buffer + ( y * srcPitch) + x)));
-    	}    	
-    }
-
-    destHeight = srcHeight;
-
+	    data = new unsigned char[destWidth * destHeight * 4];
+	    
+	    // Get the current glColor.
+	    float ftglColour[4];
+	    glGetFloatv( GL_CURRENT_COLOR, ftglColour);
+	    
+	    for(int y = 0; y < srcHeight; ++y)
+	    {
+	    	--destHeight;
+	    	for(int x = 0; x < srcWidth; ++x)
+	    	{
+				*( data + ( destHeight * destWidth  + x) * 4 + 0) = static_cast<unsigned char>( ftglColour[0] * 255.0f);
+				*( data + ( destHeight * destWidth  + x) * 4 + 1) = static_cast<unsigned char>( ftglColour[1] * 255.0f);
+				*( data + ( destHeight * destWidth  + x) * 4 + 2) = static_cast<unsigned char>( ftglColour[2] * 255.0f);
+				*( data + ( destHeight * destWidth  + x) * 4 + 3) = static_cast<unsigned char>( ftglColour[3] * (*( source->buffer + ( y * srcPitch) + x)));
+	    	}    	
+	    }
+
+	    destHeight = srcHeight;
+	}
+	
 	bBox = FTBBox( glyph);
 	numGreys = source->num_grays;
 	advance = glyph->advance.x >> 16;
@@ -66,13 +69,14 @@ FTPixmapGlyph::FTPixmapGlyph( FT_Glyph glyph)
 
 FTPixmapGlyph::~FTPixmapGlyph()
 {
-	delete[] data;
+	if( data)
+		delete [] data;
 }
 
 
 float FTPixmapGlyph::Render( const FT_Vector& pen)
 {
-	if( data != 0 )
+	if( data)
 	{
 		glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT);
 		
diff --git a/src/FTTextureGlyph.cpp b/src/FTTextureGlyph.cpp
index e7cfd17..858c6b0 100755
--- a/src/FTTextureGlyph.cpp
+++ b/src/FTTextureGlyph.cpp
@@ -26,25 +26,26 @@ FTTextureGlyph::FTTextureGlyph( FT_Glyph glyph, int id, int xOffset, int yOffset
 	// FIXME check the pixel mode
 	//ft_pixel_mode_grays
 	    
-	int srcWidth = source->width;
-	int srcHeight = source->rows;
-	int srcPitch = source->pitch;
+	int srcPitch = source->pitch;   
+    destWidth = source->width;
+    destHeight = source->rows;
     
-    destWidth = srcWidth;
-    destHeight = srcHeight;
-    
-    data = new unsigned char[destWidth * destHeight];
-
-    for(int y = 0; y < srcHeight; ++y)
+    // Not sure what the standard behavior should be here?
+    if( destWidth && destHeight)
     {
-    	for(int x = 0; x < srcWidth; ++x)
-    	{
-			*( data + ( y * destWidth  + x)) = *( source->buffer + ( y * srcPitch) + x);
-    	}    	
-    }
-
-	glBindTexture( GL_TEXTURE_2D, glTextureID);
-	glTexSubImage2D( GL_TEXTURE_2D, 0, xOffset, yOffset, destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, data);
+	    data = new unsigned char[destWidth * destHeight];
+
+	    for(int y = 0; y < destHeight; ++y)
+	    {
+	    	for(int x = 0; x < destWidth; ++x)
+	    	{
+				*( data + ( y * destWidth  + x)) = *( source->buffer + ( y * srcPitch) + x);
+	    	}    	
+	    }
+
+		glBindTexture( GL_TEXTURE_2D, glTextureID);
+		glTexSubImage2D( GL_TEXTURE_2D, 0, xOffset, yOffset, destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, data);
+	}
 
 
 //		0    
@@ -55,7 +56,7 @@ FTTextureGlyph::FTTextureGlyph( FT_Glyph glyph, int id, int xOffset, int yOffset
 //		+----+
 //		     1
 	
-	// FIXME ????
+	// Texture co-ords
 	uv[0].x = static_cast<float>(xOffset) / static_cast<float>(width);
 	uv[0].y = static_cast<float>(yOffset) / static_cast<float>(height);
 	uv[1].x = static_cast<float>( xOffset + destWidth) / static_cast<float>(width);
@@ -68,7 +69,8 @@ FTTextureGlyph::FTTextureGlyph( FT_Glyph glyph, int id, int xOffset, int yOffset
  	pos.x = bitmap->left;
 	pos.y = bitmap->top;
 	
-	delete [] data;
+	if( data)
+		delete [] data;
 	
 // discard glyph image (bitmap or not)
 	// Is this the right place to do this?