OpenTTD
|
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. | |
virtual const char * | GetFontName () |
Get the name of this font. | |
![]() | |
FontCache (FontSize fs) | |
Create a new font cache. | |
virtual | ~FontCache () |
Clean everything up. | |
FontSize | GetSize () const |
Get the FontSize of the font. | |
virtual int | GetHeight () const |
Get the height of the font. | |
int | GetAscender () const |
Get the ascender value of the font. | |
int | GetDescender () const |
Get the descender value of the font. | |
int | GetUnitsPerEM () const |
Get the units per EM value of the font. | |
bool | HasParent () |
Check whether the font cache has a parent. |
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. |
Additional Inherited Members | |
![]() | |
static FontCache * | Get (FontSize fs) |
Get the font cache of a given font size. | |
![]() | |
FontCache * | parent |
The parent of this font cache. | |
const FontSize | fs |
The size of the font. | |
int | height |
The height of the font. | |
int | ascender |
The ascender value of the font. | |
int | descender |
The descender value of the font. | |
int | units_per_em |
The units per EM value of the font. |
Font cache for fonts that are based on a freetype font.
Definition at line 208 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 268 of file fontcache.cpp.
References _default_font_height, abs(), FontCache::ascender, Clamp(), DEBUG, FontCache::descender, FontCache::fs, FS_SMALL, FontCache::height, MAX_FONT_SIZE, min(), and FontCache::units_per_em.
|
virtual |
Do we need to draw a glyph shadow?
Implements FontCache.
Definition at line 584 of file fontcache.cpp.
References FontCache::fs, and FS_NORMAL.
|
inlinevirtual |
Get the name of this font.
Implements FontCache.
Definition at line 252 of file fontcache.cpp.
References face.
|
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 614 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 475 of file fontcache.cpp.
References SpriteLoader::CommonPixel::a, SpriteLoader::Sprite::AllocateData(), FontCache::ascender, SpriteLoader::Sprite::data, Blitter::Encode(), face, FontCache::fs, FS_NORMAL, BlitterFactory::GetCurrentBlitter(), FontCache::GetGlyph(), HasBit(), FontCache::height, SpriteLoader::Sprite::height, SpriteLoader::CommonPixel::m, MapCharToGlyph(), max(), FontCache::parent, FreeTypeFontCache::GlyphEntry::sprite, ST_FONT, SpriteLoader::Sprite::type, usererror(), Sprite::width, SpriteLoader::Sprite::width, FreeTypeFontCache::GlyphEntry::width, SpriteLoader::Sprite::x_offs, SpriteLoader::Sprite::y_offs, and ZOOM_LVL_NORMAL.
Referenced by GetGlyphWidth().
|
virtual |
Get the width of the glyph with the given key.
key | The key to look up. |
Implements FontCache.
Definition at line 590 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 243 of file fontcache.cpp.
References FontCache::GetUnicodeGlyph(), and FontCache::parent.
Map a character into a glyph.
key | The character. |
Implements FontCache.
Definition at line 603 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 244 of file fontcache.cpp.
References FontCache::parent, and FontCache::SetUnicodeGlyph().
|
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 235 of file fontcache.cpp.
Referenced by ClearFontCache().