freetype应用范例

//-------------------------------------------------------------------------------------
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);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路漫漫其修远.

你的鼓励是我寻找真相的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值