📄 dspstr.c
字号:
/**********************************************************************/
/* */
/* 本程序中包括五个子函数, 其用途是在图形方式下输出16*16点阵汉字和美*/
/*观的英文字符(8*16点阵). */
/* */
/**********************************************************************/
#ifndef __DSPSTR_C
#define __DSPSTR_C
#include <graphics.h>
#include <string.h>
#include <stdio.h>
#include <dos.h>
#include "constants.h"
/*=====================================================*/
//使用本程序时,请将下面一段程序加入你的主程序中
/*
FILE *fnt16;
struct ffblk ffblk;
检测字形库文件fnt16是否存在?
if( findfirst("fnt16", &ffblk, 0) ){
cprintf("File \"fnt16\"not found!\a");
return;
}
else fnt16=fopen("fnt16","rb");
//
InitAsc16ImgPtr();
=======================================================*/
unsigned char far *pAsc16Img;
void InitAsc16ImgPtr(void)
{ struct REGPACK rp;
rp.r_ax=0x1130; rp.r_bx=0x0600; intr(0x10,&rp);
pAsc16Img=(unsigned char far*)MK_FP(rp.r_es,rp.r_bp);
}
//---------------------------------------------------//
// 在指定光标(x,y)处显示16*16点阵的汉字和8*16点阵的英文
// 符号,但不移动光标.
//---------------------------------------------------//
//Display a string by draw lines.
void out16textxy(int x, int y, unsigned char *str, int strcol,int strbkcol)
{ static unsigned char mat[32],*pm;
unsigned char far *pa;
unsigned char qu,wei;
unsigned *pi,i;
if(!*str)return;
//Set background color.
if(strbkcol>=0){
setfillstyle(SOLID_FILL,strbkcol);
bar(x,y,x+strlen(str)*8-1,y+15);
}
//Set forground color.
setcolor(strcol);
while( *str ){
//Process ASCII code.
if( *str<0xa1 || (*str>=0xa1&&*(str+1)<0xa1) ){
pa=pAsc16Img+ (*str)*16;//Cal Start address.
//Draw 16 lines.
for(i=y; i<y+16; i++,pa++){
if(*pa){//If the line is NULL,then draw line is not needed,less time 30%.
setlinestyle(USERBIT_LINE,*pa,1);
line(x+7,i,x,i);
}
}
x+=8; str++;
continue;
}
//Process HZ.
//Cal dot matrix start address in font file.
qu=*str-0xa1; wei=*(str+1)-0xa1;
//Read dot matrix.
fseek(fnt16,(long)(qu*94+wei)*32,0);
fread(mat,32,1,fnt16);
//Exchange High/Low bytes of a Integer for line style.
for(i=0,pm=mat;i<16;++i,pm+=2){ qu=*pm; *pm=*(pm+1); *(pm+1)=qu; }
//Draw 16 lines.
pi=(unsigned*)mat;
for(i=y; i<y+16; i++){
setlinestyle(USERBIT_LINE,*pi++,1);
line(x+15,i,x,i);
}
str+=2; x+=16;
}
setlinestyle(SOLID_LINE,1,1);
}
//---------------------------------------------------//
// 在指定光标(x,y)处显示16*16点阵的汉字,但不移动光标
//---------------------------------------------------//
//Display HZ by Function "putimage()".
void outcctextxy_put(int x, int y, unsigned char *str, int strcol,int strbkcol)
{ static unsigned char mat[32],*pMat;
static unsigned char far img[134]={15,0,15,0},*pImg;
void far *pvImg=(void far *)img;
unsigned idot,*pi,i;
unsigned char qu, wei,cte;
long addr;
int y1,maxX,maxY;
if(strbkcol>=0) setfillstyle(SOLID_FILL,strbkcol);
setcolor(strcol);
while( *str ){
//Cal the Dot image Offset address in file FNTLIB.
if( *str<0xa0 || *(str+1)<0xa0 ){ str+=2; continue;}//is ASCII character. Ignore!
qu=*str-0xa0; wei=*(str+1)-0xa0;
addr=(long)((qu-1)*94+wei-1)*32;
//Read Dot Image.
fseek(fnt16,addr,0);
fread(mat,32,1,fnt16);
//Cal putimage bit-plane IMAGE.
for(i=4;i<134;++i)img[i]='\0';
if(strcol&DARKGRAY){//0x8
pMat=mat; pImg=img+4;
for(i=0;i<16;++i,pMat+=2,pImg+=8){ *pImg=*pMat; *(pImg+1)=*(pMat+1); }
}
if(strcol&RED){//0x4
pMat=mat; pImg=img+6;
for(i=0;i<16;++i,pMat+=2,pImg+=8){ *pImg=*pMat; *(pImg+1)=*(pMat+1); }
}
if(strcol&GREEN){//0x2
pMat=mat; pImg=img+8;
for(i=0;i<16;++i,pMat+=2,pImg+=8){ *pImg=*pMat; *(pImg+1)=*(pMat+1); }
}
if(strcol&BLUE){//0x1
pMat=mat; pImg=img+10;
for(i=0;i<16;++i,pMat+=2,pImg+=8){ *pImg=*pMat; *(pImg+1)=*(pMat+1); }
}
putimage(x, y, pvImg, COPY_PUT);
str+=2; x+=16;
}
setlinestyle(SOLID_LINE,1,1);
}
//---------------------------------------------------//
// 在指定缺省光标处显示16*16点阵的汉字和8*16点阵的英文
// 符号,且移动光标.
//---------------------------------------------------//
//Display a string by draw lines.
void out16text(unsigned char *str, int strcol,int strbkcol)
{ static unsigned char mat[32],*pm;
unsigned char far *pa;
unsigned char qu,wei;
unsigned x,x1,y,*pi,i;
if(!*str)return;
x=getx(); y=gety();
x1=x+strlen(str)*8;
//Set background color.
if(strbkcol>=0){
setfillstyle(SOLID_FILL,strbkcol);
bar(x,y,x1-1,y+15);
}
//Set forground color.
setcolor(strcol);
while( *str ){
//Process ASCII code.
if( *str<0xa1 || (*str>=0xa1&&*(str+1)<0xa1) ){
pa=pAsc16Img+ (*str)*16;//Cal Start address.
//Draw 16 lines.
for(i=y; i<y+16; i++){
setlinestyle(USERBIT_LINE,*pa++,1);
line(x+7,i,x,i);
}
x+=8; str++;
continue;
}
//Process HZ.
//Cal dot matrix start address in font file.
qu=*str-0xa1; wei=*(str+1)-0xa1;
//Read dot matrix.
fseek(fnt16,(qu*94+wei)*32,0);
fread(mat,32,1,fnt16);
//Exchange High/Low bytes of a Integer for line style.
for(i=0,pm=mat;i<16;++i,pm+=2){ qu=*pm; *pm=*(pm+1); *(pm+1)=qu; }
//Draw 16 lines.
pi=(unsigned*)mat;
for(i=y; i<y+16; i++){
setlinestyle(USERBIT_LINE,*pi++,1);
line(x+15,i,x,i);
}
str+=2; x+=16;
}
setlinestyle(SOLID_LINE,1,1);
moveto(x1,y);
}
void outcc24xy( int x, int y, int beg,int end,
int strcol, int strbkcol, int dist)
//Note: the value in "str" is: 0,1,2,3,4... stand-by the serial no.
{ int x1,y1;
char mat,i,cou;
if( beg>end )return;
for(cou=beg; cou<=end; cou++){
fseek(fnt16,94L*32*13+cou*72,0);
for(x1=x; x1<x+24; x1++){
for(i=0;i<3;++i){
mat= fgetc(fnt16);
for(y1=y+i*8; y1<y+8*(i+1); y1++){
if(mat&0x80) putpixel(x1,y1,strcol);
else if(strbkcol>=0)putpixel(x1,y1,strbkcol);
mat<<=1;
}
}
}
x+=24+dist;
}
}
void outcc24xyplus( int x, int y, int beg, int end, int strcol, int strbkcol, int dist)
//Note: the value in "str" is: 0,1,2,3,4... stand-by the serial no.
{ int x1,y1;
char mat,i,cou;
if( beg>end)return;
for(cou=beg; cou<=end; cou++){
fseek(fnt16,94L*32*13+cou*72,0);
for(x1=x; x1<x+48; x1+=2){
for(i=0;i<3;++i){
mat= fgetc(fnt16);
for(y1=y+i*16; y1<y+16*(i+1); y1+=2){
if(mat&0x80){
putpixel(x1,y1,strcol); putpixel(x1,y1+1,strcol);
putpixel(x1+1,y1,strcol); putpixel(x1+1,y1+1,strcol);
}
else if(strbkcol>=0){
putpixel(x1,y1,strbkcol); putpixel(x1,y1+1,strbkcol);
putpixel(x1+1,y1,strbkcol); putpixel(x1+1,y1+1,strbkcol);
}
mat<<=1;
}
}
}
x+=48+dist;
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -