1
#include "FTPixmapGlyph.h"
3
FTPixmapGlyph::FTPixmapGlyph( FT_GlyphSlot glyph)
9
err = FT_Render_Glyph( glyph, FT_RENDER_MODE_NORMAL);
10
if( err || ft_glyph_format_bitmap != glyph->format)
15
FT_Bitmap bitmap = glyph->bitmap;
17
//check the pixel mode
20
int srcWidth = bitmap.width;
21
int srcHeight = bitmap.rows;
23
// FIXME What about dest alignment?
25
destHeight = srcHeight;
27
if( destWidth && destHeight)
29
data = new unsigned char[destWidth * destHeight * 4];
31
// Get the current glColor.
33
// glGetFloatv( GL_CURRENT_COLOR, ftglColour);
34
ftglColour[0] = ftglColour[1] = ftglColour[2] = ftglColour[3] = 1.0;
36
unsigned char redComponent = static_cast<unsigned char>( ftglColour[0] * 255.0f);
37
unsigned char greenComponent = static_cast<unsigned char>( ftglColour[1] * 255.0f);
38
unsigned char blueComponent = static_cast<unsigned char>( ftglColour[2] * 255.0f);
40
unsigned char* src = bitmap.buffer;
42
unsigned char* dest = data + ((destHeight - 1) * destWidth) * 4;
43
size_t destStep = destWidth * 4 * 2;
45
if( ftglColour[3] == 1.0f)
47
for( int y = 0; y < srcHeight; ++y)
49
for( int x = 0; x < srcWidth; ++x)
51
*dest++ = redComponent;
52
*dest++ = greenComponent;
53
*dest++ = blueComponent;
61
for( int y = 0; y < srcHeight; ++y)
63
for( int x = 0; x < srcWidth; ++x)
65
*dest++ = redComponent;
66
*dest++ = greenComponent;
67
*dest++ = blueComponent;
68
*dest++ = static_cast<unsigned char>(ftglColour[3] * *src++);
74
destHeight = srcHeight;
77
pos.x = glyph->bitmap_left;
78
pos.y = srcHeight - glyph->bitmap_top;
82
FTPixmapGlyph::~FTPixmapGlyph()
88
float FTPixmapGlyph::Render( const FTPoint& pen)
94
dx= floor( (pen.x + pos.x ) );
95
dy= ( (pen.y - pos.y ) );
97
// Move the glyph origin
98
glBitmap( 0, 0, 0.0f, 0.0f, dx, dy, (const GLubyte*)0);
100
glPixelStorei( GL_UNPACK_ROW_LENGTH, 0);
102
glDrawPixels( destWidth, destHeight, GL_RGBA, GL_UNSIGNED_BYTE, (const GLvoid*)data);
104
// Restore the glyph origin
105
glBitmap( 0, 0, 0.0f, 0.0f, -dx, -dy, (const GLubyte*)0);