Added method and member variable to Cache the width of a space in nsFontMetricsWin.cpp.

Added code to nsRenderingContextWin::GetWidth to use the cached width to optimize the
common case of measuring the width of a single character.


git-svn-id: svn://10.0.0.236/trunk@33848 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
kmcclusk%netscape.com 1999-06-04 23:09:27 +00:00
parent 79a9957748
commit e70243131f
3 changed files with 23 additions and 0 deletions

View File

@ -31,6 +31,7 @@ PLHashTable* nsFontMetricsWin::gFamilyNames = nsnull;
nsFontMetricsWin :: nsFontMetricsWin()
{
NS_INIT_REFCNT();
mSpaceWidth = 0;
}
nsFontMetricsWin :: ~nsFontMetricsWin()
@ -126,6 +127,12 @@ nsFontMetricsWin :: Destroy()
return NS_OK;
}
nsresult nsFontMetricsWin :: GetSpaceWidth(nscoord &aSpaceWidth)
{
aSpaceWidth = mSpaceWidth;
return NS_OK;
}
void
nsFontMetricsWin::FillLogFont(LOGFONT* logFont)
{
@ -904,6 +911,11 @@ HDC dc1 = NULL;
mMaxDescent = NSToCoordRound(metrics.tmDescent * dev2app);
mMaxAdvance = NSToCoordRound(metrics.tmMaxCharWidth * dev2app);
// Cache the width of a single space.
SIZE size;
::GetTextExtentPoint32(dc, " ", 1, &size);
mSpaceWidth = NSToCoordRound(size.cx * dev2app);
::SelectObject(dc, oldfont);
if (NULL == mDeviceContext->mDC){

View File

@ -81,6 +81,7 @@ public:
NS_IMETHOD GetFont(const nsFont *&aFont);
NS_IMETHOD GetFontHandle(nsFontHandle &aHandle);
virtual nsresult GetSpaceWidth(nscoord &aSpaceWidth);
virtual nsFontWin* FindGlobalFont(HDC aDC, PRUnichar aChar);
virtual nsFontWin* FindLocalFont(HDC aDC, PRUnichar aChar);
nsFontWin* FindFont(HDC aDC, PRUnichar aChar);
@ -96,6 +97,7 @@ public:
PRUint16 mFontsAlloc;
PRUint16 mFontsCount;
PRUint16 mFontsIndex;
nscoord mSpaceWidth;
static nsGlobalFont* gGlobalFonts;
static int gGlobalFontsCount;

View File

@ -1426,8 +1426,17 @@ NS_IMETHODIMP nsRenderingContextWin :: GetWidth(const char* aString,
PRUint32 aLength,
nscoord& aWidth)
{
if (nsnull != mFontMetrics)
{
// Check for the very common case of trying to get the width of a single
// space.
if ((1 == aLength) && (aString[0] == ' '))
{
nsFontMetricsWin* fontMetricsWin = (nsFontMetricsWin*)mFontMetrics;
return fontMetricsWin->GetSpaceWidth(aWidth);
}
SIZE size;
SetupFontAndColor();