Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1418877
  • 博文数量: 430
  • 博客积分: 9995
  • 博客等级: 中将
  • 技术积分: 4388
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-24 18:04
文章存档

2013年(1)

2008年(2)

2007年(14)

2006年(413)

分类:

2006-11-17 09:02:58



程序示例(DELPHI和C代码)

地址的定位(Delphi 源码)
function TForm1.GetBeginAddr(LX:string;PX,PY,HanW,HanH:integer):integer;
var
  cb,qx:integer;
begin
  qx:=0;
  if (HanW mod 8)>0 then cb:=trunc(HanW/8)+1
  else cb:=trunc(HanW/8);
  cb:=cb*HanH;
  if LX='GB2312' then begin
    qx:=PX-$A1;
    qx:=qx*94+PY-$A1;
  end;
  if LX='GBK' then begin
    if PY<$7F then qx:=PY-$40
    else qx:=PY-$41;
    qx:=qx+(PX-$81)*190;
  end;
  if LX='BIG5' then begin
    if PY<$7F then qx:=PY-$40
    else qx:=PY-$62;
  qx:=qx+(PX-$A1)*157;
  end;
  if LX='SJIS' then begin
    if PY<$A0 then qx:=PY-$81
    else qx:=PY-$CE;
    qx:=qx+(PX-$A1)*188;
  end;
  if LX='UNICODE' then begin
    qx:=PX*$100+PY;
  end;
  qx:=qx*cb;
  result:=qx;
end;
 
默认取点模式的显示(Delphi 源码)
procedure TForm1.Button2Click(Sender: TObject);
var
  b0,b1,b2:Byte;
  cw,cb:integer;
  i,j,k,len,px:integer;
  rad:integer;
begin
  if FPHandle=0 then exit;
  if (SpinEdit1.Value mod 8)>0 then cw:=trunc(SpinEdit1.Value/8)+1
  else cw:=trunc(SpinEdit1.Value/8);
  cb:=cw*SpinEdit2.Value;
  if (RadioButton2.Checked) then px:=cb*SpinEdit4.Value
  else begin
    px:=GetBeginAddr(ComboBox1.Text,strtoint('$'+ComboBox2.Text),
      strtoint('$'+ComboBox3.Text),SpinEdit1.Value,SpinEdit2.Value);
  end;
  FileSeek(FPHandle,px,0);
  rad:=SpinEdit3.Value;
  image1.Picture.Bitmap.Width:=spinedit1.Value*rad;
  image1.Picture.Bitmap.Height:=spinedit2.Value*rad;
  image1.Width:=spinedit1.Value*rad;
  image1.Height:=spinedit2.Value*rad;
  image1.Left:=trunc((GroupBox1.Width-image1.Width)/2);
  image1.Top:=trunc((GroupBox1.Height-image1.Height)/2);
  image1.Canvas.Brush.Color:=clWhite;
  image1.Canvas.FillRect(Rect(0,0,image1.Width,image1.Height));
  for i:=0 to SpinEdit2.Value-1 do begin
    len:=0;
    for j:=0 to cw-1 do begin
      fileRead(FPHandle,B0,1);
      B1:=B0;
      for k:=0 to 7 do begin
        B2:=B1;
        b2:=b2 shl k;
        b2:=b2 shr 7;
        if b2<>0 then begin
        image1.Canvas.Brush.Color:=clBlack;
        image1.Canvas.FillRect(Rect(len*rad,i*rad,
            (len+1)*rad-1,(i+1)*rad-1));
        end else begin
          image1.Canvas.Brush.Color:=clBlue;
          image1.Canvas.FrameRect(Rect(len*rad,i*rad,
            (len+1)*rad-1,(i+1)*rad-1));
        end;
        len:=len+1;
        if len>SpinEdit1.Value-1 then break;
      end;
    end;
  end;
end;
 
BORLAND C++ 3.1源码示例

void HzkClass::ReadBig5HzkLib( byte First,byte Second, byte *Buf)//读取BIG5编码的点阵汉字库
{
  long q;
  int b;

  if(!InitOk) return;
  if(First<0xa1 || First>0xf9) return; //不符合BIG5编码要求
  if((Second<0x40)||(Second>0x7e && Second<0xa1)
        ||(Second> 0xfe))return;//不符合BIG5编码要求
  q=157*(First-0xa1); //BIG5编码是一个区157个汉字
  if(Second<0xa1)
    q=q+(Second-0x40);
  else
    q=q+(Second-0x62);
  q=q*BufLen;

  if(HzkW&0x07)??b=HzkW>>3+1;//得到每行占用多少字节
  else??b=HzkW>>3;

  if(HzkPosition==XMS){
    if(xmsget(handle,q,Buf,HzkH*b)==0){
      memset(HzkBuf,0,BufLen);
      strcpy(ErrorMessage,"Read Dot From XMS Error!");
      ErrorCode=1;
    }
  }else{
    if(FPHandle!=NULL){
      fseek(FPHandle,q,SEEK_SET);
      fread(Buf,1,BufLen,FPHandle);
    }else{
      strcpy(ErrorMessage,"FPHandle Not Opened File!");
      ErrorCode=2;
    }
  }
}

void HzkClass::ReadHzkLib( byte First, byte Second, byte *Buf)
//读取GB2312编码的点阵汉字库
{
  long q;//注:HzkH是字体高度,HzkW是字体的宽度
  int b;

  if(!InitOk) return;
  if(First<0xa1 && Second<0xa1) return; //不符合GB2312编码要求
  q=94*(First-0xa1);
  q=q+(Second-0xa1);
  q=q*BufLen;

  if(HzkW&0x07)??b=HzkW>>3+1;//得到每行占用多少字节
  else??b=HzkW>>3;

  if(HzkPosition==XMS){
    if(xmsget(handle,q,Buf,HzkH*b)==0){
      memset(HzkBuf,0,BufLen);
      strcpy(ErrorMessage,"Read Dot From XMS Error!");
      ErrorCode=1;
    }
  }else{
    if(FPHandle!=NULL){
      fseek(FPHandle,q,SEEK_SET);
      fread(Buf,1,BufLen,FPHandle);
    }else{
      strcpy(ErrorMessage,"FPHandle Not Opened File!");
      ErrorCode=2;
    }
  }
}


void HzkClass::ShowHzk( PixelMode mode, int x, int y, byte * Buf )
//显示从汉字库中读出的汉字
{
register byte i;
register int x0,y0;
RasterBlock *buf;
if(!NoBColor){//显示背景色,则用块显示,可以提高显示速度
  if((buf=(RasterBlock *)malloc(500))==NULL)return;
    buf->width = HzkW-1;
    buf->height= HzkH-1;
  }
  for(y0=0;y0     i=0x80;
    x0=0;
    while(i){
      if(*Buf&i){
        if(!NoBColor) buf->data[y0*HzkW+x0]=FColor;
        else drwpoint(mode,FColor,x0+x,y0+y);
      }else if(!NoBColor) buf->data[y0*HzkW+x0]=BColor;
      if((x0+8)         if(*(Buf+1)&i){
          if(!NoBColor) buf->data[y0*HzkW+x0+8]=FColor;
          else drwpoint(mode,FColor,x0+x+8,y0+y);
        }else if(!NoBColor) buf->data[y0*HzkW+x0+8]=BColor;
      }
      i>>=1;
      x0++;
    }
    Buf+=2;
  }
  if(!NoBColor){
    blkput(SET,x,y,buf);
    free(buf);
  }
}


阅读(2381) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~