Added a check for zero dimension bitmaps
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
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?