📄 mainfont.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MainFont.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
try
{
//以只读方式打开字库文件,并将数据读到缓冲区中。
iFileHandle = FileOpen("hzk16", fmOpenRead);
iFileLength = FileSeek(iFileHandle,0,2);
FileSeek(iFileHandle,0,0);
pszBuffer = new char[iFileLength+1];
iBytesRead = FileRead(iFileHandle, pszBuffer, iFileLength);
OKButton->Enabled=true;
ForwardButton->Enabled=true;
NextButton->Enabled=true;
}
catch(...)
{
Application->MessageBox("打开文件错误", "错误信息", IDOK);
}
dptr=0;//设置冲区起始指针
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormDestroy(TObject *Sender)
{
delete [] pszBuffer;
FileClose(iFileHandle);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::NextButtonClick(TObject *Sender)
{
PaintFont();
}
void __fastcall TMainForm::ForwardButtonClick(TObject *Sender)
{
if(dptr>=64)
{
dptr=dptr-64;
PaintFont();
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::DrawRect()
{
int width=320;
int height=320;
PaintBox1->Canvas->Brush->Color=clBlack;
PaintBox1->Canvas->FillRect(Rect(0,0,PaintBox1->Width,PaintBox1->Height));
PaintBox1->Canvas->Pen->Color = clYellow;
for(int i=0;i<17;i++)
{
PaintBox1->Canvas->MoveTo(1,i*20);
PaintBox1->Canvas->LineTo(width,i*20);
PaintBox1->Canvas->MoveTo(i*20,1);
PaintBox1->Canvas->LineTo(i*20,height);
}
}
void __fastcall TMainForm::PaintBox1Paint(TObject *Sender)
{
DrawRect();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::PaintFont()
{
PaintBox2->Canvas->Brush->Color=clBlack;
PaintBox2->Canvas->FillRect(Rect(0,0,PaintBox2->Width,PaintBox2->Height));
PaintBox1->Canvas->Brush->Color=clBlack;
PaintBox1->Canvas->FillRect(Rect(0,0,PaintBox1->Width,PaintBox1->Height));
DrawRect();
POINT point;
point.x=0;point.y=0;
int i,j;
char ch,ch1;
PaintBox1->Canvas->Brush->Color=clBlue;
for(i=0;i<16;i++)
{
for(j=0;j<2;j++)
{
ch=*(pszBuffer+dptr); dptr++;
ch1=ch;ch>>=7;ch&=0x1;
if(ch==1)
{
PaintBox2->Canvas->Pixels[point.x][point.y] = clRed;
PaintBox1->Canvas->FillRect(Rect(point.x*20+1,
point.y*20+1,point.x*20+19,point.y*20+19));
}
point.x++;
ch=ch1;ch>>=6;ch&=0x1;
if(ch==1)
{
PaintBox2->Canvas->Pixels[point.x][point.y] = clRed;
PaintBox1->Canvas->FillRect(Rect(point.x*20+1,
point.y*20+1,point.x*20+19,point.y*20+19));
}
point.x++;
ch=ch1;ch>>=5;ch&=0x1;
if(ch==1)
{
PaintBox2->Canvas->Pixels[point.x][point.y] = clRed;
PaintBox1->Canvas->FillRect(Rect(point.x*20+1,
point.y*20+1,point.x*20+19,point.y*20+19));
}
point.x++;
ch=ch1;ch>>=4;ch&=0x1;
if(ch==1)
{
PaintBox2->Canvas->Pixels[point.x][point.y] = clRed;
PaintBox1->Canvas->FillRect(Rect(point.x*20+1,
point.y*20+1,point.x*20+19,point.y*20+19));
}
point.x++;
ch=ch1;ch>>=3;ch&=0x1;
if(ch==1)
{
PaintBox2->Canvas->Pixels[point.x][point.y] = clRed;
PaintBox1->Canvas->FillRect(Rect(point.x*20+1,
point.y*20+1,point.x*20+19,point.y*20+19));
}
point.x++;
ch=ch1;ch>>=2;ch&=0x1;
if(ch==1)
{
PaintBox2->Canvas->Pixels[point.x][point.y] = clRed;
PaintBox1->Canvas->FillRect(Rect(point.x*20+1,
point.y*20+1,point.x*20+19,point.y*20+19));
}
point.x++;
ch=ch1;ch>>=1;ch&=0x1;
if(ch==1)
{
PaintBox2->Canvas->Pixels[point.x][point.y] = clRed;
PaintBox1->Canvas->FillRect(Rect(point.x*20+1,
point.y*20+1,point.x*20+19,point.y*20+19));
}
point.x++;
ch=ch1;ch&=0x1;
if(ch==1)
{
PaintBox2->Canvas->Pixels[point.x][point.y] = clRed;
PaintBox1->Canvas->FillRect(Rect(point.x*20+1,
point.y*20+1,point.x*20+19,point.y*20+19));
}
point.x++;
}
point.y++;
point.x=0;
}
}
//---------------------------------------------------------------------------
int __fastcall TMainForm::GetWordPtr(int x1,int x2)
{
int size;
if((x1&0x80)!=0)
{
x1=x1&0x7f; //内码转换为区位码
x2=x2&0x7f;
x1=x1-0x20;
x2=x2-0x20;
size=((x1-1)*94+(x2-1))*32;
//16点阵汉字:
// 偏移量=((区号-1)*94+(位号-1))*32
// 或:偏移量=((机内码高8位-0xA1)*94+(机内码低8位-0xA1))*32
//24点阵汉字:
//前16区: 偏移量=((区号-1)*94+(位号-1))*72
//后16区: 偏移量=((区号-17)*94+(位号-1))*72
}
else
{
size=(188+x1-33)*32; //为字符时
}
/////////////////////////////////
return size;
}
void __fastcall TMainForm::OKButtonClick(TObject *Sender)
{
AnsiString cs;
cs=Edit1->Text;
char cs1[2];
wsprintf(cs1,cs.c_str());
dptr=GetWordPtr(cs1[0],cs1[1]);
PaintFont();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -