OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

fontcache.h
Go to the documentation of this file.
1 /* $Id: fontcache.h 27004 2014-10-12 20:43:25Z peter1138 $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
9
12 #ifndef FONTCACHE_H
13 #define FONTCACHE_H
14
15 #include "string_type.h"
16 #include "spritecache.h"
17
19 typedef uint32 GlyphID;
20 static const GlyphID SPRITE_GLYPH = 1U << 30;
21
23 class FontCache {
24 private:
25 static FontCache *caches[FS_END];
26 protected:
27 FontCache *parent;
28 const FontSize fs;
29 int height;
30 int ascender;
31 int descender;
32 int units_per_em;
33 public:
34 FontCache(FontSize fs);
35 virtual ~FontCache();
36
41 inline FontSize GetSize() const { return this->fs; }
42
47 virtual int GetHeight() const { return this->height; }
48
53 inline int GetAscender() const { return this->ascender; }
54
59 inline int GetDescender() const{ return this->descender; }
60
65 inline int GetUnitsPerEM() const { return this->units_per_em; }
66
72 virtual SpriteID GetUnicodeGlyph(WChar key) = 0;
73
79 virtual void SetUnicodeGlyph(WChar key, SpriteID sprite) = 0;
80
82 virtual void InitializeUnicodeGlyphMap() = 0;
83
85 virtual void ClearFontCache() = 0;
86
92 virtual const Sprite *GetGlyph(GlyphID key) = 0;
93
99 virtual uint GetGlyphWidth(GlyphID key) = 0;
100
105 virtual bool GetDrawGlyphShadow() = 0;
106
112 virtual GlyphID MapCharToGlyph(WChar key) = 0;
113
120 virtual const void *GetFontTable(uint32 tag, size_t &length) = 0;
121
126 virtual const char *GetFontName() = 0;
127
133 static inline FontCache *Get(FontSize fs)
134 {
135 assert(fs < FS_END);
136 return FontCache::caches[fs];
137 }
138
142 inline bool HasParent()
143 {
144 return this->parent != NULL;
145 }
146 };
147
149 static inline SpriteID GetUnicodeGlyph(FontSize size, WChar key)
150 {
151 return FontCache::Get(size)->GetUnicodeGlyph(key);
152 }
153
155 static inline void SetUnicodeGlyph(FontSize size, WChar key, SpriteID sprite)
156 {
157 FontCache::Get(size)->SetUnicodeGlyph(key, sprite);
158 }
159
161 static inline void InitializeUnicodeGlyphMap()
162 {
163 for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
164 FontCache::Get(fs)->InitializeUnicodeGlyphMap();
165 }
166 }
167
168 static inline void ClearFontCache()
169 {
170 for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) {
171 FontCache::Get(fs)->ClearFontCache();
172 }
173 }
174
176 static inline const Sprite *GetGlyph(FontSize size, WChar key)
177 {
178 FontCache *fc = FontCache::Get(size);
179 return fc->GetGlyph(fc->MapCharToGlyph(key));
180 }
181
183 static inline uint GetGlyphWidth(FontSize size, WChar key)
184 {
185 FontCache *fc = FontCache::Get(size);
186 return fc->GetGlyphWidth(fc->MapCharToGlyph(key));
187 }
188
189 static inline bool GetDrawGlyphShadow(FontSize size)
190 {
191 return FontCache::Get(size)->GetDrawGlyphShadow();
192 }
193
194 #ifdef WITH_FREETYPE
195
197 struct FreeTypeSubSetting {
198 char font[MAX_PATH];
199 uint size;
200 bool aa;
201 };
202
204 struct FreeTypeSettings {
205 FreeTypeSubSetting small;
206 FreeTypeSubSetting medium;
207 FreeTypeSubSetting large;
208 FreeTypeSubSetting mono;
209 };
210
211 extern FreeTypeSettings _freetype;
212
213 #endif /* WITH_FREETYPE */
214
215 void InitFreeType(bool monospace);
216 void UninitFreeType();
217
218 #endif /* FONTCACHE_H */