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

📄 hz_slp.c

📁 SLP矢量汉字显示应用程序 华光系统矢量汉字字库( SLP文件)汉字的显示
💻 C
字号:
/*程序清单。,SLP矢量汉字显示应用程序
程序实例,显示了4种字体及其x,Y方向的任意缩放。chin96( )函数中的各个形
参的含义,读者可以从变量命名的字面上_看便知。注意,在汉字字符串中,不应插入非

汉字
(ASCII)字符,否则要出错。如欲实现ASSII字符与汉字字符同时使用,则在程序中还应

加入
判断及非汉字字符的处理,这里不再多述。
上述程序在386,486或286微机上均调试通过,操作系统为Dos。*/

#include <conio.h>
#include <stdio.h>
#include <graphics.h>
#include <math.h>

#define FONT_SIZE 96
/*原始字体大小*/
#define F_COLOR	4
#define B_COLOR 7

typedef struct{
unsigned char data_length;
unsigned char pos1;
unsigned int pos2;
} SLP_item;

void initgr(void);
void init_chin (void);
void chin96 (int x, int y, char *, int font);
void set_chin_size(int x,int y);
FILE * fp96, * fp96_H, * fp96_S, *fp96_F,*fp96_K;
int chin_sizex=96, chin_sizey=96;

void main ( )
{
int i;
initgr();
setbkcolor (B_COLOR);
cleardevice ( );
chin96(10,1,"黑体",1);
chin96(340,1,"宋体",2);
chin96(10, 121,"仿宋体",3);
chin96(340,121, "楷体",4);
set_chin_size(48,48);
chin96(2,280, "矢量汉字显示应用",4);
set_chin_size (60,100);
chin96(200,350,"源程序",2);
getch ( );
fcloseall ( );
textmode (3);
}

void initgr(void)
{
   int GraphDriver,GraphMode,ErrorCode;
   GraphDriver=DETECT;
	initgraph(&GraphDriver,&GraphMode,"e:\\borlandc\\bgi");
   ErrorCode=graphresult();
	if(ErrorCode!=0){
      printf("Graphics System Error:%s\n",grapherrormsg(ErrorCode));//???????grapherrormsg(ErrorCode)??
      exit(1);
   }
}

void chin96 (int xx0,int yy0,char *str,int chin_font)
{
	SLP_item hi;
	long chinpos1,chinpos2;
	unsigned char ch1,ch2,t1;
	int data[1024],xy[256];
	int i,j,p_num;
	float xt,yt,scalex,scaley;
	unsigned int length_c,No_C;
	switch (chin_font) {
		case 1:
		fp96= fp96_H;
		break;
		case 2:
		fp96= fp96_S;
		break;
		case 3:
		fp96=fp96_F;
		break;
		case 4:
		fp96= fp96_K;
		break;
		default:
		fp96=fp96_H ;
	}
	scalex= (float) chin_sizex/FONT_SIZE;
	scaley= (float) chin_sizey/FONT_SIZE;
	setfillstyle (SOLID_FILL , F_COLOR);
	setcolor (F_COLOR);
	while ( (*str)) {
		ch1= (*str);
		str++;
		ch2= (*str);
		str++;
		if((ch1==0)||(ch2==0))break;
		No_C=((ch1-160-16)* 94+ ch2-160);
		chinpos1= (long) (No_C-1) *4L;//?4L
		fseek (fp96,chinpos1,SEEK_SET);
		fread(&hi,sizeof(SLP_item),1,fp96);
		length_c=hi.data_length*4;
		chinpos2= (long)(hi.pos1)*256L*256L+hi.pos2;//2561
		fseek (fp96,chinpos2,SEEK_SET);
		for (i=0; i< length_c; i++ ) {
			data[i]=getc(fp96);
		}
		i= 0;
		while (i< length_c-1) {
			t1=data[i];
			if (t1==0) break;
			p_num =t1;
			t1*=2;
			for(j=0;j< t1;j-= 2){
				i++;
				xt=(scalex*data[i]);
				i++;
				yt= (scaley*data[i]);
				xy[j]=xx0+(int)(xt+0.5);
				xy[j+1]=yy0+ (int)(yt+0.5);
			}
			setfillstyle(SOLID_FILL ,F_COLOR);
			if (chin_font==4) {
			float tn2;
			int tn1,tcolor[1024];
			for(j=0;j<p_num;j++){
				tcolor[j]=getpixel(xy[2*j],xy[2*j+1]);
			}
			tn1=0;
			for(j=0;j< p_num;j++){
				if(tcolor[j]==F_COLOR)tn1++;
			}
			tn2= (float)tn1/(float)p_num ;
			if(tn2> 0.9) setfillstyle(SOLID_FILL ,B_COLOR);
			}
			i++;
			fillpoly (p_num ,xy);
		}
		xx0+= (int)(scalex * FONT_SIZE+ 0.5);
	}
}

void init_chin (void)
{
fp96_H=fopen("htl.slp","rb" );
if(fp96_H==NULL)
printf ("Can not open file htl.slp\n");
fp96_S=fopen("ssl.slp","rb");
if(fp96_S==NULL)
printf( "Can not open file ssl.slp\n");
fp96_F=fopen("fsl.slp", "rb");
if(fp96_F==NULL)
printf( "Can not open file fsl.slp\n");
fp96_K=fopen( "ktl.slp","rb");
if(fp96_K==NULL)
printf( "Can not open file ktl.slp\n" );
}
void set_chin_size(int x,int y)
{
if((x<0)||(y< 0)) {
x=96; y=96;
}
chin_sizex= x;
chin_sizey= y;
}

⌨️ 快捷键说明

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