?? hz_slp.c
字號(hào):
/*程序清單。,SLP矢量漢字顯示應(yīng)用程序
程序?qū)嵗?顯示了4種字體及其x,Y方向的任意縮放。chin96( )函數(shù)中的各個(gè)形
參的含義,讀者可以從變量命名的字面上_看便知。注意,在漢字字符串中,不應(yīng)插入非
漢字
(ASCII)字符,否則要出錯(cuò)。如欲實(shí)現(xiàn)ASSII字符與漢字字符同時(shí)使用,則在程序中還應(yīng)
加入
判斷及非漢字字符的處理,這里不再多述。
上述程序在386,486或286微機(jī)上均調(diào)試通過,操作系統(tǒng)為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, "矢量漢字顯示應(yīng)用",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;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -