00001 /* $Id: fontcache.h 25502 2013-06-28 19:44:28Z rubidium $ */ 00002 00003 /* 00004 * This file is part of OpenTTD. 00005 * 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. 00006 * 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. 00007 * 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/>. 00008 */ 00009 00012 #ifndef FONTCACHE_H 00013 #define FONTCACHE_H 00014 00015 #include "string_type.h" 00016 #include "spritecache.h" 00017 00019 typedef uint32 GlyphID; 00020 static const GlyphID SPRITE_GLYPH = 1U << 30; 00021 00023 class FontCache { 00024 private: 00025 static FontCache *caches[FS_END]; 00026 protected: 00027 FontCache *parent; 00028 const FontSize fs; 00029 int height; 00030 int ascender; 00031 int descender; 00032 int units_per_em; 00033 public: 00034 FontCache(FontSize fs); 00035 virtual ~FontCache(); 00036 00041 inline FontSize GetSize() const { return this->fs; } 00042 00047 inline int GetHeight() const { return this->height; } 00048 00053 inline int GetAscender() const { return this->ascender; } 00054 00059 inline int GetDescender() const{ return this->descender; } 00060 00065 inline int GetUnitsPerEM() const { return this->units_per_em; } 00066 00072 virtual SpriteID GetUnicodeGlyph(WChar key) = 0; 00073 00079 virtual void SetUnicodeGlyph(WChar key, SpriteID sprite) = 0; 00080 00082 virtual void InitializeUnicodeGlyphMap() = 0; 00083 00085 virtual void ClearFontCache() = 0; 00086 00092 virtual const Sprite *GetGlyph(GlyphID key) = 0; 00093 00099 virtual uint GetGlyphWidth(GlyphID key) = 0; 00100 00105 virtual bool GetDrawGlyphShadow() = 0; 00106 00112 virtual GlyphID MapCharToGlyph(WChar key) = 0; 00113 00120 virtual const void *GetFontTable(uint32 tag, size_t &length) = 0; 00121 00127 static inline FontCache *Get(FontSize fs) 00128 { 00129 assert(fs < FS_END); 00130 return FontCache::caches[fs]; 00131 } 00132 00136 inline bool HasParent() 00137 { 00138 return this->parent != NULL; 00139 } 00140 }; 00141 00143 static inline SpriteID GetUnicodeGlyph(FontSize size, WChar key) 00144 { 00145 return FontCache::Get(size)->GetUnicodeGlyph(key); 00146 } 00147 00149 static inline void SetUnicodeGlyph(FontSize size, WChar key, SpriteID sprite) 00150 { 00151 FontCache::Get(size)->SetUnicodeGlyph(key, sprite); 00152 } 00153 00155 static inline void InitializeUnicodeGlyphMap() 00156 { 00157 for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) { 00158 FontCache::Get(fs)->InitializeUnicodeGlyphMap(); 00159 } 00160 } 00161 00162 static inline void ClearFontCache() { 00163 for (FontSize fs = FS_BEGIN; fs < FS_END; fs++) { 00164 FontCache::Get(fs)->ClearFontCache(); 00165 } 00166 } 00167 00169 static inline const Sprite *GetGlyph(FontSize size, WChar key) 00170 { 00171 FontCache *fc = FontCache::Get(size); 00172 return fc->GetGlyph(fc->MapCharToGlyph(key)); 00173 } 00174 00176 static inline uint GetGlyphWidth(FontSize size, WChar key) 00177 { 00178 FontCache *fc = FontCache::Get(size); 00179 return fc->GetGlyphWidth(fc->MapCharToGlyph(key)); 00180 } 00181 00182 static inline bool GetDrawGlyphShadow(FontSize size) 00183 { 00184 return FontCache::Get(size)->GetDrawGlyphShadow(); 00185 } 00186 00187 #ifdef WITH_FREETYPE 00188 00190 struct FreeTypeSubSetting { 00191 char font[MAX_PATH]; 00192 uint size; 00193 bool aa; 00194 }; 00195 00197 struct FreeTypeSettings { 00198 FreeTypeSubSetting small; 00199 FreeTypeSubSetting medium; 00200 FreeTypeSubSetting large; 00201 FreeTypeSubSetting mono; 00202 }; 00203 00204 extern FreeTypeSettings _freetype; 00205 00206 #endif /* WITH_FREETYPE */ 00207 00208 void InitFreeType(bool monospace); 00209 void UninitFreeType(); 00210 00211 #endif /* FONTCACHE_H */