FontMetricsCache Class Reference

Holds a cache of char widths, ascent, descent and em for a particular font. More...

#include <fontimpl.h>

List of all members.

Static Public Member Functions

static void InvalidateCharMetrics ()
 Invalidate the FontMetricsCache.
static BOOL GetCharMetrics (wxDC *pDC, WCHAR ch, CharDescription &FontDesc, CharMetrics *pCharMetrics)
 Get the metrics of a given char for the font selected in the DC, Note: Uses a single entry cache for speed.

Protected Types

enum  CacheInfo { NUMENTRIES = 3 }

Static Protected Attributes

static FontMetricsCacheEntry mpFontMetricsData [NUMENTRIES]

Private Member Functions

 CC_DECLARE_MEMDUMP (FontMetricsCache)


Detailed Description

Holds a cache of char widths, ascent, descent and em for a particular font.

Author:
Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/1/96

Definition at line 158 of file fontimpl.h.


Member Enumeration Documentation

enum FontMetricsCache::CacheInfo [protected]
 

Enumerator:
NUMENTRIES 

Definition at line 168 of file fontimpl.h.

00168 { NUMENTRIES=3 };


Member Function Documentation

FontMetricsCache::CC_DECLARE_MEMDUMP FontMetricsCache   )  [private]
 

BOOL FontMetricsCache::GetCharMetrics wxDC *  pDC,
WCHAR  ch,
CharDescription FontDesc,
CharMetrics pCharMetrics
[static]
 

Get the metrics of a given char for the font selected in the DC, Note: Uses a single entry cache for speed.

Author:
Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/1/96
Parameters:
pDC = a pointer to a device context [INPUTS] ch = a character code FontDesc = a font description
pCharMetrics = metrics of char requested [OUTPUTS]
Returns:
FALSE if fails

Definition at line 1068 of file fontbase.cpp.

01069 {
01070     // TRACEUSER("wuerthne", _T("FontMetricsCache::GetCharMetrics %04x"), ch);
01071     IGNOREPARAM(pDC);
01072     ERROR2IF(pCharMetrics==NULL,FALSE,"FontMetricsCache::GetCharMetrics() - pCharMetrics==NULL");
01073     ERROR2IF(FontDesc.GetCharCode()!=FONTEMCHAR,FALSE,"FontMetricsCache::GetCharMetrics() - FontDesc char should be 'FONTEMCHAR'");
01074 
01075     // find if font is in cache (and if so which entry)
01076     INT32 CacheEntry = 0;
01077     while (CacheEntry<NUMENTRIES && mpFontMetricsData[CacheEntry].GetFontDesc()!=FontDesc)
01078         CacheEntry +=1;
01079 
01080     // if font not in cache, recache it, or if char not in cached range, get it explicitly
01081     MILLIPOINT CharWidth  = 0;
01082     BOOL CharInCacheRange = FontMetricsCacheEntry::CharInCacheRange(ch);
01083     if (CacheEntry>=NUMENTRIES || !CharInCacheRange)
01084     {
01085         // get design size of font, and default heigh
01086         INT32 DesignSize    = TextManager::GetDesignSize(pDC);  // ignores pDC
01087         INT32 DefaultHeight = TextManager::GetDefaultHeight();
01088 
01089         CachedFontItem* pItem = FONTMANAGER->GetFont(FontDesc.GetTypefaceHandle());
01090         if (pItem==NULL || pItem->IsCorrupt())
01091             return FALSE;
01092 
01093         // get a LogFont, create a font and select it into the DC
01094         LOGFONT CharLogFont;
01095         if (TextManager::GetLogFontFromCharDescriptor(pDC, FontDesc, &CharLogFont, DesignSize)==FALSE)
01096             return FALSE;
01097 
01098         // if font not in cache, cache its metrics throwing out a random entry
01099         if (CacheEntry>=NUMENTRIES)
01100         {
01101             CacheEntry = rand() % NUMENTRIES;
01102             if (mpFontMetricsData[CacheEntry].CacheFontMetrics(pDC, FontDesc, DefaultHeight, DesignSize) == FALSE)
01103                 return FALSE;
01104         }
01105 
01106         // if char not in cache, find it's width separately (unless it is FONTEMCHAR - eg for kern code, blank line)
01107         if (!CharInCacheRange)
01108         {
01109             if (ch==FONTEMCHAR)
01110                 CharWidth = mpFontMetricsData[CacheEntry].GetFontEmWidth();
01111             else
01112             {
01113 #ifdef __WXGTK__
01114                 // FTFontMan returns the scaled character width already
01115                 if (FTFontMan::GetCharWidth(FontDesc, ch, ch, &CharWidth)==FALSE)
01116 #endif
01117                     return FALSE;
01118             }
01119         }
01120     }
01121 
01122     if (CharInCacheRange)
01123         CharWidth = mpFontMetricsData[CacheEntry].GetCharWidthFromCache(ch);
01124 
01125     pCharMetrics->CharWidth   = CharWidth;
01126     pCharMetrics->FontAscent  = mpFontMetricsData[CacheEntry].GetFontAscent();
01127     pCharMetrics->FontEmWidth = mpFontMetricsData[CacheEntry].GetFontEmWidth();
01128     pCharMetrics->FontDescent = mpFontMetricsData[CacheEntry].GetFontDescent();
01129     return TRUE;
01130 }

void FontMetricsCache::InvalidateCharMetrics  )  [static]
 

Invalidate the FontMetricsCache.

Author:
Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/1/96

Definition at line 1141 of file fontbase.cpp.

01142 {
01143     CharDescription emptyCharDesc(0, 0, 0, 0);
01144     for (INT32 i=0; i<NUMENTRIES; i++)
01145         mpFontMetricsData[i].SetFontDesc( emptyCharDesc );
01146 }


Member Data Documentation

FontMetricsCacheEntry FontMetricsCache::mpFontMetricsData [static, protected]
 

Definition at line 170 of file fontimpl.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:54:31 2007 for Camelot by  doxygen 1.4.4