OpenTTD Source  13.2.1
spritefontcache.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #ifndef SPRITEFONTCACHE_H
11 #define SPRITEFONTCACHE_H
12 
13 #include "../string_func.h"
14 #include "../fontcache.h"
15 
17 class SpriteFontCache : public FontCache {
18 private:
20  SpriteID GetUnicodeGlyph(WChar key);
21 
22  void ClearGlyphToSpriteMap();
23 public:
26  virtual void SetUnicodeGlyph(WChar key, SpriteID sprite);
27  virtual void InitializeUnicodeGlyphMap();
28  virtual void ClearFontCache();
29  virtual const Sprite *GetGlyph(GlyphID key);
30  virtual uint GetGlyphWidth(GlyphID key);
31  virtual bool GetDrawGlyphShadow();
32  virtual GlyphID MapCharToGlyph(WChar key) { assert(IsPrintable(key)); return SPRITE_GLYPH | key; }
33  virtual const void *GetFontTable(uint32 tag, size_t &length) { length = 0; return nullptr; }
34  virtual std::string GetFontName() { return "sprite"; }
35  virtual bool IsBuiltInFont() { return true; }
36 };
37 
38 #endif /* SPRITEFONTCACHE_H */
GlyphID
uint32 GlyphID
Glyphs are characters from a font.
Definition: fontcache.h:17
SpriteFontCache::InitializeUnicodeGlyphMap
virtual void InitializeUnicodeGlyphMap()
Initialize the glyph map.
Definition: spritefontcache.cpp:56
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:36
SpriteFontCache::GetGlyphWidth
virtual uint GetGlyphWidth(GlyphID key)
Get the width of the glyph with the given key.
Definition: spritefontcache.cpp:119
SpriteFontCache::GetFontName
virtual std::string GetFontName()
Get the name of this font.
Definition: spritefontcache.h:34
SpriteFontCache
Font cache for fonts that are based on a freetype font.
Definition: spritefontcache.h:17
SpriteFontCache::MapCharToGlyph
virtual GlyphID MapCharToGlyph(WChar key)
Map a character into a glyph.
Definition: spritefontcache.h:32
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
SpriteFontCache::GetFontTable
virtual const void * GetFontTable(uint32 tag, size_t &length)
Read a font table from the font.
Definition: spritefontcache.h:33
SpriteFontCache::glyph_to_spriteid_map
SpriteID ** glyph_to_spriteid_map
Mapping of glyphs to sprite IDs.
Definition: spritefontcache.h:19
FontCache::fs
const FontSize fs
The size of the font.
Definition: fontcache.h:26
SpriteFontCache::GetDrawGlyphShadow
virtual bool GetDrawGlyphShadow()
Do we need to draw a glyph shadow?
Definition: spritefontcache.cpp:126
FontCache
Font cache for basic fonts.
Definition: fontcache.h:21
SpriteFontCache::SetUnicodeGlyph
virtual void SetUnicodeGlyph(WChar key, SpriteID sprite)
Map a SpriteID to the key.
Definition: spritefontcache.cpp:49
SpriteFontCache::ClearFontCache
virtual void ClearFontCache()
Clear the font cache.
Definition: spritefontcache.cpp:105
SpriteFontCache::~SpriteFontCache
~SpriteFontCache()
Free everything we allocated.
Definition: spritefontcache.cpp:38
SpriteFontCache::ClearGlyphToSpriteMap
void ClearGlyphToSpriteMap()
Clear the glyph to sprite mapping.
Definition: spritefontcache.cpp:94
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:202
SpriteFontCache::IsBuiltInFont
virtual bool IsBuiltInFont()
Is this a built-in sprite font?
Definition: spritefontcache.h:35
SpriteFontCache::GetGlyph
virtual const Sprite * GetGlyph(GlyphID key)
Get the glyph (sprite) of the given key.
Definition: spritefontcache.cpp:112
SpriteFontCache::SpriteFontCache
SpriteFontCache(FontSize fs)
Create a new sprite font cache.
Definition: spritefontcache.cpp:28
Sprite
Data structure describing a sprite.
Definition: spritecache.h:17