Main Page | File List | File Members

FTPixmapGlyph.cpp

Go to the documentation of this file.
00001 #include "FTPixmapGlyph.h" 00002 00003 FTPixmapGlyph::FTPixmapGlyph( FT_GlyphSlot glyph) 00004 : FTGlyph( glyph), 00005 destWidth(0), 00006 destHeight(0), 00007 data(0) 00008 { 00009 err = FT_Render_Glyph( glyph, FT_RENDER_MODE_NORMAL); 00010 if( err || ft_glyph_format_bitmap != glyph->format) 00011 { 00012 return; 00013 } 00014 00015 FT_Bitmap bitmap = glyph->bitmap; 00016 00017 //check the pixel mode 00018 //ft_pixel_mode_grays 00019 00020 int srcWidth = bitmap.width; 00021 int srcHeight = bitmap.rows; 00022 00023 // FIXME What about dest alignment? 00024 destWidth = srcWidth; 00025 destHeight = srcHeight; 00026 00027 if( destWidth && destHeight) 00028 { 00029 data = new unsigned char[destWidth * destHeight * 4]; 00030 00031 // Get the current glColor. 00032 float ftglColour[4]; 00033 glGetFloatv( GL_CURRENT_COLOR, ftglColour); 00034 00035 unsigned char redComponent = static_cast<unsigned char>( ftglColour[0] * 255.0f); 00036 unsigned char greenComponent = static_cast<unsigned char>( ftglColour[1] * 255.0f); 00037 unsigned char blueComponent = static_cast<unsigned char>( ftglColour[2] * 255.0f); 00038 00039 unsigned char* src = bitmap.buffer; 00040 00041 unsigned char* dest = data + ((destHeight - 1) * destWidth) * 4; 00042 size_t destStep = destWidth * 4 * 2; 00043 00044 if( ftglColour[3] == 1.0f) 00045 { 00046 for( int y = 0; y < srcHeight; ++y) 00047 { 00048 for( int x = 0; x < srcWidth; ++x) 00049 { 00050 *dest++ = redComponent; 00051 *dest++ = greenComponent; 00052 *dest++ = blueComponent; 00053 *dest++ = *src++; 00054 } 00055 dest -= destStep; 00056 } 00057 } 00058 else 00059 { 00060 for( int y = 0; y < srcHeight; ++y) 00061 { 00062 for( int x = 0; x < srcWidth; ++x) 00063 { 00064 *dest++ = redComponent; 00065 *dest++ = greenComponent; 00066 *dest++ = blueComponent; 00067 *dest++ = static_cast<unsigned char>(ftglColour[3] * *src++); 00068 } 00069 dest -= destStep; 00070 } 00071 } 00072 00073 destHeight = srcHeight; 00074 } 00075 00076 pos.x = glyph->bitmap_left; 00077 pos.y = srcHeight - glyph->bitmap_top; 00078 } 00079 00080 00081 FTPixmapGlyph::~FTPixmapGlyph() 00082 { 00083 delete [] data; 00084 } 00085 00086 00087 float FTPixmapGlyph::Render( const FTPoint& pen) 00088 { 00089 if( data) 00090 { 00091 // Move the glyph origin 00092 glBitmap( 0, 0, 0.0f, 0.0f, pen.x + pos.x, pen.y - pos.y, (const GLubyte*)0); 00093 00094 glPixelStorei( GL_UNPACK_ROW_LENGTH, 0); 00095 00096 glDrawPixels( destWidth, destHeight, GL_RGBA, GL_UNSIGNED_BYTE, (const GLvoid*)data); 00097 00098 // Restore the glyph origin 00099 glBitmap( 0, 0, 0.0f, 0.0f, -pen.x - pos.x, -pen.y + pos.y, (const GLubyte*)0); 00100 } 00101 00102 return advance; 00103 }

Generated on Wed Aug 18 19:46:15 2004 for FTGL by doxygen 1.3.7