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