FTPixmapGlyph.cxx

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     destWidth = srcWidth;
00024     destHeight = srcHeight;
00025     
00026     if( destWidth && destHeight)
00027     {
00028         data = new unsigned char[destWidth * destHeight * 2];
00029         unsigned char* src = bitmap.buffer;
00030 
00031         unsigned char* dest = data + ((destHeight - 1) * destWidth * 2);
00032         size_t destStep = destWidth * 2 * 2;
00033 
00034         for( int y = 0; y < srcHeight; ++y)
00035         {
00036             for( int x = 0; x < srcWidth; ++x)
00037             {
00038                 *dest++ = static_cast<unsigned char>(255);
00039                 *dest++ = *src++;
00040             }
00041             dest -= destStep;
00042         }
00043 
00044         destHeight = srcHeight;
00045     }
00046 
00047     pos.X(glyph->bitmap_left);
00048     pos.Y(srcHeight - glyph->bitmap_top);
00049 }
00050 
00051 
00052 FTPixmapGlyph::~FTPixmapGlyph()
00053 {
00054     delete [] data;
00055 }
00056 
00057 
00058 const FTPoint& FTPixmapGlyph::Render( const FTPoint& pen)
00059 {
00060     glBitmap( 0, 0, 0.0f, 0.0f, pen.X() + pos.X(), pen.Y() - pos.Y(), (const GLubyte*)0);
00061     
00062     if( data)
00063     {
00064         glPixelStorei( GL_UNPACK_ROW_LENGTH, 0);
00065         glPixelStorei( GL_UNPACK_ALIGNMENT, 2);
00066 
00067         glDrawPixels( destWidth, destHeight, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, (const GLvoid*)data);
00068     }
00069         
00070     glBitmap( 0, 0, 0.0f, 0.0f, -pos.X(), pos.Y(), (const GLubyte*)0);
00071 
00072     return advance;
00073 }

Generated on Tue Jul 5 14:16:16 2011 for ROOT_528-00b_version by  doxygen 1.5.1