When we write some application software, in order to make the software more popular and easy to learn and use, the user interface with Chinese characters is an essential condition. In text mode, as long as the support of Chinese character operating system, it is not a problem to display Chinese characters. Just use printf or cprintf. #include void Main () {printf ("I'm learning C!") ");}
Displaying Chinese characters in graphical mode is a bit of a hassle. Fortunately, there are a lot of people engaged in the study of this problem, and developed a number of functions for Chinese character display. These functions do not require the support of the Chinese character system, but use the font files. such as Ucdos's HZK16.
The first step in Chinese character display is to open the font file.
Function:
int OpenHz(const char *Hz16Path); 功能:打开字库文件Hz16Pathint handle; /*打开的字库文件指针*/
int OpenHz(const char *Hz16Path)
{
return (handle=open(Hz16Path,O_RDONLY|O_BINARY));
}
After opening the font file, you can use the function described below to display the 16-point array of Chinese characters.
Function:
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);
}