00001 #include <string>
00002
00003 #include "FTBitmapGlyph.h"
00004
00005 FTBitmapGlyph::FTBitmapGlyph( FT_Glyph glyph)
00006 : FTGlyph( glyph),
00007 destWidth(0),
00008 destHeight(0),
00009 data(0)
00010 {
00011 err = FT_Glyph_To_Bitmap( &glyph, ft_render_mode_mono, 0, 1);
00012 if( err || ft_glyph_format_bitmap != glyph->format)
00013 {
00014 return;
00015 }
00016
00017 FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph;
00018 FT_Bitmap* source = &bitmap->bitmap;
00019
00020 unsigned int srcWidth = source->width;
00021 unsigned int srcHeight = source->rows;
00022 unsigned int srcPitch = source->pitch;
00023
00024 destWidth = srcWidth;
00025 destHeight = srcHeight;
00026 destPitch = srcPitch;
00027
00028 if( destWidth && destHeight)
00029 {
00030 data = new unsigned char[destPitch * destHeight];
00031 unsigned char* dest = data + (( destHeight - 1) * destPitch);
00032
00033 unsigned char* src = source->buffer;
00034
00035 for( unsigned int y = 0; y < srcHeight; ++y)
00036 {
00037 memcpy( dest, src, srcPitch);
00038 dest -= destPitch;
00039 src += srcPitch;
00040 }
00041 }
00042
00043 pos.x = bitmap->left;
00044 pos.y = static_cast<int>(srcHeight) - bitmap->top;
00045
00046 FT_Done_Glyph( glyph );
00047 }
00048
00049
00050 FTBitmapGlyph::~FTBitmapGlyph()
00051 {
00052 delete [] data;
00053 }
00054
00055
00056 float FTBitmapGlyph::Render( const FTPoint& pen)
00057 {
00058 if( data)
00059 {
00060 glBitmap( 0, 0, 0.0, 0.0, pen.x + pos.x, pen.y - pos.y, (const GLubyte*)0 );
00061
00062 glPixelStorei( GL_UNPACK_ROW_LENGTH, destPitch * 8);
00063 glBitmap( destWidth, destHeight, 0.0f, 0.0, 0.0, 0.0, (const GLubyte*)data);
00064
00065 glBitmap( 0, 0, 0.0, 0.0, -pen.x - pos.x, -pen.y + pos.y, (const GLubyte*)0 );
00066 }
00067
00068 return advance;
00069 }