[wadalabfont-kit] / jis2prim / BitmapFontFile.h  

View of /jis2prim/BitmapFontFile.h

Parent Directory | Revision Log
Revision: 1.2 - (download) (as text) (annotate)
Tue Aug 6 06:30:43 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.1: +11 -10 lines
*** empty log message ***
#ifndef _BITMAP_FONT_FILE_H
#define _BITMAP_FONT_FILE_H

#include <hash_map>
#include <fstream>
#include <cstdlib>
#include <iostream>

#include "BitmapFont.h"
class BitmapFontFile{
 private:
  std::hash_map<int,BitmapFont> fonts;
 public:
  BitmapFontFile(const std::string& filename){
    std::ifstream from(filename.c_str());
    if(!from) {
      std::cerr << "Cannot open input file " << filename << '\n';
      abort(); 
    }
    long code;
    std::string hexdata;
    while(!from.eof()){
      std::string line;
      getline(from,line);
      std::string::size_type pos=line.find(' ');
      std::string key;
      std::string rest;
      if(pos!=std::string::npos){
	key=line.substr(0,pos);
	rest=line.substr(pos+1);
      }
      else key=line;
      if(key.compare("STARTCHAR")==0){
	code=strtol(rest.c_str(),0,16);
      }
      else if(key.compare("BITMAP")==0){
	hexdata="";
      }
      else if(key.compare("ENDCHAR")==0){
	fonts[code]=BitmapFont(24,24,hexdata);
      }
      else
	hexdata+=key;
    }
  }
  BitmapFont find(int code){
    return fonts[code];
  }
};
#endif /* _BITMAP_FONT_FILE_H */

ktanaka

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help