⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 在 BC++ 编译,原代码字模提取程序,可以使用在单片机和液晶自己编程等等.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <iostream.h>
//#include <graphics.h>
#define  HZDZ_LEN 32
//点的宽度
#define   POINTER_WIDTH     16
//点的高度
#define   POINTER_HEIGHT    16
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
 Byte avifilename;
 FILE *fp;

// char i;
unsigned char hzdz[HZDZ_LEN];
unsigned char line[16];
unsigned char linebuff[32];
        Byte buf[33];
        Byte bbuf[33];
 String  trans;
 String  ks="●";
 String  fks="■";
 String  yks="●";
unsigned char k1=0;
unsigned long gethzdz(unsigned int n);

unsigned char    Size = 15;
 int mask =0x8000;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void Translate(String str)
 {
        String st;
        int  num;
        st =str;
        trans ="";
       if(Form1->CheckBox3->Checked==true) yks=fks;
       else yks=ks;
       for (num =1; num<=4; num++)
       {
       switch  (st[num])
             {
                 case    '0' :trans =trans+"        ";   break;
                 case    '1' :trans =trans+"      "+yks;   break;
                 case    '2' :trans =trans+"    "+yks+"  ";   break;
                 case    '3' :trans =trans+"    "+yks+yks;     break;
                 case    '4' :trans =trans+"  "+yks+"    ";   break;
                 case    '5' :trans =trans+"  "+yks+"  "+yks; break;
                 case    '6' :trans =trans+"  "+yks+yks+"  "; break;
                 case    '7' :trans =trans+"  "+yks+yks+yks;  break;
                 case    '8' :trans =trans+yks+"      ";   break;
                 case    '9' :trans =trans+yks+"    "+yks;    break;
                 case    'A' :trans =trans+yks+"  "+yks+"  "; break;
                 case    'B' :trans =trans+yks+"  "+yks+yks;  break;
                 case    'C' :trans =trans+yks+yks+"    ";    break;
                 case    'D' :trans =trans+yks+yks+"  "+yks;  break;
                 case    'E' :trans =trans+yks+yks+yks+"  ";  break;
                 case    'F' :trans =trans+yks+yks+yks+yks;   break;
                }
    
          }
  //       Form1->Memo4->Lines->Add(" "+trans);
 //      Translate =trans;
//    return  Translate(trans);

}

