[wadalabfont-kit] / jis2prim / BitmapFont.h  

View of /jis2prim/BitmapFont.h

Parent Directory | Revision Log
Revision: 1.2 - (download) (as text) (annotate)
Fri Feb 22 12:03:48 2002 UTC (22 years, 8 months ago) by ktanaka
Branch: MAIN
Changes since 1.1: +19 -1 lines
*** empty log message ***
#ifndef _BITMAP_FONT_H
#define _BITMAP_FONT_H

#include <vector>
#include <string>
#include <algorithm>

typedef pair<int,int> pixel;

class BitmapFont{
  friend ostream& operator<<(ostream &os,const BitmapFont &bf);
 private:
  int width, height;
  vector<bool> bitmap;
  vector<pixel> pixels;
 public:
  int getWidth() const { return width; }
  int getHeight() const { return height; }
  BitmapFont(){}
  BitmapFont(const BitmapFont& b){
    width=b.width;
    height=b.height;
    bitmap=b.bitmap;
    pixels=b.pixels;
  }
  BitmapFont(int w,int h) :width(w),height(h),bitmap(w*h,false){
  }
  // 暗黙のうちに幅が4ビットの倍数だと仮定している。
  BitmapFont(int w,int h,const string& hex) :width(w),height(h),bitmap(){
    for(string::const_iterator it=hex.begin();it!=hex.end();it++){
      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(pair<int,int>(x,y));
  }
  bool get(int x, int y) const{
    if(x<0 || x>=width || y<0 || y>=height){
      return false;
    }
    return bitmap[y*width+x];
  }
  int getIndex(const pixel &px){
    vector<pixel>::iterator it=find(pixels.begin(),pixels.end(),px);
    if(it!=pixels.end()){
      return it-pixels.begin();
    }
    return -1;
  }
};
#endif /* _BITMAP_FONT_H */

ktanaka

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help