您的位置:首页 > 其它

获得位图之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);//加入链表
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: