OpenTTD
Data Structures | Public Member Functions | Private Types | Private Member Functions | Private Attributes
FreeTypeFontCache Class Reference

Font cache for fonts that are based on a freetype font. More...

Inheritance diagram for FreeTypeFontCache:
FontCache

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 SpriteGetGlyph (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.
- Public Member Functions inherited from FontCache
 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

GlyphEntryGetGlyphPtr (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 Public Member Functions inherited from FontCache
static FontCacheGet (FontSize fs)
 Get the font cache of a given font size.
- Protected Attributes inherited from FontCache
FontCacheparent
 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.

Detailed Description

Font cache for fonts that are based on a freetype font.

Definition at line 208 of file fontcache.cpp.

Constructor & Destructor Documentation

FreeTypeFontCache::FreeTypeFontCache ( FontSize  fs,
FT_Face  face,
int  pixels 
)

Create a new FreeTypeFontCache.

Parameters
fsThe font size that is going to be cached.
faceThe font that has to be loaded.
pixelsThe 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.

Member Function Documentation

bool FreeTypeFontCache::GetDrawGlyphShadow ( )
virtual

Do we need to draw a glyph shadow?

Returns
True if it has to be done, otherwise false.

Implements FontCache.

Definition at line 584 of file fontcache.cpp.

References FontCache::fs, and FS_NORMAL.

virtual const char* FreeTypeFontCache::GetFontName ( )
inlinevirtual

Get the name of this font.

Returns
The name of the font.

Implements FontCache.

Definition at line 252 of file fontcache.cpp.

References face.

const void * FreeTypeFontCache::GetFontTable ( uint32  tag,
size_t &  length 
)
virtual

Read a font table from the font.

Parameters
tagThe of the table to load.
lengthThe length of the read data.
Returns
The loaded table 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().

const Sprite * FreeTypeFontCache::GetGlyph ( GlyphID  key)
virtual
uint FreeTypeFontCache::GetGlyphWidth ( GlyphID  key)
virtual

Get the width of the glyph with the given key.

Parameters
keyThe key to look up.
Returns
The width.

Implements FontCache.

Definition at line 590 of file fontcache.cpp.

References GetGlyph(), FontCache::GetGlyphWidth(), FontCache::parent, FreeTypeFontCache::GlyphEntry::sprite, and FreeTypeFontCache::GlyphEntry::width.

virtual SpriteID FreeTypeFontCache::GetUnicodeGlyph ( WChar  key)
inlinevirtual

Get the SpriteID mapped to the given key.

Parameters
keyThe key to get the sprite for.
Returns
The sprite.

Implements FontCache.

Definition at line 243 of file fontcache.cpp.

References FontCache::GetUnicodeGlyph(), and FontCache::parent.

GlyphID FreeTypeFontCache::MapCharToGlyph ( WChar  key)
virtual

Map a character into a glyph.

Parameters
keyThe character.
Returns
The glyph ID used to draw the character.

Implements FontCache.

Definition at line 603 of file fontcache.cpp.

References face, FontCache::MapCharToGlyph(), and FontCache::parent.

Referenced by GetGlyph().

virtual void FreeTypeFontCache::SetUnicodeGlyph ( WChar  key,
SpriteID  sprite 
)
inlinevirtual

Map a SpriteID to the key.

Parameters
keyThe key to map to.
spriteThe sprite that is being mapped.

Implements FontCache.

Definition at line 244 of file fontcache.cpp.

References FontCache::parent, and FontCache::SetUnicodeGlyph().

Field Documentation

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 235 of file fontcache.cpp.

Referenced by ClearFontCache().


The documentation for this class was generated from the following file: