[wadalabfont-kit] / jis2prim / BitmapFont.cc  

View of /jis2prim/BitmapFont.cc

Parent Directory | Revision Log
Revision: 1.4 - (download) (as text) (annotate)
Tue Aug 20 11:10:36 2002 UTC (22 years, 3 months ago) by ktanaka
Branch: MAIN
CVS Tags: SNAP-20040518, SNAP-20030702, SNAP-20030630, SNAP-20030624, HEAD
Changes since 1.3: +57 -0 lines
*** empty log message ***
#include "BitmapFont.h"

int BitmapFont::getWidth() const { return width; }
int BitmapFont::getHeight() const { return height; }
int BitmapFont::getSize() const { return width*height; }
int BitmapFont::getPixelSize() const { return pixels.size(); }
pixel BitmapFont::getPixelAt(int index) const { return pixels[index]; }
BitmapFont::BitmapFont(){}
BitmapFont::BitmapFont(const BitmapFont& b){
  width=b.width;
  height=b.height;
  bitmap=b.bitmap;
  pixels=b.pixels;
}
BitmapFont::BitmapFont(int w,int h) :width(w),height(h),bitmap(w*h,false){
}
BitmapFont::BitmapFont(int w,int h,const std::vector<pixel> &pxls)
  :width(w),height(h),bitmap(w*h,false),pixels(pxls){
  std::vector<pixel>::iterator it;
  for(it=pixels.begin();it!=pixels.end();it++){
    int x=it->first, y=it->second;
    assert(0<= x && x<width && 0<=y && y<height);
    bitmap[y*width+x]=true;
  }
}
// 暗黙のうちに幅が4ビットの倍数だと仮定している。
BitmapFont::BitmapFont(int w,int h,const std::string& hex) :width(w),height(h),bitmap(){
  for(std::string::const_iterator it=hex.begin();it!=hex.end();it++){
    std::string s;
    s+= *it;
    long val=strtol(s.c_str(),0,16);
    assert(val>=0 && val<16);
    for(int i=0;i<4;i++){
      bool pixel=false;
      if((val&(1<<(3-i)))!=0){
	pixel=true;
      }
      bitmap.push_back(pixel);
    }
  }
  for(int y=0;y<height;y++)
    for(int x=0;x<width;x++)
      if(get(x,y))
	pixels.push_back(std::pair<int,int>(x,y));
}
bool BitmapFont::get(int x, int y) const{
  if(x<0 || x>=width || y<0 || y>=height){
    return false;
  }
  return bitmap[y*width+x];
}
int BitmapFont::getIndex(const pixel &px) const{
  std::vector<pixel>::const_iterator it=find(pixels.begin(),pixels.end(),px);
  if(it!=pixels.end()){
    return it-pixels.begin();
  }
  return -1;
}
ostream& operator<<(ostream &os,const BitmapFont &bf){
#if 0
  os << "width= " << bf.getWidth()  <<",height=" << bf.getHeight() <<"\n";
#endif
  for(int y=0;y<bf.getHeight();y++){
    for(int x=0;x<bf.getWidth();x++){
      if(bf.get(x,y)) os << '@';
      else os << '.';
    }
    os << "\n";
  }
#if 0
  vector<pixel>::iterator it;
  for(it=bf.pixels.begin();it!=bf.pixels.end();it++)
    os << '(' << (*it).first << ',' << (*it).second << ')';
  os << "\n";
#endif
  return os;
}

ktanaka

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help