diff --git a/gfx/public/nsIFontMetrics.h b/gfx/public/nsIFontMetrics.h index e71f4a7b50a..74d709a2e72 100644 --- a/gfx/public/nsIFontMetrics.h +++ b/gfx/public/nsIFontMetrics.h @@ -154,6 +154,13 @@ public: * Returns the font handle associated with these metrics */ NS_IMETHOD GetFontHandle(nsFontHandle &aHandle) = 0; + +#ifdef _WIN32 + /** + * Returns the average character width + */ + NS_IMETHOD GetAveCharWidth(nscoord& aAveCharWidth) = 0; +#endif }; #endif /* nsIFontMetrics_h___ */ diff --git a/gfx/src/windows/nsFontMetricsWin.cpp b/gfx/src/windows/nsFontMetricsWin.cpp index 19d5c128b5b..328f2d6edac 100644 --- a/gfx/src/windows/nsFontMetricsWin.cpp +++ b/gfx/src/windows/nsFontMetricsWin.cpp @@ -2524,6 +2524,7 @@ HDC dc1 = NULL; mMaxAscent = NSToCoordRound(metrics.tmAscent * dev2app); mMaxDescent = NSToCoordRound(metrics.tmDescent * dev2app); mMaxAdvance = NSToCoordRound(metrics.tmMaxCharWidth * dev2app); + mAveCharWidth = NSToCoordRound(metrics.tmAveCharWidth * dev2app); // Cache the width of a single space. SIZE size; @@ -2647,6 +2648,13 @@ nsFontMetricsWin::GetFontHandle(nsFontHandle &aHandle) return NS_OK; } +NS_IMETHODIMP +nsFontMetricsWin::GetAveCharWidth(nscoord &aAveCharWidth) +{ + aAveCharWidth = mAveCharWidth; + return NS_OK; +} + nsFontWin::nsFontWin(LOGFONT* aLogFont, HFONT aFont, PRUint32* aMap) { if (aLogFont) { @@ -2678,7 +2686,6 @@ nsFontWinUnicode::GetWidth(HDC aDC, const PRUnichar* aString, PRUint32 aLength) { SIZE size; ::GetTextExtentPoint32W(aDC, aString, aLength, &size); - return size.cx; } diff --git a/gfx/src/windows/nsFontMetricsWin.h b/gfx/src/windows/nsFontMetricsWin.h index 388935b94ae..d3accaf94bf 100644 --- a/gfx/src/windows/nsFontMetricsWin.h +++ b/gfx/src/windows/nsFontMetricsWin.h @@ -123,6 +123,7 @@ public: NS_IMETHOD GetFont(const nsFont *&aFont); NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup); NS_IMETHOD GetFontHandle(nsFontHandle &aHandle); + NS_IMETHOD GetAveCharWidth(nscoord &aAveCharWidth); virtual nsresult GetSpaceWidth(nscoord &aSpaceWidth); virtual nsFontWin* FindGlobalFont(HDC aDC, PRUnichar aChar); @@ -199,6 +200,7 @@ protected: nscoord mMaxAscent; nscoord mMaxDescent; nscoord mMaxAdvance; + nscoord mAveCharWidth; #ifdef MOZ_MATHML float mItalicSlope; #endif