Changed interface nsIFontMetrics to use the XPCOM conventions for returning
a nsresult git-svn-id: svn://10.0.0.236/trunk@8785 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
6edcfe6a82
commit
1568e2814d
@ -70,6 +70,7 @@ nsCSSLayout::VerticallyAlignChildren(nsIPresContext* aCX,
|
||||
nscoord kidYTop = 0;
|
||||
|
||||
PRBool isPass2Kid = PR_FALSE;
|
||||
nscoord fontHeight, fontAscent, fontDescent;
|
||||
switch (verticalAlignUnit) {
|
||||
case eStyleUnit_Coord:
|
||||
kidYTop = aMaxAscent + textStyle->mVerticalAlign.GetCoordValue();
|
||||
@ -115,15 +116,18 @@ nsCSSLayout::VerticallyAlignChildren(nsIPresContext* aCX,
|
||||
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
|
||||
// XXX spec says use the 'x' height but our font api
|
||||
// doesn't give us that information.
|
||||
kidYTop = aMaxAscent - (fm->GetHeight() / 2) - kidRect.height/2;
|
||||
fm->GetHeight(fontHeight);
|
||||
kidYTop = aMaxAscent - (fontHeight / 2) - kidRect.height/2;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
|
||||
kidYTop = aMaxAscent + fm->GetMaxDescent() - kidRect.height;
|
||||
fm->GetMaxDescent(fontDescent);
|
||||
kidYTop = aMaxAscent + fontDescent - kidRect.height;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
|
||||
kidYTop = aMaxAscent - fm->GetMaxAscent();
|
||||
fm->GetMaxAscent(fontAscent);
|
||||
kidYTop = aMaxAscent - fontAscent;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ nsFontMetricsMac :: ~nsFontMetricsMac()
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsFontMetricsMac, kIFontMetricsIID)
|
||||
|
||||
nsresult nsFontMetricsMac :: Init(const nsFont& aFont, nsIDeviceContext* aCX)
|
||||
NS_IMETHODIMP nsFontMetricsMac :: Init(const nsFont& aFont, nsIDeviceContext* aCX)
|
||||
{
|
||||
/* NS_ASSERTION(!(nsnull == aCX), "attempt to init fontmetrics with null device context");
|
||||
|
||||
@ -236,28 +236,30 @@ nsresult nsFontMetricsMac :: Init(const nsFont& aFont, nsIDeviceContext* aCX)
|
||||
mLeading = 0;
|
||||
}*/
|
||||
|
||||
nscoord nsFontMetricsMac :: GetWidth(char ch)
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetWidth(char ch, nscoord &aWidth)
|
||||
{
|
||||
//if (ch < 256)
|
||||
// return mCharWidths[ch];
|
||||
//else
|
||||
return 0; //XXX
|
||||
aWidth = 0; //XXX
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetWidth(PRUnichar ch)
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetWidth(PRUnichar ch, nscoord &aWidth)
|
||||
{
|
||||
//if (ch < 256)
|
||||
// return mCharWidths[PRUint8(ch)];
|
||||
// else
|
||||
return 0;/* XXX */
|
||||
aWidth = 0;/* XXX */
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetWidth(const nsString& aString)
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetWidth(const nsString& aString, nscoord &aWidth)
|
||||
{
|
||||
return GetWidth(aString.GetUnicode(), aString.Length());
|
||||
return GetWidth(aString.GetUnicode(), aString.Length(), aWidth);
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetWidth(const char *aString)
|
||||
NS_IMETHOPIMP nsFontMetricsMac :: GetWidth(const char *aString, nscoord &aWidth)
|
||||
{
|
||||
/* PRInt32 rc = 0 ;
|
||||
|
||||
@ -266,9 +268,10 @@ nscoord nsFontMetricsMac :: GetWidth(const char *aString)
|
||||
rc = (PRInt32) ::XTextWidth(fs, aString, nsCRT::strlen(aString));
|
||||
|
||||
return (nscoord(rc * mContext->GetDevUnitsToAppUnits()));*/
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetWidth(const PRUnichar *aString, PRUint32 aLength)
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetWidth(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth)
|
||||
{
|
||||
// XChar2b * xstring ;
|
||||
// XChar2b * thischar ;
|
||||
@ -294,55 +297,67 @@ nscoord nsFontMetricsMac :: GetWidth(const PRUnichar *aString, PRUint32 aLength)
|
||||
|
||||
//return (nscoord(width * mContext->GetDevUnitsToAppUnits()));
|
||||
|
||||
return width;
|
||||
aWidth = width;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// XXX this needs to be implemented correctly
|
||||
nscoord nsFontMetricsMac:: GetWidth(nsIDeviceContext *aContext, const nsString& aString)
|
||||
NS_IMETHODIMP nsFontMetricsMac:: GetWidth(nsIDeviceContext *aContext,
|
||||
const nsString& aString,
|
||||
nscoord &aWidth)
|
||||
{
|
||||
return GetWidth(aString.GetUnicode(), aString.Length());
|
||||
return GetWidth(aString.GetUnicode(), aString.Length(), aWidth);
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetHeight()
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetHeight(nscoord &aHeight)
|
||||
{
|
||||
//return mHeight;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetLeading()
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetLeading(nscoord &aLeading)
|
||||
{
|
||||
//return mLeading;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetMaxAscent()
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetMaxAscent(nscoord &aAscent)
|
||||
{
|
||||
//return mMaxAscent;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetMaxDescent()
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetMaxDescent(nscoord &aDescent)
|
||||
{
|
||||
//return mMaxDescent;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsMac :: GetMaxAdvance()
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetMaxAdvance(nscoord &aAdvance)
|
||||
{
|
||||
//return mMaxAdvance;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
const nscoord * nsFontMetricsMac :: GetWidths()
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetWidths(const nscoord *&aWidths)
|
||||
{
|
||||
//return mCharWidths;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
const nsFont& nsFontMetricsMac :: GetFont()
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetFont(const nsFont *&aFont)
|
||||
{
|
||||
//return *mFont;
|
||||
//return nsnull;
|
||||
aFont = nsnull;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsFontHandle nsFontMetricsMac :: GetFontHandle()
|
||||
NS_IMETHODIMP nsFontMetricsMac :: GetFontHandle(nsFontHandle &aHandle)
|
||||
{
|
||||
//return (nsFontHandle)mFontHandle;
|
||||
return nsnull;
|
||||
aHandle = nsnull;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -40,21 +40,21 @@ public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult Init(const nsFont& aFont, nsIDeviceContext* aContext);
|
||||
virtual nscoord GetWidth(char aC);
|
||||
virtual nscoord GetWidth(PRUnichar aC);
|
||||
virtual nscoord GetWidth(const nsString& aString);
|
||||
virtual nscoord GetWidth(const char *aString);
|
||||
virtual nscoord GetWidth(const PRUnichar *aString, PRUint32 aLength);
|
||||
virtual nscoord GetWidth(nsIDeviceContext *aContext, const nsString& aString);
|
||||
virtual nscoord GetHeight();
|
||||
virtual nscoord GetLeading();
|
||||
virtual nscoord GetMaxAscent();
|
||||
virtual nscoord GetMaxDescent();
|
||||
virtual nscoord GetMaxAdvance();
|
||||
virtual const nscoord *GetWidths();
|
||||
virtual const nsFont& GetFont();
|
||||
virtual nsFontHandle GetFontHandle();
|
||||
NS_IMETHOD Init(const nsFont& aFont, nsIDeviceContext* aContext);
|
||||
NS_IMETHOD GetWidth(char aC, nscoord &aWidth);
|
||||
NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth);
|
||||
NS_IMETHOD GetWidth(const nsString& aString, nscoord &aWidth);
|
||||
NS_IMETHOD GetWidth(const char *aString, nscoord &aWidth);
|
||||
NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth);
|
||||
NS_IMETHOD GetWidth(nsIDeviceContext *aContext, const nsString& aString, nscoord &aWidth);
|
||||
NS_IMETHOD GetHeight(nscoord &aHeight);
|
||||
NS_IMETHOD GetLeading(nscoord &aLeading);
|
||||
NS_IMETHOD GetMaxAscent(nscoord &aAscent);
|
||||
NS_IMETHOD GetMaxDescent(nscoord &aDescent);
|
||||
NS_IMETHOD GetMaxAdvance(nscoord &aAdvance);
|
||||
NS_IMETHOD GetWidths(const nscoord *aWidths);
|
||||
NS_IMETHOD GetFont(const nsFont *&aFont);
|
||||
NS_IMETHOD GetFontHandle(nsFontHandle& aHandle);
|
||||
|
||||
/*protected:
|
||||
void RealizeFont();
|
||||
|
||||
@ -539,7 +539,9 @@ void nsRenderingContextMac :: SetFont(const nsFont& aFont)
|
||||
|
||||
const nsFont& nsRenderingContextMac :: GetFont()
|
||||
{
|
||||
return mFontMetrics->GetFont();
|
||||
const nsFont* font;
|
||||
mFontMetrics->GetFont(font);
|
||||
return *font;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
@ -56,7 +56,7 @@ nsFontMetricsUnix :: ~nsFontMetricsUnix()
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsFontMetricsUnix, kIFontMetricsIID)
|
||||
|
||||
nsresult nsFontMetricsUnix :: Init(const nsFont& aFont, nsIDeviceContext* aCX)
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: Init(const nsFont& aFont, nsIDeviceContext* aCX)
|
||||
{
|
||||
NS_ASSERTION(!(nsnull == aCX), "attempt to init fontmetrics with null device context");
|
||||
|
||||
@ -265,28 +265,32 @@ void nsFontMetricsUnix::RealizeFont()
|
||||
mLeading = 0;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsUnix :: GetWidth(char ch)
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetWidth(char ch, nscoord &aWidth)
|
||||
{
|
||||
if (ch < 256)
|
||||
return mCharWidths[ch];
|
||||
aWidth = mCharWidths[ch];
|
||||
else
|
||||
return 0; //XXX
|
||||
aWidth = 0; //XXX
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsUnix :: GetWidth(PRUnichar ch)
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetWidth(PRUnichar ch, nscoord &aWidth)
|
||||
{
|
||||
if (ch < 256)
|
||||
return mCharWidths[PRUint8(ch)];
|
||||
aWidth = mCharWidths[PRUint8(ch)];
|
||||
else
|
||||
return 0;/* XXX */
|
||||
aWidth = 0;/* XXX */
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsUnix :: GetWidth(const nsString& aString)
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetWidth(const nsString& aString, nscoord &aWidth)
|
||||
{
|
||||
return GetWidth(aString.GetUnicode(), aString.Length());
|
||||
return GetWidth(aString.GetUnicode(), aString.Length(), aWidth);
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsUnix :: GetWidth(const char *aString)
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetWidth(const char *aString, nscoord &aWidth)
|
||||
{
|
||||
PRInt32 rc = 0 ;
|
||||
|
||||
@ -294,10 +298,13 @@ nscoord nsFontMetricsUnix :: GetWidth(const char *aString)
|
||||
|
||||
float dev2app;
|
||||
mContext->GetDevUnitsToAppUnits(dev2app);
|
||||
return nscoord(rc * dev2app);
|
||||
aWidth = nscoord(rc * dev2app);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsUnix :: GetWidth(const PRUnichar *aString, PRUint32 aLength)
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetWidth(const PRUnichar *aString,
|
||||
PRUint32 aLength,
|
||||
nscoord &aWidth)
|
||||
{
|
||||
XChar2b * thischar ;
|
||||
PRUint16 aunichar;
|
||||
@ -328,53 +335,64 @@ nscoord nsFontMetricsUnix :: GetWidth(const PRUnichar *aString, PRUint32 aLength
|
||||
|
||||
float dev2app;
|
||||
mContext->GetDevUnitsToAppUnits(dev2app);
|
||||
return nscoord(width * dev2app);
|
||||
aWidth = nscoord(width * dev2app);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// XXX this needs to be implemented
|
||||
nscoord nsFontMetricsUnix :: GetWidth(nsIDeviceContext *aContext, const nsString& aString)
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetWidth(nsIDeviceContext *aContext,
|
||||
const nsString& aString,
|
||||
nscoord &aWidth)
|
||||
{
|
||||
return GetWidth(aString.GetUnicode(), aString.Length());
|
||||
return GetWidth(aString.GetUnicode(), aString.Length(), aWidth);
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsUnix :: GetHeight()
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetHeight(nscoord &aHeight)
|
||||
{
|
||||
return mHeight;
|
||||
aHeight = mHeight;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsUnix :: GetLeading()
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetLeading(nscoord &aLeading)
|
||||
{
|
||||
return mLeading;
|
||||
aLeading = mLeading;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsUnix :: GetMaxAscent()
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetMaxAscent(nscoord &aAscent)
|
||||
{
|
||||
return mMaxAscent;
|
||||
aAscent = mMaxAscent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsUnix :: GetMaxDescent()
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetMaxDescent(nscoord &aDescent)
|
||||
{
|
||||
return mMaxDescent;
|
||||
aDescent = mMaxDescent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsUnix :: GetMaxAdvance()
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetMaxAdvance(nscoord &aAdvance)
|
||||
{
|
||||
return mMaxAdvance;
|
||||
aAdvance = mMaxAdvance;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const nscoord * nsFontMetricsUnix :: GetWidths()
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetWidths(const nscoord *&aWidths)
|
||||
{
|
||||
return mCharWidths;
|
||||
aWidths = mCharWidths;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const nsFont& nsFontMetricsUnix :: GetFont()
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetFont(const nsFont*& aFont)
|
||||
{
|
||||
return *mFont;
|
||||
aFont = mFont;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsFontHandle nsFontMetricsUnix :: GetFontHandle()
|
||||
NS_IMETHODIMP nsFontMetricsUnix :: GetFontHandle(nsFontHandle &aHandle)
|
||||
{
|
||||
return (nsFontHandle)mFontHandle;
|
||||
aHandle = (nsFontHandle)mFontHandle;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -42,21 +42,21 @@ public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult Init(const nsFont& aFont, nsIDeviceContext* aContext);
|
||||
virtual nscoord GetWidth(char aC);
|
||||
virtual nscoord GetWidth(PRUnichar aC);
|
||||
virtual nscoord GetWidth(const nsString& aString);
|
||||
virtual nscoord GetWidth(const char *aString);
|
||||
virtual nscoord GetWidth(const PRUnichar *aString, PRUint32 aLength);
|
||||
virtual nscoord GetWidth(nsIDeviceContext *aContext, const nsString& aString);
|
||||
virtual nscoord GetHeight();
|
||||
virtual nscoord GetLeading();
|
||||
virtual nscoord GetMaxAscent();
|
||||
virtual nscoord GetMaxDescent();
|
||||
virtual nscoord GetMaxAdvance();
|
||||
virtual const nscoord *GetWidths();
|
||||
virtual const nsFont& GetFont();
|
||||
virtual nsFontHandle GetFontHandle();
|
||||
NS_IMETHOD Init(const nsFont& aFont, nsIDeviceContext* aContext);
|
||||
NS_IMETHOD GetWidth(char aC);
|
||||
NS_IMETHOD GetWidth(PRUnichar aC);
|
||||
NS_IMETHOD GetWidth(const nsString& aString);
|
||||
NS_IMETHOD GetWidth(const char *aString);
|
||||
NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength);
|
||||
NS_IMETHOD GetWidth(nsIDeviceContext *aContext, const nsString& aString);
|
||||
NS_IMETHOD GetHeight();
|
||||
NS_IMETHOD GetLeading();
|
||||
NS_IMETHOD GetMaxAscent();
|
||||
NS_IMETHOD GetMaxDescent();
|
||||
NS_IMETHOD GetMaxAdvance();
|
||||
NS_IMETHOD nscoord *GetWidths(const nscoord *&aWidths);
|
||||
NS_IMETHOD GetFont(const nsFont*& aFont);
|
||||
NS_IMETHOD GetFontHandle(nsFontHandle &aHandle);
|
||||
|
||||
protected:
|
||||
void RealizeFont();
|
||||
|
||||
@ -533,7 +533,9 @@ void nsRenderingContextUnix :: SetFont(const nsFont& aFont)
|
||||
if (mFontMetrics)
|
||||
{
|
||||
// mCurrFontHandle = ::XLoadFont(mRenderingSurface->display, (char *)mFontMetrics->GetFontHandle());
|
||||
mCurrFontHandle = (Font)mFontMetrics->GetFontHandle();
|
||||
nsFontHandle fontHandle;
|
||||
mFontMetrics->GetFontHandle(fontHandle);
|
||||
mCurrFontHandle = (Font)fontHandle;
|
||||
|
||||
::XSetFont(mRenderingSurface->display,
|
||||
mRenderingSurface->gc,
|
||||
@ -546,7 +548,9 @@ void nsRenderingContextUnix :: SetFont(const nsFont& aFont)
|
||||
|
||||
const nsFont& nsRenderingContextUnix :: GetFont()
|
||||
{
|
||||
return mFontMetrics->GetFont();
|
||||
const nsFont* font;
|
||||
mFontMetrics->GetFont(font);
|
||||
return *font;
|
||||
}
|
||||
|
||||
nsIFontMetrics* nsRenderingContextUnix :: GetFontMetrics()
|
||||
@ -951,7 +955,7 @@ void nsRenderingContextUnix :: DrawString(const char *aString, PRUint32 aLength,
|
||||
|
||||
if (mFontMetrics)
|
||||
{
|
||||
PRUint8 deco = mFontMetrics->GetFont().decorations;
|
||||
PRUint8 deco = GetFont().decorations;
|
||||
|
||||
if (deco & NS_FONT_DECORATION_OVERLINE)
|
||||
DrawLine(aX, aY, aX + aWidth, aY);
|
||||
@ -993,7 +997,7 @@ void nsRenderingContextUnix :: DrawString(const PRUnichar *aString, PRUint32 aLe
|
||||
|
||||
if (mFontMetrics)
|
||||
{
|
||||
PRUint8 deco = mFontMetrics->GetFont().decorations;
|
||||
PRUint8 deco = GetFont().decorations;
|
||||
|
||||
if (deco & NS_FONT_DECORATION_OVERLINE)
|
||||
DrawLine(aX, aY, aX + aWidth, aY);
|
||||
|
||||
@ -82,7 +82,9 @@ NS_IMETHODIMP FontCacheImpl :: GetMetricsFor(const nsFont& aFont, nsIFontMetrics
|
||||
{
|
||||
aMetrics = (nsIFontMetrics*) mFontMetrics.ElementAt(cnt);
|
||||
|
||||
if (aFont.Equals(aMetrics->GetFont()))
|
||||
const nsFont* font;
|
||||
aMetrics->GetFont(font);
|
||||
if (aFont.Equals(*font))
|
||||
{
|
||||
NS_ADDREF(aMetrics);
|
||||
return NS_OK;
|
||||
|
||||
@ -43,47 +43,47 @@ class nsIFontMetrics : public nsISupports
|
||||
|
||||
public:
|
||||
//initializer
|
||||
virtual nsresult Init(const nsFont& aFont, nsIDeviceContext *aContext) = 0;
|
||||
NS_IMETHOD Init(const nsFont& aFont, nsIDeviceContext *aContext) = 0;
|
||||
|
||||
//get the width of an 8 bit char
|
||||
virtual nscoord GetWidth(char aC) = 0;
|
||||
NS_IMETHOD GetWidth(char aC, nscoord &aWidth) = 0;
|
||||
|
||||
//get the width of a unicode char
|
||||
virtual nscoord GetWidth(PRUnichar aC) = 0;
|
||||
NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth) = 0;
|
||||
|
||||
//get the width of an nsString
|
||||
virtual nscoord GetWidth(const nsString& aString) = 0;
|
||||
NS_IMETHOD GetWidth(const nsString& aString, nscoord &aWidth) = 0;
|
||||
|
||||
//get the width of 8 bit character string
|
||||
virtual nscoord GetWidth(const char *aString) = 0;
|
||||
NS_IMETHOD GetWidth(const char *aString, nscoord &aWidth) = 0;
|
||||
|
||||
//get the width of a Unicode character string
|
||||
virtual nscoord GetWidth(const PRUnichar *aString, PRUint32 aLength) = 0;
|
||||
NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth) = 0;
|
||||
|
||||
virtual nscoord GetWidth(nsIDeviceContext *aContext, const nsString& aString) = 0;
|
||||
NS_IMETHOD GetWidth(nsIDeviceContext *aContext, const nsString& aString, nscoord &aWidth) = 0;
|
||||
|
||||
//get the height as this font
|
||||
virtual nscoord GetHeight() = 0;
|
||||
NS_IMETHOD GetHeight(nscoord &aHeight) = 0;
|
||||
|
||||
//get height - (ascent + descent)
|
||||
virtual nscoord GetLeading() = 0;
|
||||
NS_IMETHOD GetLeading(nscoord &aLeading) = 0;
|
||||
|
||||
//get the maximum character ascent
|
||||
virtual nscoord GetMaxAscent() = 0;
|
||||
NS_IMETHOD GetMaxAscent(nscoord &aAscent) = 0;
|
||||
|
||||
//get the maximum character descent
|
||||
virtual nscoord GetMaxDescent() = 0;
|
||||
NS_IMETHOD GetMaxDescent(nscoord &aDescent) = 0;
|
||||
|
||||
//get the maximum character advance for the font
|
||||
virtual nscoord GetMaxAdvance() = 0;
|
||||
NS_IMETHOD GetMaxAdvance(nscoord &aAdvance) = 0;
|
||||
|
||||
//get the widths of the first 256 characters of the font
|
||||
virtual const nscoord *GetWidths() = 0;
|
||||
NS_IMETHOD GetWidths(const nscoord *&aWidths) = 0;
|
||||
|
||||
//get the font associated width these metrics
|
||||
virtual const nsFont& GetFont() = 0;
|
||||
NS_IMETHOD GetFont(const nsFont *&aFont) = 0;
|
||||
|
||||
virtual nsFontHandle GetFontHandle() = 0;
|
||||
NS_IMETHOD GetFontHandle(nsFontHandle &aHandle) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsIFontMetrics_h___ */
|
||||
|
||||
@ -86,7 +86,7 @@ NS_IMPL_ISUPPORTS(nsFontMetricsWin, kIFontMetricsIID)
|
||||
// Note: The presentation context has a reference to this font
|
||||
// metrics, therefore avoid circular references by not AddRef'ing the
|
||||
// presentation context.
|
||||
nsresult nsFontMetricsWin :: Init(const nsFont& aFont, nsIDeviceContext *aContext)
|
||||
NS_IMETHODIMP nsFontMetricsWin :: Init(const nsFont& aFont, nsIDeviceContext *aContext)
|
||||
{
|
||||
mFont = new nsFont(aFont);
|
||||
|
||||
@ -235,37 +235,42 @@ void nsFontMetricsWin::RealizeFont(nsIDeviceContext *aContext)
|
||||
::ReleaseDC(win, dc);
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsWin :: GetWidth(char ch)
|
||||
NS_IMETHODIMP nsFontMetricsWin :: GetWidth(char ch, nscoord &aWidth)
|
||||
{
|
||||
return mCharWidths[PRUint8(ch)];
|
||||
aWidth = mCharWidths[PRUint8(ch)];
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsWin :: GetWidth(PRUnichar ch)
|
||||
NS_IMETHODIMP nsFontMetricsWin :: GetWidth(PRUnichar ch, nscoord &aWidth)
|
||||
{
|
||||
if (ch < 256) {
|
||||
return mCharWidths[ch];
|
||||
aWidth = mCharWidths[ch];
|
||||
return NS_OK;
|
||||
}
|
||||
return 0;/* XXX */
|
||||
aWidth = 0;/* XXX */
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsWin :: GetWidth(const nsString& aString)
|
||||
NS_IMETHODIMP nsFontMetricsWin :: GetWidth(const nsString& aString, nscoord &aWidth)
|
||||
{
|
||||
return GetWidth(aString.GetUnicode(), aString.Length());
|
||||
return GetWidth(aString.GetUnicode(), aString.Length(), aWidth);
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsWin :: GetWidth(const char *aString)
|
||||
NS_IMETHODIMP nsFontMetricsWin :: GetWidth(const char *aString, nscoord &aWidth)
|
||||
{
|
||||
// XXX use native text measurement routine
|
||||
nscoord sum = 0;
|
||||
aWidth = 0;
|
||||
PRUint8 ch;
|
||||
while ((ch = PRUint8(*aString++)) != 0) {
|
||||
sum += mCharWidths[ch];
|
||||
aWidth += mCharWidths[ch];
|
||||
}
|
||||
|
||||
return sum;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsWin :: GetWidth(nsIDeviceContext *aContext, const nsString& aString)
|
||||
NS_IMETHODIMP nsFontMetricsWin :: GetWidth(nsIDeviceContext *aContext,
|
||||
const nsString& aString,
|
||||
nscoord &aWidth)
|
||||
{
|
||||
char * str = aString.ToNewCString();
|
||||
//if (str) {
|
||||
@ -295,62 +300,73 @@ nscoord nsFontMetricsWin :: GetWidth(nsIDeviceContext *aContext, const nsString&
|
||||
//printf("[%s] %d %d = %d\n", str, size.cx, nscoord(((float)size.cx)*aContext->GetDevUnitsToTwips()), GetWidth(str));
|
||||
|
||||
delete[] str;
|
||||
return nscoord(float(size.cx) * dev2twip);
|
||||
aWidth = nscoord(float(size.cx) * dev2twip);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsWin :: GetWidth(const PRUnichar *aString, PRUint32 aLength)
|
||||
NS_IMETHODIMP nsFontMetricsWin :: GetWidth(const PRUnichar *aString,
|
||||
PRUint32 aLength,
|
||||
nscoord &aWidth)
|
||||
{
|
||||
|
||||
// XXX use native text measurement routine
|
||||
nscoord sum = 0;
|
||||
aWidth = 0;
|
||||
while (aLength != 0) {
|
||||
PRUnichar ch = *aString++;
|
||||
if (ch < 256) {
|
||||
sum += mCharWidths[ch];
|
||||
aWidth += mCharWidths[ch];
|
||||
} else {
|
||||
// XXX not yet
|
||||
}
|
||||
--aLength;
|
||||
}
|
||||
return sum;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsWin :: GetHeight()
|
||||
NS_IMETHODIMP nsFontMetricsWin :: GetHeight(nscoord &aHeight)
|
||||
{
|
||||
return mHeight;
|
||||
aHeight = mHeight;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsWin :: GetLeading()
|
||||
NS_IMETHODIMP nsFontMetricsWin :: GetLeading(nscoord &aLeading)
|
||||
{
|
||||
return mLeading;
|
||||
aLeading = mLeading;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsWin :: GetMaxAscent()
|
||||
NS_IMETHODIMP nsFontMetricsWin :: GetMaxAscent(nscoord &aAscent)
|
||||
{
|
||||
return mMaxAscent;
|
||||
aAscent = mMaxAscent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsWin :: GetMaxDescent()
|
||||
NS_IMETHODIMP nsFontMetricsWin :: GetMaxDescent(nscoord &aDescent)
|
||||
{
|
||||
return mMaxDescent;
|
||||
aDescent = mMaxDescent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nscoord nsFontMetricsWin :: GetMaxAdvance()
|
||||
NS_IMETHODIMP nsFontMetricsWin :: GetMaxAdvance(nscoord &aAdvance)
|
||||
{
|
||||
return mMaxAdvance;
|
||||
aAdvance = mMaxAdvance;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const nscoord * nsFontMetricsWin :: GetWidths()
|
||||
NS_IMETHODIMP nsFontMetricsWin :: GetWidths(const nscoord *&aWidths)
|
||||
{
|
||||
return mCharWidths;
|
||||
aWidths = mCharWidths;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const nsFont& nsFontMetricsWin :: GetFont()
|
||||
NS_IMETHODIMP nsFontMetricsWin :: GetFont(const nsFont *&aFont)
|
||||
{
|
||||
return *mFont;
|
||||
aFont = mFont;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsFontHandle nsFontMetricsWin::GetFontHandle()
|
||||
NS_IMETHODIMP nsFontMetricsWin::GetFontHandle(nsFontHandle &aHandle)
|
||||
{
|
||||
return mFontHandle;
|
||||
aHandle = mFontHandle;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -42,22 +42,22 @@ public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult Init(const nsFont& aFont, nsIDeviceContext *aContext);
|
||||
virtual nscoord GetWidth(char aC);
|
||||
virtual nscoord GetWidth(PRUnichar aC);
|
||||
virtual nscoord GetWidth(const nsString& aString);
|
||||
virtual nscoord GetWidth(const char *aString);
|
||||
virtual nscoord GetWidth(const PRUnichar *aString, PRUint32 aLength);
|
||||
virtual nscoord GetWidth(nsIDeviceContext *aContext, const nsString& aString);
|
||||
NS_IMETHOD Init(const nsFont& aFont, nsIDeviceContext *aContext);
|
||||
NS_IMETHOD GetWidth(char aC, nscoord &aWidth);
|
||||
NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth);
|
||||
NS_IMETHOD GetWidth(const nsString& aString, nscoord &aWidth);
|
||||
NS_IMETHOD GetWidth(const char *aString, nscoord &aWidth);
|
||||
NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth);
|
||||
NS_IMETHOD GetWidth(nsIDeviceContext *aContext, const nsString& aString, nscoord &aWidth);
|
||||
|
||||
virtual nscoord GetHeight();
|
||||
virtual nscoord GetLeading();
|
||||
virtual nscoord GetMaxAscent();
|
||||
virtual nscoord GetMaxDescent();
|
||||
virtual nscoord GetMaxAdvance();
|
||||
virtual const nscoord *GetWidths();
|
||||
virtual const nsFont& GetFont();
|
||||
virtual nsFontHandle GetFontHandle();
|
||||
NS_IMETHOD GetHeight(nscoord &aHeight);
|
||||
NS_IMETHOD GetLeading(nscoord &aLeading);
|
||||
NS_IMETHOD GetMaxAscent(nscoord &aAscent);
|
||||
NS_IMETHOD GetMaxDescent(nscoord &aDescent);
|
||||
NS_IMETHOD GetMaxAdvance(nscoord &aAdvance);
|
||||
NS_IMETHOD GetWidths(const nscoord *&aWidths);
|
||||
NS_IMETHOD GetFont(const nsFont *&aFont);
|
||||
NS_IMETHOD GetFontHandle(nsFontHandle &aHandle);
|
||||
|
||||
protected:
|
||||
void RealizeFont(nsIDeviceContext *aContext);
|
||||
|
||||
@ -743,7 +743,9 @@ void nsRenderingContextWin :: SetFont(const nsFont& aFont)
|
||||
|
||||
const nsFont& nsRenderingContextWin :: GetFont()
|
||||
{
|
||||
return mFontMetrics->GetFont();
|
||||
const nsFont* font;
|
||||
mFontMetrics->GetFont(font);
|
||||
return *font;
|
||||
}
|
||||
|
||||
nsIFontMetrics* nsRenderingContextWin :: GetFontMetrics()
|
||||
@ -1118,7 +1120,7 @@ void nsRenderingContextWin :: DrawString(const char *aString, PRUint32 aLength,
|
||||
mTMatrix->TransformCoord(&x,&y);
|
||||
::ExtTextOut(mDC,x,y,0,NULL,aString,aLength,NULL);
|
||||
|
||||
if (mFontMetrics->GetFont().decorations & NS_FONT_DECORATION_OVERLINE)
|
||||
if (GetFont().decorations & NS_FONT_DECORATION_OVERLINE)
|
||||
DrawLine(aX, aY, aX + aWidth, aY);
|
||||
}
|
||||
|
||||
@ -1132,7 +1134,7 @@ void nsRenderingContextWin :: DrawString(const PRUnichar *aString, PRUint32 aLen
|
||||
mTMatrix->TransformCoord(&x,&y);
|
||||
::ExtTextOutW(mDC,x,y,0,NULL,aString,aLength,NULL);
|
||||
|
||||
if (mFontMetrics->GetFont().decorations & NS_FONT_DECORATION_OVERLINE)
|
||||
if (GetFont().decorations & NS_FONT_DECORATION_OVERLINE)
|
||||
DrawLine(aX, aY, aX + aWidth, aY);
|
||||
}
|
||||
|
||||
@ -1269,7 +1271,9 @@ void nsRenderingContextWin :: SetupFontAndColor(void)
|
||||
{
|
||||
if ((mFontMetrics != mCurrFontMetrics) || (NULL == mCurrFontMetrics))
|
||||
{
|
||||
HFONT tfont = (HFONT)mFontMetrics->GetFontHandle();
|
||||
nsFontHandle fontHandle;
|
||||
mFontMetrics->GetFontHandle(fontHandle);
|
||||
HFONT tfont = (HFONT)fontHandle;
|
||||
|
||||
::SelectObject(mDC, tfont);
|
||||
|
||||
|
||||
@ -2217,7 +2217,7 @@ nsCSSBlockFrame::ReflowBlockFrame(nsCSSBlockReflowState& aState,
|
||||
else {
|
||||
const nsFont& defaultFont = aState.mPresContext->GetDefaultFont();
|
||||
nsIFontMetrics* fm = aState.mPresContext->GetMetricsFor(defaultFont);
|
||||
childTopMargin = fm->GetHeight();
|
||||
fm->GetHeight(childTopMargin);
|
||||
NS_RELEASE(fm);
|
||||
}
|
||||
}
|
||||
@ -2407,7 +2407,7 @@ nsCSSBlockFrame::ReflowBlockFrame(nsCSSBlockReflowState& aState,
|
||||
if (NS_STYLE_DISPLAY_LIST_ITEM != childDisplay->mDisplay) {
|
||||
const nsFont& defaultFont = aState.mPresContext->GetDefaultFont();
|
||||
nsIFontMetrics* fm = aState.mPresContext->GetMetricsFor(defaultFont);
|
||||
childBottomMargin = fm->GetHeight();
|
||||
fm->GetHeight(childBottomMargin);
|
||||
NS_RELEASE(fm);
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,7 +348,9 @@ nsCSSInlineLayout::PlaceFrame(nsIFrame* aFrame,
|
||||
// take care of that).
|
||||
nsIFontMetrics* fm =
|
||||
mLineLayout.mPresContext->GetMetricsFor(mContainerFont->mFont);
|
||||
nscoord dx = fm->GetHeight() / 2; // from old layout engine
|
||||
nscoord height;
|
||||
fm->GetHeight(height);
|
||||
nscoord dx = height / 2; // from old layout engine
|
||||
NS_RELEASE(fm);
|
||||
aFrameRect.x = mX - aFrameRect.width - dx;
|
||||
if (aFrameRect.x < 0) aFrameRect.x = 0;
|
||||
|
||||
@ -111,8 +111,8 @@ BRFrame::InlineReflow(nsCSSLineLayout& aLineLayout,
|
||||
mStyleContext->GetStyleData(eStyleStruct_Font);
|
||||
nsIFontMetrics* fm = aLineLayout.mPresContext->GetMetricsFor(font->mFont);
|
||||
|
||||
aMetrics.ascent = fm->GetMaxAscent();
|
||||
aMetrics.descent = fm->GetMaxDescent();
|
||||
fm->GetMaxAscent(aMetrics.ascent);
|
||||
fm->GetMaxDescent(aMetrics.descent);
|
||||
aMetrics.height = aMetrics.ascent + aMetrics.descent;
|
||||
aMetrics.width = 0;
|
||||
NS_RELEASE(fm);
|
||||
|
||||
@ -278,7 +278,8 @@ HRuleFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
||||
lineHeight = thickness + NSIntPixelsToTwips(2, p2t);
|
||||
const nsFont& defaultFont = aPresContext->GetDefaultFont();
|
||||
nsIFontMetrics* fm = aPresContext->GetMetricsFor(defaultFont);
|
||||
nscoord defaultLineHeight = fm->GetHeight();
|
||||
nscoord defaultLineHeight;
|
||||
fm->GetHeight(defaultLineHeight);
|
||||
NS_RELEASE(fm);
|
||||
if (lineHeight < defaultLineHeight) {
|
||||
lineHeight = defaultLineHeight;
|
||||
|
||||
@ -231,6 +231,7 @@ BulletFrame::Paint(nsIPresContext& aCX,
|
||||
{
|
||||
const nsStyleDisplay* disp =
|
||||
(const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);
|
||||
nscoord width;
|
||||
|
||||
if (disp->mVisible) {
|
||||
const nsStyleList* myList =
|
||||
@ -293,8 +294,8 @@ BulletFrame::Paint(nsIPresContext& aCX,
|
||||
fm = aCX.GetMetricsFor(myFont->mFont);
|
||||
GetListItemText(&aCX, nsnull, *myList, text);
|
||||
aRenderingContext.SetFont(myFont->mFont);
|
||||
aRenderingContext.DrawString(text, mPadding.left, mPadding.top,
|
||||
fm->GetWidth(text));
|
||||
fm->GetWidth(text, width);
|
||||
aRenderingContext.DrawString(text, mPadding.left, mPadding.top, width);
|
||||
NS_RELEASE(fm);
|
||||
break;
|
||||
}
|
||||
@ -523,6 +524,8 @@ BulletFrame::GetDesiredSize(nsIPresContext* aCX,
|
||||
{
|
||||
const nsStyleList* myList =
|
||||
(const nsStyleList*)mStyleContext->GetStyleData(eStyleStruct_List);
|
||||
nscoord ascent;
|
||||
|
||||
if (myList->mListStyleImage.Length() > 0) {
|
||||
mImageLoader.SetURL(myList->mListStyleImage);
|
||||
mImageLoader.GetDesiredSize(aCX, aReflowState, aMetrics);
|
||||
@ -556,13 +559,14 @@ BulletFrame::GetDesiredSize(nsIPresContext* aCX,
|
||||
case NS_STYLE_LIST_STYLE_BASIC:
|
||||
case NS_STYLE_LIST_STYLE_SQUARE:
|
||||
t2p = aCX->GetTwipsToPixels();
|
||||
bulletSize = NSTwipsToIntPixels((nscoord)NSToIntRound(0.8f * (float(fm->GetMaxAscent()) / 2.0f)), t2p);
|
||||
fm->GetMaxAscent(ascent);
|
||||
bulletSize = NSTwipsToIntPixels((nscoord)NSToIntRound(0.8f * (float(ascent) / 2.0f)), t2p);
|
||||
if (bulletSize < 1) {
|
||||
bulletSize = MIN_BULLET_SIZE;
|
||||
}
|
||||
p2t = aCX->GetPixelsToTwips();
|
||||
bulletSize = NSIntPixelsToTwips(bulletSize, p2t);
|
||||
mPadding.bottom = (fm->GetMaxAscent() / 8);
|
||||
mPadding.bottom = ascent / 8;
|
||||
if (NS_STYLE_LIST_STYLE_POSITION_INSIDE == myList->mListStylePosition) {
|
||||
mPadding.right = bulletSize / 2;
|
||||
}
|
||||
@ -578,15 +582,17 @@ BulletFrame::GetDesiredSize(nsIPresContext* aCX,
|
||||
case NS_STYLE_LIST_STYLE_LOWER_ALPHA:
|
||||
case NS_STYLE_LIST_STYLE_UPPER_ALPHA:
|
||||
GetListItemText(aCX, aState, *myList, text);
|
||||
fm->GetHeight(aMetrics.height);
|
||||
if (NS_STYLE_LIST_STYLE_POSITION_INSIDE == myList->mListStylePosition) {
|
||||
// Inside bullets need some extra width to get the padding
|
||||
// between the list item and the content that follows.
|
||||
mPadding.right = fm->GetHeight() / 2; // From old layout engine
|
||||
mPadding.right = aMetrics.height / 2; // From old layout engine
|
||||
}
|
||||
aMetrics.width = mPadding.right + fm->GetWidth(text);
|
||||
aMetrics.height = fm->GetHeight();
|
||||
aMetrics.ascent = fm->GetMaxAscent();
|
||||
aMetrics.descent = fm->GetMaxDescent();
|
||||
|
||||
fm->GetWidth(text, aMetrics.width);
|
||||
aMetrics.width += mPadding.right;
|
||||
fm->GetMaxAscent(aMetrics.ascent);
|
||||
fm->GetMaxDescent(aMetrics.descent);
|
||||
break;
|
||||
}
|
||||
NS_RELEASE(fm);
|
||||
|
||||
@ -455,7 +455,8 @@ ImageFrame::MeasureString(nsIFontMetrics* aFontMetrics,
|
||||
PRUint32& aMaxFit)
|
||||
{
|
||||
nscoord totalWidth = 0;
|
||||
nscoord spaceWidth = aFontMetrics->GetWidth(' ');
|
||||
nscoord spaceWidth;
|
||||
aFontMetrics->GetWidth(' ', spaceWidth);
|
||||
|
||||
aMaxFit = 0;
|
||||
while (aLength > 0) {
|
||||
@ -471,7 +472,8 @@ ImageFrame::MeasureString(nsIFontMetrics* aFontMetrics,
|
||||
}
|
||||
|
||||
// Measure this chunk of text, and see if it fits
|
||||
nscoord width = aFontMetrics->GetWidth(aString, len);
|
||||
nscoord width;
|
||||
aFontMetrics->GetWidth(aString, len, width);
|
||||
PRBool fits = (totalWidth + width) <= aMaxWidth;
|
||||
|
||||
// If it fits on the line, or it's the first word we've processed then
|
||||
@ -530,8 +532,9 @@ ImageFrame::DisplayAltText(nsIPresContext& aPresContext,
|
||||
// Format the text to display within the formatting rect
|
||||
nsIFontMetrics* fm = aRenderingContext.GetFontMetrics();
|
||||
|
||||
nscoord maxDescent = fm->GetMaxDescent();
|
||||
nscoord height = fm->GetHeight();
|
||||
nscoord maxDescent, height;
|
||||
fm->GetMaxDescent(maxDescent);
|
||||
fm->GetHeight(height);
|
||||
|
||||
// XXX It would be nice if there was a way to have the font metrics tell
|
||||
// use where to break the text given a maximum width. At a minimum we need
|
||||
|
||||
@ -888,7 +888,8 @@ TextFrame::PaintRegularText(nsIPresContext& aPresContext,
|
||||
nsString textStr;
|
||||
textStr.Append(compressedStr, endPnt->GetOffset()- mContentOffset);
|
||||
|
||||
nscoord textLen = fm->GetWidth(deviceContext, textStr);
|
||||
nscoord textLen;
|
||||
fm->GetWidth(deviceContext, textStr, textLen);
|
||||
|
||||
// Draw little blue triangle
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,255));
|
||||
@ -1016,7 +1017,7 @@ TextFrame::PaintRegularText(nsIPresContext& aPresContext,
|
||||
|
||||
if (startCoord > 0) {
|
||||
textStr.Append(compressedStr, startCoord);
|
||||
startTwipLen = fm->GetWidth(deviceContext, textStr);
|
||||
fm->GetWidth(deviceContext, textStr, startTwipLen);
|
||||
aRenderingContext.DrawString(compressedStr, startCoord, dx, dy, startTwipLen);
|
||||
}
|
||||
//---------------------------------------------------
|
||||
@ -1026,7 +1027,8 @@ TextFrame::PaintRegularText(nsIPresContext& aPresContext,
|
||||
textStr.SetLength(0);
|
||||
textStr.Append(compressedStr+startCoord, selTextCharLen);
|
||||
|
||||
nscoord selTextTwipLen = fm->GetWidth(deviceContext, textStr);
|
||||
nscoord selTextTwipLen;
|
||||
fm->GetWidth(deviceContext, textStr, selTextTwipLen);
|
||||
|
||||
rect.x = startTwipLen;
|
||||
rect.width = selTextTwipLen;
|
||||
@ -1050,7 +1052,8 @@ TextFrame::PaintRegularText(nsIPresContext& aPresContext,
|
||||
textStr.SetLength(0);
|
||||
textStr.Append(compressedStr+endCoord, compressedStrLen-selTextCharLen);
|
||||
|
||||
PRUint32 endTextTwipLen = fm->GetWidth(deviceContext, textStr);
|
||||
nscoord endTextTwipLen;
|
||||
fm->GetWidth(deviceContext, textStr, endTextTwipLen);
|
||||
|
||||
aRenderingContext.SetColor(color->mColor);
|
||||
aRenderingContext.DrawString(compressedStr+endCoord, compressedStrLen-endCoord,
|
||||
@ -1078,7 +1081,7 @@ TextFrame::PaintRegularText(nsIPresContext& aPresContext,
|
||||
|
||||
if (startOffset > 0) {
|
||||
textStr.Append(compressedStr, startOffset);
|
||||
startTwipLen = fm->GetWidth(deviceContext, textStr);
|
||||
fm->GetWidth(deviceContext, textStr, startTwipLen);
|
||||
aRenderingContext.DrawString(compressedStr, startOffset, dx, dy, startTwipLen);
|
||||
}
|
||||
|
||||
@ -1089,7 +1092,8 @@ TextFrame::PaintRegularText(nsIPresContext& aPresContext,
|
||||
textStr.SetLength(0);
|
||||
textStr.Append(compressedStr+startOffset, selTextCharLen);
|
||||
|
||||
nscoord selTextTwipLen = fm->GetWidth(deviceContext, textStr);
|
||||
nscoord selTextTwipLen;
|
||||
fm->GetWidth(deviceContext, textStr, selTextTwipLen);
|
||||
|
||||
rect.x = startTwipLen;
|
||||
rect.width = selTextTwipLen;
|
||||
@ -1146,7 +1150,8 @@ TextFrame::PaintRegularText(nsIPresContext& aPresContext,
|
||||
textStr.SetLength(0);
|
||||
textStr.Append(compressedStr, selTextCharLen);
|
||||
|
||||
nscoord selTextTwipLen = fm->GetWidth(deviceContext, textStr);
|
||||
nscoord selTextTwipLen;
|
||||
fm->GetWidth(deviceContext, textStr, selTextTwipLen);
|
||||
|
||||
rect.width = selTextTwipLen;
|
||||
|
||||
@ -1165,7 +1170,8 @@ TextFrame::PaintRegularText(nsIPresContext& aPresContext,
|
||||
textStr.SetLength(0);
|
||||
textStr.Append(compressedStr+endOffset, compressedStrLen-selTextCharLen);
|
||||
|
||||
PRUint32 endTextTwipLen = fm->GetWidth(deviceContext, textStr);
|
||||
nscoord endTextTwipLen;
|
||||
fm->GetWidth(deviceContext, textStr, endTextTwipLen);
|
||||
|
||||
const nsStyleColor* color = (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
|
||||
aRenderingContext.SetColor(color->mColor);
|
||||
@ -1297,7 +1303,8 @@ TextFrame::ReflowNormal(nsCSSLineLayout& aLineLayout,
|
||||
mContentOffset = aStartingOffset;
|
||||
|
||||
nsIFontMetrics* fm = aLineLayout.mPresContext->GetMetricsFor(aFont.mFont);
|
||||
PRInt32 spaceWidth = fm->GetWidth(' ');
|
||||
PRInt32 spaceWidth;
|
||||
fm->GetWidth(' ', spaceWidth);
|
||||
PRBool wrapping = PR_TRUE;
|
||||
if (NS_STYLE_WHITESPACE_NORMAL != aTextStyle.mWhiteSpace) {
|
||||
wrapping = PR_FALSE;
|
||||
@ -1369,7 +1376,7 @@ TextFrame::ReflowNormal(nsCSSLineLayout& aLineLayout,
|
||||
}
|
||||
break;
|
||||
}
|
||||
width = fm->GetWidth(wordStart, PRUint32(cp - wordStart));
|
||||
fm->GetWidth(wordStart, PRUint32(cp - wordStart), width);
|
||||
skipWhitespace = PR_FALSE;
|
||||
isWhitespace = PR_FALSE;
|
||||
}
|
||||
@ -1440,15 +1447,15 @@ TextFrame::ReflowNormal(nsCSSLineLayout& aLineLayout,
|
||||
|
||||
// Set desired size to the computed size
|
||||
aMetrics.width = x;
|
||||
aMetrics.height = fm->GetHeight();
|
||||
aMetrics.ascent = fm->GetMaxAscent();
|
||||
aMetrics.descent = fm->GetMaxDescent();
|
||||
fm->GetHeight(aMetrics.height);
|
||||
fm->GetMaxAscent(aMetrics.ascent);
|
||||
fm->GetMaxDescent(aMetrics.descent);
|
||||
if (!wrapping) {
|
||||
maxWordWidth = x;
|
||||
}
|
||||
if (nsnull != aMetrics.maxElementSize) {
|
||||
aMetrics.maxElementSize->width = maxWordWidth;
|
||||
aMetrics.maxElementSize->height = fm->GetHeight();
|
||||
fm->GetHeight(aMetrics.maxElementSize->height);
|
||||
}
|
||||
NS_RELEASE(fm);
|
||||
return (cp == end) ? NS_FRAME_COMPLETE : NS_FRAME_NOT_COMPLETE;
|
||||
@ -1470,7 +1477,8 @@ TextFrame::ReflowPre(nsCSSLineLayout& aLineLayout,
|
||||
|
||||
mFlags |= TEXT_IS_PRE;
|
||||
nsIFontMetrics* fm = aLineLayout.mPresContext->GetMetricsFor(aFont.mFont);
|
||||
const PRInt32* widths = fm->GetWidths();
|
||||
const PRInt32* widths;
|
||||
fm->GetWidths(widths);
|
||||
PRInt32 width = 0;
|
||||
PRBool hasMultibyte = PR_FALSE;
|
||||
PRUint16 tabs = 0;
|
||||
@ -1502,7 +1510,9 @@ TextFrame::ReflowPre(nsCSSLineLayout& aLineLayout,
|
||||
if (ch < 256) {
|
||||
width += widths[ch];
|
||||
} else {
|
||||
widths += fm->GetWidth(ch);
|
||||
nscoord charWidth;
|
||||
fm->GetWidth(ch, charWidth);
|
||||
widths += charWidth;
|
||||
hasMultibyte = PR_TRUE;
|
||||
}
|
||||
col++;
|
||||
@ -1516,9 +1526,9 @@ TextFrame::ReflowPre(nsCSSLineLayout& aLineLayout,
|
||||
mContentOffset = aStartingOffset;
|
||||
mContentLength = cp - cpStart;
|
||||
aMetrics.width = width;
|
||||
aMetrics.height = fm->GetHeight();
|
||||
aMetrics.ascent = fm->GetMaxAscent();
|
||||
aMetrics.descent = fm->GetMaxDescent();
|
||||
fm->GetHeight(aMetrics.height);
|
||||
fm->GetMaxAscent(aMetrics.ascent);
|
||||
fm->GetMaxDescent(aMetrics.descent);
|
||||
if (nsnull != aMetrics.maxElementSize) {
|
||||
aMetrics.maxElementSize->width = aMetrics.width;
|
||||
aMetrics.maxElementSize->height = aMetrics.height;
|
||||
@ -1548,7 +1558,7 @@ void TextFrame::CalcActualPosition(PRUint32 &aMsgType,
|
||||
aWidth = 0;
|
||||
}
|
||||
else {
|
||||
aWidth = aFM->GetWidth(aCPStart, aOffset-1);
|
||||
aFM->GetWidth(aCPStart, aOffset-1, aWidth);
|
||||
}
|
||||
} else if (aMsgType == NS_MOUSE_LEFT_BUTTON_DOWN) {
|
||||
aOffset = PRUint32(aCP - aCPStart)-1;
|
||||
@ -1613,7 +1623,7 @@ void TextFrame::CalcCursorPosition(nsIPresContext& aCX,
|
||||
for (i=1;i<PRInt32(compressedStrLen);i++) {
|
||||
strncpy(buffer, compressedStr, i);
|
||||
buffer[i] = 0;
|
||||
width = fm->GetWidth(buffer);
|
||||
fm->GetWidth(buffer, width);
|
||||
//printf("%s %d %d\n", buf, i, width);
|
||||
if (width >= aEvent->point.x) {
|
||||
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) {
|
||||
|
||||
@ -471,10 +471,11 @@ nsInputFrame::GetTextSize(nsIPresContext& aPresContext, nsInputFrame* aFrame,
|
||||
|
||||
nsIFontMetrics* fontMet;
|
||||
fontCache->GetMetricsFor(font, fontMet);
|
||||
aSize.width = fontMet->GetWidth(aString);
|
||||
aSize.height = fontMet->GetHeight();
|
||||
fontMet->GetWidth(aString, aSize.width);
|
||||
fontMet->GetHeight(aSize.height);
|
||||
|
||||
nscoord charWidth = fontMet->GetWidth("W");
|
||||
nscoord charWidth;
|
||||
fontMet->GetWidth("W", charWidth);
|
||||
|
||||
NS_RELEASE(fontMet);
|
||||
NS_RELEASE(fontCache);
|
||||
|
||||
@ -70,6 +70,7 @@ nsCSSLayout::VerticallyAlignChildren(nsIPresContext* aCX,
|
||||
nscoord kidYTop = 0;
|
||||
|
||||
PRBool isPass2Kid = PR_FALSE;
|
||||
nscoord fontHeight, fontAscent, fontDescent;
|
||||
switch (verticalAlignUnit) {
|
||||
case eStyleUnit_Coord:
|
||||
kidYTop = aMaxAscent + textStyle->mVerticalAlign.GetCoordValue();
|
||||
@ -115,15 +116,18 @@ nsCSSLayout::VerticallyAlignChildren(nsIPresContext* aCX,
|
||||
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
|
||||
// XXX spec says use the 'x' height but our font api
|
||||
// doesn't give us that information.
|
||||
kidYTop = aMaxAscent - (fm->GetHeight() / 2) - kidRect.height/2;
|
||||
fm->GetHeight(fontHeight);
|
||||
kidYTop = aMaxAscent - (fontHeight / 2) - kidRect.height/2;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
|
||||
kidYTop = aMaxAscent + fm->GetMaxDescent() - kidRect.height;
|
||||
fm->GetMaxDescent(fontDescent);
|
||||
kidYTop = aMaxAscent + fontDescent - kidRect.height;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
|
||||
kidYTop = aMaxAscent - fm->GetMaxAscent();
|
||||
fm->GetMaxAscent(fontAscent);
|
||||
kidYTop = aMaxAscent - fontAscent;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@ -238,8 +238,8 @@ HandleThrobberEvent(nsGUIEvent *aEvent)
|
||||
cx->SetColor(NS_RGB(255, 255, 255));
|
||||
cx->SetFont(tfont);
|
||||
met = cx->GetFontMetrics();
|
||||
w = met->GetWidth(str[0]) + met->GetWidth(str[1]);
|
||||
h = met->GetHeight();
|
||||
met->GetWidth(str, w);
|
||||
met->GetHeight(h);
|
||||
cx->DrawString(str, 2, (bounds.width - w) >> 1, (bounds.height - h) >> 1, 0);
|
||||
NS_RELEASE(met);
|
||||
}
|
||||
|
||||
@ -842,8 +842,10 @@ void nsWindow::SetFont(const nsFont &aFont)
|
||||
|
||||
XmFontList fontList = NULL;
|
||||
XmFontListEntry entry = NULL;
|
||||
XFontStruct * fontStruct = XQueryFont(XtDisplay(mWidget),
|
||||
(XID)metrics->GetFontHandle());
|
||||
nsFontHandle fontHandle;
|
||||
metrics->GetFontHandle(fontHandle);
|
||||
XFontStruct * fontStruct = XQueryFont(XtDisplay(mWidget), (XID)fontHandle);
|
||||
|
||||
if (fontStruct != NULL) {
|
||||
entry = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG,
|
||||
XmFONT_IS_FONT, fontStruct);
|
||||
|
||||
@ -1061,7 +1061,9 @@ void nsWindow::SetFont(const nsFont &aFont)
|
||||
mContext->GetFontCache(fontCache);
|
||||
nsIFontMetrics* metrics;
|
||||
fontCache->GetMetricsFor(aFont, metrics);
|
||||
HFONT hfont = metrics->GetFontHandle();
|
||||
nsFontHandle fontHandle;
|
||||
metrics->GetFontHandle(fontHandle);
|
||||
HFONT hfont = (HFONT)fontHandle;
|
||||
|
||||
// Draw in the new font
|
||||
::SendMessage(mWnd, WM_SETFONT, (WPARAM)hfont, (LPARAM)0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user