OpenTTD Source 20241224-master-gf74b0cf984
FontCache Class Referenceabstract

Font cache for basic fonts. More...

#include <fontcache.h>

Inheritance diagram for FontCache:
MockFontCache SpriteFontCache TrueTypeFontCache CoreTextFontCache FreeTypeFontCache Win32FontCache

Public Member Functions

 FontCache (FontSize fs)
 Create a new font cache.
 
virtual ~FontCache ()
 Clean everything up.
 
FontSize GetSize () const
 Get the FontSize of the font.
 
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.
 
virtual int GetFontSize () const
 Get the nominal font size of the font.
 
virtual void SetUnicodeGlyph (char32_t key, SpriteID sprite)=0
 Map a SpriteID to the key.
 
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.
 
virtual uint GetGlyphWidth (GlyphID key)=0
 Get the width of the glyph with the given key.
 
virtual bool GetDrawGlyphShadow ()=0
 Do we need to draw a glyph shadow?
 
virtual GlyphID MapCharToGlyph (char32_t key, bool fallback=true)=0
 Map a character into a glyph.
 
virtual const void * GetOSHandle ()
 Get the native OS font handle, if there is one.
 
virtual std::string GetFontName ()=0
 Get the name of this font.
 
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 void InitializeFontCaches ()
 
static int GetDefaultFontHeight (FontSize fs)
 
static FontCacheGet (FontSize fs)
 Get the font cache of a given font size.
 
static std::string GetName (FontSize fs)
 Get the font name of a given font size.
 

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.
 

Static Protected Attributes

static FontCachecaches [FS_END]
 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 35 of file fontcache.cpp.

References caches, fs, parent, and Layouter::ResetFontCache().

◆ ~FontCache()

FontCache::~FontCache ( )
virtual

Clean everything up.

Definition at line 44 of file fontcache.cpp.

References caches, fs, parent, and Layouter::ResetFontCache().

Member Function Documentation

◆ ClearFontCache()

virtual void FontCache::ClearFontCache ( )
pure virtual

◆ 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 129 of file fontcache.h.

References caches, and fs.

Referenced by MissingGlyphSearcher::FindMissingGlyphs(), GetCharacterHeight(), GetGlyph(), GetGlyphWidth(), GetName(), InitFontCache(), InitializeUnicodeGlyphMap(), SetUnicodeGlyph(), SurveyFont(), and UninitFontCache().

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

Referenced by FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun().

◆ GetDefaultFontHeight()

int FontCache::GetDefaultFontHeight ( FontSize  fs)
static

Definition at line 51 of file fontcache.cpp.

◆ 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 SpriteFontCache, TrueTypeFontCache, and MockFontCache.

Referenced by DrawLayoutLine().

◆ GetFontName()

virtual std::string FontCache::GetFontName ( )
pure virtual

Get the name of this font.

Returns
The name of the font.

Implemented in FreeTypeFontCache, SpriteFontCache, CoreTextFontCache, Win32FontCache, and MockFontCache.

Referenced by GetName(), HFontFromFont(), and SurveyFont().

◆ 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 66 of file fontcache.h.

References height.

◆ 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 SpriteFontCache, TrueTypeFontCache, and MockFontCache.

Referenced by DrawLayoutLine(), GetGlyph(), and TrueTypeFontCache::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 SpriteFontCache, TrueTypeFontCache, and MockFontCache.

Referenced by DrawLayoutLine(), FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(), GetGlyphWidth(), TrueTypeFontCache::GetGlyphWidth(), and UniscribeShapeRun().

◆ GetHeight()

int FontCache::GetHeight ( ) const
inline

Get the height of the font.

Returns
The height of the font.

Definition at line 48 of file fontcache.h.

References height.

Referenced by FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(), GetCharacterHeight(), HFontFromFont(), and UniscribeShapeRun().

◆ GetName()

std::string FontCache::GetName ( FontSize  fs)
static

Get the font name of a given font size.

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

Definition at line 61 of file fontcache.cpp.

References fs, Get(), and GetFontName().

◆ GetOSHandle()

virtual const void * FontCache::GetOSHandle ( )
inlinevirtual

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

Returns
Opaque OS font handle.

Reimplemented in FreeTypeFontCache, CoreTextFontCache, and Win32FontCache.

Definition at line 113 of file fontcache.h.

Referenced by HFontFromFont().

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

Referenced by FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(), FallbackParagraphLayout::NextLine(), and UniscribeShapeRun().

◆ HasParent()

bool FontCache::HasParent ( )
inline

Check whether the font cache has a parent.

Definition at line 140 of file fontcache.h.

Referenced by InitFontCache(), and UninitFontCache().

◆ InitializeFontCaches()

void FontCache::InitializeFontCaches ( )
static

Definition at line 85 of file fontcache.cpp.

◆ InitializeUnicodeGlyphMap()

virtual void FontCache::InitializeUnicodeGlyphMap ( )
pure virtual

◆ IsBuiltInFont()

virtual bool FontCache::IsBuiltInFont ( )
pure virtual

◆ MapCharToGlyph()

virtual GlyphID FontCache::MapCharToGlyph ( char32_t  key,
bool  fallback = true 
)
pure virtual

◆ SetUnicodeGlyph()

virtual void FontCache::SetUnicodeGlyph ( char32_t  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 SpriteFontCache, TrueTypeFontCache, and MockFontCache.

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

Field Documentation

◆ ascender

int FontCache::ascender
protected

The ascender value of the font.

Definition at line 27 of file fontcache.h.

Referenced by SpriteFontCache::ClearFontCache(), GetAscender(), and SpriteFontCache::SpriteFontCache().

◆ caches

FontCache * FontCache::caches
staticprotected

All the font caches.

Definition at line 23 of file fontcache.h.

Referenced by FontCache(), Get(), and ~FontCache().

◆ descender

int FontCache::descender
protected

The descender value of the font.

Definition at line 28 of file fontcache.h.

Referenced by GetDescender().

◆ fs

◆ height

int FontCache::height
protected

◆ parent


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