1 /*
2  * Copyright 2011-2013 Arx Libertatis Team (see the AUTHORS file)
3  *
4  * This file is part of Arx Libertatis.
5  *
6  * Arx Libertatis is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Arx Libertatis is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Arx Libertatis.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ARX_GRAPHICS_FONT_FONTCACHE_H
21 #define ARX_GRAPHICS_FONT_FONTCACHE_H
22 
23 #include <stddef.h>
24 #include <string>
25 #include <map>
26 #include <utility>
27 
28 #include "graphics/font/Font.h"
29 #include "io/resource/ResourcePath.h"
30 
31 class FontCache {
32 
33 	typedef std::map<unsigned, Font *> FontMap;
34 
35 	struct FontFile {
36 
37 		size_t size;
38 		char * data;
39 
FontFileFontFile40 		FontFile() : size(0), data(NULL) { }
41 
42 		FontMap sizes;
43 
44 	};
45 
46 public:
47 
48 	static void initialize();
49 	static void shutdown();
50 
51 	static Font * getFont(const res::path & fontFile, unsigned int fontSize);
52 	static void releaseFont(Font * pFont);
53 
54 private:
55 
56 	// Disable creation from outside.
57 	FontCache();
58 	~FontCache();
59 
60 	Font * create(const res::path & fontFile, FontFile & file, unsigned int fontSize);
61 
62 
63 	typedef std::map<res::path, FontFile> FontFiles;
64 	FontFiles files;
65 
66 	static FontCache * instance;
67 };
68 
69 #endif // ARX_GRAPHICS_FONT_FONTCACHE_H
70