回 帖 发 新 帖 刷新版面

主题: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个回复)

31 楼

我也要一个汉字自库文件.
我的邮箱是xuzq_nj@sina.com

32 楼

我想要一个~     
  最好把那上面一程式也发给我~  
  我的邮箱是:kingte159@yahoo.com.cn
  谢谢~

33 楼

你给我发发一个12*12点阵汉字库文件hzk12,好吗?
我的email是liqiaodayu@126.com

34 楼

我想要一个hzk12汉字包,谢谢~

35 楼

呵呵,顶下~~
我现在用VC2005,不用那么麻烦,谢~~

36 楼

我也想hzk12汉字包,麻烦楼主也给我发一份儿,谢谢了。
邮箱:liheng88860@126.com

我来回复

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