#include <fontimpl.h>
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) |
Definition at line 158 of file fontimpl.h.
|
Definition at line 168 of file fontimpl.h. 00168 { NUMENTRIES=3 };
|
|
|
|
Get the metrics of a given char for the font selected in the DC, Note: Uses a single entry cache for speed.
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 }
|
|
Invalidate the FontMetricsCache.
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 }
|
|
Definition at line 170 of file fontimpl.h. |