汉字点阵显示程序
/*
=========================================================
汉字点阵显示程序
读取汉字16×16点阵
源文件名: CC_FONT.CPP
Shuping Fu Chengdu College of Education Jan 1993
=========================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
FILE *cclibfp;
void ReadCCLIB(unsigned char high,unsigned char low,unsigned char *buf)
{
long p;
high=high-0xa0; /* 将内码高字节转换成区位码 */
low=low-0xa0; /* 将内码低字节转换成区位码 */
/* if(high>=15) high-=6; 对压缩了10-15区的字库,要此句.如王码系统 */
p=(long)((high-1)*94+low-1)*32; /* 计算出汉字在汉字库中的起始位置 */
fseek(cclibfp,p,SEEK_SET); /* 字库定位 */
fread(buf,sizeof(unsigned char),32,cclibfp); /* 读字库32个字节 */
}
void main(int argc,char *argv[])
{
unsigned char chn[2],buf[32];
char string[5];
unsigned long i16;
int i,j;
if(argc<2)
{
printf("\n\7格式: CC_FONT <汉字16点阵字库文件名>\n");
exit(0);
}
if((cclibfp=fopen(argv[1],"rb"))==NULL)
{
printf("\n\7不能打开汉字库文件");
exit(1);
}
while(1)
{
printf("\n输入一个汉字(E结束): ");
scanf("%s",chn);
if(chn[0]=='E' || chn[0]=='e')
break;
ReadCCLIB(chn[0],chn[1],buf);
printf("\n\n");
for(i=0;i<32;i+=2)
{
i16=buf[i]<<8 | buf[i+1];
itoa(i16,string,16);
for(j=0;j<4;j++)
string[j]=toupper(string[j]);
for(j=strlen(string);j<4;j++)
printf("0");
printf("%s ",string);
for(j=0;j<16;j++)
if(i16 & (0x8000>>j))
printf("■");
else
printf("□");
printf("\n");
}
printf("\n\n");
}
fclose(cclibfp);
}