这个类实现了把一个字符串转成RGB点阵,RGB转YUV,和把RGB点阵保存成BMP文件。点阵数据可以直接往其他背景上叠加。
TextToImageFT::TextToImageFT(void)
{
m_rgb24Buff = NULL;
m_yuvBuff = NULL;
expanded_data = NULL;
}
TextToImageFT::~TextToImageFT(void)
{
if(m_rgb24Buff)
free(m_rgb24Buff);
m_rgb24Buff = NULL;
if(m_yuvBuff)
free(m_yuvBuff);
m_yuvBuff = NULL;
if(expanded_data)
free(expanded_data);
expanded_data = NULL;
}
int TextToImageFT::InitFT(const char * fname, unsigned int nHeight)
{
ftHeiht = nHeight;
//初始化FreeType库..
if (FT_Init_FreeType( &ftLibrary ))
{
printf("FT_Init_FreeType failed");
return -1;
}
//加载一个字体,取默认的Face,一般为Regualer
if (FT_New_Face( ftLibrary, fname, 0, &ftFace))
{
printf("FT_New_Face failed (there is probably a problem with your font file)");
return -1;
}
//大小要乘64.这是规定。照做就可以了。
FT_Set_Char_Size(ftFace,ftHeiht << 6, ftHeiht << 6, 96, 96);
#if 0
FT_Matrix matrix;
FT_Vector pen;
//给它设置个旋转矩阵
float angle = (float) -0/180.* 3.14;
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
FT_Set_Transform( ftFace, &matrix, &pen );
#endif
return 0;
}
int TextToImageFT::FreeFT()
{
FT_Done_Face(ftFace);
FT_Done_FreeType(ftLibrary);