Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Location: gdi.h
Link against: gdi.lib

Class CFontCache

CFontCache

Support

Supported from 5.0

Description

Font cache.

When a CFont* needs to be found for a particular TFontSpec, the cache can be searched to see if the TFontSpec is already in the cache. If the TFontSpec is in the cache, its corresponding CFont* can be returned. Otherwise GetNearestFontInTwips() must be used to search all of the available fonts for the nearest CFont — a procedure which takes much longer than a simple cache search.

The current font cache should be destroyed and a new cache created whenever the zoom factor or device map changes, as these changes break the relation between CFont and TFontSpec.

Derivation

CBaseBase class for all classes to be instantiated on the heap
CFontCacheFont cache

Defined in CFontCache:
AddEntryL(), CFontCache(), RemoveFirstEntry(), Search(), iNumHits, iNumMisses, ~CFontCache()

Inherited from CBase:
operator new()


Construction and destruction


CFontCache()

CFontCache();

Description

Default constructor.

This constructs a CFontCache of size KMaxFontCacheEntries.


CFontCache()

CFontCache(TInt aMaxEntries);

Description

Constructor specifying the number of cache entries.

Parameters

TInt aMaxEntries

Number of entries for this cache. You must ensure this is less than or equal to KMaxFontCacheEntries.


~CFontCache()

~CFontCache();

Description

Destructor.

This destroys the cashe and releases its allocated memory.

[Top]


Searching the cache


Search()

CFont* Search(const TFontSpec& aFontSpec);

Description

Searches the cache for a specified font.

The CFont returned is that which corresponds to the font specification aFontSpec.

Parameters

const TFontSpec& aFontSpec

The specification of the font to be searched for.

Return value

CFont*

If an entry for the font specification is found in the cache, the pointer to the font corresponding to the font specification is returned. Otherwise NULL is returned.

[Top]


Maintaining the cache


AddEntryL()

CFont* AddEntryL(CFont* aFont,const TFontSpec& aFontSpec);

Description

Adds a font entry to the cache.

The font, and the font specification required to extract it from the cache, are both specified. If the cache is already full, the font replaces the oldest entry already in the cache, which is returned.

Parameters

CFont* aFont

The font to be stored in the cache.

const TFontSpec& aFontSpec

The font's corresponding font specification.

Return value

CFont*

If the cache isn't full, NULL is returned. If the cache is full, the displaced cache entry is returned.


RemoveFirstEntry()

CFont* RemoveFirstEntry();

Description

Removes the first entry from the font cache and returns it.

Return value

CFont*

The entry removed from the font cache. If the cache is empty, NULL is returned.

[Top]


Public data members

Description

The two public member data items provide statistics of cache usage.


iNumHits

TInt iNumHits

Description

The number of cache hits since the font cache was created — i.e. successful results from CFontCache::Search().


iNumMisses

TInt iNumMisses

Description

The number of cache misses since the font cache was created — i.e. unsuccessful results from CFontCache::Search().