当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
图形模式下的汉字显示
发布时间:2010/8/4 10:32:22 来源:城市学习网 编辑:ziteng
  #include void main(){printf(\"我正在学习C语言!\");}
  在图形模式下显示汉字就稍稍麻烦些。可幸的是有很多人从事这一问题的研究,并开发了一些用于汉字显示的函数。这些函数不需要汉字系统的支持,但用到其中的字库文件。如UCDOS的HZK16。
  汉字显示的第一步是打开字库文件。
  函数: int OpenHz(const char *Hz16Path); 功能:打开字库文件Hz16Pathint handle; /*打开的字库文件指针*/int OpenHz(const char *Hz16Path){return (handle=open(Hz16Path,O_RDONLY|O_BINARY));} 打开字库文件后,就可以用下面介绍的函数显示16点阵的汉字。
  函数: int WrtHz16(int x,int y,int z,int color,char *p); 功能:在(x,y)用color颜色显示汉字串p,汉字之间的空格数为z。intWrtHz16(int x, int y,int z,int color,char *p)
  {
  unsigned int i,c1,c2,f=0; /*x,y:write at (x,y);*/
  int rec,i1,i2,i3; /*z:space between;*/
  long l; /*color:txt color*/
  char by[32]; /*p:HZ str*/
  if( handle<0 ) return -1; while((i=*p++)!=0){
  if(i>0xa1)
  if(f==0){
  c1=(i-0xa1)&0x07f;
  f=1;
  }
  else{
  c2=(i-0xa1)&0x07f;
  f=0;
  rec=c1*94+c2;
  l=rec*32L;
  lseek(handle,l,SEEK_SET);
  read(handle,by,32);
  for(i1=0;i1<16;i1++)
  for(i2=0;i2<2;i2++)
  for(i3=0;i3<8;i3++)
  if(GetBit(by[i1*2+i2],7-i3))
  putpixel(x+i2*8+i3,y+i1,color);
  x=x+z+16;
  }
  }
  return(x);
  }
  函数GetBit定义如下:
  函数: int GetBit(unsigned char c,int n); 功能:取得汉字的点阵数据。
  int GetBit(unsigned char c,int n)
  {
  return((c>>n)&1);
  }
  汉字显示结束,应该关闭字库文件。
  void CloseHz(void)
  {
  close( handle );
  }
  #include \"\\Caic\\Include\\Hz.h\"
  #include
  #include const char* Hz16Path = \"\\\\UCDOS\\\\Hzk16.\";
  const char* HzStr = \"苦丁香C语言辅助学习软件\";
  void main(){
  int gr=DETECT,gm;
  initgraph(&gr,&gm,\"\\\\Caic\\\\Bgi\");
  OpenHz( Hz16Path );
  Wrt16Hz(20,20,4,RED,HzStr);
  CloseHz();
  getch();
  closegraph();
  }显示24点阵及放大汉字
  下面探讨一下如何显示24点阵及放大汉字。24点阵字库也可在任意一种汉字系统中找到。如UCDOS的HZK24S [NextPage]   函数: int WrtHz24(int x,int y,int z,int color,int m,\\int n,char *p); 功能:显示24点阵及放大汉字。
  int WrtHz24(int x,int y,int z,int color,int m,int n,char *p)
  {
  unsigned int i,c1,c2,f=0; /*z: 汉字字符间的空格*/
  int i1,i2,i3,i4,i5,rec; /*x,y: 先是位置(x,y)*/
  long l; /*color:汉字颜色*/
  char by[72]; /*m: x 方向的放大倍数*/
  /*n: y 方向的放大倍数*/
  if( handle<0 ) return -1; /*p: 显示汉字串*/ while((i=*p++)!=0){
  if(i>0xa1)
  if(f==0){
  c1=(i-0xa1)&0x7f;
  f=1;
  }
  else{
  c2=(i-0xa1)&0x7f;
  f=0;
  rec=(c1-15)*94+c2;
  l=rec*72L;
  lseek(handle,l,SEEK_SET);
  read(handle,by,72);
  for(i1=0;i1<24*m;i1=i1+m)
  for(i4=0;i4
  for(i2=0;i2<=2;i2++)
  for(i3=0;i3<8;i3++)
  if(GetBit(by[i1/m*3+i2],7-i3))
  for(i5=0;i5
  putpixel(x+i1+i4,y+i2*8*n+i3*n+i5,color);
  x=x+24*m+z;
  }
  }
  return(x);
  } 使用Wrt24Hz的例子:#include \"\\Caic\\Include\\Hz.h\"
  #include
  #include const char* Hz24Path = \"C:\\\\Ucdos\\\\fnt\\\\hzk24s.\"
  const char* HzStr = \"苦丁香C语言辅助学习软件\";
  void main(){
  int gr=DETECT,gm;
  initgraph(&gr,gm,\"\\\\Caic\\\\Bgi\");
  OpenHz( Hz24Path );
  Wrt24Hz(20,20, /*先是在(x,y)*/
  4, /*汉字间的空格为4*/
  RED, /*用红色显示*/
  2, /*x 方向放大2倍*/
  4, /*y 方向放大4倍*/
  HzStr); /*显示字符串*/
  CloseHz();
  getch();
  closegraph();
  }
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved