Revision: 1.1 - (view) (download) (as text)
1 : | ktanaka | 1.1 | #ifndef _BITMAP_FONT_FILE_H |
2 : | #define _BITMAP_FONT_FILE_H | ||
3 : | |||
4 : | #include <hash_map> | ||
5 : | #include <fstream> | ||
6 : | #include <cstdlib> | ||
7 : | |||
8 : | #include "BitmapFont.h" | ||
9 : | class BitmapFontFile{ | ||
10 : | private: | ||
11 : | hash_map<int,BitmapFont> fonts; | ||
12 : | public: | ||
13 : | BitmapFontFile(const string& filename){ | ||
14 : | ifstream from(filename.c_str()); | ||
15 : | if(!from) { | ||
16 : | cerr << "Cannot open input file " << filename << '\n'; | ||
17 : | abort(); | ||
18 : | } | ||
19 : | long code; | ||
20 : | string hexdata; | ||
21 : | while(!from.eof()){ | ||
22 : | string line; | ||
23 : | getline(from,line); | ||
24 : | string::size_type pos=line.find(' '); | ||
25 : | string key; | ||
26 : | string rest; | ||
27 : | if(pos!=string::npos){ | ||
28 : | key=line.substr(0,pos); | ||
29 : | rest=line.substr(pos+1); | ||
30 : | } | ||
31 : | else key=line; | ||
32 : | if(key.compare("STARTCHAR")==0){ | ||
33 : | code=strtol(rest.c_str(),0,16); | ||
34 : | } | ||
35 : | else if(key.compare("BITMAP")==0){ | ||
36 : | hexdata=""; | ||
37 : | } | ||
38 : | else if(key.compare("ENDCHAR")==0){ | ||
39 : | fonts[code]=BitmapFont(24,24,hexdata); | ||
40 : | } | ||
41 : | else | ||
42 : | hexdata+=key; | ||
43 : | } | ||
44 : | } | ||
45 : | BitmapFont find(int code){ | ||
46 : | return fonts[code]; | ||
47 : | } | ||
48 : | }; | ||
49 : | #endif /* _BITMAP_FONT_FILE_H */ |
ktanaka Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |