Make nsIFontMetrics::GetAveCharWidth() on all platforms (Rick.Ju@sun.com's patch, bug 50998), r=cbiesinger@web.de, sr=rbs@maths.uq.edu.au

git-svn-id: svn://10.0.0.236/trunk@129999 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
jkeiser%netscape.com
2002-09-19 01:47:14 +00:00
parent ae365c964e
commit 0321a23661
11 changed files with 43 additions and 18 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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<nsIAtom> mLangGroup;

View File

@@ -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;

View File

@@ -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<nsIAtom> mLangGroup;
};

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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