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