freetype应用范例
2015-11-20 13:27
225 查看
//------------------------------------------------------------------------------------- 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); }
相关文章推荐
- 故障案例:phpadmin点击打开一个数据库卡死
- iOS- 详解文本属性Attributes
- supervisor提高nodejs调试效率
- zip文件解压读取
- Office 365 系列二 ------- 如何批量部署Office 客户端
- confluence
- Android React Native的使用细节问题
- NSMutableParagraphStyle /NSParagraphStyle 文本属性Attributes
- 更改状态栏颜色
- MySQL学习-常用命令整理
- 哈工大物联网感知技术学习心得
- 量价齐动 央行多管齐下维稳资金面
- Eclipse设置提示
- C#根据文件流判断文件类型
- 数字证书原理,公钥私钥加密原理
- 在Linux 上,编写一个每秒接收 100万UDP数据包的程序究竟有多难?
- 用JS实现了一个简单的计算器。
- css引入特殊字体
- 基于HTML5的可预览多图片Ajax上传
- POJ 2002 Squares