Main Page | Class Hierarchy | Data Structures | File List | Data Fields | Globals

FTBitmapGlyph.cpp

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

Generated on Sun Dec 5 22:24:05 2004 for FTGL by doxygen 1.3.6