зеркало из https://github.com/mozilla/pjs.git
Added code to nsFontMetricsGTK to cache the width of a single space.
Modifed nsRenderingContextGTK::GetWidth to detect when a single space is passed in and pass back the cached value, rather than re-measuring a space.
This commit is contained in:
Родитель
f086c5861f
Коммит
31bee26128
|
@ -60,6 +60,7 @@ nsFontMetricsGTK::nsFontMetricsGTK()
|
|||
mStrikeoutOffset = 0;
|
||||
mUnderlineSize = 0;
|
||||
mUnderlineOffset = 0;
|
||||
mSpaceWidth = 0;
|
||||
}
|
||||
|
||||
nsFontMetricsGTK::~nsFontMetricsGTK()
|
||||
|
@ -418,6 +419,9 @@ void nsFontMetricsGTK::RealizeFont()
|
|||
// 56% of ascent, best guess for non-true type
|
||||
mXHeight = NSToCoordRound((float) fontInfo->ascent* f * 0.56f);
|
||||
|
||||
gint rawWidth = gdk_text_width(mFontHandle, " ", 1);
|
||||
mSpaceWidth = NSToCoordRound(rawWidth * f);
|
||||
|
||||
unsigned long pr = 0;
|
||||
|
||||
if (::XGetFontProperty(fontInfo, XA_X_HEIGHT, &pr))
|
||||
|
@ -2179,4 +2183,11 @@ nsFontMetricsGTK::DrawString(nsDrawingSurfaceGTK* aSurface, nsFontGTK* aFont,
|
|||
aY + aFont->mBaselineAdjust, (char*) buf, len);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFontMetricsGTK::GetSpaceWidth(nscoord &aSpaceWidth)
|
||||
{
|
||||
aSpaceWidth = mSpaceWidth;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif /* FONT_SWITCHING */
|
||||
|
|
|
@ -100,6 +100,8 @@ public:
|
|||
NS_IMETHOD GetFont(const nsFont *&aFont);
|
||||
NS_IMETHOD GetFontHandle(nsFontHandle &aHandle);
|
||||
|
||||
virtual nsresult GetSpaceWidth(nscoord &aSpaceWidth);
|
||||
|
||||
#ifdef FONT_SWITCHING
|
||||
|
||||
nsFontGTK* FindFont(PRUnichar aChar);
|
||||
|
@ -149,6 +151,7 @@ protected:
|
|||
nscoord mStrikeoutOffset;
|
||||
nscoord mUnderlineSize;
|
||||
nscoord mUnderlineOffset;
|
||||
nscoord mSpaceWidth;
|
||||
|
||||
#ifdef FONT_SWITCHING
|
||||
|
||||
|
|
|
@ -913,6 +913,12 @@ NS_IMETHODIMP nsRenderingContextGTK::FillArc(nscoord aX, nscoord aY,
|
|||
NS_IMETHODIMP
|
||||
nsRenderingContextGTK::GetWidth(char aC, nscoord &aWidth)
|
||||
{
|
||||
// Check for the very common case of trying to get the width of a single
|
||||
// space.
|
||||
if ((aC == ' ') && (nsnull != mFontMetrics)) {
|
||||
nsFontMetricsGTK* fontMetricsGTK = (nsFontMetricsGTK*)mFontMetrics;
|
||||
return fontMetricsGTK->GetSpaceWidth(aWidth);
|
||||
}
|
||||
return GetWidth(&aC, 1, aWidth);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче