OpenTTD Source  1.11.2
FontCache Class Referenceabstract

Font cache for basic fonts. More...

#include <fontcache.h>

Inheritance diagram for FontCache:
SpriteFontCache TrueTypeFontCache CoreTextFontCache FreeTypeFontCache Win32FontCache

Public Member Functions

 FontCache (FontSize fs)
 Create a new font cache. More...
 
virtual ~FontCache ()
 Clean everything up.
 
FontSize GetSize () const
 Get the FontSize of the font. More...
 
virtual int GetHeight () const
 Get the height of the font. More...
 
int GetAscender () const
 Get the ascender value of the font. More...
 
int GetDescender () const
 Get the descender value of the font. More...
 
int GetUnitsPerEM () const
 Get the units per EM value of the font. More...
 
virtual int GetFontSize () const
 Get the nominal font size of the font. More...
 
virtual SpriteID GetUnicodeGlyph (WChar key)=0
 Get the SpriteID mapped to the given key. More...
 
virtual void SetUnicodeGlyph (WChar key, SpriteID sprite)=0
 Map a SpriteID to the key. More...
 
virtual void InitializeUnicodeGlyphMap ()=0
 Initialize the glyph map.
 
virtual void ClearFontCache ()=0
 Clear the font cache.
 
virtual const SpriteGetGlyph (GlyphID key)=0
 Get the glyph (sprite) of the given key. More...
 
virtual uint GetGlyphWidth (GlyphID key)=0
 Get the width of the glyph with the given key. More...
 
virtual bool GetDrawGlyphShadow ()=0
 Do we need to draw a glyph shadow? More...
 
virtual GlyphID MapCharToGlyph (WChar key)=0
 Map a character into a glyph. More...
 
virtual const void * GetFontTable (uint32 tag, size_t &length)=0
 Read a font table from the font. More...
 
virtual const void * GetOSHandle ()
 Get the native OS font handle, if there is one. More...
 
virtual const char * GetFontName ()=0
 Get the name of this font. More...
 
bool HasParent ()
 Check whether the font cache has a parent.
 
virtual bool IsBuiltInFont ()=0
 Is this a built-in sprite font?
 

Static Public Member Functions

static FontCacheGet (FontSize fs)
 Get the font cache of a given font size. More...
 

Static Protected Member Functions

static int GetDefaultFontHeight (FontSize fs)
 

Protected Attributes

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.
 

Static Private Attributes

static FontCachecaches [FS_END] = { new SpriteFontCache(FS_NORMAL), new SpriteFontCache(FS_SMALL), new SpriteFontCache(FS_LARGE), new SpriteFontCache(FS_MONO) }
 All the font caches.
 

Detailed Description

Font cache for basic fonts.

Definition at line 21 of file fontcache.h.

Constructor & Destructor Documentation

◆ FontCache()

FontCache::FontCache ( FontSize  fs)

Create a new font cache.

Parameters
fsThe size of the font.

Definition at line 41 of file fontcache.cpp.

Member Function Documentation

◆ Get()

static FontCache* FontCache::Get ( FontSize  fs)
inlinestatic

Get the font cache of a given font size.

Parameters
fsThe font size to look up.
Returns
The font cache.

Definition at line 149 of file fontcache.h.

References fs.

Referenced by GetCharacterHeight(), GetGlyph(), GetGlyphWidth(), GetUnicodeGlyph(), and SetUnicodeGlyph().

◆ GetAscender()

int FontCache::GetAscender ( ) const
inline

Get the ascender value of the font.

Returns
The ascender value of the font.

Definition at line 54 of file fontcache.h.

References ascender.

◆ GetDescender()

int FontCache::GetDescender ( ) const
inline

Get the descender value of the font.

Returns
The descender value of the font.

Definition at line 60 of file fontcache.h.

References descender.

◆ GetDrawGlyphShadow()

virtual bool FontCache::GetDrawGlyphShadow ( )
pure virtual

Do we need to draw a glyph shadow?

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

Implemented in TrueTypeFontCache, and SpriteFontCache.

◆ GetFontName()

virtual const char* FontCache::GetFontName ( )
pure virtual

Get the name of this font.

Returns
The name of the font.

Implemented in Win32FontCache, CoreTextFontCache, FreeTypeFontCache, and SpriteFontCache.

◆ GetFontSize()

virtual int FontCache::GetFontSize ( ) const
inlinevirtual

Get the nominal font size of the font.

Returns
The nominal font size.

Reimplemented in TrueTypeFontCache.

Definition at line 72 of file fontcache.h.

References height.

◆ GetFontTable()

virtual const void* FontCache::GetFontTable ( uint32  tag,
size_t &  length 
)
pure 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.

Implemented in TrueTypeFontCache, and SpriteFontCache.

◆ GetGlyph()

virtual const Sprite* FontCache::GetGlyph ( GlyphID  key)
pure virtual

Get the glyph (sprite) of the given key.

Parameters
keyThe key to look up.
Returns
The sprite.

Implemented in TrueTypeFontCache, and SpriteFontCache.

Referenced by GetGlyph().

◆ GetGlyphWidth()

virtual uint FontCache::GetGlyphWidth ( GlyphID  key)
pure virtual

Get the width of the glyph with the given key.

Parameters
keyThe key to look up.
Returns
The width.

Implemented in TrueTypeFontCache, and SpriteFontCache.

Referenced by GetGlyphWidth().

◆ GetHeight()

virtual int FontCache::GetHeight ( ) const
inlinevirtual

Get the height of the font.

Returns
The height of the font.

Reimplemented in SpriteFontCache.

Definition at line 48 of file fontcache.h.

References height.

Referenced by GetCharacterHeight().

◆ GetOSHandle()

virtual const void* FontCache::GetOSHandle ( )
inlinevirtual

Get the native OS font handle, if there is one.

Returns
Opaque OS font handle.

Reimplemented in Win32FontCache, and CoreTextFontCache.

Definition at line 133 of file fontcache.h.

◆ GetSize()

FontSize FontCache::GetSize ( ) const
inline

Get the FontSize of the font.

Returns
The FontSize.

Definition at line 42 of file fontcache.h.

References fs.

◆ GetUnicodeGlyph()

virtual SpriteID FontCache::GetUnicodeGlyph ( WChar  key)
pure virtual

Get the SpriteID mapped to the given key.

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

Implemented in TrueTypeFontCache, and SpriteFontCache.

Referenced by TrueTypeFontCache::GetUnicodeGlyph(), and GetUnicodeGlyph().

◆ GetUnitsPerEM()

int FontCache::GetUnitsPerEM ( ) const
inline

Get the units per EM value of the font.

Returns
The units per EM value of the font.

Definition at line 66 of file fontcache.h.

References units_per_em.

◆ MapCharToGlyph()

virtual GlyphID FontCache::MapCharToGlyph ( WChar  key)
pure virtual

Map a character into a glyph.

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

Implemented in Win32FontCache, CoreTextFontCache, FreeTypeFontCache, and SpriteFontCache.

Referenced by GetGlyph(), and GetGlyphWidth().

◆ SetUnicodeGlyph()

virtual void FontCache::SetUnicodeGlyph ( WChar  key,
SpriteID  sprite 
)
pure virtual

Map a SpriteID to the key.

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

Implemented in TrueTypeFontCache, and SpriteFontCache.

Referenced by TrueTypeFontCache::SetUnicodeGlyph(), and SetUnicodeGlyph().


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