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

📄 unit1.cpp

📁 一个字体编辑工具
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TMyButton::TMyButton(TComponent* Owner)
        : TBitBtn(Owner)
{
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  FILE *fp;

  fp=fopen("Number.Fnt","rb+");
  if (fp==NULL)
   {
     fp=fopen("Number.Fnt","wb");
     for (int i=0;i<MyButtonWidth*31;i++)
     {
       fputc(0x00,fp);
     }
   }
  fclose(fp);

  Image1->Visible=false;
  Panel1->Height=164;
  Panel1->Width =184;
  UpDown1->Max=30;
  UpDown1->Position=0;



  for (int i=0;i<MyButtonHeight;i++)
    for (int j=0;j<MyButtonWidth;j++)
    {
        MyButton[i][j]=new TMyButton(this);
        MyButton[i][j]->Parent=Panel1;
        MyButton[i][j]->Enabled=True;
        MyButton[i][j]->Width =20;
        MyButton[i][j]->Height=20;
        MyButton[i][j]->Top=i*20;
        MyButton[i][j]->Left=j*20;
        MyButton[i][j]->OnClick=PublicMouseClick;
        MyButton[i][j]->flag=false;
    }
 ReadDataFromFile();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PublicMouseClick(TObject *Sender)
{
//
   TMyButton * tmpButton=dynamic_cast<TMyButton*>(Sender);
   if (tmpButton==NULL) return;
   tmpButton->flag=!tmpButton->flag;
   if (tmpButton->flag==true)
      tmpButton->Glyph=Image1->Picture->Bitmap;
   else
      tmpButton->Glyph=NULL;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ReadFromButton()
{
  unsigned char tmpChar;
  for (int j=0;j<MyButtonWidth;j++)
  {
    tmpChar=0x00;
    for (int i=0;i<MyButtonHeight;i++)
    {
       tmpChar<<=1;
       if (MyButton[i][j]->flag==true)
       {
        tmpChar|=0x01;
       }
    }
    WriteUnit[j]=tmpChar;
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WriteToButton()
{
  unsigned char tmpChar;
  for (int j=0;j<MyButtonWidth;j++)
  {
    tmpChar=WriteUnit[j];
    for (int i=0;i<MyButtonHeight;i++)
    {
      if ((tmpChar&0x80)==0x80)
      {
         MyButton[i][j]->flag=true;
         MyButton[i][j]->Glyph=Image1->Picture->Bitmap;
      }
      else
      {
         MyButton[i][j]->flag=false;
         MyButton[i][j]->Glyph=NULL;
       }  
      tmpChar<<=1;
    }
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  FILE *fp;

  fp=fopen("Number.Fnt","rb+");
  if (fp==NULL) return;

  ReadFromButton();

  fseek(fp,UpDown1->Position*MyButtonWidth*1L,SEEK_SET);
  fwrite(WriteUnit,MyButtonWidth,1,fp);

  fclose(fp);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::UpDown1Click(TObject *Sender, TUDBtnType Button)
{
//
  ReadDataFromFile();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClearButtonDisplay()
{
  for (int i=0;i<MyButtonHeight;i++)
    for (int j=0;j<MyButtonWidth;j++)
    {
        MyButton[i][j]->flag=false;
        MyButton[i][j]->Glyph=NULL;
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
   ClearButtonDisplay();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ReadDataFromFile()
{
  FILE *fp;

  fp=fopen("Number.Fnt","rb+");
  if (fp==NULL) return;

  ClearButtonDisplay();

  fseek(fp,UpDown1->Position*MyButtonWidth*1L,SEEK_SET);
  fread(WriteUnit,MyButtonWidth,1,fp);

  fclose(fp);
  WriteToButton();

  Label1->Caption="当前字符: "+IntToStr(UpDown1->Position+1);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
//
  FILE *fp1,*fp2;
  fp1=fopen("Number.Fnt","rb+");
  if (fp1==NULL) return;
  fp2=fopen("Number.Txt","wt");
  if (fp2==NULL) return;

  unsigned char ch;
  for (int i=0;i<31;i++)
  {

    fprintf(fp2,"  DB ",ch);
    for (int j=0;j<MyButtonWidth;j++)
    {
      ch=fgetc(fp1);
      fprintf(fp2,"0x%+02x",ch);
      if (j<MyButtonWidth-1) fprintf(fp2,",");
    }
    fprintf(fp2,"  ;%d\n",i+1);
  }
  fclose(fp1);
  fclose(fp2);
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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