新闻中心

EEPW首页>嵌入式系统>设计应用> HZK16点阵字库程序

HZK16点阵字库程序

作者: 时间:2016-11-11 来源:网络 收藏
  1. /*******************************************************************************
  2. **程序名称:演示使用HZK16点阵字库的程序
  3. **程序描述:使用HZK16实现显示16*16点阵汉字
  4. **性能提升:
  5. **程序版本:V1.0
  6. **程序作者:syrchina
  7. **最后修改:2011年8月16日
  8. *******************************************************************************/
  9. #include
  10. /*******************************************************************************
  11. **函数名称:Bytes_Read_from_HZK16
  12. **函数描述:从字库文件中读取一个汉字的字模点阵数据
  13. **入口参数:unsigned char*s 指向目标汉字的指针,
  14. char*constchs 用于存储字模的数组首地址
  15. **出口参数:无
  16. *******************************************************************************/
  17. void Bytes_Read_from_HZK16(unsigned char*s,char*constchs)
  18. {
  19. FILE*fp;
  20. unsigned long offset;
  21. offset=((s[0]-0xa1)*94+(s[1]-0xa1))*32;//根据内码找出汉字在HZK16中的偏移位置
  22. if((fp=fopen("HZK16","r"))==NULL)return;//打开字库文件
  23. fseek(fp,offset,SEEK_SET);//文件指针偏移到要找的汉字处
  24. fread(chs,32,1,fp);//读取该汉字的字模
  25. fclose(fp);
  26. }
  27. /*******************************************************************************
  28. **函数名称:Bytes_Display
  29. **函数描述:在屏幕上显示一个汉字
  30. **入口参数:char*constchs 存储了汉字点阵数据的数组首地址
  31. **出口参数:无
  32. *******************************************************************************/
  33. void Bytes_Display(char*constchs)
  34. {
  35. inti,j;
  36. for(i=0;i<32;i++)//显示
  37. {
  38. if(i%2==0)printf("n");//每行两字节,16X16点阵
  39. for(j=7;j>=0;j--)
  40. {
  41. if(chs[i]&(0x1<
  42. {printf("O");}//由高到低,为1则输出O,反之输出-;
  43. else
  44. {printf("-");}
  45. }
  46. }
  47. }
  48. /*******************************************************************************
  49. **函数名称:main
  50. **函数描述:main 函数
  51. **入口参数:无
  52. **出口参数:无
  53. *******************************************************************************/
  54. intmain(void)
  55. {
  56. char chs[32];//16*16=256个点
  57. unsigned char s[]="中国";//要显示的汉字
  58. Bytes_Read_from_HZK16(&s[0],chs);//去字库中读取汉字字模
  59. Bytes_Display(chs);//在屏幕上显示这个汉字
  60. printf("n");
  61. Bytes_Read_from_HZK16(&s[2],chs);//去字库中读取汉字字模,注意每个汉字占2个char的存储空间
  62. Bytes_Display(chs);//在屏幕上显示这个汉字
  63. return 0;
  64. }


关键词:HZK16点阵字库程

评论


技术专区

关闭