⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hzktst.c

📁 用于分析各种点阵字库结构和程序
💻 C
字号:
#ifndef __HZKTST_C
#define __HZKTST_C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <bios.h>
#include <io.h>
#include <dir.h>
#include <graphics.h>

#include "constant.h"
#include "dspstr.h"
#include "draw3d.h"
#include "gettext.h"

//定义图形方式下的颜色值.
#define bkcol 	LIGHTBLUE
#define lincol	LIGHTGRAY
#define strcol	WHITE
#define teBLACK	5

#define MaxDotX 11
#define MaxDotY 9
#define XL      230
#define YT      45
#define INCRE	25

typedef struct{
	unsigned char dotx,doty,codefrm,bytefrm;
}stDotFrm;
#define MaxEvent	MaxDotX*MaxDotY*2*3

stDotFrm F[MaxEvent];

/******************************/
//         主程序             //
/******************************/
void main(int argc, char *argv[] )
{
	unsigned char ts[3];
	struct time t1,t2;
	FILE *src;//,*fte;//, *fnt16;
	struct ffblk ffblk;
	char fname[128]=" <无> ", fname1[128],workpath[128], dspstr[200];
	char *pstr1,*pstr2, *pte, *pte1,cte;
	int gdriver = DETECT, gmode, errorcode;
	int qu,wei;
	long addr,addr1,lchar=0L,lchar1;
	int ioffset;
	int i, i1, i2, i3, iH,i1H,i2H,j,ite,ite1,k;
	int x, y, x1, y1, color, maxx, maxy,maxcolor, seed;
	int DotX[MaxDotX]={6, 8,10,12,16,20,24,32,40,48,64};//,80,96};//表示字库为?*?点阵
	int DotY[MaxDotY]={8,12,16,20,24,32,40,48,64};//,80,96};
	int idotx,idoty,te1,te2;
	int iBytesPerChar;
	int CodeFrm=0; //字形码的排列顺序:0-按行/1-按列/2-同时8列
	char *CodeFrmStr[3]={"--","| ","= "};//"从左到右    ","从上到下    ","8列从上到下 "};
	int ByteFrm=0;//每个字节中象素的编码顺序:0-从低位到高位/1-从高位到低位
	char *ByteFrmStr[2]={"D7..D0","D0..D7"};
	int xc[25],yc[25];
	int ikey, iAutoCnt=0;
	char F_Auto=0,F_Grid=1,F_Exit;
	void far *pBuf;
	unsigned char far *pp;
	unsigned imgsize;

	if(argc);
	for(i=0;i<MaxEvent;++i){
		F[i].dotx	=(i/6/MaxDotY)%MaxDotX;
		F[i].doty	=(i/6)%MaxDotY;
		F[i].codefrm=(i/2)%3;
		F[i].bytefrm=i%2;
	}
	for(i=0;i<25;++i){
		xc[i]=XL+40+80*(i%5);
		yc[i]=YT+40+80*((i/5)%5);
	}
	//显示软件功能及作者.
	cprintf("This Program is used to detect the format of a RENDER_font-file.");
	cprintf("\n\rWrite by LiuLunHong, HUST.   All rights reserved! 1997.7.1");

	// 检测符号库文件FNT16是否存在?
	strcpy(workpath,argv[0]);
	pte=workpath+strlen(workpath)-1;
	while( *pte!='\\' && pte>workpath )pte--;
	*pte=0;
	sprintf(fname,"%s\\HZKLIB",workpath);
	if( findfirst(fname, &ffblk, 0) ){
		printf("\n\nFile \"HZKLIB\"not found!\a");
		return;
	}
	else  fnt16=fopen(fname,"rb");

	//Initiate ASCII 16*8 Dot Matrix far pointer.
	InitAsc16ImgPtr();

	// 检测文件EGAVGA.BGI是否存在?
	/*  sprintf(fname,"%s\\egavga.bgi",workpath);
	if( findfirst(fname, &ffblk, 0) ){
		cprintf("File \"egavga.bgi\"not found!\a");
		return;
	}*/

	//改写Ctrl-Break中断及Ctrl-P, PrintSreen中断.
	//*****************待写****************

	//请求输入源文件名称.
	cprintf("\n\rPlease input the filename of CCLIB:");
	fname[0]=0;
	TMGetRollStr( wherex(), wherey(), 15, fname);
	if( !fname[0] )return;
	strupr(fname);//UpperCase fname.
	if( findfirst(fname, &ffblk, 0) ){
		cprintf("\n\rFile not found!\a");
		return;
	}

	// Auto recognize the Dot Number.
	idotx=4;	idoty=2;//16*16 dots
	src=fopen(fname,"rb");
	pte=strrchr(fname,'\\');
	if(!pte)pte=fname;
	pte1=strpbrk(pte,"0123456789");
	ite=atoi(pte1);
	if(ite){
		while(ite>=100)ite/=10;
		for(ite1=0;ite1<MaxDotY;ite1++){
			if(ite==DotY[ite1])break;
		}
		if(ite==DotY[ite1]){
			idoty=ite1;
			if(strstr(pte,"ASC")){ idotx=ite1-1; if(idotx<0)idotx=0;}
			else	idotx=ite1+2;
		}
	}
	if(idotx>MaxDotX)idotx=MaxDotX;
	if(idoty>MaxDotY)idoty=MaxDotY;

	//屏幕初始化为图形方式.
	registerbgidriver(EGAVGA_driver);
	initgraph(&gdriver, &gmode, workpath);
	setbkcolor(LIGHTGRAY);
	cleardevice();

	out16textxy(0,0,"︸",CYAN,-1);
	imgsize=imagesize(0,0,15,15);
	pBuf=(void far *)malloc(imgsize);
	getimage(0,0,15,15,pBuf);
	for(i=0; i<480; i+=16)
	for(j=0; j<640; j+=16)
		putimage(j,i,pBuf,COPY_PUT);
	free(pBuf);	pBuf=NULL;

	//控制变量置初值.
	setpalette(teBLACK,0);
	ioffset=0;
	addr=(long)ioffset;
	if(CodeFrm==1){
		if(DotY[idoty]%8)	iBytesPerChar=DotX[idotx]*(DotY[idoty]/8+1);
		else		iBytesPerChar=DotX[idotx]*DotY[idoty]/8;
	}
	else {
		if(DotX[idotx]%8)	iBytesPerChar=DotY[idoty]*(DotX[idotx]/8+1);
		else		iBytesPerChar=DotY[idoty]*DotX[idotx]/8;
	}
	//Display Main interface
	DrawFrame1(5,5,635,35,1);
	out16textxy(13,13,"点阵字库结构分析程序 Ver 2.0",teBLACK,-1);
	out16textxy(12,12,"点阵字库结构分析程序 Ver 2.0",LIGHTGREEN,-1);
	out16textxy(520,13,"2000年3月18日",teBLACK,-1);
	//DrawFrame(1,1,1,1);
	out16textxy(10, 50,"字库文件 :",teBLACK,-1);		     DrawFrame2(92, 48,189, 67,1);
	out16textxy(10, 75,"文件大小 :        字节",teBLACK,-1);DrawFrame2(92, 73,149, 92,1);
	out16textxy(10,100,"字符总数 :",teBLACK,-1);            DrawFrame2(92, 98,141,117,1);
	out16textxy(10,125,"字节/字符:",teBLACK,-1);            DrawFrame2(92,123,117,142,1);
	sprintf(dspstr,"%12s",fname);
	if(strlen(fname)>=12)	{ dspstr[11]=16;dspstr[12]=0;}
	out16textxy(93,50,dspstr,WHITE,CYAN);
	sprintf(dspstr,"%7ld",ffblk.ff_fsize); out16textxy(93,75,dspstr,WHITE,CYAN);
	sprintf(dspstr,"%6ld",ffblk.ff_fsize/iBytesPerChar); out16textxy(93,100,dspstr,WHITE,CYAN);
	sprintf(dspstr,"%3d",iBytesPerChar); 	out16textxy(93,125,dspstr,WHITE,CYAN);

	out16textxy(10,175,"点阵结构:   ×    ><  +-",teBLACK,-1);   DrawFrame2(84,173,101,192,1);   DrawFrame2(124,173,141,192,1);
	out16textxy(10,200,"字节编排:         ↑  ↓",teBLACK,-1);   DrawFrame2(84,198,101,217,1);
	out16textxy(10,225,"象素顺序:         ←  →",teBLACK,-1);   DrawFrame2(84,223,133,242,1);
	out16textxy(10,250,"字符序号:         PU  PD",teBLACK,-1);   DrawFrame2(84,248,133,267,1);
	out16textxy(10,275,"字节偏移:      Home  End",teBLACK,-1);   DrawFrame2(84,273,101,292,1);
	setcolor(RED);	line(4,455,635,455);
	setcolor(teBLACK);	line(4,456,635,456);
	out16textxy(10,460,"F1-帮助  F2-自动分析  F3-打开字库  F4-网格  ESC-退出",teBLACK,-1);
	out16textxy(540,460,"设计: 刘伦洪",teBLACK,-1);
	out16textxy(539,459,"设计: 刘伦洪",LIGHTRED,-1);

	//开始主循环.
	F_Exit=0;
	while( ! F_Exit ){
		if(idotx>MaxDotX)idotx=MaxDotX;
		if(idoty>MaxDotY)idoty=MaxDotY;
		if(idotx<0)idotx=0;
		if(idoty<0)idoty=0;
		//显示外框.
		setfillstyle(SOLID_FILL,teBLACK);
		bar(XL,YT,XL+400,YT+400);
		if(F_Grid){
			setcolor(DARKGRAY);
			x=XL;	y=YT;
			for(x=XL;x<XL+400;x+=8)line(x,y,x,y+400);
			x=XL;	y=YT;
			for(y=YT;y<YT+400;y+=8)line(x,y,x+400,y);
			for(i=0; i<25; ++i){
				line(xc[i]-40,yc[i]-40,xc[i]+40,yc[i]+40);
				line(xc[i]+40,yc[i]-40,xc[i]-40,yc[i]+40);
			}
		}
		setcolor(LIGHTGRAY);
		for(i=XL;i<=XL+400;i+=80)line(i,YT,i,YT+400);
		for(i=YT;i<=YT+400;i+=80)line(XL,i,XL+400,i);

		//Calc. the number of bytes occupied by each character.
		if(CodeFrm==1){
			if(DotY[idoty]%8)	iBytesPerChar=DotX[idotx]*(DotY[idoty]/8+1);
			else		iBytesPerChar=DotX[idotx]*DotY[idoty]/8;
		}
		else{
			if(DotX[idotx]%8)	iBytesPerChar=DotY[idoty]*(DotX[idotx]/8+1);
			else		iBytesPerChar=DotY[idoty]*DotX[idotx]/8;
		}
		//Renew lchar and addr
		lchar=(addr-ioffset)/iBytesPerChar;
		addr=lchar*iBytesPerChar+ioffset;
		//显示汉字提示.
		setcolor(strcol);
		sprintf(dspstr, "%2d", DotX[idotx]);
		out16textxy( 85,175,dspstr, strcol,CYAN);
		sprintf(dspstr, "%2d", DotY[idoty]);
		out16textxy(125,175,dspstr, strcol,CYAN);
		sprintf(dspstr, "%s", CodeFrmStr[CodeFrm] );
		out16textxy(85,200,dspstr, strcol,CYAN);
		sprintf(dspstr, "%s", ByteFrmStr[ByteFrm]);
		out16textxy(85,225,dspstr, strcol,CYAN);
		sprintf(dspstr, "%6ld",lchar+1);
		out16textxy(85,250,dspstr, strcol,CYAN);
		sprintf(dspstr, "%2d",ioffset);
		out16textxy(85,275,dspstr, strcol,CYAN);

		sprintf(dspstr,"%6ld",ffblk.ff_fsize/iBytesPerChar);
		out16textxy(93,100,dspstr,WHITE,CYAN);

		sprintf(dspstr,"%3d",iBytesPerChar);
		out16textxy(93,125,dspstr,WHITE,CYAN);

		//处理字库点阵码.
		fseek(src,addr,SEEK_SET);
		for(i3=0;i3<25;++i3){
			x=xc[i3]-DotX[idotx]/2+1;      y=yc[i3]-DotY[idoty]/2+1;
//			if(F_Grid){
//				setcolor(DARKGRAY);
//				rectangle(x-1,y-1,x+DotX[idotx],y+DotY[idoty]);
//			}
			if(CodeFrm==0){//按行从左至右,即先取完一行的代码,再取下一行
				x1=x; y1=y;
				for(i=0; i<DotY[idoty]; i++){
					i1H=DotX[idotx]/8;   if(DotX[idotx]%8)i1H++;
					for(i1=0; i1<i1H; i1++){
						cte=fgetc(src); if( feof(src) )break;
						i2 =i1*8;
						i2H=i1*8+8;	if(i2H>DotX[idotx])i2H=DotX[idotx];
						if(!ByteFrm){//高位为第一个象素
							for(;i2<i2H;i2++){
								if(cte&0x80)putpixel(x1,y1,15);
								cte<<=1; x1++; }
						}
						else {//低位为第一个象素
							for(;i2<i2H;i2++){
								if(cte&0x01)putpixel(x1,y1,15);
								cte>>=1; x1++; }
						}
					}
					x1=x; y1++;
				}
			}

			if(CodeFrm==1){//按列从上至下,即先取完第一列的代码,再取下一列.
				x1=x; y1=y;
				for(i=0; i<DotX[idotx]; i++){
					i1H=DotY[idoty]/8;   if(DotY[idoty]%8)i1H++;
					for(i1=0; i1<i1H; i1++){
						cte=fgetc(src); if( feof(src) )break;
						i2 =i1*8;
						i2H=i1*8+8;	if(i2H>DotY[idoty])i2H=DotY[idoty];
						if(!ByteFrm){//高位为第一个象素
							for(;i2<i2H;i2++){
								if(cte&0x80)putpixel(x1,y1,15);
								cte<<=1; y1++; }
						}
						else {//低位为第一个象素
							for(;i2<i2H;i2++){
								if(cte&0x01)putpixel(x1,y1,15);
								cte>>=1; y1++; }
						}
					}
					y1=y; x1++;
				}
			}

			if(CodeFrm==2){//wps格式->8列从上到下.即先取左8列(从上至下),再取右8列;
				iH=DotX[idotx]/8;	if(DotX[idotx]%8)iH++;
				for(i=0;i<iH; i++){
					y1=y;
					for(i1=0; i1<DotY[idoty]; i1++){
						x1=x+i*8;
						cte=fgetc(src); if( feof(src) )break;
						i2 =i*8;
						i2H=i*8+8;	if(i2H>DotX[idotx])i2H=DotX[idotx];
						if(!ByteFrm){//高位为第一个象素
							for (;i2<i2H;i2++){
								if(cte & 0x80)putpixel(x1,y1,15);
								cte<<=1; x1++; }
						}
						else {//低位为第一个象素
							for (;i2<i2H;i2++){
								if(cte & 0x01)putpixel(x1,y1,15);
								cte>>=1; x1++; }
						}
						y1++;
					}
				}
			}
		}

		//开始处理按键.
		if(!F_Auto){  ikey=bioskey(0);    cte=ikey;   }
		else{
			delay(200);
			if(bioskey(1)){
				sound(2000);	delay(500);	nosound();
				for(i=0;i<14*16;i+=16)out16textxy(i,416,"︸",CYAN,LIGHTGRAY);
//					setfillstyle(SOLID_FILL,CYAN);	bar(10,420,600,440);
					F_Auto=0; ikey=bioskey(0); cte =ikey;
				}
				idotx=F[iAutoCnt].dotx;
				idoty=F[iAutoCnt].doty;
				CodeFrm=F[iAutoCnt].codefrm;
				ByteFrm=F[iAutoCnt].bytefrm;
				if(iAutoCnt<MaxEvent)iAutoCnt++;
				else{
					sound(2000);	delay(500);	nosound();
					for(i=0;i<14*16;i+=16)out16textxy(i,416,"︸",CYAN,LIGHTGRAY);
//					setfillstyle(SOLID_FILL,CYAN);	bar(10,420,600,440);
					F_Auto=0; cte =ikey;
				}
				continue;
			}
			while( bioskey(1) ) bioskey(0);
			switch(ikey){
			case ESC:	F_Exit=1; break;//退出系统.
			case BKSP://opposite to ' ' following.
				if(iAutoCnt>0)iAutoCnt--;
				idotx=F[iAutoCnt].dotx;
				idoty=F[iAutoCnt].doty;
				CodeFrm=F[iAutoCnt].codefrm;
				ByteFrm=F[iAutoCnt].bytefrm;
				break;
			case LARROW:ByteFrm=0; break;
			case RARROW:ByteFrm=1; break;
			case UARROW:if(CodeFrm>0)CodeFrm--; break;
			case DARROW:if(CodeFrm<2)CodeFrm++; break;
			case HOME:	if(ioffset>0){ioffset--;  addr--;} break;
			case END:	if(ioffset<48){ioffset++; addr++;} break;
			case PGDN://显示字库的下一组汉字
			case CTRL_PGDN:
				if(ikey==PGDN)lchar1=lchar+INCRE;
				else	lchar1=lchar+INCRE*10;
				addr1=(long)lchar1*iBytesPerChar+ioffset;
				if(addr1>=ffblk.ff_fsize) cprintf("\a");
				else{ addr=addr1;	lchar=lchar1;}
				break;
			case PGUP://显示字库的前一组汉字
			case CTRL_PGUP:
				if(ikey==PGUP)lchar-=INCRE;
				else	lchar-=INCRE*10;
				if(lchar<0L){ lchar=0L; cprintf("\a"); }
				addr=lchar*iBytesPerChar+ioffset;
				break;
			case F1://Display HELP! Reserved for next process.
				break;
			case F2:
				F_Auto=1;
				out16textxy(10,416,"正在自动扫描,请按任意键停止.",LIGHTRED,-1 );
				break;
			case F3:
				strcpy(fname1,fname);
				GMGetRollStr( 93,50,96, WHITE, teBLACK,fname1);
				if(fname1[0]==0){
					sound(2000);delay(200);nosound();
					sprintf(dspstr,"%12s",fname);
					if(strlen(dspstr)>12){ dspstr[11]=16; dspstr[12]=0; }
					out16textxy(93,50,dspstr,WHITE,CYAN);
					break;
				}
				if( findfirst(fname1, &ffblk, 0) ){
					sound(2000);delay(200);nosound();
					sprintf(dspstr,"%12s",fname);
					if(strlen(dspstr)>12){ dspstr[11]=16; dspstr[12]=0; }
					out16textxy(93,50,dspstr,WHITE,CYAN);
					break;
				}
				strcpy(fname,fname1);
				fclose(src);
				addr=(long)ioffset; lchar=0;
				src=fopen(fname,"rb");
				strupr(fname);
				//Begin Auto recognize Dot Number.
				pte=strrchr(fname,'\\');
				if(!pte)pte=fname;
				pte1=strpbrk(pte,"0123456789");
				ite=atoi(pte1);
				if(ite){
					while(ite>=100)ite/=10;
					for(ite1=0;ite1<MaxDotY;ite1++){
						if(ite==DotY[ite1])break;
					}
					if(ite==DotY[ite1]){
						idoty=ite1;
						if(strstr(pte,"ASC")){ idotx=ite1-1; if(idotx<0)idotx=0;}
						else	idotx=ite1+2;
					}
				}

				iAutoCnt=0;
				sprintf(dspstr,"%12s",fname);
				if(strlen(dspstr)>12){ dspstr[11]=16; dspstr[12]=0; }
				out16textxy(93,50,dspstr,WHITE,CYAN);
				sprintf(dspstr,"%7ld",ffblk.ff_fsize);
				out16textxy(93,75,dspstr,WHITE,CYAN);
				break;
			case F4:if(F_Grid)F_Grid=0; else F_Grid=1; break;
			case F5://从当前字库中抽取字模.有待完善!
				break;
			default:
				switch(cte){
				case ' '://opposite to BKSP before.
					if(iAutoCnt<MaxEvent-1)iAutoCnt++;
					idotx=F[iAutoCnt].dotx;		idoty=F[iAutoCnt].doty;
					CodeFrm=F[iAutoCnt].codefrm;	ByteFrm=F[iAutoCnt].bytefrm;
					break;
				case '>': case '.'://x点阵加大
					idotx++; if(idotx>=MaxDotX)idotx=MaxDotX-1;	break;
				case '<': case ','://x点阵变小
					idotx--; if(idotx<0)idotx=0;	break;
				case '+': case '='://y点阵加大
					idoty++; if(idoty>=MaxDotY)idoty=MaxDotY-1;
					break;
				case '-': case '_'://y点阵变小
					idoty--; if(idoty<0)idoty=0;	break;
				default: break;
			}
			break;
		}
	}
	fclose(src);
	fclose(fnt16);
	closegraph();
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -