获得位图之GBK
2013-04-08 17:34
120 查看
国标是的位码以0xA1为开始,区码也是以0XA1为开始。是16X16的点阵,根据位码-0XA1和区码-0XA1为索引
#include <config.h> #include <fonts_manager.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/mman.h> #include <unistd.h> static int GBKFontInit(char *pcFontFile, unsigned int dwFontSize); static int GBKGetFontBitmap(unsigned int dwCode, PT_FontBitMap ptFontBitMap); static T_FontOpr g_tGBKFontOpr = { .name = "gbk", .FontInit = GBKFontInit, .GetFontBitmap = GBKGetFontBitmap, }; static int g_iFdHZK; static unsigned char *g_pucHZKMem; static unsigned char *g_pucHZKMemEnd; static int GBKFontInit(char *pcFontFile, unsigned int dwFontSize) { struct stat tStat; if (16 != dwFontSize) { DBG_PRINTF("GBK can't support %d fontsize\n", dwFontSize); return -1; } g_iFdHZK = open(pcFontFile, O_RDONLY);//打开字体文件 if (g_iFdHZK < 0) { DBG_PRINTF("can't open %s\n", pcFontFile); return -1; } if(fstat(g_iFdHZK, &tStat))//获得文件的属性 { DBG_PRINTF("can't get fstat\n"); return -1; } g_pucHZKMem = (unsigned char *)mmap(NULL , tStat.st_size, PROT_READ, MAP_SHARED, g_iFdHZK, 0);//映射到内存 if (g_pucHZKMem == (unsigned char *)-1) { DBG_PRINTF("can't mmap for hzk16\n"); return -1; } g_pucHZKMemEnd = g_pucHZKMem + tStat.st_size;//结束地址 return 0; } static int GBKGetFontBitmap(unsigned int dwCode, PT_FontBitMap ptFontBitMap) { int iArea; int iWhere; int iPenX = ptFontBitMap->iCurOriginX; int iPenY = ptFontBitMap->iCurOriginY; DBG_PRINTF("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__); if (dwCode & 0xffff0000) { DBG_PRINTF("don't support this code : 0x%x\n", dwCode); return -1; } iArea = (int)(dwCode & 0xff) - 0xA1;//获得区吗索引 iWhere = (int)((dwCode >> 8) & 0xff) - 0xA1;//获得位码索引 if ((iArea < 0) || (iWhere < 0)) { DBG_PRINTF("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__); return -1; } //坐标转化,把笛卡尔坐标(原点右下脚)转化为LCD坐标(原点左下角), ptFontBitMap->iXLeft = iPenX; ptFontBitMap->iYTop = iPenY - 16; ptFontBitMap->iXMax = iPenX + 16; ptFontBitMap->iYMax = iPenY; ptFontBitMap->iBpp = 1; ptFontBitMap->iPitch = 2; ptFontBitMap->pucBuffer = g_pucHZKMem + (iArea * 94 + iWhere)*32;//获得字体点阵 if (ptFontBitMap->pucBuffer >= g_pucHZKMemEnd) { return -1; } ptFontBitMap->iNextOriginX = iPenX + 16; ptFontBitMap->iNextOriginY = iPenY; DBG_PRINTF("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__); return 0; } int GBKInit(void) { return RegisterFontOpr(&g_tGBKFontOpr);//加入链表 }
相关文章推荐
- 如何获得Image控件中的位图数组?
- 使用不安全代码将 Bitmap 位图转为 WPF 的 ImageSource 以获得高性能和持续小的内存占用
- 获得位图之点阵
- 获得位图的信息
- 获得位图之freetype
- DC/画线/获得窗口指针/画刷/位图
- MFC下获得位图句柄的方法
- 获得位图非屏蔽色/屏蔽色区域的算法
- 加载位图,获得bitmapData
- PHP中GBK和UTF8编码处理
- C#中RichTextBox获得当前行号的方法
- vc获得显示屏幕大小
- 主打陌生人社交约你妹获得千万级天使投资
- jquery获得iframe内容的高度
- (转)PL/SQL编辑数据"这些查询结果不可更新,请包括ROWID或使用SELECT...FOR UPDATE获得可更新结果"处理
- jQuery - 获得内容和属性
- Inside VCL:接口指针调用函数的时候,如何获得对象指针以完成函数调用?
- 位图按钮
- 微软终于获得UI设计之道了?
- Service层进行事务管理,Dao层获得session进行事务处理抛异常的情况