//---------------------------------------------------------------------------
void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
  SpeedButton1->Caption =TimeToStr(Now());
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{

       int  j;
       Byte p[33];
       long q[17];
       String k,st;

       Word w;
       long count;
       int n;
       int  num; 
       int m;
       int jk;
       String sss;
       long canshu;
       String stemp;

    if ((fp = fopen("HZK16", "rb"))== NULL)
   {
     MessageDlg("  字库文件没有打开 ! ",mtError, TMsgDlgButtons() << mbOK, 0);
      return ;
   }


        FileMode  =  0;
        k =Edit1->Text;
                            //(94*(qh-1)+(wh-1))*32L;
        j =((Byte(k[1])-0xA1)*94+(Byte(k[2])-0xA1))*32;
      fseek(fp,j,SEEK_SET);

    Memo1->Text="";
    Memo1->Text=""+ char(13)+char(10);
    Memo2->Text="";
    Memo3->Text="";
    Memo1->Lines->Add(" ");
    n =1;
    Label5->Caption ="";
    sss ="";
    fread(buf+1,32,1,fp);
    for(count =1;  count<33;  count++)
    {
        if(Form1->CheckBox1->Checked==true)
          stemp ="0x"+IntToHex(Byte(buf[n]),2);

        else  stemp =IntToHex(Byte(buf[n]),2)+"H";
        if(Form1->CheckBox2->Checked==true)
          {
                if ((n % 33)!=0 ) stemp =stemp+",";
 //       if (stemp[1]>'9')  stemp ="0"+stemp;
                sss =sss+stemp;
                if (n %16==0 ) sss =sss+char(13)+char(10);
            }
        else   {
                if ((n % 33)!=0 ) stemp =stemp+",";
 //       if (stemp[1]>'9')  stemp ="0"+stemp;
                sss =sss+stemp;
                if (n %8==0 ) sss =sss+char(13)+char(10);
            }
       Label5->Caption =Label5->Caption+IntToHex(Byte(buf[n]),2);
        n++;
        if  (n % 2==1)
        {

        Translate(Label5->Caption);
         Memo1->Lines->Add(" "+trans);
        Label5->Caption ="";
        }
     }

       Memo2->Text =sss;
     for (n =1; n<33; n++)
     {
          if (n %2==1)  p[((n+1) / 2)]  =Byte(buf[n]);
          if (n %2==0 ) p[((n) / 2)+16] =Byte(buf[n]);

     }
         for (n = 1; n<17;n++)
            {
                 q[n] =p[n]*256+p[n+16];

            }
       sss ="";
        for (m =1;m<17;m++ )
        {
            w =0;
            switch (m)
              {
                 case       1:count =0x8000;  break;
                 case       2:count =0x4000;  break;
                 case       3:count =0x2000;  break;
                 case       4:count =0x1000;  break;
                 case       5:count =0x800;   break;
                 case       6:count =0x400;   break;
                 case       7:count =0x200;   break;
                 case       8:count =0x100;   break;
                 case       9:count =0x80;    break;
                 case      10:count =0x40;    break;
                 case      11:count =0x20;    break;
                 case      12:count =0x10;    break;
                 case      13:count =0x8;     break;
                 case      14:count =0x4;     break;
                 case      15:count =0x2;     break;
                 case      16:count =0x1;     break;
                 }

        for   (n=1; n<17; n++)
        {
              switch (n)
              {
                 case       1:canshu =0x8000;  break;
                 case       2:canshu =0x4000;  break;
                 case       3:canshu =0x2000;  break;
                 case       4:canshu =0x1000;  break;
                 case       5:canshu =0x800;   break;
                 case       6:canshu =0x400;   break;
                 case       7:canshu =0x200;   break;
                 case       8:canshu =0x100;   break;
                 case       9:canshu =0x80;    break;
                 case      10:canshu =0x40;    break;
                 case      11:canshu =0x20;    break;
                 case      12:canshu =0x10;    break;
                 case      13:canshu =0x8;     break;
                 case      14:canshu =0x4;     break;
                 case      15:canshu =0x2;     break;
                 case      16:canshu =0x1;     break;
                }
            
            if ((q[n] & count)!=0 )
            {
              w=w+ canshu;
             }
           }
         if(Form1->CheckBox1->Checked==true)
          {
          stemp ="0x"+IntToHex(((w&0xff00)>>8),2)+",";
          sss=sss+stemp;
          stemp= "0x"+IntToHex((w&0x00ff),2);}

        else { stemp =IntToHex(((w&0xff00)>>8),2)+"H,";
          sss=sss+stemp;
          stemp= IntToHex((w&0x00ff),2)+"H";}

        if(Form1->CheckBox2->Checked==true)
          {
                if ((m % 33)!=0 ) stemp =stemp+",";
 //       if (stemp[1]>'9')  stemp ="0"+stemp;
                sss =sss+stemp;
                if (m %8==0 ) sss =sss+char(13)+char(10);
            }
        else   {
                if ((m % 33)!=0 ) stemp =stemp+",";
 //       if (stemp[1]>'9')  stemp ="0"+stemp;
                sss =sss+stemp;
                if (m %4==0 ) sss =sss+char(13)+char(10);
            }
       Form1->Label5->Caption=Form1->Label5->Caption+IntToHex(Byte(buf[n]),2);
       }
          Form1->Memo3->Text =sss;
        fclose(fp);
}
/* x,y为显示坐标,s为显示字符串,colour为颜色 */
//void hanzi16(int x,int y,char *s,int colour)
void hanzi16(String s)
{
FILE *fp;
char i;
char buffer[32]; /* 32字节的字模缓冲区 */
register I,j,k,z,x;
unsigned char qh,wh;
unsigned long location;
        Form1->Memo4->Text ="";
        if((fp=fopen("hzk16","rb"))==NULL)
        {
         Form1->Memo4->Text =printf("Can't open hzk16!");
         getch();
         exit(0);
        }
//while(s!=0)
//        {
        qh=Byte(s[1])-0xa0;
        wh=Byte(s[2])-0xa0;
        Form1->Memo3->Text = IntToHex(qh,2)+IntToHex(wh,2);
        location=(94*(qh-1)+(wh-1)*32L); /* 计算汉字字模在文件中的位置 */
        fseek(fp,location,SEEK_SET);
        fread(buffer,32,1,fp);
        for(z=0;z<32;z++)
        {
        Form1->Memo4->Text = Form1->Memo4->Text+IntToHex(Byte(buffer[z]),2)+"H,";
        }
        for(i=0;i<16;i++)
        for(j=0;j<2;j++)
        for(k=0;k<8;k++)
        if(((buffer[i*2+j]>>(7-k))&0x1)!=NULL)
//        Form1->Memo4->Text =Form1->Memo4->Text+j;
//         Form1->Memo1->Text=(x+8*j+k+Form1->Memo1->Lines+I+1);
 //       putpixel(x+8*j+k,y+I,colour);
        s+=2;
//        x+=16; /* 汉字间距 */
 //       }
fclose(fp);
}

