diff --git a/mozilla/gfx/public/nsIFontMetrics.h b/mozilla/gfx/public/nsIFontMetrics.h index 6dac281acca..82a75119b76 100644 --- a/mozilla/gfx/public/nsIFontMetrics.h +++ b/mozilla/gfx/public/nsIFontMetrics.h @@ -223,12 +223,10 @@ public: */ NS_IMETHOD GetFontHandle(nsFontHandle &aHandle) = 0; -#if defined(_WIN32) || defined(XP_OS2) || defined(MOZ_X11) /** * Returns the average character width */ NS_IMETHOD GetAveCharWidth(nscoord& aAveCharWidth) = 0; -#endif /** * Returns the often needed width of the space character diff --git a/mozilla/gfx/src/beos/nsFontMetricsBeOS.cpp b/mozilla/gfx/src/beos/nsFontMetricsBeOS.cpp index c03efedfdba..35a390be7a0 100644 --- a/mozilla/gfx/src/beos/nsFontMetricsBeOS.cpp +++ b/mozilla/gfx/src/beos/nsFontMetricsBeOS.cpp @@ -291,10 +291,13 @@ void nsFontMetricsBeOS::RealizeFont(nsIDeviceContext* aContext) mMaxAdvance = nscoord((mFontHandle.BoundingBox().Width()+1) * f); //fyy +1 + float rawWidth = mFontHandle.StringWidth("x"); + mAveCharWidth = NSToCoordRound(rawWidth * f); + // 56% of ascent, best guess for non-true type mXHeight = NSToCoordRound((float) height.ascent* f * 0.56f); - float rawWidth = mFontHandle.StringWidth(" "); + rawWidth = mFontHandle.StringWidth(" "); mSpaceWidth = NSToCoordRound(rawWidth * f); /* Temp */ @@ -408,7 +411,12 @@ NS_IMETHODIMP nsFontMetricsBeOS::GetMaxAdvance(nscoord &aAdvance) return NS_OK; } - +NS_IMETHODIMP nsFontMetricsBeOS::GetAveCharWidth(nscoord &aAveCharWidth) +{ + aAveCharWidth = mAveCharWidth; + return NS_OK; +} + NS_IMETHODIMP nsFontMetricsBeOS::GetSpaceWidth(nscoord &aSpaceWidth) { aSpaceWidth = mSpaceWidth; diff --git a/mozilla/gfx/src/beos/nsFontMetricsBeOS.h b/mozilla/gfx/src/beos/nsFontMetricsBeOS.h index f58d7a86cf2..1d7253aa629 100644 --- a/mozilla/gfx/src/beos/nsFontMetricsBeOS.h +++ b/mozilla/gfx/src/beos/nsFontMetricsBeOS.h @@ -84,6 +84,7 @@ public: NS_IMETHOD GetMaxAscent(nscoord &aAscent); NS_IMETHOD GetMaxDescent(nscoord &aDescent); NS_IMETHOD GetMaxAdvance(nscoord &aAdvance); + NS_IMETHOD GetAveCharWidth(nscoord &aAveCharWidth); NS_IMETHOD GetFont(const nsFont *&aFont); NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup); NS_IMETHOD GetFontHandle(nsFontHandle &aHandle); @@ -110,6 +111,7 @@ protected: nscoord mMaxAscent; nscoord mMaxDescent; nscoord mMaxAdvance; + nscoord mAveCharWidth; nscoord mXHeight; nscoord mSuperscriptOffset; nscoord mSubscriptOffset; diff --git a/mozilla/gfx/src/mac/nsFontMetricsMac.cpp b/mozilla/gfx/src/mac/nsFontMetricsMac.cpp index 54ab7072591..36d84afda89 100644 --- a/mozilla/gfx/src/mac/nsFontMetricsMac.cpp +++ b/mozilla/gfx/src/mac/nsFontMetricsMac.cpp @@ -108,6 +108,7 @@ NS_IMETHODIMP nsFontMetricsMac::Init(const nsFont& aFont, nsIAtom* aLangGroup, n mMaxDescent = mEmDescent; mMaxAdvance = NSToCoordRound(float(::CharWidth('M')) * dev2app); // don't use fInfo.widMax here + mAveCharWidth = NSToCoordRound(float(::CharWidth('x')) * dev2app); mSpaceWidth = NSToCoordRound(float(::CharWidth(' ')) * dev2app); Point frac; @@ -372,6 +373,12 @@ NS_IMETHODIMP nsFontMetricsMac :: GetMaxAdvance(nscoord &aAdvance) return NS_OK; } +NS_IMETHODIMP nsFontMetricsMac :: GetAveCharWidth(nscoord &aAveCharWidth) +{ + aAveCharWidth = mAveCharWidth; + return NS_OK; +} + nsresult nsFontMetricsMac :: GetSpaceWidth(nscoord &aSpaceWidth) { aSpaceWidth = mSpaceWidth; diff --git a/mozilla/gfx/src/mac/nsFontMetricsMac.h b/mozilla/gfx/src/mac/nsFontMetricsMac.h index 259b98daca6..d199b728bbb 100644 --- a/mozilla/gfx/src/mac/nsFontMetricsMac.h +++ b/mozilla/gfx/src/mac/nsFontMetricsMac.h @@ -79,6 +79,7 @@ public: NS_IMETHOD GetMaxAscent(nscoord &aAscent); NS_IMETHOD GetMaxDescent(nscoord &aDescent); NS_IMETHOD GetMaxAdvance(nscoord &aAdvance); + NS_IMETHOD GetAveCharWidth(nscoord &aAveCharWidth); NS_IMETHOD GetWidths(const nscoord *&aWidths); NS_IMETHOD GetFont(const nsFont *&aFont); NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup); @@ -100,6 +101,7 @@ protected: nscoord mMaxAscent; nscoord mMaxDescent; nscoord mMaxAdvance; + nscoord mAveCharWidth; nscoord mSpaceWidth; nscoord mXHeight; nsCOMPtr mLangGroup; diff --git a/mozilla/gfx/src/photon/nsFontMetricsPh.cpp b/mozilla/gfx/src/photon/nsFontMetricsPh.cpp index 2af3ac3b62d..fb957bea7fb 100644 --- a/mozilla/gfx/src/photon/nsFontMetricsPh.cpp +++ b/mozilla/gfx/src/photon/nsFontMetricsPh.cpp @@ -262,7 +262,9 @@ NS_IMETHODIMP nsFontMetricsPh::Init ( const nsFont& aFont, nsIAtom* aLangGroup, mAscent = mMaxAscent = NSToCoordRound(node->ascender * dev2app * -1.0); mDescent = mMaxDescent = NSToCoordRound(node->descender * dev2app); mMaxAdvance = NSToCoordRound(node->width * dev2app); - mAveCharWidth = PR_MAX(1, NSToCoordRound(mSpaceWidth * dev2app)); + + PfExtentText(&extent, NULL, NSFullFontName, "x", 1); + mAveCharWidth = (int) ((extent.lr.x - extent.ul.x + 1) * dev2app); mXHeight = NSToCoordRound((float)node->ascender * dev2app * 0.56f * -1.0); // 56% of ascent, best guess for non-true type mSuperscriptOffset = mXHeight; // XXX temporary code! @@ -407,6 +409,12 @@ NS_IMETHODIMP nsFontMetricsPh :: GetMaxAdvance( nscoord &aAdvance ) return NS_OK; } +NS_IMETHODIMP nsFontMetricsPh :: GetAveCharWidth( nscoord &aAveCharWidth) +{ + aAveCharWidth = mAveCharWidth; + return NS_OK; +} + NS_IMETHODIMP nsFontMetricsPh :: GetFont(const nsFont *&aFont) { aFont = mFont; diff --git a/mozilla/gfx/src/photon/nsFontMetricsPh.h b/mozilla/gfx/src/photon/nsFontMetricsPh.h index 5a18e8686a1..a87652aca1d 100644 --- a/mozilla/gfx/src/photon/nsFontMetricsPh.h +++ b/mozilla/gfx/src/photon/nsFontMetricsPh.h @@ -80,6 +80,7 @@ public: NS_IMETHOD GetMaxAscent(nscoord &aAscent); NS_IMETHOD GetMaxDescent(nscoord &aDescent); NS_IMETHOD GetMaxAdvance(nscoord &aAdvance); + NS_IMETHOD GetAveCharWidth(nscoord &aAveCharWidth); NS_IMETHOD GetFont(const nsFont *&aFont); NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup); NS_IMETHOD GetFontHandle(nsFontHandle &aHandle); @@ -111,7 +112,7 @@ protected: nscoord mUnderlineSize; nscoord mUnderlineOffset; nscoord mSpaceWidth; - nscoord mAveCharWidth; + nscoord mAveCharWidth; nsCOMPtr mLangGroup; }; diff --git a/mozilla/gfx/src/qt/nsFontMetricsQT.cpp b/mozilla/gfx/src/qt/nsFontMetricsQT.cpp index 1e8e391f5b5..58cdead9de3 100644 --- a/mozilla/gfx/src/qt/nsFontMetricsQT.cpp +++ b/mozilla/gfx/src/qt/nsFontMetricsQT.cpp @@ -644,6 +644,7 @@ nsFontMetricsQT::nsFontMetricsQT() mMaxAscent = 0; mMaxDescent = 0; mMaxAdvance = 0; + mAveCharWidth = 0; mXHeight = 0; mSuperscriptOffset = 0; mSubscriptOffset = 0; @@ -913,6 +914,8 @@ void nsFontMetricsQT::RealizeFont() mEmHeight = nscoord(fm.height() * f); mMaxAdvance = nscoord(fm.maxWidth() * f); + mAveCharWidth = nscoord(fm.width(QChar('x')) * f); + mEmAscent = mMaxAscent; mEmDescent = mMaxDescent; @@ -1025,6 +1028,12 @@ NS_IMETHODIMP nsFontMetricsQT::GetMaxAdvance(nscoord &aAdvance) return NS_OK; } +NS_IMETHODIMP nsFontMetricsQT::GetAveCharWidth(nscoord &aAveCharWidth) +{ + aAveCharWidth = mAveCharWidth; + return NS_OK; +} + NS_IMETHODIMP nsFontMetricsQT::GetSpaceWidth(nscoord &aSpaceWidth) { aSpaceWidth = mSpaceWidth; diff --git a/mozilla/gfx/src/qt/nsFontMetricsQT.h b/mozilla/gfx/src/qt/nsFontMetricsQT.h index d009cc24887..ffa37cdcc7d 100644 --- a/mozilla/gfx/src/qt/nsFontMetricsQT.h +++ b/mozilla/gfx/src/qt/nsFontMetricsQT.h @@ -138,6 +138,7 @@ public: NS_IMETHOD GetMaxAscent(nscoord &aAscent); NS_IMETHOD GetMaxDescent(nscoord &aDescent); NS_IMETHOD GetMaxAdvance(nscoord &aAdvance); + NS_IMETHOD GetAveCharWidth(nscoord &aAveCharWidth); NS_IMETHOD GetFont(const nsFont *&aFont); NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup); NS_IMETHOD GetFontHandle(nsFontHandle &aHandle); @@ -201,6 +202,7 @@ protected: nscoord mMaxAscent; nscoord mMaxDescent; nscoord mMaxAdvance; + nscoord mAveCharWidth; nscoord mXHeight; nscoord mSuperscriptOffset; nscoord mSubscriptOffset; diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 8ab0eefbd5f..63c7e310bbb 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -567,13 +567,7 @@ public: SetFontFromStyle(&aRenderingContext, sc); // some users of the struct expect this state aRenderingContext.GetFontMetrics(mNormalFont); mNormalFont->GetSpaceWidth(mSpaceWidth); -#if defined(_WIN32) || defined(XP_OS2)|| defined(MOZ_X11) mNormalFont->GetAveCharWidth(mAveCharWidth); -#endif /* defined(_WIN32) || defined(XP_OS2) || defined(MOZ_X11) */ - if (0 == mAveCharWidth) { - // provide a default if it could not be resolved - mAveCharWidth = 10; - } mLastFont = mNormalFont; // Get the small-caps font if needed diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 8ab0eefbd5f..63c7e310bbb 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -567,13 +567,7 @@ public: SetFontFromStyle(&aRenderingContext, sc); // some users of the struct expect this state aRenderingContext.GetFontMetrics(mNormalFont); mNormalFont->GetSpaceWidth(mSpaceWidth); -#if defined(_WIN32) || defined(XP_OS2)|| defined(MOZ_X11) mNormalFont->GetAveCharWidth(mAveCharWidth); -#endif /* defined(_WIN32) || defined(XP_OS2) || defined(MOZ_X11) */ - if (0 == mAveCharWidth) { - // provide a default if it could not be resolved - mAveCharWidth = 10; - } mLastFont = mNormalFont; // Get the small-caps font if needed