//-------------------------------------------------------------------------------------
void LoadTextBitmap(RGN_HANDLE Handle, BITMAP_S *pstBitmap, int size, unsigned short* incode, int len)
{
FT_Library pFTLib =NULL;
FT_Face pFTFace = NULL;
FT_Glyph glyph;
FT_UInt glyph_index;
FT_Error error = 0;
int i = 0;
len /= 2;
if (len < 1)
return;
error = FT_Init_FreeType(&pFTLib);
if(error){
return;
}
error = FT_New_Face(pFTLib, "./simsun.ttf", 0, &pFTFace);
if(error){
return;
}
if(0 !=FT_Set_Char_Size(pFTFace, 0, size<<6, 300, 300)){
return;
}
FT_Bitmap *bitmap = malloc(sizeof(FT_Bitmap)*len);
FT_BitmapGlyph bitmap_glyph;
int totalSize = 0;
int totalWidth = 0;
for (i=0; i<len; i++){
glyph_index =FT_Get_Char_Index(pFTFace, incode[i]);
FT_Load_Glyph(pFTFace, glyph_index, FT_LOAD_DEFAULT);
error =FT_Get_Glyph(pFTFace->glyph, &glyph);
if (error){
return;
}
FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 0);
bitmap_glyph = (FT_BitmapGlyph)glyph;
bitmap[i] = bitmap_glyph->bitmap;
totalSize += bitmap[i].width * bitmap[i].rows;
totalWidth += (bitmap[i].width);
int w = bitmap[i].width;
int h = bitmap[i].rows;
int j,k;
for (k=0; k<h; k++){
for (j=0; j<w; j++){
if((bitmap[i].buffer[k * w + j]) == 0 ){
printf("0");
}else{
printf("1");
}
}
printf("\n");
}
}
pstBitmap->pData = calloc(1, totalSize*2);
if (NULL == pstBitmap->pData){
return;
}
pstBitmap->enPixelFormat = PIXEL_FORMAT_RGB_1555;
pstBitmap->u32Width = totalWidth;
pstBitmap->u32Height = bitmap[0].rows;
int j,k;
unsigned short *pDst = pstBitmap->pData;
char *pSrc;
int h = bitmap[0].rows;
int off_j = 0;
for (k=0; k<h; k++){
off_j=0;
for (i=0; i<len; i++){
int w = bitmap[i].width;
for (j=0; j<w; j++){
if((bitmap[i].buffer[k * w + j]) == 0 ){
printf("0");
pDst[k*totalWidth+off_j+j] = 0;
}else{
pDst[k*totalWidth+off_j+j] = 0xEFFF;
printf("1");
}
}
off_j += w;
}
printf("\n");
}
free(pstBitmap->pData);
free(bitmap);
}