|
||||
在西文环境下制作小字库显示汉字编程上海市浦东沈家弄路340号 计算中心(200120) 魏为民 |
|
众所周知,为了在西文环境下显示汉字至少要有一个汉字库,汉字库一般比较大, 而其实所需要显示的汉字并不多。这样我们可以把所要显示的汉字字模从字库中取出来, 放到一个小的字库文件中。 用Turbo C语言在西文环境下显示汉字有三种方法:直接写视频缓冲区Vid eo-buffer;读字库字模,利用Putpixel()画点方式写汉字;读字库 字模,利用setlinestyle()用户定义方式结合line()画线方式写汉 字。其中方法1显示速度快但系统兼容性差,方法2较为普及,方法3最适宜于16×1 6点阵字库。本文采用第3种方法。 本文中Filter.c将源程序中的汉字过滤存放到文件INPUT-DAT.T XT中;Make-hzk.c将文件INPUT-DAT.TXT中汉字对应的16× 16点阵字库字模存放到小字库文件SCCLIB.DOT中;Show-hzk.c显 示小字库文件SCCLIB16.DOT内容。 16×16点阵字库可以是任何一个汉字系统下的16×16点阵字库。所有程序在 Herc/CGA/EGA/VGA模式PC/XT/286/386上通过。* Fi lter.C V1.13 93.8.28* * Function * Filter the chinese characters form a C source file* Usage * Filter c source file Out file * #imclude <stdio.h> #include <stdlib.h> #defile CR OxOa FILE *InFile,*OutFile; main(int argc,char *argvll) { int ch, iOutFile=0; if(argc !=3){ Printf(“\n 007USAGE:FILTER C source file Out file\n”); exit(1); { if((InFile=fopen(argv[1],“r”))==NULL) { printf(“\n 007Can’t open the Csourc e file\n”); exit(1); } if((OutFile=fopen(argv[2],“w”))==NULL) } printf(“\n 007Can’t open the output f ile INPUT DAT.TXT\m”); exit(1); { while ((ch=fgetc(InFile))!=EOF) { if((ch>Oxal)&&(ch<Oxfe)) { fputc(ch,OutFile); ch=fget,(InFile); fputc(ch,OutFile); i OutFile++; if (!(i OutFile % 20))fputc(CR,OutF ile); } } fclose(InFile); fclose(OutFile); } /* * Make hxk.C V1.13 93.8.28 * * Function * Make chinese character dot libfile * Usage * MAKE HZK In file Out file * Example * Files * C:\CCLIBJ.DOT 16×16 dot lib file * INPUT DAT.TXT Input text file * SCCLIB16.DOT OutPut 16×16 dotlib fi le * SeeAlso * Bugs * 16×16 chinese dot lib * #include <sldio.h> #include <sldkib.h> FILE *InFile,*OutFile,*CclibFile,*fopen ();ain(int argc,char *argv[]) { int ch; unsigned char buf[32]; unsigned char high byte,low byte; long p; if argc !=3){ printf(“\n\007USAGE:MAKE HZKIn fil e Out file\n”); print(“In file:Input chiese charac ter text file INPUT DAT.TXT\n”); printf(“Out file:Output smallchine se character lib SCCLIB16.DOT\n”); exit(1); } if((InFile=fopen(argv[1],“r”))==NULL) { print(“\\007Can’t open the input ch inese character”); printf(“text file INPUT DAT.TXT\n”) ; exit(1); } if((OutFile=fopen(argv[2],“eb”))==NUL L”){ printf(“\n\007Can’t open the output small chinese character”); printf(“lib file SCCLIB16.DOT\n”); exit(1); } if((CclibFile=fopen(“C:\CCLIBJ.DOT“,” “rb”))==NULL) PRINT(“\nCan not open CCLIB!\n\007” ); EXIT(1); } fseek(OutFile,0,0); while(! feof(InFile)){ ch=fgetr(InFile); if(ch>=Oxal && ch<=Oxfo){ high byte=ch; low byte=fgetc(InFile); p=high byte-Oxal; if (P>=15 )p-=6; p=p*94*low byte-Oxal; fseek(CclibFile,(long)p*32,SEEK SET ); FREAD(buf,sizeof(unsigned char),32, CclibFile); fwrite(buf,sizeof(unsigned char),32 ,OutFile); } } fclose(InFile); fcloce(OutFile); fclose(CclibFile); * * Show hzk.C V1.13 93.8.28 * * Function * Show MAKE HZK.EXE make lib fileconte nt* Usage * Show hzk SCCLIB16.DOT * Seealso * Turbo C * setlinestyle(USERBIT LINE,upattern ,NORM WIDTH);* LINE(); * Bugs * 16×16chinese dot */ #include <stdoio.h> #include <stdlib.h> #include <graphics.h> #include <string.h> #include <ctype.h> #defile MaxBufSize 2048 #defile SPACE Ox20 #defile CR OxOa FILE *Lib dat File; main(int argc, char *argv[]) { long I offset; unsigned char buf[32]; unsigned int upattern; int x start=5,y start=5; int x,y,MaxX,MaxY; int i,dot space dot=12,color=YELLOW; if(argc !=2){ printf(“\n\007USAGE:Show hzk SCCLIB 16.DOT\n”); exit(1); } if((Lib dat File=fopen(argv[1],“rb”)) ==NULL){ printf(“\n\007Can’t open the small chinese character”); printf(“lib file SCCLIB16.DOT\n”); exit(1); } Initiaze(); MaxX=getmaxx(); MaxY=getmaxy(); x=x start; y=y start; setcolor(cotor); I offset=0; while(!feof(Lib dat File)) { fseck(Lib dat File,(long)I offset*3 2,SEEK SET); fread(buf,sizeof(unsigned char),32, Lib dat File); I offset++; for(i=0;;i<32;i+=2) { upattern=(buf[i]<<8) 丨 buf[i+1]; setlinestyle(USERBIT LINE,upatter n,NORM WIDTH); line(x+15,y+i\2,x,y+i\2); } x=x+16+dot space dot; if(x>MaxX) { x=x start; y+=24; } if((y+16)>MaxY){ getch(); cleardevice(); y=y start; } } fclose(Lib dat File); getch(); closegraph(); } /* * INITIALIZE:Initializes the graphics system and reports * any errors which occured. */ Initialize(void) { int GraphDriver,GraphMode,ErrorCode; GraphDriver=DETECT; initgraph( &GraphDriver, &GraphMode,“ ”); ErrorCode=graphresult(); if(ErrorCode!=grOk) { print(“Graphics System Error:%s\n”, grapherrormsg(ErrorCode); exit(1); } } (计算机世界报 1994年 第1期) |
周报全文频道联系方式:010-68130909 |
||||||
| 【关于我们】 【广告服务】 【周报发行】 【投稿指南】 【投稿声明】 【联系方式】 【法律声明】 【媒体手册】 【编读往来】 |
||||||
| Copyright© ccw.com.cn,All rights reserved | ||||||
| 中国计算机世界出版服务公司版权所有 | ||||||