diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index d695afe6ce05..1e8ea7dc3707 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -2492,10 +2492,9 @@ GetScrollableLineHeight(nsIFrame* aTargetFrame) const nsFont& f = font->mFont; nsRefPtr fm = aTargetFrame->PresContext()->GetMetricsFor(f); NS_ASSERTION(fm, "FontMetrics is null!"); - nscoord lineHeight = 0; if (fm) - fm->GetMaxHeight(lineHeight); - return lineHeight; + return fm->MaxHeight(); + return 0; } void diff --git a/gfx/src/nsFontMetrics.cpp b/gfx/src/nsFontMetrics.cpp index 155a6c971609..2807254c0ee5 100644 --- a/gfx/src/nsFontMetrics.cpp +++ b/gfx/src/nsFontMetrics.cpp @@ -40,31 +40,31 @@ #include "nsBoundingMetrics.h" #include "nsRenderingContext.h" #include "nsThebesDeviceContext.h" +#include "gfxTextRunCache.h" -class AutoTextRun { +namespace { + +class AutoTextRun : public gfxTextRunCache::AutoTextRun { public: AutoTextRun(nsFontMetrics* aMetrics, nsRenderingContext* aRC, - const char* aString, PRInt32 aLength) { - mTextRun = gfxTextRunCache::MakeTextRun( + const char* aString, PRInt32 aLength) + : gfxTextRunCache::AutoTextRun(gfxTextRunCache::MakeTextRun( reinterpret_cast(aString), aLength, aMetrics->GetThebesFontGroup(), aRC->ThebesContext(), aMetrics->AppUnitsPerDevPixel(), - ComputeFlags(aMetrics)); - } + ComputeFlags(aMetrics))) + {} + AutoTextRun(nsFontMetrics* aMetrics, nsRenderingContext* aRC, - const PRUnichar* aString, PRInt32 aLength) { - mTextRun = gfxTextRunCache::MakeTextRun( + const PRUnichar* aString, PRInt32 aLength) + : gfxTextRunCache::AutoTextRun(gfxTextRunCache::MakeTextRun( aString, aLength, aMetrics->GetThebesFontGroup(), aRC->ThebesContext(), aMetrics->AppUnitsPerDevPixel(), - ComputeFlags(aMetrics)); - } - gfxTextRun* operator->() { return mTextRun.get(); } - gfxTextRun* get() { return mTextRun.get(); } + ComputeFlags(aMetrics))) + {} private: - gfxTextRunCache::AutoTextRun mTextRun; - static PRUint32 ComputeFlags(nsFontMetrics* aMetrics) { PRUint32 flags = 0; if (aMetrics->GetRightToLeftTextRunMode()) { @@ -74,6 +74,24 @@ private: } }; +class StubPropertyProvider : public gfxTextRun::PropertyProvider { +public: + virtual void GetHyphenationBreaks(PRUint32 aStart, PRUint32 aLength, + PRPackedBool* aBreakBefore) { + NS_ERROR("This shouldn't be called because we never call BreakAndMeasureText"); + } + virtual gfxFloat GetHyphenWidth() { + NS_ERROR("This shouldn't be called because we never enable hyphens"); + return 0; + } + virtual void GetSpacing(PRUint32 aStart, PRUint32 aLength, + Spacing* aSpacing) { + NS_ERROR("This shouldn't be called because we never enable spacing"); + } +}; + +} // anon namespace + nsFontMetrics::nsFontMetrics() { mFontStyle = nsnull; @@ -118,11 +136,10 @@ nsFontMetrics::Init(const nsFont& aFont, nsIAtom* aLanguage, return NS_OK; } -nsresult +void nsFontMetrics::Destroy() { mDeviceContext = nsnull; - return NS_OK; } // XXXTODO get rid of this macro @@ -134,42 +151,36 @@ const gfxFont::Metrics& nsFontMetrics::GetMetrics() const return mFontGroup->GetFontAt(0)->GetMetrics(); } -nsresult -nsFontMetrics::GetXHeight(nscoord& aResult) +nscoord +nsFontMetrics::XHeight() { - aResult = ROUND_TO_TWIPS(GetMetrics().xHeight); - return NS_OK; + return ROUND_TO_TWIPS(GetMetrics().xHeight); } -nsresult -nsFontMetrics::GetSuperscriptOffset(nscoord& aResult) +nscoord +nsFontMetrics::SuperscriptOffset() { - aResult = ROUND_TO_TWIPS(GetMetrics().superscriptOffset); - return NS_OK; + return ROUND_TO_TWIPS(GetMetrics().superscriptOffset); } -nsresult -nsFontMetrics::GetSubscriptOffset(nscoord& aResult) +nscoord +nsFontMetrics::SubscriptOffset() { - aResult = ROUND_TO_TWIPS(GetMetrics().subscriptOffset); - return NS_OK; + return ROUND_TO_TWIPS(GetMetrics().subscriptOffset); } -nsresult +void nsFontMetrics::GetStrikeout(nscoord& aOffset, nscoord& aSize) { aOffset = ROUND_TO_TWIPS(GetMetrics().strikeoutOffset); aSize = ROUND_TO_TWIPS(GetMetrics().strikeoutSize); - return NS_OK; } -nsresult +void nsFontMetrics::GetUnderline(nscoord& aOffset, nscoord& aSize) { aOffset = ROUND_TO_TWIPS(mFontGroup->GetUnderlineOffset()); aSize = ROUND_TO_TWIPS(GetMetrics().underlineSize); - - return NS_OK; } // GetMaxAscent/GetMaxDescent/GetMaxHeight must contain the @@ -191,91 +202,80 @@ static gfxFloat ComputeMaxAscent(const gfxFont::Metrics& aMetrics) return NS_floor(aMetrics.maxAscent + 0.5); } -nsresult -nsFontMetrics::GetInternalLeading(nscoord &aLeading) +nscoord +nsFontMetrics::InternalLeading() { - aLeading = ROUND_TO_TWIPS(GetMetrics().internalLeading); - return NS_OK; + return ROUND_TO_TWIPS(GetMetrics().internalLeading); } -nsresult -nsFontMetrics::GetExternalLeading(nscoord &aLeading) +nscoord +nsFontMetrics::ExternalLeading() { - aLeading = ROUND_TO_TWIPS(GetMetrics().externalLeading); - return NS_OK; + return ROUND_TO_TWIPS(GetMetrics().externalLeading); } -nsresult -nsFontMetrics::GetEmHeight(nscoord &aHeight) +nscoord +nsFontMetrics::EmHeight() { - aHeight = ROUND_TO_TWIPS(GetMetrics().emHeight); - return NS_OK; + return ROUND_TO_TWIPS(GetMetrics().emHeight); } -nsresult -nsFontMetrics::GetEmAscent(nscoord &aAscent) +nscoord +nsFontMetrics::EmAscent() { - aAscent = ROUND_TO_TWIPS(GetMetrics().emAscent); - return NS_OK; + return ROUND_TO_TWIPS(GetMetrics().emAscent); } -nsresult -nsFontMetrics::GetEmDescent(nscoord &aDescent) +nscoord +nsFontMetrics::EmDescent() { - aDescent = ROUND_TO_TWIPS(GetMetrics().emDescent); - return NS_OK; + return ROUND_TO_TWIPS(GetMetrics().emDescent); } -nsresult -nsFontMetrics::GetMaxHeight(nscoord &aHeight) +nscoord +nsFontMetrics::MaxHeight() { - aHeight = CEIL_TO_TWIPS(ComputeMaxAscent(GetMetrics())) + + return CEIL_TO_TWIPS(ComputeMaxAscent(GetMetrics())) + CEIL_TO_TWIPS(ComputeMaxDescent(GetMetrics(), mFontGroup)); - return NS_OK; } -nsresult -nsFontMetrics::GetMaxAscent(nscoord &aAscent) +nscoord +nsFontMetrics::MaxAscent() { - aAscent = CEIL_TO_TWIPS(ComputeMaxAscent(GetMetrics())); - return NS_OK; + return CEIL_TO_TWIPS(ComputeMaxAscent(GetMetrics())); } -nsresult -nsFontMetrics::GetMaxDescent(nscoord &aDescent) +nscoord +nsFontMetrics::MaxDescent() { - aDescent = CEIL_TO_TWIPS(ComputeMaxDescent(GetMetrics(), mFontGroup)); - return NS_OK; + return CEIL_TO_TWIPS(ComputeMaxDescent(GetMetrics(), mFontGroup)); } -nsresult -nsFontMetrics::GetMaxAdvance(nscoord &aAdvance) +nscoord +nsFontMetrics::MaxAdvance() { - aAdvance = CEIL_TO_TWIPS(GetMetrics().maxAdvance); - return NS_OK; + return CEIL_TO_TWIPS(GetMetrics().maxAdvance); } -nsresult -nsFontMetrics::GetLanguage(nsIAtom** aLanguage) -{ - *aLanguage = mLanguage; - NS_IF_ADDREF(*aLanguage); - return NS_OK; -} - -nsresult -nsFontMetrics::GetAveCharWidth(nscoord& aAveCharWidth) +nscoord +nsFontMetrics::AveCharWidth() { // Use CEIL instead of ROUND for consistency with GetMaxAdvance - aAveCharWidth = CEIL_TO_TWIPS(GetMetrics().aveCharWidth); - return NS_OK; + return CEIL_TO_TWIPS(GetMetrics().aveCharWidth); } -nsresult -nsFontMetrics::GetSpaceWidth(nscoord& aSpaceCharWidth) +nscoord +nsFontMetrics::SpaceWidth() { - aSpaceCharWidth = CEIL_TO_TWIPS(GetMetrics().spaceWidth); - return NS_OK; + return CEIL_TO_TWIPS(GetMetrics().spaceWidth); +} + +already_AddRefed +nsFontMetrics::GetLanguage() +{ + nsIAtom* result = mLanguage.get(); + NS_IF_ADDREF(result); + return result; } PRInt32 @@ -287,145 +287,93 @@ nsFontMetrics::GetMaxStringLength() return PR_MAX(1, len); } -class StubPropertyProvider : public gfxTextRun::PropertyProvider { -public: - virtual void GetHyphenationBreaks(PRUint32 aStart, PRUint32 aLength, - PRPackedBool* aBreakBefore) { - NS_ERROR("This shouldn't be called because we never call BreakAndMeasureText"); - } - virtual gfxFloat GetHyphenWidth() { - NS_ERROR("This shouldn't be called because we never enable hyphens"); - return 0; - } - virtual void GetSpacing(PRUint32 aStart, PRUint32 aLength, - Spacing* aSpacing) { - NS_ERROR("This shouldn't be called because we never enable spacing"); - } -}; - -nsresult -nsFontMetrics::GetWidth(const char* aString, PRUint32 aLength, nscoord& aWidth, +nscoord +nsFontMetrics::GetWidth(const char* aString, PRUint32 aLength, nsRenderingContext *aContext) { - if (aLength == 0) { - aWidth = 0; - return NS_OK; - } + if (aLength == 0) + return 0; - // callers that hit this should not be so stupid - if ((aLength == 1) && (aString[0] == ' ')) - return GetSpaceWidth(aWidth); + if (aLength == 1 && aString[0] == ' ') + return SpaceWidth(); StubPropertyProvider provider; AutoTextRun textRun(this, aContext, aString, aLength); - if (!textRun.get()) - return NS_ERROR_FAILURE; - - aWidth = NSToCoordRound(textRun->GetAdvanceWidth(0, aLength, &provider)); - - return NS_OK; + return NSToCoordRound(textRun->GetAdvanceWidth(0, aLength, &provider)); } -nsresult +nscoord nsFontMetrics::GetWidth(const PRUnichar* aString, PRUint32 aLength, - nscoord& aWidth, PRInt32 *aFontID, nsRenderingContext *aContext) { - if (aLength == 0) { - aWidth = 0; - return NS_OK; - } + if (aLength == 0) + return 0; - // callers that hit this should not be so stupid - if ((aLength == 1) && (aString[0] == ' ')) - return GetSpaceWidth(aWidth); + if (aLength == 1 && aString[0] == ' ') + return SpaceWidth(); StubPropertyProvider provider; AutoTextRun textRun(this, aContext, aString, aLength); - if (!textRun.get()) - return NS_ERROR_FAILURE; - - aWidth = NSToCoordRound(textRun->GetAdvanceWidth(0, aLength, &provider)); - - return NS_OK; + return NSToCoordRound(textRun->GetAdvanceWidth(0, aLength, &provider)); } // Draw a string using this font handle on the surface passed in. -nsresult +void nsFontMetrics::DrawString(const char *aString, PRUint32 aLength, nscoord aX, nscoord aY, - const nscoord* aSpacing, nsRenderingContext *aContext) { if (aLength == 0) - return NS_OK; + return; - NS_ASSERTION(!aSpacing, "Spacing not supported here"); StubPropertyProvider provider; AutoTextRun textRun(this, aContext, aString, aLength); - if (!textRun.get()) - return NS_ERROR_FAILURE; gfxPoint pt(aX, aY); if (mTextRunRTL) { pt.x += textRun->GetAdvanceWidth(0, aLength, &provider); } - textRun->Draw(aContext->ThebesContext(), pt, 0, aLength, - &provider, nsnull); - return NS_OK; + textRun->Draw(aContext->ThebesContext(), pt, 0, aLength, &provider, nsnull); } -nsresult +void nsFontMetrics::DrawString(const PRUnichar* aString, PRUint32 aLength, nscoord aX, nscoord aY, nsRenderingContext *aContext, nsRenderingContext *aTextRunConstructionContext) { if (aLength == 0) - return NS_OK; + return; StubPropertyProvider provider; AutoTextRun textRun(this, aTextRunConstructionContext, aString, aLength); - if (!textRun.get()) - return NS_ERROR_FAILURE; gfxPoint pt(aX, aY); if (mTextRunRTL) { pt.x += textRun->GetAdvanceWidth(0, aLength, &provider); } - textRun->Draw(aContext->ThebesContext(), pt, 0, aLength, - &provider, nsnull); - return NS_OK; + textRun->Draw(aContext->ThebesContext(), pt, 0, aLength, &provider, nsnull); } #ifdef MOZ_MATHML -nsresult +nsBoundingMetrics nsFontMetrics::GetBoundingMetrics(const PRUnichar *aString, PRUint32 aLength, - nsRenderingContext *aContext, - nsBoundingMetrics &aBoundingMetrics) + nsRenderingContext *aContext) { - if (aLength == 0) { - aBoundingMetrics = nsBoundingMetrics(); - return NS_OK; - } + if (aLength == 0) + return nsBoundingMetrics(); - AutoTextRun textRun(this, aContext, aString, aLength); - if (!textRun.get()) - return NS_ERROR_FAILURE; - - // note that TIGHT_HINTED_OUTLINE_EXTENTS can be expensive (on Windows) - // but this is only used for MathML positioning so it's not critical StubPropertyProvider provider; + AutoTextRun textRun(this, aContext, aString, aLength); gfxTextRun::Metrics theMetrics = textRun->MeasureText(0, aLength, gfxFont::TIGHT_HINTED_OUTLINE_EXTENTS, aContext->ThebesContext(), &provider); - aBoundingMetrics.leftBearing = NSToCoordFloor(theMetrics.mBoundingBox.X()); - aBoundingMetrics.rightBearing - = NSToCoordCeil(theMetrics.mBoundingBox.XMost()); - aBoundingMetrics.width = NSToCoordRound(theMetrics.mAdvanceWidth); - aBoundingMetrics.ascent = NSToCoordCeil(- theMetrics.mBoundingBox.Y()); - aBoundingMetrics.descent = NSToCoordCeil(theMetrics.mBoundingBox.YMost()); - - return NS_OK; + nsBoundingMetrics m; + m.leftBearing = NSToCoordFloor( theMetrics.mBoundingBox.X()); + m.rightBearing = NSToCoordCeil( theMetrics.mBoundingBox.XMost()); + m.ascent = NSToCoordCeil( -theMetrics.mBoundingBox.Y()); + m.descent = NSToCoordCeil( theMetrics.mBoundingBox.YMost()); + m.width = NSToCoordRound( theMetrics.mAdvanceWidth); + return m; } #endif /* MOZ_MATHML */ diff --git a/gfx/src/nsFontMetrics.h b/gfx/src/nsFontMetrics.h index 8cd1ccc0ac17..17ba2dbea438 100644 --- a/gfx/src/nsFontMetrics.h +++ b/gfx/src/nsFontMetrics.h @@ -43,14 +43,10 @@ #include "nsCoord.h" #include "nsFont.h" #include "gfxFont.h" -#include "gfxTextRunCache.h" -class gfxFontGroup; -class gfxUserFontSet; class nsIAtom; class nsIDeviceContext; class nsRenderingContext; -class nsString; class nsThebesDeviceContext; struct nsBoundingMetrics; @@ -94,93 +90,103 @@ public: * Destroy this font metrics. This breaks the association between * the font metrics and the device context. */ - nsresult Destroy(); + void Destroy(); /** * Return the font's x-height. */ - nsresult GetXHeight(nscoord& aResult); + nscoord XHeight(); /** * Return the font's superscript offset (the distance from the * baseline to where a superscript's baseline should be placed). * The value returned will be positive. */ - nsresult GetSuperscriptOffset(nscoord& aResult); + nscoord SuperscriptOffset(); /** * Return the font's subscript offset (the distance from the * baseline to where a subscript's baseline should be placed). * The value returned will be positive. */ - nsresult GetSubscriptOffset(nscoord& aResult); + nscoord SubscriptOffset(); /** * Return the font's strikeout offset (the distance from the * baseline to where a strikeout should be placed) and size. * Positive values are above the baseline, negative below. */ - nsresult GetStrikeout(nscoord& aOffset, nscoord& aSize); + void GetStrikeout(nscoord& aOffset, nscoord& aSize); /** * Return the font's underline offset (the distance from the * baseline to where a underline should be placed) and size. * Positive values are above the baseline, negative below. */ - nsresult GetUnderline(nscoord& aOffset, nscoord& aSize); + void GetUnderline(nscoord& aOffset, nscoord& aSize); /** * Returns the amount of internal leading for the font. * This is normally the difference between the max ascent * and the em ascent. */ - nsresult GetInternalLeading(nscoord &aLeading); + nscoord InternalLeading(); /** * Returns the amount of external leading for the font. * em ascent(?) plus external leading is the font designer's * recommended line-height for this font. */ - nsresult GetExternalLeading(nscoord &aLeading); + nscoord ExternalLeading(); /** * Returns the height of the em square. * This is em ascent plus em descent. */ - nsresult GetEmHeight(nscoord &aHeight); + nscoord EmHeight(); /** * Returns the ascent part of the em square. */ - nsresult GetEmAscent(nscoord &aAscent); + nscoord EmAscent(); /** * Returns the descent part of the em square. */ - nsresult GetEmDescent(nscoord &aDescent); + nscoord EmDescent(); /** * Returns the height of the bounding box. * This is max ascent plus max descent. */ - nsresult GetMaxHeight(nscoord &aHeight); + nscoord MaxHeight(); /** * Returns the maximum distance characters in this font extend * above the base line. */ - nsresult GetMaxAscent(nscoord &aAscent); + nscoord MaxAscent(); /** * Returns the maximum distance characters in this font extend * below the base line. */ - nsresult GetMaxDescent(nscoord &aDescent); + nscoord MaxDescent(); /** * Returns the maximum character advance for the font. */ - nsresult GetMaxAdvance(nscoord &aAdvance); + nscoord MaxAdvance(); + + /** + * Returns the average character width + */ + nscoord AveCharWidth(); + + /** + * Returns the often needed width of the space character + */ + nscoord SpaceWidth(); /** * Returns the font associated with these metrics. The return value @@ -191,44 +197,31 @@ public: /** * Returns the language associated with these metrics */ - nsresult GetLanguage(nsIAtom** aLanguage); - - /** - * Returns the average character width - */ - nsresult GetAveCharWidth(nscoord& aAveCharWidth); - - /** - * Returns the often needed width of the space character - */ - nsresult GetSpaceWidth(nscoord& aSpaceCharWidth); + already_AddRefed GetLanguage(); PRInt32 GetMaxStringLength(); // Get the width for this string. aWidth will be updated with the // width in points, not twips. Callers must convert it if they // want it in another format. - nsresult GetWidth(const char* aString, PRUint32 aLength, nscoord& aWidth, - nsRenderingContext *aContext); - nsresult GetWidth(const PRUnichar* aString, PRUint32 aLength, - nscoord& aWidth, PRInt32 *aFontID, - nsRenderingContext *aContext); + nscoord GetWidth(const char* aString, PRUint32 aLength, + nsRenderingContext *aContext); + nscoord GetWidth(const PRUnichar* aString, PRUint32 aLength, + nsRenderingContext *aContext); // Draw a string using this font handle on the surface passed in. - nsresult DrawString(const char *aString, PRUint32 aLength, - nscoord aX, nscoord aY, - const nscoord* aSpacing, - nsRenderingContext *aContext); - nsresult DrawString(const PRUnichar* aString, PRUint32 aLength, - nscoord aX, nscoord aY, - nsRenderingContext *aContext, - nsRenderingContext *aTextRunConstructionContext); + void DrawString(const char *aString, PRUint32 aLength, + nscoord aX, nscoord aY, + nsRenderingContext *aContext); + void DrawString(const PRUnichar* aString, PRUint32 aLength, + nscoord aX, nscoord aY, + nsRenderingContext *aContext, + nsRenderingContext *aTextRunConstructionContext); #ifdef MOZ_MATHML - nsresult GetBoundingMetrics(const PRUnichar *aString, - PRUint32 aLength, - nsRenderingContext *aContext, - nsBoundingMetrics &aBoundingMetrics); + nsBoundingMetrics GetBoundingMetrics(const PRUnichar *aString, + PRUint32 aLength, + nsRenderingContext *aContext); #endif /* MOZ_MATHML */ // Set the direction of the text rendering diff --git a/gfx/src/nsRenderingContext.cpp b/gfx/src/nsRenderingContext.cpp index 8c146af9bc66..4418a2748a31 100644 --- a/gfx/src/nsRenderingContext.cpp +++ b/gfx/src/nsRenderingContext.cpp @@ -494,9 +494,7 @@ nscoord nsRenderingContext::GetWidth(char aC) { if (aC == ' ' && mFontMetrics) { - nscoord width; - mFontMetrics->GetSpaceWidth(width); - return width; + return mFontMetrics->SpaceWidth(); } return GetWidth(&aC, 1); @@ -527,7 +525,7 @@ nsRenderingContext::GetWidth(const char* aString, PRUint32 aLength) nscoord width = 0; while (aLength > 0) { PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength); - width += GetWidthInternal(aString, len); + width += mFontMetrics->GetWidth(aString, len, this); aLength -= len; aString += len; } @@ -541,7 +539,7 @@ nsRenderingContext::GetWidth(const PRUnichar *aString, PRUint32 aLength) nscoord width = 0; while (aLength > 0) { PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength); - width += GetWidthInternal(aString, len); + width += mFontMetrics->GetWidth(aString, len, this); aLength -= len; aString += len; } @@ -558,15 +556,15 @@ nsRenderingContext::GetBoundingMetrics(const PRUnichar* aString, // Assign directly in the first iteration. This ensures that // negative ascent/descent can be returned and the left bearing // is properly initialized. - nsBoundingMetrics totalMetrics; - mFontMetrics->GetBoundingMetrics(aString, len, this, totalMetrics); + nsBoundingMetrics totalMetrics + = mFontMetrics->GetBoundingMetrics(aString, len, this); aLength -= len; aString += len; while (aLength > 0) { len = FindSafeLength(aString, aLength, maxChunkLength); - nsBoundingMetrics metrics; - mFontMetrics->GetBoundingMetrics(aString, len, this, metrics); + nsBoundingMetrics metrics + = mFontMetrics->GetBoundingMetrics(aString, len, this); totalMetrics += metrics; aLength -= len; aString += len; @@ -582,11 +580,11 @@ nsRenderingContext::DrawString(const char *aString, PRUint32 aLength, PRUint32 maxChunkLength = GetMaxChunkLength(); while (aLength > 0) { PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength); - mFontMetrics->DrawString(aString, len, aX, aY, nsnull, this); + mFontMetrics->DrawString(aString, len, aX, aY, this); aLength -= len; if (aLength > 0) { - nscoord width = GetWidthInternal(aString, len); + nscoord width = mFontMetrics->GetWidth(aString, len, this); aX += width; aString += len; } @@ -618,7 +616,7 @@ nsRenderingContext::DrawString(const PRUnichar *aString, PRUint32 aLength, while (aLength > 0) { PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength); - nscoord width = GetWidthInternal(aString, len); + nscoord width = mFontMetrics->GetWidth(aString, len, this); if (isRTL) { aX -= width; } @@ -630,27 +628,3 @@ nsRenderingContext::DrawString(const PRUnichar *aString, PRUint32 aLength, aString += len; } } - -nscoord -nsRenderingContext::GetWidthInternal(const char* aString, PRUint32 aLength) -{ - if (aLength == 0) { - return 0; - } - - nscoord width; - mFontMetrics->GetWidth(aString, aLength, width, this); - return width; -} - -nscoord -nsRenderingContext::GetWidthInternal(const PRUnichar *aString, PRUint32 aLength) -{ - if (aLength == 0) { - return 0; - } - - nscoord width; - mFontMetrics->GetWidth(aString, aLength, width, nsnull, this); - return width; -} diff --git a/gfx/src/nsRenderingContext.h b/gfx/src/nsRenderingContext.h index 6611f8978a4f..85b790428728 100644 --- a/gfx/src/nsRenderingContext.h +++ b/gfx/src/nsRenderingContext.h @@ -146,8 +146,6 @@ public: protected: PRInt32 GetMaxChunkLength(); - nscoord GetWidthInternal(const char *aString, PRUint32 aLength); - nscoord GetWidthInternal(const PRUnichar *aString, PRUint32 aLength); nsRefPtr mThebes; nsCOMPtr mDeviceContext; diff --git a/gfx/src/nsThebesDeviceContext.cpp b/gfx/src/nsThebesDeviceContext.cpp index bd1924cc70c1..ac3084fc20d6 100644 --- a/gfx/src/nsThebesDeviceContext.cpp +++ b/gfx/src/nsThebesDeviceContext.cpp @@ -151,8 +151,7 @@ nsFontCache::GetMetricsFor(const nsFont& aFont, nsIAtom* aLanguage, for (PRInt32 i = n; i >= 0; --i) { fm = mFontMetrics[i]; if (fm->Font().Equals(aFont) && fm->GetUserFontSet() == aUserFontSet) { - nsCOMPtr language; - fm->GetLanguage(getter_AddRefs(language)); + nsCOMPtr language = fm->GetLanguage(); if (aLanguage == language.get()) { if (i != n) { // promote it to the end of the cache diff --git a/layout/base/nsCaret.cpp b/layout/base/nsCaret.cpp index f3fe6a878f3d..42ed4eed5467 100644 --- a/layout/base/nsCaret.cpp +++ b/layout/base/nsCaret.cpp @@ -360,8 +360,8 @@ nsCaret::GetGeometryForFrame(nsIFrame* aFrame, nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm)); NS_ASSERTION(fm, "We should be able to get the font metrics"); if (fm) { - fm->GetMaxAscent(ascent); - fm->GetMaxDescent(descent); + ascent = fm->MaxAscent(); + descent = fm->MaxDescent(); } nscoord height = ascent + descent; framePos.y = baseline - ascent; diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index eba2f1353421..66abab6c2eef 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -1644,7 +1644,7 @@ nsLayoutUtils::PaintFrame(nsRenderingContext* aRenderingContext, nsIFrame* aFram nsIWidget *widget = aFrame->GetNearestWidget(); if (widget) { PRInt32 pixelRatio = presContext->AppUnitsPerDevPixel(); - nsIntRegion visibleWindowRegion(visibleRegion.ToOutsidePixels(presContext->AppUnitsPerDevPixel())); + nsIntRegion visibleWindowRegion(visibleRegion.ToOutsidePixels(pixelRatio)); widget->UpdateTransparentRegion(visibleWindowRegion); } } @@ -2845,9 +2845,8 @@ nsLayoutUtils::GetStringWidth(const nsIFrame* aFrame, nsLayoutUtils::GetCenteredFontBaseline(nsFontMetrics* aFontMetrics, nscoord aLineHeight) { - nscoord fontAscent, fontHeight; - aFontMetrics->GetMaxAscent(fontAscent); - aFontMetrics->GetMaxHeight(fontHeight); + nscoord fontAscent = aFontMetrics->MaxAscent(); + nscoord fontHeight = aFontMetrics->MaxHeight(); nscoord leading = aLineHeight - fontHeight; return fontAscent + leading/2; diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 75b2e0b06f43..01186f643746 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -8809,12 +8809,10 @@ void ReflowCountMgr::PaintCount(const char* aName, aRenderingContext->SetFont(fm); char buf[16]; sprintf(buf, "%d", counter->mCount); - nscoord x = 0, y; - nscoord width, height; + nscoord x = 0, y = fm->MaxAscent(); + nscoord width, height = fm->MaxHeight(); aRenderingContext->SetTextRunRTL(PR_FALSE); aRenderingContext->GetWidth((char*)buf, width); - fm->GetMaxHeight(height); - fm->GetMaxAscent(y); PRUint32 color; PRUint32 color2; diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index e76dafbb2d4d..7dcb97fda061 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -1878,11 +1878,11 @@ nscoord nsListControlFrame::CalcFallbackRowHeight() { nscoord rowHeight = 0; - + nsRefPtr fontMet; nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet)); if (fontMet) { - fontMet->GetMaxHeight(rowHeight); + rowHeight = fontMet->MaxHeight(); } return rowHeight; diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp index 9a86d808a2c2..1697b5783b4a 100644 --- a/layout/forms/nsTextControlFrame.cpp +++ b/layout/forms/nsTextControlFrame.cpp @@ -237,8 +237,8 @@ nsTextControlFrame::CalcIntrinsicSize(nsRenderingContext* aRenderingContext, lineHeight = nsHTMLReflowState::CalcLineHeight(GetStyleContext(), NS_AUTOHEIGHT); - fontMet->GetAveCharWidth(charWidth); - fontMet->GetMaxAdvance(charMaxAdvance); + charWidth = fontMet->AveCharWidth(); + charMaxAdvance = fontMet->MaxAdvance(); // Set the width equal to the width in characters PRInt32 cols = GetCols(); diff --git a/layout/generic/nsBRFrame.cpp b/layout/generic/nsBRFrame.cpp index f22d3d4923c8..aac6e7a137b0 100644 --- a/layout/generic/nsBRFrame.cpp +++ b/layout/generic/nsBRFrame.cpp @@ -239,8 +239,7 @@ BRFrame::GetBaseline() const if (GetStateBits() & BR_USING_CENTERED_FONT_BASELINE) { ascent = nsLayoutUtils::GetCenteredFontBaseline(fm, logicalHeight); } else { - fm->GetMaxAscent(ascent); - ascent += GetUsedBorderAndPadding().top; + ascent = fm->MaxAscent() + GetUsedBorderAndPadding().top; } } return NS_MIN(mRect.height, ascent); diff --git a/layout/generic/nsBulletFrame.cpp b/layout/generic/nsBulletFrame.cpp index 448281847b63..e5dd44226bd2 100644 --- a/layout/generic/nsBulletFrame.cpp +++ b/layout/generic/nsBulletFrame.cpp @@ -388,8 +388,7 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt, nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); GetListItemText(*myList, text); aRenderingContext.SetFont(fm); - nscoord ascent; - fm->GetMaxAscent(ascent); + nscoord ascent = fm->MaxAscent(); aRenderingContext.SetTextRunRTL(mTextIsRTL); aRenderingContext.DrawString(text, mPadding.left + aPt.x, mPadding.top + aPt.y + ascent); @@ -1361,7 +1360,7 @@ nsBulletFrame::GetDesiredSize(nsPresContext* aCX, case NS_STYLE_LIST_STYLE_DISC: case NS_STYLE_LIST_STYLE_CIRCLE: case NS_STYLE_LIST_STYLE_SQUARE: - fm->GetMaxAscent(ascent); + ascent = fm->MaxAscent(); bulletSize = NS_MAX(nsPresContext::CSSPixelsToAppUnits(MIN_BULLET_SIZE), NSToCoordRound(0.8f * (float(ascent) / 2.0f))); mPadding.bottom = NSToCoordRound(float(ascent) / 8.0f); @@ -1422,11 +1421,13 @@ nsBulletFrame::GetDesiredSize(nsPresContext* aCX, case NS_STYLE_LIST_STYLE_MOZ_ETHIOPIC_HALEHAME_TI_ER: case NS_STYLE_LIST_STYLE_MOZ_ETHIOPIC_HALEHAME_TI_ET: GetListItemText(*myList, text); - fm->GetMaxHeight(aMetrics.height); + aMetrics.height = fm->MaxHeight(); aRenderingContext->SetFont(fm); - aMetrics.width = nsLayoutUtils::GetStringWidth(this, aRenderingContext, text.get(), text.Length()); + aMetrics.width = + nsLayoutUtils::GetStringWidth(this, aRenderingContext, + text.get(), text.Length()); aMetrics.width += mPadding.right; - fm->GetMaxAscent(aMetrics.ascent); + aMetrics.ascent = fm->MaxAscent(); break; } } @@ -1601,7 +1602,7 @@ nsBulletFrame::GetBaseline() const case NS_STYLE_LIST_STYLE_DISC: case NS_STYLE_LIST_STYLE_CIRCLE: case NS_STYLE_LIST_STYLE_SQUARE: - fm->GetMaxAscent(ascent); + ascent = fm->MaxAscent(); bottomPadding = NSToCoordRound(float(ascent) / 8.0f); ascent = NS_MAX(nsPresContext::CSSPixelsToAppUnits(MIN_BULLET_SIZE), NSToCoordRound(0.8f * (float(ascent) / 2.0f))); @@ -1609,7 +1610,7 @@ nsBulletFrame::GetBaseline() const break; default: - fm->GetMaxAscent(ascent); + ascent = fm->MaxAscent(); break; } } diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index e83e490e476e..aa00fe819a8e 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -2206,7 +2206,7 @@ nsGfxScrollFrameInner::GetLineScrollAmount() const NS_ASSERTION(fm, "FontMetrics is null, assuming fontHeight == 1 appunit"); nscoord fontHeight = 1; if (fm) { - fm->GetMaxHeight(fontHeight); + fontHeight = fm->MaxHeight(); } return nsSize(fontHeight, fontHeight); diff --git a/layout/generic/nsHTMLReflowState.cpp b/layout/generic/nsHTMLReflowState.cpp index 12941b315c13..a21136d47121 100644 --- a/layout/generic/nsHTMLReflowState.cpp +++ b/layout/generic/nsHTMLReflowState.cpp @@ -2112,10 +2112,9 @@ GetNormalLineHeight(nsFontMetrics* aFontMetrics) nscoord normalLineHeight; - nscoord externalLeading, internalLeading, emHeight; - aFontMetrics->GetExternalLeading(externalLeading); - aFontMetrics->GetInternalLeading(internalLeading); - aFontMetrics->GetEmHeight(emHeight); + nscoord externalLeading = aFontMetrics->ExternalLeading(); + nscoord internalLeading = aFontMetrics->InternalLeading(); + nscoord emHeight = aFontMetrics->EmHeight(); switch (GetNormalLineHeightCalcControl()) { case eIncludeExternalLeading: normalLineHeight = emHeight+ internalLeading + externalLeading; diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 73ee2af2a93a..d0f228327ce3 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -976,10 +976,9 @@ nsImageFrame::DisplayAltText(nsPresContext* aPresContext, // Format the text to display within the formatting rect nsFontMetrics* fm = aRenderingContext.FontMetrics(); - nscoord maxAscent, maxDescent, height; - fm->GetMaxAscent(maxAscent); - fm->GetMaxDescent(maxDescent); - fm->GetMaxHeight(height); + nscoord maxAscent = fm->MaxAscent(); + nscoord maxDescent = fm->MaxDescent(); + nscoord height = fm->MaxHeight(); // 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 diff --git a/layout/generic/nsInlineFrame.cpp b/layout/generic/nsInlineFrame.cpp index 8ccd135f0e71..071805f74fa7 100644 --- a/layout/generic/nsInlineFrame.cpp +++ b/layout/generic/nsInlineFrame.cpp @@ -656,8 +656,8 @@ nsInlineFrame::ReflowFrames(nsPresContext* aPresContext, // The height of our box is the sum of our font size plus the top // and bottom border and padding. The height of children do not // affect our height. - fm->GetMaxAscent(aMetrics.ascent); - fm->GetMaxHeight(aMetrics.height); + aMetrics.ascent = fm->MaxAscent(); + aMetrics.height = fm->MaxHeight(); } else { NS_WARNING("Cannot get font metrics - defaulting sizes to 0"); aMetrics.ascent = aMetrics.height = 0; @@ -914,8 +914,9 @@ nsInlineFrame::GetBaseline() const { nscoord ascent = 0; nsRefPtr fm; - if (NS_SUCCEEDED(nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)))) { - fm->GetMaxAscent(ascent); + nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); + if (fm) { + ascent = fm->MaxAscent(); } return NS_MIN(mRect.height, ascent + GetUsedBorderAndPadding().top); } diff --git a/layout/generic/nsLineLayout.cpp b/layout/generic/nsLineLayout.cpp index 23f359a52a31..bfbcc2b90205 100644 --- a/layout/generic/nsLineLayout.cpp +++ b/layout/generic/nsLineLayout.cpp @@ -1810,8 +1810,7 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd) // of the parent's box. This is identical to the baseline // alignment except for the addition of the subscript // offset to the baseline Y. - nscoord parentSubscript; - fm->GetSubscriptOffset(parentSubscript); + nscoord parentSubscript = fm->SubscriptOffset(); nscoord revisedBaselineY = baselineY + parentSubscript; pfd->mBounds.y = revisedBaselineY - pfd->mAscent; pfd->mVerticalAlign = VALIGN_OTHER; @@ -1824,8 +1823,7 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd) // of the parent's box. This is identical to the baseline // alignment except for the subtraction of the superscript // offset to the baseline Y. - nscoord parentSuperscript; - fm->GetSuperscriptOffset(parentSuperscript); + nscoord parentSuperscript = fm->SuperscriptOffset(); nscoord revisedBaselineY = baselineY - parentSuperscript; pfd->mBounds.y = revisedBaselineY - pfd->mAscent; pfd->mVerticalAlign = VALIGN_OTHER; @@ -1866,8 +1864,7 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd) { // Align the midpoint of the frame with 1/2 the parents // x-height above the baseline. - nscoord parentXHeight; - fm->GetXHeight(parentXHeight); + nscoord parentXHeight = fm->XHeight(); if (frameSpan) { pfd->mBounds.y = baselineY - (parentXHeight + pfd->mBounds.height)/2; @@ -1884,8 +1881,7 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd) { // The top of the logical box is aligned with the top of // the parent element's text. - nscoord parentAscent; - fm->GetMaxAscent(parentAscent); + nscoord parentAscent = fm->MaxAscent(); if (frameSpan) { pfd->mBounds.y = baselineY - parentAscent - pfd->mBorderPadding.top + frameSpan->mTopLeading; @@ -1901,8 +1897,7 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd) { // The bottom of the logical box is aligned with the // bottom of the parent elements text. - nscoord parentDescent; - fm->GetMaxDescent(parentDescent); + nscoord parentDescent = fm->MaxDescent(); if (frameSpan) { pfd->mBounds.y = baselineY + parentDescent - pfd->mBounds.height + pfd->mBorderPadding.bottom - diff --git a/layout/generic/nsPageFrame.cpp b/layout/generic/nsPageFrame.cpp index be5addcf53e9..5141bc932775 100644 --- a/layout/generic/nsPageFrame.cpp +++ b/layout/generic/nsPageFrame.cpp @@ -520,8 +520,8 @@ nsPageFrame::PaintHeaderFooter(nsRenderingContext& aRenderingContext, nscoord ascent = 0; nscoord visibleHeight = 0; if (fontMet) { - fontMet->GetMaxHeight(visibleHeight); - fontMet->GetMaxAscent(ascent); + visibleHeight = fontMet->MaxHeight(); + ascent = fontMet->MaxAscent(); } // print document headers and footers diff --git a/layout/generic/nsTextFrameThebes.cpp b/layout/generic/nsTextFrameThebes.cpp index 84d3685d3a97..99488f908a12 100644 --- a/layout/generic/nsTextFrameThebes.cpp +++ b/layout/generic/nsTextFrameThebes.cpp @@ -4338,10 +4338,9 @@ nsTextFrame::UnionTextDecorationOverflow(nsPresContext* aPresContext, if (IsFloatingFirstLetterChild()) { // The underline/overline drawable area must be contained in the overflow // rect when this is in floating first letter frame at *both* modes. - nscoord fontAscent, fontHeight; nsFontMetrics* fm = aProvider.GetFontMetrics(); - fm->GetMaxAscent(fontAscent); - fm->GetMaxHeight(fontHeight); + nscoord fontAscent = fm->MaxAscent(); + nscoord fontHeight = fm->MaxHeight(); nsRect fontRect(0, mAscent - fontAscent, GetSize().width, fontHeight); aVisualOverflowRect->UnionRect(*aVisualOverflowRect, fontRect); } @@ -6786,11 +6785,8 @@ nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth, // the height manually. nsFontMetrics* fm = provider.GetFontMetrics(); if (fm) { - nscoord ascent, descent; - fm->GetMaxAscent(ascent); - fm->GetMaxDescent(descent); - textMetrics.mAscent = gfxFloat(ascent); - textMetrics.mDescent = gfxFloat(descent); + textMetrics.mAscent = gfxFloat(fm->MaxAscent()); + textMetrics.mDescent = gfxFloat(fm->MaxDescent()); } } // The "end" iterator points to the first character after the string mapped @@ -6895,10 +6891,9 @@ nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth, // Otherwise, ascent should contain the overline drawable area. // And also descent should contain the underline drawable area. // nsFontMetrics::GetMaxAscent/GetMaxDescent contains them. - nscoord fontAscent, fontDescent; nsFontMetrics* fm = provider.GetFontMetrics(); - fm->GetMaxAscent(fontAscent); - fm->GetMaxDescent(fontDescent); + nscoord fontAscent = fm->MaxAscent(); + nscoord fontDescent = fm->MaxDescent(); aMetrics.ascent = NS_MAX(NSToCoordCeil(textMetrics.mAscent), fontAscent); nscoord descent = NS_MAX(NSToCoordCeil(textMetrics.mDescent), fontDescent); aMetrics.height = aMetrics.ascent + descent; diff --git a/layout/mathml/nsMathMLContainerFrame.cpp b/layout/mathml/nsMathMLContainerFrame.cpp index 449b566c236b..f5c31807a368 100644 --- a/layout/mathml/nsMathMLContainerFrame.cpp +++ b/layout/mathml/nsMathMLContainerFrame.cpp @@ -100,9 +100,8 @@ nsMathMLContainerFrame::ReflowError(nsRenderingContext& aRenderingContext, // reflow metrics nsFontMetrics* fm = aRenderingContext.FontMetrics(); - fm->GetMaxAscent(aDesiredSize.ascent); - nscoord descent; - fm->GetMaxDescent(descent); + aDesiredSize.ascent = fm->MaxAscent(); + nscoord descent = fm->MaxDescent(); aDesiredSize.height = aDesiredSize.ascent + descent; aDesiredSize.width = mBoundingMetrics.width; @@ -140,11 +139,11 @@ void nsDisplayMathMLError::Paint(nsDisplayListBuilder* aBuilder, aCtx->FillRect(nsRect(pt, mFrame->GetSize())); aCtx->SetColor(NS_RGB(255,255,255)); - nscoord ascent; - aCtx->FontMetrics()->GetMaxAscent(ascent); + nscoord ascent = aCtx->FontMetrics()->MaxAscent(); - nsAutoString errorMsg; errorMsg.AssignLiteral("invalid-markup"); - aCtx->DrawString(errorMsg.get(), PRUint32(errorMsg.Length()), pt.x, pt.y+ascent); + NS_NAMED_LITERAL_STRING(errorMsg, "invalid-markup"); + aCtx->DrawString(errorMsg.get(), PRUint32(errorMsg.Length()), + pt.x, pt.y+ascent); } /* ///////////// diff --git a/layout/mathml/nsMathMLFrame.cpp b/layout/mathml/nsMathMLFrame.cpp index 4ef1dfd6ec95..ee660e57ed72 100644 --- a/layout/mathml/nsMathMLFrame.cpp +++ b/layout/mathml/nsMathMLFrame.cpp @@ -286,8 +286,7 @@ nsMathMLFrame::GetRuleThickness(nsRenderingContext& aRenderingContext, Equals(aFontMetrics->Font()), "unexpected state"); - nscoord xHeight; - aFontMetrics->GetXHeight(xHeight); + nscoord xHeight = aFontMetrics->XHeight(); PRUnichar overBar = 0x00AF; nsBoundingMetrics bm = aRenderingContext.GetBoundingMetrics(&overBar, 1); aRuleThickness = bm.ascent + bm.descent; @@ -308,8 +307,7 @@ nsMathMLFrame::GetAxisHeight(nsRenderingContext& aRenderingContext, Equals(aFontMetrics->Font()), "unexpected state"); - nscoord xHeight; - aFontMetrics->GetXHeight(xHeight); + nscoord xHeight = aFontMetrics->XHeight(); PRUnichar minus = 0x2212; // not '-', but official Unicode minus sign nsBoundingMetrics bm = aRenderingContext.GetBoundingMetrics(&minus, 1); aAxisHeight = bm.ascent - (bm.ascent + bm.descent)/2; @@ -340,10 +338,9 @@ nsMathMLFrame::CalcLength(nsPresContext* aPresContext, return NSToCoordRound(aCSSValue.GetFloatValue() * (float)font->mFont.size); } else if (eCSSUnit_XHeight == unit) { - nscoord xHeight; const nsStyleFont* font = aStyleContext->GetStyleFont(); nsRefPtr fm = aPresContext->GetMetricsFor(font->mFont); - fm->GetXHeight(xHeight); + nscoord xHeight = fm->XHeight(); return NSToCoordRound(aCSSValue.GetFloatValue() * (float)xHeight); } diff --git a/layout/mathml/nsMathMLFrame.h b/layout/mathml/nsMathMLFrame.h index b1bb73d44372..a199b503b2ef 100644 --- a/layout/mathml/nsMathMLFrame.h +++ b/layout/mathml/nsMathMLFrame.h @@ -270,8 +270,7 @@ public: nscoord& aSubScriptShift1, nscoord& aSubScriptShift2) { - nscoord xHeight; - fm->GetXHeight(xHeight); + nscoord xHeight = fm->XHeight(); aSubScriptShift1 = NSToCoordRound(150.000f/430.556f * xHeight); aSubScriptShift2 = NSToCoordRound(247.217f/430.556f * xHeight); } @@ -283,8 +282,7 @@ public: nscoord& aSupScriptShift2, nscoord& aSupScriptShift3) { - nscoord xHeight; - fm->GetXHeight(xHeight); + nscoord xHeight = fm->XHeight(); aSupScriptShift1 = NSToCoordRound(412.892f/430.556f * xHeight); aSupScriptShift2 = NSToCoordRound(362.892f/430.556f * xHeight); aSupScriptShift3 = NSToCoordRound(288.889f/430.556f * xHeight); @@ -296,8 +294,7 @@ public: GetSubDrop(nsFontMetrics* fm, nscoord& aSubDrop) { - nscoord xHeight; - fm->GetXHeight(xHeight); + nscoord xHeight = fm->XHeight(); aSubDrop = NSToCoordRound(50.000f/430.556f * xHeight); } @@ -305,8 +302,7 @@ public: GetSupDrop(nsFontMetrics* fm, nscoord& aSupDrop) { - nscoord xHeight; - fm->GetXHeight(xHeight); + nscoord xHeight = fm->XHeight(); aSupDrop = NSToCoordRound(386.108f/430.556f * xHeight); } @@ -316,8 +312,7 @@ public: nscoord& numShift2, nscoord& numShift3) { - nscoord xHeight; - fm->GetXHeight(xHeight); + nscoord xHeight = fm->XHeight(); numShift1 = NSToCoordRound(676.508f/430.556f * xHeight); numShift2 = NSToCoordRound(393.732f/430.556f * xHeight); numShift3 = NSToCoordRound(443.731f/430.556f * xHeight); @@ -328,8 +323,7 @@ public: nscoord& denShift1, nscoord& denShift2) { - nscoord xHeight; - fm->GetXHeight(xHeight); + nscoord xHeight = fm->XHeight(); denShift1 = NSToCoordRound(685.951f/430.556f * xHeight); denShift2 = NSToCoordRound(344.841f/430.556f * xHeight); } @@ -338,9 +332,9 @@ public: GetEmHeight(nsFontMetrics* fm, nscoord& emHeight) { -#if 0 +#if 0 // should switch to this API in order to scale with changes of TextZoom - fm->GetEmHeight(emHeight); + emHeight = fm->EmHeight(); #else emHeight = NSToCoordRound(float(fm->Font().size)); #endif @@ -350,8 +344,7 @@ public: GetAxisHeight (nsFontMetrics* fm, nscoord& axisHeight) { - fm->GetXHeight (axisHeight); - axisHeight = NSToCoordRound(250.000f/430.556f * axisHeight); + axisHeight = NSToCoordRound(250.000f/430.556f * fm->XHeight()); } static void @@ -362,8 +355,7 @@ public: nscoord& bigOpSpacing4, nscoord& bigOpSpacing5) { - nscoord xHeight; - fm->GetXHeight(xHeight); + nscoord xHeight = fm->XHeight(); bigOpSpacing1 = NSToCoordRound(111.111f/430.556f * xHeight); bigOpSpacing2 = NSToCoordRound(166.667f/430.556f * xHeight); bigOpSpacing3 = NSToCoordRound(200.000f/430.556f * xHeight); @@ -375,8 +367,7 @@ public: GetRuleThickness(nsFontMetrics* fm, nscoord& ruleThickness) { - nscoord xHeight; - fm->GetXHeight(xHeight); + nscoord xHeight = fm->XHeight(); ruleThickness = NSToCoordRound(40.000f/430.556f * xHeight); } diff --git a/layout/mathml/nsMathMLTokenFrame.cpp b/layout/mathml/nsMathMLTokenFrame.cpp index 02385e8e0c66..effb78c991ee 100644 --- a/layout/mathml/nsMathMLTokenFrame.cpp +++ b/layout/mathml/nsMathMLTokenFrame.cpp @@ -211,9 +211,8 @@ nsMathMLTokenFrame::Place(nsRenderingContext& aRenderingContext, nsRefPtr fm = PresContext()->GetMetricsFor(GetStyleFont()->mFont); - nscoord ascent, descent; - fm->GetMaxAscent(ascent); - fm->GetMaxDescent(descent); + nscoord ascent = fm->MaxAscent(); + nscoord descent = fm->MaxDescent(); aDesiredSize.mBoundingMetrics = mBoundingMetrics; aDesiredSize.width = mBoundingMetrics.width; diff --git a/layout/mathml/nsMathMLmencloseFrame.cpp b/layout/mathml/nsMathMLmencloseFrame.cpp index 33945df789d2..c5b6fc918d2a 100644 --- a/layout/mathml/nsMathMLmencloseFrame.cpp +++ b/layout/mathml/nsMathMLmencloseFrame.cpp @@ -399,7 +399,7 @@ nsMathMLmencloseFrame::PlaceInternal(nsRenderingContext& aRenderingContext, // Rule 11, App. G, TeXbook // psi = clearance between rule and content if (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) - fm->GetXHeight(phi); + phi = fm->XHeight(); else phi = mRuleThickness; psi = mRuleThickness + phi / 4; diff --git a/layout/mathml/nsMathMLmfencedFrame.cpp b/layout/mathml/nsMathMLmfencedFrame.cpp index 325725a01d81..3779d44c7350 100644 --- a/layout/mathml/nsMathMLmfencedFrame.cpp +++ b/layout/mathml/nsMathMLmfencedFrame.cpp @@ -269,10 +269,11 @@ nsMathMLmfencedFrame::Reflow(nsPresContext* aPresContext, nsIFrame* childFrame = firstChild; nscoord ascent = 0, descent = 0; if (firstChild || mOpenChar || mCloseChar || mSeparatorsCount > 0) { - // We use the ASCII metrics to get our minimum height. This way, if we have - // borders or a background, they will fit better with other elements on the line - fm->GetMaxAscent(ascent); - fm->GetMaxDescent(descent); + // We use the ASCII metrics to get our minimum height. This way, + // if we have borders or a background, they will fit better with + // other elements on the line. + ascent = fm->MaxAscent(); + descent = fm->MaxDescent(); } while (childFrame) { nsHTMLReflowMetrics childDesiredSize(aDesiredSize.mFlags diff --git a/layout/mathml/nsMathMLmfracFrame.cpp b/layout/mathml/nsMathMLmfracFrame.cpp index 52aebd547edc..24d86e70caa8 100644 --- a/layout/mathml/nsMathMLmfracFrame.cpp +++ b/layout/mathml/nsMathMLmfracFrame.cpp @@ -436,8 +436,7 @@ nsMathMLmfracFrame::PlaceInternal(nsRenderingContext& aRenderingContext, nscoord slashRatio = 3; // Define the constant used in the expression of the maximum width - nscoord em; - fm->GetEmHeight(em); + nscoord em = fm->EmHeight(); nscoord slashMaxWidthConstant = 2 * em; // For large line thicknesses the minimum slash height is limited to the @@ -477,8 +476,7 @@ nsMathMLmfracFrame::PlaceInternal(nsRenderingContext& aRenderingContext, numShift += delta; denShift += delta; } else { - nscoord xHeight = 0; - fm->GetXHeight (xHeight); + nscoord xHeight = fm->XHeight(); numShift += xHeight / 2; denShift += xHeight / 4; } diff --git a/layout/mathml/nsMathMLmmultiscriptsFrame.cpp b/layout/mathml/nsMathMLmmultiscriptsFrame.cpp index f01084f136e6..e9aa36c46e03 100644 --- a/layout/mathml/nsMathMLmmultiscriptsFrame.cpp +++ b/layout/mathml/nsMathMLmmultiscriptsFrame.cpp @@ -164,8 +164,7 @@ nsMathMLmmultiscriptsFrame::Place(nsRenderingContext& aRenderingContext, PresContext()->GetUserFontSet()); nsFontMetrics* fm = aRenderingContext.FontMetrics(); - nscoord xHeight; - fm->GetXHeight (xHeight); + nscoord xHeight = fm->XHeight(); nscoord ruleSize; GetRuleThickness (aRenderingContext, fm, ruleSize); diff --git a/layout/mathml/nsMathMLmoFrame.cpp b/layout/mathml/nsMathMLmoFrame.cpp index 2c8b25c9aa10..092eb2bc3b11 100644 --- a/layout/mathml/nsMathMLmoFrame.cpp +++ b/layout/mathml/nsMathMLmoFrame.cpp @@ -854,9 +854,8 @@ nsMathMLmoFrame::Stretch(nsRenderingContext& aRenderingContext, firstChild->SetPosition(firstChild->GetPosition() - nsPoint(0, dy)); } else if (useMathMLChar) { - nscoord ascent, descent; - fm->GetMaxAscent(ascent); - fm->GetMaxDescent(descent); + nscoord ascent = fm->MaxAscent(); + nscoord descent = fm->MaxDescent(); aDesiredStretchSize.ascent = NS_MAX(mBoundingMetrics.ascent + leading, ascent); aDesiredStretchSize.height = aDesiredStretchSize.ascent + NS_MAX(mBoundingMetrics.descent + leading, descent); diff --git a/layout/mathml/nsMathMLmoverFrame.cpp b/layout/mathml/nsMathMLmoverFrame.cpp index c7440eedf8b8..bd17ce17bb7d 100644 --- a/layout/mathml/nsMathMLmoverFrame.cpp +++ b/layout/mathml/nsMathMLmoverFrame.cpp @@ -285,8 +285,7 @@ nsMathMLmoverFrame::Place(nsRenderingContext& aRenderingContext, PresContext()->GetUserFontSet()); nsFontMetrics* fm = aRenderingContext.FontMetrics(); - nscoord xHeight = 0; - fm->GetXHeight (xHeight); + nscoord xHeight = fm->XHeight(); nscoord ruleThickness; GetRuleThickness (aRenderingContext, fm, ruleThickness); diff --git a/layout/mathml/nsMathMLmrootFrame.cpp b/layout/mathml/nsMathMLmrootFrame.cpp index 2851f98cf385..aa4e9449fb5a 100644 --- a/layout/mathml/nsMathMLmrootFrame.cpp +++ b/layout/mathml/nsMathMLmrootFrame.cpp @@ -161,8 +161,7 @@ GetRadicalXOffsets(nscoord aIndexWidth, nscoord aSqrWidth, // The index is tucked in closer to the radical while making sure // that the kern does not make the index and radical collide nscoord dxIndex, dxSqr; - nscoord xHeight = 0; - aFontMetrics->GetXHeight(xHeight); + nscoord xHeight = aFontMetrics->XHeight(); nscoord indexRadicalKern = NSToCoordRound(1.35f * xHeight); if (indexRadicalKern > aIndexWidth) { dxIndex = indexRadicalKern - aIndexWidth; @@ -281,7 +280,7 @@ nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext, // psi = clearance between rule and content nscoord phi = 0, psi = 0; if (NS_MATHML_IS_DISPLAYSTYLE(mPresentationData.flags)) - fm->GetXHeight(phi); + phi = fm->XHeight(); else phi = ruleThickness; psi = ruleThickness + phi/4; diff --git a/layout/mathml/nsMathMLmsubFrame.cpp b/layout/mathml/nsMathMLmsubFrame.cpp index 6a6e4e42c00b..fa7ae42b438a 100644 --- a/layout/mathml/nsMathMLmsubFrame.cpp +++ b/layout/mathml/nsMathMLmsubFrame.cpp @@ -156,7 +156,7 @@ nsMathMLmsubFrame::PlaceSubScript (nsPresContext* aPresContext, nsRefPtr fm = aPresContext->GetMetricsFor(baseFrame->GetStyleFont()->mFont); - fm->GetXHeight (xHeight); + xHeight = fm->XHeight(); nscoord minShiftFromXHeight = (nscoord) (bmSubScript.ascent - (4.0f/5.0f) * xHeight); diff --git a/layout/mathml/nsMathMLmsubsupFrame.cpp b/layout/mathml/nsMathMLmsubsupFrame.cpp index 834b8beb1eb3..46abdc4bda89 100644 --- a/layout/mathml/nsMathMLmsubsupFrame.cpp +++ b/layout/mathml/nsMathMLmsubsupFrame.cpp @@ -198,8 +198,7 @@ nsMathMLmsubsupFrame::PlaceSubSupScript(nsPresContext* aPresContext, nsFontMetrics* fm = aRenderingContext.FontMetrics(); // get x-height (an ex) - nscoord xHeight; - fm->GetXHeight (xHeight); + nscoord xHeight = fm->XHeight(); nscoord ruleSize; GetRuleThickness (aRenderingContext, fm, ruleSize); diff --git a/layout/mathml/nsMathMLmsupFrame.cpp b/layout/mathml/nsMathMLmsupFrame.cpp index a0c10353b393..3d1b9ea814ac 100644 --- a/layout/mathml/nsMathMLmsupFrame.cpp +++ b/layout/mathml/nsMathMLmsupFrame.cpp @@ -157,7 +157,7 @@ nsMathMLmsupFrame::PlaceSuperScript(nsPresContext* aPresContext, nsRefPtr fm = aPresContext->GetMetricsFor(baseFrame->GetStyleFont()->mFont); - fm->GetXHeight (xHeight); + xHeight = fm->XHeight(); nscoord minShiftFromXHeight = (nscoord) (bmSupScript.descent + (1.0f/4.0f) * xHeight); nscoord italicCorrection; diff --git a/layout/mathml/nsMathMLmunderFrame.cpp b/layout/mathml/nsMathMLmunderFrame.cpp index d629fa4591dc..793f08acb703 100644 --- a/layout/mathml/nsMathMLmunderFrame.cpp +++ b/layout/mathml/nsMathMLmunderFrame.cpp @@ -282,8 +282,7 @@ nsMathMLmunderFrame::Place(nsRenderingContext& aRenderingContext, PresContext()->GetUserFontSet()); nsFontMetrics* fm = aRenderingContext.FontMetrics(); - nscoord xHeight = 0; - fm->GetXHeight (xHeight); + nscoord xHeight = fm->XHeight(); nscoord ruleThickness; GetRuleThickness (aRenderingContext, fm, ruleThickness); diff --git a/layout/mathml/nsMathMLmunderoverFrame.cpp b/layout/mathml/nsMathMLmunderoverFrame.cpp index 6e377b0481dc..5019bdd7d28e 100644 --- a/layout/mathml/nsMathMLmunderoverFrame.cpp +++ b/layout/mathml/nsMathMLmunderoverFrame.cpp @@ -324,8 +324,7 @@ nsMathMLmunderoverFrame::Place(nsRenderingContext& aRenderingContext, PresContext()->GetUserFontSet()); nsFontMetrics* fm = aRenderingContext.FontMetrics(); - nscoord xHeight = 0; - fm->GetXHeight (xHeight); + nscoord xHeight = fm->XHeight(); nscoord ruleThickness; GetRuleThickness (aRenderingContext, fm, ruleThickness); diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 2a973d833b58..61364c209234 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -310,9 +310,7 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue, font.size = aFontSize; nsRefPtr fm = aPresContext->GetMetricsFor(font, aUseUserFontSet); - nscoord xHeight; - fm->GetXHeight(xHeight); - return ScaleCoord(aValue, float(xHeight)); + return ScaleCoord(aValue, float(fm->XHeight())); } case eCSSUnit_Char: { nsFont font = styleFont->mFont; diff --git a/layout/svg/base/src/nsSVGUtils.cpp b/layout/svg/base/src/nsSVGUtils.cpp index fd1d95e0b6eb..e076d77b477c 100644 --- a/layout/svg/base/src/nsSVGUtils.cpp +++ b/layout/svg/base/src/nsSVGUtils.cpp @@ -297,8 +297,7 @@ nsSVGUtils::GetFontXHeight(nsStyleContext *aStyleContext) return 1.0f; } - nscoord xHeight; - fontMetrics->GetXHeight(xHeight); + nscoord xHeight = fontMetrics->XHeight(); return nsPresContext::AppUnitsToFloatCSSPixels(xHeight) / presContext->TextZoom(); } diff --git a/layout/xul/base/src/nsListBoxBodyFrame.cpp b/layout/xul/base/src/nsListBoxBodyFrame.cpp index e47546df0a9a..30c197c7300a 100644 --- a/layout/xul/base/src/nsListBoxBodyFrame.cpp +++ b/layout/xul/base/src/nsListBoxBodyFrame.cpp @@ -227,7 +227,7 @@ nsListBoxBodyFrame::Init(nsIContent* aContent, } nsRefPtr fm; nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); - fm->GetMaxHeight(mRowHeight); + mRowHeight = fm->MaxHeight(); return rv; } diff --git a/layout/xul/base/src/nsTextBoxFrame.cpp b/layout/xul/base/src/nsTextBoxFrame.cpp index af32ec3e6c94..2f7dcc03e67b 100644 --- a/layout/xul/base/src/nsTextBoxFrame.cpp +++ b/layout/xul/base/src/nsTextBoxFrame.cpp @@ -481,8 +481,7 @@ nsTextBoxFrame::DrawText(nsRenderingContext& aRenderingContext, nscoord offset; nscoord size; - nscoord ascent; - fontMet->GetMaxAscent(ascent); + nscoord ascent = fontMet->MaxAscent(); nscoord baseline = presContext->RoundAppUnitsToNearestDevPixels(aTextRect.y + ascent); @@ -657,7 +656,7 @@ nsTextBoxFrame::CalculateUnderline(nsRenderingContext& aRenderingContext) nscoord offset, baseline; nsFontMetrics* metrics = aRenderingContext.FontMetrics(); metrics->GetUnderline(offset, mAccessKeyInfo->mAccessUnderlineSize); - metrics->GetMaxAscent(baseline); + baseline = metrics->MaxAscent(); mAccessKeyInfo->mAccessOffset = baseline - offset; } } @@ -996,16 +995,19 @@ nsTextBoxFrame::MarkIntrinsicWidthsDirty() } void -nsTextBoxFrame::GetTextSize(nsPresContext* aPresContext, nsRenderingContext& aRenderingContext, - const nsString& aString, nsSize& aSize, nscoord& aAscent) +nsTextBoxFrame::GetTextSize(nsPresContext* aPresContext, + nsRenderingContext& aRenderingContext, + const nsString& aString, + nsSize& aSize, nscoord& aAscent) { nsRefPtr fontMet; nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet)); - fontMet->GetMaxHeight(aSize.height); + aSize.height = fontMet->MaxHeight(); aRenderingContext.SetFont(fontMet); aSize.width = - nsLayoutUtils::GetStringWidth(this, &aRenderingContext, aString.get(), aString.Length()); - fontMet->GetMaxAscent(aAscent); + nsLayoutUtils::GetStringWidth(this, &aRenderingContext, + aString.get(), aString.Length()); + aAscent = fontMet->MaxAscent(); } void diff --git a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index 2c3d8f78b2d2..765ac9d7b441 100644 --- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -1264,8 +1264,7 @@ nsTreeBodyFrame::GetCoordsForCellItem(PRInt32 aRow, nsITreeColumn* aCol, const n nsRefPtr fm; nsLayoutUtils::GetFontMetricsForStyleContext(textContext, getter_AddRefs(fm)); - nscoord height; - fm->GetMaxHeight(height); + nscoord height = fm->MaxHeight(); nsMargin textMargin; textContext->GetStyleMargin()->GetMargin(textMargin); @@ -3572,9 +3571,8 @@ nsTreeBodyFrame::PaintText(PRInt32 aRowIndex, nsLayoutUtils::GetFontMetricsForStyleContext(textContext, getter_AddRefs(fontMet)); - nscoord height, baseline; - fontMet->GetMaxHeight(height); - fontMet->GetMaxAscent(baseline); + nscoord height = fontMet->MaxHeight(); + nscoord baseline = fontMet->MaxAscent(); // Center the text. XXX Obey vertical-align style prop? if (height < textRect.height) {