回 帖 发 新 帖 刷新版面

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

沙发

请发一个hzk12到我的邮箱:jtchang@21cn.com  我有用处。
我现有的是16*16的点阵字库,没有12*12的点阵字库。用在哪里,你看下面这个函数就知道了(pascal编的,UCDOS的HZK16文件):

procedure putone;
type
    chinesep=array[1..32] of byte;
var
    s:string;
    a:chinesep;
    f:file of chinesep;
    i,j:integer;
    k:byte;
    q,w:longint;

begin
    s:='你';
    q:=ord(s[1])-160;
    w:=ord(s[2])-160;
    q:=(q-1)*94+(w-1);
    assign(f,'HZK16') ;
    reset(f);
    if (q<0) or (q>=filesize(f)) then
      begin
         close(f);
         exit;
      end;
    seek(f,q);
    read(f,a);
    close(f);

    for i:=1 to 32 do
     begin
       k:=a[i];
       for j:=1 to 8 do
        begin
           if k and $80 <>0  then write('  ')
             else  if i mod 2=1 then write('感')
                   else  write('谢');
             k:=k shl 1;
        end;
       if i mod 2=0 then writeln;
     end;
end;

调用后运行结果:

感感感  感感感  谢谢谢谢谢谢谢谢
感感感  感感感  谢谢谢谢谢谢谢谢
感感感  感感感  谢谢谢谢谢谢谢谢
感感  感感感                谢谢
感感  感感感  感谢谢谢谢谢  谢谢
感    感感  感感谢谢谢谢  谢谢谢
  感  感  感感感谢  谢谢谢谢谢谢
感感  感感感感感谢  谢谢谢谢谢谢
感感  感感感感  谢  谢  谢谢谢谢
感感  感感感感  谢  谢谢  谢谢谢
感感  感感感  感谢  谢谢    谢谢
感感  感感  感感谢  谢谢谢  谢谢
感感  感感感感感谢  谢谢谢谢谢谢
感感  感感感感感谢  谢谢谢谢谢谢
感感  感感感感  谢  谢谢谢谢谢谢
感感  感感感感感  谢谢谢谢谢谢谢


(^_^)

板凳

这里给大家提供一个的地方:(将网页滚动到底部就看到了)[url=http://go8.jaying.net/tc256/download/download.htm]http://go8.jaying.net/tc256/download/download.htm[/url]

3 楼

在TC2下可以吗?

4 楼

没问题,只要你按照我源程序中的要求做就行了。

5 楼

Tc3上,与tc2上有去别吗?

6 楼

ding

7 楼

请问运行后的结果是怎么样的

8 楼

我用的是软件生成的汉字库文件。。。。并且我将名字改成了你写的hzk12。。行不行?

9 楼

在tc2.0下编译的

10 楼

行不行关键看你生成的这个汉字库文件的格式和我用的是否一致。
如果你的符合标准,应该可以的。
你自己试一下就行了。

我来回复

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