port performance enhancements from gtk fonts

git-svn-id: svn://10.0.0.236/trunk@34165 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
blizzard%redhat.com
1999-06-08 02:40:24 +00:00
parent 0ab0217597
commit 52eeaca3ad
3 changed files with 19 additions and 0 deletions

View File

@@ -62,6 +62,7 @@ nsFontMetricsXlib::nsFontMetricsXlib()
mStrikeoutOffset = 0;
mUnderlineSize = 0;
mUnderlineOffset = 0;
mSpaceWidth = 0;
}
nsFontMetricsXlib::~nsFontMetricsXlib()
@@ -419,6 +420,8 @@ void nsFontMetricsXlib::RealizeFont()
// 56% of ascent, best guess for non-true type
mXHeight = NSToCoordRound((float) mFontHandle->ascent* f * 0.56f);
int rawWidth = XTextWidth(mFontHandle, " ", 1);
mSpaceWidth = NSToCoordRound(rawWidth * f);
unsigned long pr = 0;
if (::XGetFontProperty(mFontHandle, XA_X_HEIGHT, &pr))
@@ -2184,4 +2187,11 @@ nsFontMetricsXlib::DrawString(nsDrawingSurfaceXlib* aSurface, nsFontXlib* aFont,
aX, aY, buf, (len / 2));
}
nsresult
nsFontMetricsXlib::GetSpaceWidth(nscoord &aSpaceWidth)
{
aSpaceWidth = mSpaceWidth;
return NS_OK;
}
#endif /* FONT_SWITCHING */

View File

@@ -102,6 +102,8 @@ public:
NS_IMETHOD GetFont(const nsFont *&aFont);
NS_IMETHOD GetFontHandle(nsFontHandle &aHandle);
virtual nsresult GetSpaceWidth(nscoord &aSpaceWidth);
#ifdef FONT_SWITCHING
nsFontXlib* FindFont(PRUnichar aChar);
@@ -152,6 +154,7 @@ protected:
nscoord mStrikeoutOffset;
nscoord mUnderlineSize;
nscoord mUnderlineOffset;
nscoord mSpaceWidth;
#ifdef FONT_SWITCHING

View File

@@ -958,6 +958,12 @@ NS_IMETHODIMP
nsRenderingContextXlib::GetWidth(char aC, nscoord& aWidth)
{
printf("nsRenderingContextXlib::GetWidth()\n");
// Check for the very common case of trying to get the width of a single
// space.
if ((aC == ' ') && (nsnull != mFontMetrics)) {
nsFontMetricsXlib* fontMetricsXlib = (nsFontMetricsXlib*)mFontMetrics;
return fontMetricsXlib->GetSpaceWidth(aWidth);
}
return GetWidth(&aC, 1, aWidth);
}