String ChineseText;
char ConvertByte(Byte inByte)
{
  char i;
  Byte b,t;
  t = 0;
  for (i= 0;i<4;i++)
  {
    b = (inByte >> i) & 1;
    t = t | (b << (3 - i));
  }
  return t;
}
char ConvertByteEx(Byte inByte)
 {
   Byte b1,t;

  b1 = inByte & 0x0F;
  b1 = ConvertByte(b1);
  t = b1;
  b1 = inByte >> 4;
  b1 = ConvertByte(b1);
  t = b1 << 4 | t;
  return t;
 }
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//  TCanvas  ca;
    char n,j;
    Word b;
    Byte b1,b2,b_conver,b_conver1;
    TRect arect;
    Byte p[2];
    unsigned int k;

//    ChineseText = Edit1->Text;
//   PaintBox1->Canvas->TextRect(Rect(0,0,16,16),0,0,ChineseText);
   arect = Rect(0,0,Size -1 ,Size -1 );
      PaintBox1->Canvas->Brush->Color = clWhite ;
    PaintBox1->Canvas->Pen->Color =  clBlue;  
     Memo4->Text="";
    for (n =0;n<16;n++)
       {
        //一个word是一行象素
       // {转换高低位}

        b1 = Byte(buf[n*2+1]);
/*
        b_conver = b1 & 0x0F;
        b_conver1 = b1 >> 4;
        b1  = b_conver1 | (b_conver << 4);
        b1  = ConvertByteEx(b1);
*/
        b2  =   Byte(buf[n * 2 + 2]);
/*
        b_conver  = b2 & 0x0F;
        b_conver1  = b2 >> 4;
/        b2  = b_conver1 | (b_conver << 4);
        b2  = ConvertByteEx(b2);
//        b = b1 | (b2 << 8);
        b = b2 | (b1 << 8);

       ((Byte*)& b)[0]=b1;
       ((Byte*)& b)[1]=b2;
*/
        b = b2 | (b1 << 8);
        Memo4->Lines->Add(IntToHex(b,4));
        for(j =0;j<16;j++)
        {
            if ((b & mask) == mask)
              {
                PaintBox1->Canvas->Pen->Color =  clRed;//clBlack;
                PaintBox1->Canvas->Brush->Color = clRed;//clBlack;
               }
            else
               {
                PaintBox1->Canvas->Pen->Color   = clWhite;
                PaintBox1->Canvas->Brush->Color  = clWhite;
               }
            PaintBox1->Canvas->Rectangle(arect);
            OffsetRect(arect,Size,0);
            b  = b << 1;
        }
        OffsetRect(arect,-Size * 16 ,Size);
    }
}
//---------------------------------------------------------------------------
// Borland C++ 3.0  (C) Copyright 1991 by Borland International

/* HZK12X.CPP */
/*
-------------------------------------------------------------------
作成日期:	2003-09-18
程序作者:	zzwj5120
E-mail:		zzwj5120@sina.com
文件说明:	1.C 源文件:	HZK12.CPP

		2.函数功能:	将文本file1.txt里所有汉字对应的点阵找出来
				(要全部是汉字,不能有换行等其他非汉字符号)

		3.读取的文件:	HZK12 (国标一、二级12*12点阵汉字库UCDOS)
				和file1.txt(文本文件,内容为汉字字符)

		4.生成的文件:	默认命令行第三个参数为file12.txt,即生成文件
				的名字,此文件包括file1.txt里的内容和,相对应的
				汉字点阵,统计说明等,数据格式可选择C51或汇编
				
其它说明:	5.把函数void hanzi_view()注释掉,转换的速度会快很多.
		                
编写目的:	1.市面上已经后很多专业的成熟的软件,提取各种字形的汉字字模,
		  作为给液晶和其他需要显示汉字设备的字库.出售液晶面板的厂家

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -