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.

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.

Detailed Description

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

Definition at line 198 of file fontcache.cpp.


Constructor & Destructor Documentation

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

Create a new FreeTypeFontCache.

Parameters:
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 257 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.


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 561 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.

Parameters:
tag The of the table to load.
length The length of the read data.
Returns:
The loaded table data.

Implements FontCache.

Definition at line 591 of file fontcache.cpp.

References SmallVector< T, S >::End(), face, SmallMap< T, U, S >::Find(), font_tables, and SmallMap< T, U, S >::Insert().

uint FreeTypeFontCache::GetGlyphWidth ( GlyphID  key  )  [virtual]

Get the width of the glyph with the given key.

Parameters:
key The key to look up.
Returns:
The width.

Implements FontCache.

Definition at line 567 of file fontcache.cpp.

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

virtual SpriteID FreeTypeFontCache::GetUnicodeGlyph ( WChar  key  )  [inline, virtual]

Get the SpriteID mapped to the given key.

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

Implements FontCache.

Definition at line 233 of file fontcache.cpp.

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

GlyphID FreeTypeFontCache::MapCharToGlyph ( WChar  key  )  [virtual]

Map a character into a glyph.

Parameters:
key The character.
Returns:
The glyph ID used to draw the character.

Implements FontCache.

Definition at line 580 of file fontcache.cpp.

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

Referenced by GetGlyph().

virtual void FreeTypeFontCache::SetUnicodeGlyph ( WChar  key,
SpriteID  sprite 
) [inline, virtual]

Map a SpriteID to the key.

Parameters:
key The key to map to.
sprite The sprite that is being mapped.

Implements FontCache.

Definition at line 234 of file fontcache.cpp.

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


Field Documentation

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

Referenced by ClearFontCache().


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