读UCDOS显示字库的程序
#include<mmsystem.h> //Project菜单/Settings/Progect Settings /Link / Object/Library Modules 加入Winmm.lib //通用控制 则加入COMCTL32.LIB
/****************************************************************** 从UCDOS的字库文件取得字模 李方君(bzyy@21cn.com) ASCII字模从ASC16文件中 汉字从HZK16文件中取得
后面的显示部分没有用,只是验证读出的数据是否正确【已经调试通过】 ******************************************************************/
//全局变量定义 #define ZM_CACHE_LONG 16384 //字模文件缓冲
#define ASC16NAME "asc16" #define HZK16NAME "hzk16"
//char szFileName[_MAX_PATH] ; //完整的驱动器,路径,加文件名 //char szTitleName[_MAX_FNAME + _MAX_EXT] ;//文件名本身
HMMIO m_hZM_ASC16; HMMIO m_hZM_HZK16;
//unsigned char cAsc16Cache[ZM_CACHE_LONG]; //unsigned char cHzk16Cache[ZM_CACHE_LONG];
unsigned char asczm[16]; unsigned char hzkzm[32]; /*************/ //文件I/O /*************/ BOOL OpenZMFile () { m_hZM_ASC16 = mmioOpen(ASC16NAME,NULL,MMIO_READ | MMIO_COMPAT | MMIO_ALLOCBUF ); m_hZM_HZK16 = mmioOpen(HZK16NAME,NULL,MMIO_READ | MMIO_COMPAT | MMIO_ALLOCBUF );
if (m_hZM_ASC16 == NULL || m_hZM_ASC16 == NULL) { return false; }
return true; }
BOOL CloseZMFile () { mmioClose(m_hZM_ASC16,MMIO_FHOPEN); mmioClose(m_hZM_HZK16,MMIO_FHOPEN); return true; }
BOOL GetZM_ASC16(unsigned char asciinum, unsigned char * zmbuf) //ASCII码值 16字节字模缓冲区(ASCII字模是8×16结构的) { int startpoit; //字符首地址 startpoit = asciinum * 16; mmioSeek (m_hZM_ASC16 , startpoit , SEEK_SET);//字模位置定位 mmioRead (m_hZM_ASC16 , (char *)zmbuf , 16); return true; }
BOOL GetZM_HZK16(unsigned char * hznum, unsigned char * zmbuf) { // unsigned char hz[] = "李"; int qm,wm,startpoit; qm= hznum[0]; /*通过区位码计算其在hzk16f文件中的偏移地址*/ qm=qm-161; if (qm>87) return false; wm=hznum[1]; wm=wm-161; if (wm>94) return false; startpoit=((long) qm * 94 + wm ) * 32; mmioSeek (m_hZM_HZK16,startpoit,SEEK_SET);//定位 mmioRead (m_hZM_HZK16,(char *)zmbuf , 32); //16*16点阵对应32个字节
return true; }
/*/////////////////////////////////// 试验性显示,用于验证读出的数据是否正确 ///////////////////////////////////*/
#define rgbGRIDDING RGB(34,19,172) //网格色 #define rgbZMDOT RGB(150,150,160) //字模点阵色 #define rgbBACK RGB(255,0,0) //点底色
HPEN colGridding ; //网格色 HPEN colZMdot; //字模点阵色 HBRUSH hZMBrush;
void DrawInit() { colGridding = CreatePen(PS_SOLID,1,rgbGRIDDING);//网格色PS_DOT colZMdot = CreatePen(PS_SOLID,1,rgbZMDOT); //字模点阵色 hZMBrush = CreateSolidBrush(rgbBACK); return; }
void DrawGridding(HDC hdc,int startx,int starty,int wn,int hn,int r = 4) //画网格 左上角起始坐标 每行格子数 每列格子数 格子内宽(即不含边线的宽) { int topx = startx,topy = starty, bottomx = startx + wn * (r + 1),bottomy = starty + hn * (r + 1); //格子现宽为1 int i,wkx,wky; SelectObject(hdc,colGridding);
for(i = 0 ; i < wn + 1 ; i ++) //画列线 { wkx = topx + i * ( r + 1 );//计算每根列线横座标 MoveToEx( hdc , wkx,topy , NULL ) ; LineTo(hdc, wkx, bottomy); }
for(i = 0 ; i < hn + 1 ; i ++) //画行线 { wky = topy + i * ( r + 1 );//计算每根行线纵座标 MoveToEx( hdc , topx,wky , NULL ) ; LineTo(hdc, bottomx , wky); }
return; }
void DrawFillBox(HDC hdc,int stx,int sty ,int r = 4) //填充格子 (包含左边列线) { SelectObject(hdc,hZMBrush); SelectObject(hdc,colZMdot); Rectangle(hdc,stx + 1,sty + 1,stx + 1 + r,sty + 1 + r);//画矩形 return; }
void DrawByteLine(HDC hdc, unsigned char db, int stx, int sty ,int r = 4) //画一个字节 字节 起始坐标(包含左边列线) 点宽 { int wkx,wky; wkx = stx ; //第一个点画位置(包含左边列线) wky = sty ; //同上 int k;
unsigned char wtest = 128; //从第一位起 for (k = 0 ; k < 8 ; k ++) //测试每位的有无 { if (wtest & db) DrawFillBox(hdc,wkx,wky,r); wtest = wtest / 2; wkx = wkx + r + 1 ;//横坐标自增 } return; }
BOOL DrawAsc16(HDC hdc, unsigned char * zmbuf, int stx, int sty , int r = 4) { int wkx,wky; wkx = stx ; //第一个点画位置(包含左边列线) wky = sty ; //同上 int i;
for (i = 0 ; i < 16 ; i ++) //每个ASCII字模有16个字节 { DrawByteLine(hdc,zmbuf,wkx,wky,r); wky = wky + r +1; }
return true; }
BOOL DrawHzk16(HDC hdc, unsigned char * zmbuf, int stx, int sty , int r = 4) { int wkx,wky; wkx = stx ; //第一个点画位置(包含左边列线) wky = sty ; //同上 int i;
for (i = 0 ; i < 32 ; i ++) //每个HZK16字模有32个字节 分成16行 { DrawByteLine(hdc,zmbuf,wkx,wky,r); //一行的第一个字节 i ++; DrawByteLine(hdc,zmbuf,wkx + 8 * (r + 1),wky,r); //一行的第二个字节 wky = wky + r +1; }
return true; }
BOOL ZMPreview(HDC hdc, int x,int y ) { MoveToEx( hdc , x,y , NULL ) ;//定位线 LineTo(hdc, x-10, y); MoveToEx( hdc , x,y , NULL ) ; LineTo(hdc, x, y-10);
int zmr = 10;//字模点阵宽 DrawGridding(hdc,x,y,16,16,zmr); //DrawAsc16(hdc,asczm , x, y ,zmr); //a1 DrawHzk16(hdc,hzkzm , x, y ,zmr);
//DrawByteLine(hdc, 201, x, y,zmr);//测试单字节显示 //unsigned char a1[16] = {170,0,170,201,170,201,0,0,170,201,170,201,0,0,170,201}; return true; } |