回 帖 发 新 帖 刷新版面

主题:TC3.0环境下显示汉字程序

/**TC3.0环境下显示汉字程序,请将本源文件和12*12点阵汉字库文件hzk12放在同一目录下再编译运行本文件。
*hzk12文件大小192kb,如果找不到地方下载可以向本人索要.
*作者:meteor135(流星雨) meteor@mail.biti.edu.cn, smith_135@163.com
*完成时间:2003年8月14日
*/
#include <stdio.h>//for FILE
#include <graphics.h>//for graphics
#define GRAPH_DVR_PATH "F:\\TC\\BGI" //请将此路径改为你本机环境对应的BGI路径

void get_hz(FILE* hzk_p, char incode[],char bytes[]);
void dis_hz(FILE* hzk_p, int x, int y, char code[], int color,int expandBy);
void put_hz(char *s,int x, int y, int color, int wordSpace, int lineSpace, int direction, int expandBy, int lineDes);
/**parameter @s:            pointer to the hanzi string to show
* parameter @x:            x coordinates the s start showing in screen
* parameter @y:            y coordinates the s start showing in screen
* parameter @color:        string s's color
* parameter @wordSpace:    word space
* parameter @lineSpace:    line space
* parameter @direction:    the direction at which string s to show, 0:left->right,others: up->down
* parameter @expandBy:     the word will be expanded by it as multiple.
* parameter @lineDes:      when direction is not 0, lineDes will control the string lines descending direction.
*/
void main()
{
    char *s="春眠不觉晓  处处闻啼鸟  夜来风雨声  花落知多少";
    int driver = DETECT;
    int mode = 0;
    initgraph(&driver,&mode,GRAPH_DVR_PATH);
    put_hz(s,20,130,WHITE,16,30,0,2,0);
    put_hz(s,250,230,GREEN,16,30,1,1,1);
    put_hz(s,340,230,YELLOW,16,30,1,1,-1);
    getch();
    closegraph();
}
void put_hz(char *s,int x, int y, int color, int wordSpace, int lineSpace, int direction, int expandBy,int lineDes)
{
    int x0 = x, y0 = y;
    FILE *hzk_p;
    if(!(hzk_p=fopen("hzk12","rb")))
    {
        printf("The file HZK12 does not exist! press any key to quit\n");
        return;
    }
    while(*s!=NULL)
    {
        while(*s!=NULL&&x<640-12*expandBy&&y<480-12*expandBy&&x>=0&&y>=0)
        {
            if(*s!=32)  //ignore space
                dis_hz(hzk_p,x,y,s,color,expandBy);
            if(direction == 0)
                x += wordSpace*expandBy;
            else
                y += wordSpace*expandBy;
            s+=2;
        }
        if(direction == 0)
        {
            x = x0;
            y += lineSpace*expandBy;
        }
        else
        {
            y = y0;
            x += lineDes*lineSpace*expandBy;
        }
    }
}
void get_hz(FILE* hzk_p, char incode[],char bytes[])
{
    unsigned char qh, wh;
    unsigned long offset;
    qh = incode[0] - 0xa0;
    wh = incode[1] - 0xa0;
    offset = (94*(qh-1)+(wh-1))*24L;
    fseek(hzk_p,offset,SEEK_SET);
    fread(bytes,24,1,hzk_p);
}
void dis_hz(FILE* hzk_p, int x, int y, char code[], int color, int expandBy)
{
    int i, j, m, n;
    char mat[24];
    get_hz(hzk_p,code,mat);
    for(i=0; i< 12; ++i)
    {
        for(j = 0; j < 12; ++j)
        {
            if(((128>>j%8)&mat[2*i+j/8])!=NULL)
            {
                for(m=0; m<expandBy; m ++)
                {
                    for(n=0;n<expandBy; n++)
                    {
                        putpixel(x+expandBy*j+m,y+expandBy*i+n,color);
                    }
                }
            }
        }
    }
}

回复列表 (共36个回复)

21 楼

楼主,我也要呀,谢谢!
huyansong168@hotmail.com

22 楼

请到这里下载:
[url=http://202.112.86.129/tc256/download/download.htm]http://202.112.86.129/tc256/download/download.htm[/url]

23 楼

请问,怎么从英文转入中文呢?[em10]

24 楼

请问,怎么从英文转入中文呢?

25 楼

楼主也给我发一个
谢谢!!!!!!!!

26 楼

27 楼

给我也发一个(flyer_fang@sohu.com)
谢谢楼主!

28 楼

unsigned char xu[]={

/* &Ograve;&Ocirc;&Iuml;&Acirc;&Ecirc;&Ccedil;'&ETH;ì'16&micro;&atilde;&Otilde;ó&Euml;&Icirc;&Igrave;&aring; ×&Ouml;&Auml;&pound;&pound;&not;32 byte */
  0x10,0x40,0x18,0x40,0x20,0xA0,0x41,0x18,
  0x92,0x0E,0x1D,0xF4,0x30,0x40,0x60,0x40,
  0xA7,0xFC,0x20,0x40,0x22,0x50,0x23,0x4C,
  0x24,0x46,0x28,0x44,0x21,0x40,0x20,0x80
};

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

void draw_dot(int x,int y,unsigned char dot)
{
     int i;
     for(i=0;i<8;i++)

         if (dot&((unsigned char)0x80>>i))putpixel( x+i,y, 12);
}

void draw_hz(int x,int y,unsigned char *hz)
{
    int i;
    for (i=0;i<32;++i)
    {
        draw_dot( x, y,hz[i]);
        if (i%2==0)
            x+=8;
        else
        { x-=8;y+=1;}

    }

}

int main()
{
    int base_x=300,base_y=200;
    int gdriver, gmode, i;
          gdriver=9;
          gmode=2;
          registerbgidriver(EGAVGA_driver);
          initgraph(&gdriver, &gmode, "");
          setbkcolor(WHITE);
          draw_hz(base_x,base_y,xu);
          getch();
}

29 楼

发个TC2下的,想打什么打么,呵呵(用hzk16)
#include <stdio.h>
#include <graphics.h>
void initgr()
{
int a[2];
detectgraph(a,a+1);
initgraph(a,a+1,"");
}
void printch(int x,int y,unsigned char *p,int color)
{
long a,b,loc;
int xx,yy,i,j;
unsigned char c;
FILE *fp;
fp=fopen("hzk16","rb");
if(fp==NULL) {closegraph();printf("Cannot find hzk16.");exit(0);}
while(*p)
{
  a=(*p)-160;b=*(p+1)-160;
  loc=((a-1)*94+b-1)*32;
  fseek(fp,loc,0);
  xx=0;yy=0;
  for(i=0;i<32;i++)
   {
    c=fgetc(fp);
    for(j=0;j<8;j++)
    {
     if((c<<j)&0x80) putpixel(x+xx,y+yy,color);
     xx++;
     if(xx>15) {xx=0;yy++;}
    }
   }
p+=2;
x+=16;
}
fclose(fp);
}

main()
{
initgr();
printch(0,0,"大江东去浪淘尽千古风流人物,故垒西边人道是三国周郎赤壁。",2);
getch();
}






30 楼

楼主,你给的地址打不开啊,请给我也发一个,谢谢了
comepaul@163.com

我来回复

您尚未登录,请登录后再回复。点此登录或注册