Font cache for fonts that are based on a freetype font. More...
Data Structures | |
struct | GlyphEntry |
Container for information about a glyph. More... | |
Public Member Functions | |
FreeTypeFontCache (FontSize fs, FT_Face face, int pixels) | |
Create a new FreeTypeFontCache. | |
~FreeTypeFontCache () | |
Free everything that was allocated for this font cache. | |
virtual SpriteID | GetUnicodeGlyph (WChar key) |
Get the SpriteID mapped to the given key. | |
virtual void | SetUnicodeGlyph (WChar key, SpriteID sprite) |
Map a SpriteID to the key. | |
virtual void | InitializeUnicodeGlyphMap () |
Initialize the glyph map. | |
virtual void | ClearFontCache () |
Reset cached glyphs. | |
virtual const Sprite * | GetGlyph (GlyphID key) |
Get the glyph (sprite) of the given key. | |
virtual uint | GetGlyphWidth (GlyphID key) |
Get the width of the glyph with the given key. | |
virtual bool | GetDrawGlyphShadow () |
Do we need to draw a glyph shadow? | |
virtual GlyphID | MapCharToGlyph (WChar key) |
Map a character into a glyph. | |
virtual const void * | GetFontTable (uint32 tag, size_t &length) |
Read a font table from the font. | |
Private Types | |
typedef SmallMap< uint32, SmallPair< size_t, const void * > > | FontTable |
Table with font table cache. | |
Private Member Functions | |
GlyphEntry * | GetGlyphPtr (GlyphID key) |
void | SetGlyphPtr (GlyphID key, const GlyphEntry *glyph, bool duplicate=false) |
Private Attributes | |
FT_Face | face |
The font face associated with this font. | |
FontTable | font_tables |
Cached font tables. | |
GlyphEntry ** | glyph_to_sprite |
The glyph cache. |
Font cache for fonts that are based on a freetype font.
Definition at line 193 of file fontcache.cpp.
FreeTypeFontCache::FreeTypeFontCache | ( | FontSize | fs, | |
FT_Face | face, | |||
int | pixels | |||
) |
Create a new FreeTypeFontCache.
fs | The font size that is going to be cached. | |
face | The font that has to be loaded. | |
pixels | The number of pixels this font should be high. |
Definition at line 252 of file fontcache.cpp.
References _default_font_height, abs(), FontCache::ascender, Clamp(), FontCache::descender, FontCache::height, MAX_FONT_SIZE, min(), and FontCache::units_per_em.
bool FreeTypeFontCache::GetDrawGlyphShadow | ( | ) | [virtual] |
Do we need to draw a glyph shadow?
Implements FontCache.
Definition at line 529 of file fontcache.cpp.
References FontCache::fs, and FS_NORMAL.
const void * FreeTypeFontCache::GetFontTable | ( | uint32 | tag, | |
size_t & | length | |||
) | [virtual] |
Read a font table from the font.
tag | The of the table to load. | |
length | The length of the read data. |
Implements FontCache.
Definition at line 559 of file fontcache.cpp.
References SmallVector< T, S >::End(), face, SmallMap< T, U, S >::Find(), font_tables, and SmallMap< T, U, S >::Insert().
Get the glyph (sprite) of the given key.
key | The key to look up. |
Implements FontCache.
Definition at line 445 of file fontcache.cpp.
References SpriteLoader::CommonPixel::a, SpriteLoader::Sprite::AllocateData(), FontCache::ascender, SpriteLoader::Sprite::data, Blitter::Encode(), face, FontCache::fs, FS_NORMAL, BlitterFactoryBase::GetCurrentBlitter(), FontCache::GetGlyph(), GetRawSprite(), GetUnicodeGlyph(), HasBit(), SpriteLoader::Sprite::height, FontCache::height, SpriteLoader::CommonPixel::m, MapCharToGlyph(), max(), FontCache::parent, FreeTypeFontCache::GlyphEntry::sprite, ST_FONT, SpriteLoader::Sprite::type, usererror(), SpriteLoader::Sprite::width, Sprite::width, FreeTypeFontCache::GlyphEntry::width, SpriteLoader::Sprite::x_offs, SpriteLoader::Sprite::y_offs, and ZOOM_LVL_NORMAL.
Referenced by GetGlyphWidth().
uint FreeTypeFontCache::GetGlyphWidth | ( | GlyphID | key | ) | [virtual] |
Get the width of the glyph with the given key.
key | The key to look up. |
Implements FontCache.
Definition at line 535 of file fontcache.cpp.
References GetGlyph(), FontCache::GetGlyphWidth(), FontCache::parent, FreeTypeFontCache::GlyphEntry::sprite, and FreeTypeFontCache::GlyphEntry::width.
Get the SpriteID mapped to the given key.
key | The key to get the sprite for. |
Implements FontCache.
Definition at line 228 of file fontcache.cpp.
References FontCache::GetUnicodeGlyph(), and FontCache::parent.
Referenced by GetGlyph().
Map a character into a glyph.
key | The character. |
Implements FontCache.
Definition at line 548 of file fontcache.cpp.
References face, FontCache::MapCharToGlyph(), and FontCache::parent.
Referenced by GetGlyph().
Map a SpriteID to the key.
key | The key to map to. | |
sprite | The sprite that is being mapped. |
Implements FontCache.
Definition at line 229 of file fontcache.cpp.
References FontCache::parent, and FontCache::SetUnicodeGlyph().
GlyphEntry** FreeTypeFontCache::glyph_to_sprite [private] |
The glyph cache.
This is structured to reduce memory consumption. 1) There is a 'segment' table for each font size. 2) Each segment table is a discrete block of characters. 3) Each block contains 256 (aligned) characters sequential characters.
The cache is accessed in the following way: For character 0x0041 ('A'): glyph_to_sprite[0x00][0x41] For character 0x20AC (Euro): glyph_to_sprite[0x20][0xAC]
Currently only 256 segments are allocated, "limiting" us to 65536 characters. This can be simply changed in the two functions Get & SetGlyphPtr.
Definition at line 220 of file fontcache.cpp.
Referenced by ClearFontCache().