Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

glyph.cpp

Go to the documentation of this file.
00001 #include "glyph.h"
00002 
00003 using namespace kerosin;
00004 
00005 Glyph::Glyph()
00006 {
00007     Reset();
00008 }
00009 
00010 bool Glyph::LoadGlyph(FT_Face face, unsigned int charCode)
00011 {
00012     int error = FT_Load_Char( face, charCode, FT_LOAD_RENDER);
00013 
00014     if (error)
00015     {
00016         return false;
00017     }
00018 
00019     Reset();
00020     
00021     mByteWidth = face->glyph->bitmap.width;
00022     mByteHeight = face->glyph->bitmap.rows;
00023 
00024     mData.reset(new unsigned char[mByteWidth*mByteHeight]);
00025 
00026     //printf("Glyph: '%c' %d\n", charCode, face->glyph->bitmap.pitch);
00027     //printf("  Res:    %dx%d\n", face->glyph->bitmap.width, face->glyph->bitmap.rows);
00028     for(int y=0; y<face->glyph->bitmap.rows; ++y)
00029     {
00030         for(int x=0; x<face->glyph->bitmap.width; ++x)
00031         {
00032             mData[y*mByteWidth + x] = face->glyph->bitmap.buffer[y*face->glyph->bitmap.pitch + x];
00033         }
00034     }
00035     mXOffset = face->glyph->metrics.horiBearingX >> 6;
00036     mYOffset = face->glyph->metrics.horiBearingY >> 6;
00037     mAdvance = face->glyph->advance.x >> 6;
00038     //printf("  Offset: %dx%d\n", mXOffset, mYOffset);
00039     //printf("  Advance:%d\n", mAdvance);
00040 
00041     return true;
00042 }
00043 
00044 void Glyph::Reset()
00045 {
00046     mByteWidth  = 0;
00047     mByteHeight = 0;
00048     mXOffset    = 0;
00049     mYOffset    = 0;
00050     mAdvance    = 0;
00051     mData.reset(NULL);
00052 }

Generated on Thu Apr 6 15:25:38 2006 for rcssserver3d by  doxygen 1.4.4