diff --git a/accessible/src/base/nsTextAttrs.cpp b/accessible/src/base/nsTextAttrs.cpp index dd53f450c26..5ef69271e98 100644 --- a/accessible/src/base/nsTextAttrs.cpp +++ b/accessible/src/base/nsTextAttrs.cpp @@ -45,6 +45,7 @@ #include "gfxFont.h" #include "gfxUserFontSet.h" #include "nsFontMetrics.h" +#include "nsLayoutUtils.h" //////////////////////////////////////////////////////////////////////////////// // Constants and structures @@ -479,10 +480,7 @@ nsFontSizeTextAttr::Format(const nscoord& aValue, nsAString& aFormattedValue) nscoord nsFontSizeTextAttr::GetFontSize(nsIFrame *aFrame) { - nsStyleFont* styleFont = - (nsStyleFont*)(aFrame->GetStyleDataExternal(eStyleStruct_Font)); - - return styleFont->mSize; + return aFrame->GetStyleFont()->mSize; } @@ -527,15 +525,8 @@ nsFontWeightTextAttr::GetFontWeight(nsIFrame *aFrame) { // nsFont::width isn't suitable here because it's necessary to expose real // value of font weight (used font might not have some font weight values). - nsStyleFont* styleFont = - (nsStyleFont*)(aFrame->GetStyleDataExternal(eStyleStruct_Font)); - - gfxUserFontSet *fs = aFrame->PresContext()->GetUserFontSet(); - nsRefPtr fm; - aFrame->PresContext()->DeviceContext()-> - GetMetricsFor(styleFont->mFont, aFrame->GetStyleVisibility()->mLanguage, - fs, *getter_AddRefs(fm)); + nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm)); gfxFontGroup *fontGroup = fm->GetThebesFontGroup(); gfxFont *font = fontGroup->GetFontAt(0); diff --git a/accessible/src/msaa/nsTextAccessibleWrap.cpp b/accessible/src/msaa/nsTextAccessibleWrap.cpp index e3619d58d09..0bbda44bb15 100644 --- a/accessible/src/msaa/nsTextAccessibleWrap.cpp +++ b/accessible/src/msaa/nsTextAccessibleWrap.cpp @@ -44,6 +44,7 @@ #include "nsIFrame.h" #include "nsFontMetrics.h" #include "nsPresContext.h" +#include "nsLayoutUtils.h" #include "gfxFont.h" @@ -256,11 +257,7 @@ __try { } nsRefPtr fm; - frame->PresContext()->DeviceContext()-> - GetMetricsFor(frame->GetStyleFont()->mFont, - frame->GetStyleVisibility()->mLanguage, - frame->PresContext()->GetUserFontSet(), - *getter_AddRefs(fm)); + nsLayoutUtils::GetFontMetricsForFrame(frame, getter_AddRefs(fm)); const nsString& name = fm->GetThebesFontGroup()->GetFontAt(0)->GetName(); if (name.IsEmpty()) diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 30e239af5f2..6fb9e504be1 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -2537,9 +2537,8 @@ GetScrollableLineHeight(nsIFrame* aTargetFrame) } // Fall back to the font height of the target frame. - const nsStyleFont* font = aTargetFrame->GetStyleFont(); - const nsFont& f = font->mFont; - nsRefPtr fm = aTargetFrame->PresContext()->GetMetricsFor(f); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(aTargetFrame, getter_AddRefs(fm)); NS_ASSERTION(fm, "FontMetrics is null!"); if (fm) return fm->MaxHeight(); diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index cabfa39fa58..1f325c26a14 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -2203,9 +2203,8 @@ nsGfxScrollFrameInner::ScrollBy(nsIntPoint aDelta, nsSize nsGfxScrollFrameInner::GetLineScrollAmount() const { - const nsStyleFont* font = mOuter->GetStyleFont(); - const nsFont& f = font->mFont; - nsRefPtr fm = mOuter->PresContext()->GetMetricsFor(f); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(mOuter, getter_AddRefs(fm)); NS_ASSERTION(fm, "FontMetrics is null, assuming fontHeight == 1 appunit"); nscoord fontHeight = 1; if (fm) { diff --git a/layout/mathml/nsMathMLFrame.cpp b/layout/mathml/nsMathMLFrame.cpp index 88893bfb0e1..5e4f6b56d41 100644 --- a/layout/mathml/nsMathMLFrame.cpp +++ b/layout/mathml/nsMathMLFrame.cpp @@ -328,8 +328,9 @@ nsMathMLFrame::CalcLength(nsPresContext* aPresContext, return NSToCoordRound(aCSSValue.GetFloatValue() * (float)font->mFont.size); } else if (eCSSUnit_XHeight == unit) { - const nsStyleFont* font = aStyleContext->GetStyleFont(); - nsRefPtr fm = aPresContext->GetMetricsFor(font->mFont); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForStyleContext(aStyleContext, + getter_AddRefs(fm)); nscoord xHeight = fm->XHeight(); return NSToCoordRound(aCSSValue.GetFloatValue() * (float)xHeight); } diff --git a/layout/mathml/nsMathMLFrame.h b/layout/mathml/nsMathMLFrame.h index a199b503b2e..f9fdf32eefb 100644 --- a/layout/mathml/nsMathMLFrame.h +++ b/layout/mathml/nsMathMLFrame.h @@ -49,6 +49,7 @@ #include "nsFrame.h" #include "nsCSSValue.h" #include "nsMathMLElement.h" +#include "nsLayoutUtils.h" class nsMathMLChar; @@ -239,9 +240,8 @@ public: GetSubDropFromChild(nsIFrame* aChild, nscoord& aSubDrop) { - const nsStyleFont* font = aChild->GetStyleFont(); - nsRefPtr fm = aChild->PresContext()->GetMetricsFor( - font->mFont); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(aChild, getter_AddRefs(fm)); GetSubDrop(fm, aSubDrop); } @@ -249,9 +249,8 @@ public: GetSupDropFromChild(nsIFrame* aChild, nscoord& aSupDrop) { - const nsStyleFont* font = aChild->GetStyleFont(); - nsRefPtr fm = aChild->PresContext()->GetMetricsFor( - font->mFont); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(aChild, getter_AddRefs(fm)); GetSupDrop(fm, aSupDrop); } diff --git a/layout/mathml/nsMathMLTokenFrame.cpp b/layout/mathml/nsMathMLTokenFrame.cpp index d139eb22f50..eee0acaf46a 100644 --- a/layout/mathml/nsMathMLTokenFrame.cpp +++ b/layout/mathml/nsMathMLTokenFrame.cpp @@ -220,8 +220,8 @@ nsMathMLTokenFrame::Place(nsRenderingContext& aRenderingContext, mBoundingMetrics += childSize.mBoundingMetrics; } - nsRefPtr fm = - PresContext()->GetMetricsFor(GetStyleFont()->mFont); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); nscoord ascent = fm->MaxAscent(); nscoord descent = fm->MaxDescent(); diff --git a/layout/mathml/nsMathMLmencloseFrame.cpp b/layout/mathml/nsMathMLmencloseFrame.cpp index f5890722bee..55521d701ff 100644 --- a/layout/mathml/nsMathMLmencloseFrame.cpp +++ b/layout/mathml/nsMathMLmencloseFrame.cpp @@ -369,9 +369,9 @@ nsMathMLmencloseFrame::PlaceInternal(nsRenderingContext& aRenderingContext, nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1); nscoord mEmHeight; - aRenderingContext.SetFont(GetStyleFont()->mFont, - PresContext()->GetUserFontSet()); - nsFontMetrics* fm = aRenderingContext.FontMetrics(); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); + aRenderingContext.SetFont(fm); GetRuleThickness(aRenderingContext, fm, mRuleThickness); GetEmHeight(fm, mEmHeight); diff --git a/layout/mathml/nsMathMLmfencedFrame.cpp b/layout/mathml/nsMathMLmfencedFrame.cpp index 721953731d1..a4832cba224 100644 --- a/layout/mathml/nsMathMLmfencedFrame.cpp +++ b/layout/mathml/nsMathMLmfencedFrame.cpp @@ -250,9 +250,9 @@ nsMathMLmfencedFrame::Reflow(nsPresContext* aPresContext, PRInt32 i; const nsStyleFont* font = GetStyleFont(); - aReflowState.rendContext->SetFont(font->mFont, - aPresContext->GetUserFontSet()); - nsFontMetrics* fm = aReflowState.rendContext->FontMetrics(); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); + aReflowState.rendContext->SetFont(fm); nscoord axisHeight, em; GetAxisHeight(*aReflowState.rendContext, fm, axisHeight); GetEmHeight(fm, em); @@ -594,7 +594,8 @@ nsMathMLmfencedFrame::GetIntrinsicWidth(nsRenderingContext* aRenderingContext) nsPresContext* presContext = PresContext(); const nsStyleFont* font = GetStyleFont(); - nsRefPtr fm = presContext->GetMetricsFor(font->mFont); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); nscoord em; GetEmHeight(fm, em); diff --git a/layout/mathml/nsMathMLmfracFrame.cpp b/layout/mathml/nsMathMLmfracFrame.cpp index f161c05d782..705bf23153d 100644 --- a/layout/mathml/nsMathMLmfracFrame.cpp +++ b/layout/mathml/nsMathMLmfracFrame.cpp @@ -240,9 +240,9 @@ nsMathMLmfracFrame::PlaceInternal(nsRenderingContext& aRenderingContext, nsPresContext* presContext = PresContext(); nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1); - aRenderingContext.SetFont(GetStyleFont()->mFont, - presContext->GetUserFontSet()); - nsFontMetrics* fm = aRenderingContext.FontMetrics(); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); + aRenderingContext.SetFont(fm); nscoord defaultRuleThickness, axisHeight; GetRuleThickness(aRenderingContext, fm, defaultRuleThickness); diff --git a/layout/mathml/nsMathMLmmultiscriptsFrame.cpp b/layout/mathml/nsMathMLmmultiscriptsFrame.cpp index e9aa36c46e0..ba97298c02b 100644 --- a/layout/mathml/nsMathMLmmultiscriptsFrame.cpp +++ b/layout/mathml/nsMathMLmmultiscriptsFrame.cpp @@ -160,9 +160,9 @@ nsMathMLmmultiscriptsFrame::Place(nsRenderingContext& aRenderingContext, // get x-height (an ex) const nsStyleFont* font = GetStyleFont(); - aRenderingContext.SetFont(font->mFont, - PresContext()->GetUserFontSet()); - nsFontMetrics* fm = aRenderingContext.FontMetrics(); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); + aRenderingContext.SetFont(fm); nscoord xHeight = fm->XHeight(); diff --git a/layout/mathml/nsMathMLmoFrame.cpp b/layout/mathml/nsMathMLmoFrame.cpp index b76719d1c19..aabe9538a1b 100644 --- a/layout/mathml/nsMathMLmoFrame.cpp +++ b/layout/mathml/nsMathMLmoFrame.cpp @@ -391,8 +391,8 @@ nsMathMLmoFrame::ProcessOperatorData() // cache the default values of lspace & rspace that we get from the dictionary. // since these values are relative to the 'em' unit, convert to twips now nscoord em; - nsRefPtr fm = - presContext->GetMetricsFor(GetStyleFont()->mFont); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); GetEmHeight(fm, em); mEmbellishData.leftSpace = NSToCoordRound(lspace * em); @@ -635,9 +635,9 @@ nsMathMLmoFrame::Stretch(nsRenderingContext& aRenderingContext, nsIFrame* firstChild = mFrames.FirstChild(); // get the axis height; - aRenderingContext.SetFont(GetStyleFont()->mFont, - PresContext()->GetUserFontSet()); - nsFontMetrics* fm = aRenderingContext.FontMetrics(); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); + aRenderingContext.SetFont(fm); nscoord axisHeight, height; GetAxisHeight(aRenderingContext, fm, axisHeight); diff --git a/layout/mathml/nsMathMLmrootFrame.cpp b/layout/mathml/nsMathMLmrootFrame.cpp index aa4e9449fb5..5575c931f1e 100644 --- a/layout/mathml/nsMathMLmrootFrame.cpp +++ b/layout/mathml/nsMathMLmrootFrame.cpp @@ -257,9 +257,9 @@ nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext, //////////// // Prepare the radical symbol and the overline bar - renderingContext.SetFont(GetStyleFont()->mFont, - aPresContext->GetUserFontSet()); - nsFontMetrics* fm = renderingContext.FontMetrics(); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); + renderingContext.SetFont(fm); // For radical glyphs from TeX fonts and some of the radical glyphs from // Mathematica fonts, the thickness of the overline can be obtained from the diff --git a/layout/mathml/nsMathMLmsubFrame.cpp b/layout/mathml/nsMathMLmsubFrame.cpp index fa7ae42b438..78c10dc2284 100644 --- a/layout/mathml/nsMathMLmsubFrame.cpp +++ b/layout/mathml/nsMathMLmsubFrame.cpp @@ -153,8 +153,8 @@ nsMathMLmsubFrame::PlaceSubScript (nsPresContext* aPresContext, // get min subscript shift limit from x-height // = h(x) - 4/5 * sigma_5, Rule 18b, App. G, TeXbook nscoord xHeight = 0; - nsRefPtr fm = - aPresContext->GetMetricsFor(baseFrame->GetStyleFont()->mFont); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(baseFrame, getter_AddRefs(fm)); xHeight = fm->XHeight(); nscoord minShiftFromXHeight = (nscoord) diff --git a/layout/mathml/nsMathMLmsubsupFrame.cpp b/layout/mathml/nsMathMLmsubsupFrame.cpp index 46abdc4bda8..32b9ab88fc0 100644 --- a/layout/mathml/nsMathMLmsubsupFrame.cpp +++ b/layout/mathml/nsMathMLmsubsupFrame.cpp @@ -193,9 +193,9 @@ nsMathMLmsubsupFrame::PlaceSubSupScript(nsPresContext* aPresContext, // subScriptShift1 = subscriptshift attribute * x-height nscoord subScriptShift1, subScriptShift2; - aRenderingContext.SetFont(baseFrame->GetStyleFont()->mFont, - aPresContext->GetUserFontSet()); - nsFontMetrics* fm = aRenderingContext.FontMetrics(); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(baseFrame, getter_AddRefs(fm)); + aRenderingContext.SetFont(fm); // get x-height (an ex) nscoord xHeight = fm->XHeight(); diff --git a/layout/mathml/nsMathMLmsupFrame.cpp b/layout/mathml/nsMathMLmsupFrame.cpp index 3d1b9ea814a..93cd1c11807 100644 --- a/layout/mathml/nsMathMLmsupFrame.cpp +++ b/layout/mathml/nsMathMLmsupFrame.cpp @@ -154,8 +154,8 @@ nsMathMLmsupFrame::PlaceSuperScript(nsPresContext* aPresContext, // get min supscript shift limit from x-height // = d(x) + 1/4 * sigma_5, Rule 18c, App. G, TeXbook nscoord xHeight = 0; - nsRefPtr fm = - aPresContext->GetMetricsFor(baseFrame->GetStyleFont()->mFont); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(baseFrame, getter_AddRefs(fm)); xHeight = fm->XHeight(); nscoord minShiftFromXHeight = (nscoord) diff --git a/layout/mathml/nsMathMLmtableFrame.cpp b/layout/mathml/nsMathMLmtableFrame.cpp index 9e38d090e61..e477ecb901a 100644 --- a/layout/mathml/nsMathMLmtableFrame.cpp +++ b/layout/mathml/nsMathMLmtableFrame.cpp @@ -637,8 +637,9 @@ nsMathMLmtableOuterFrame::Reflow(nsPresContext* aPresContext, case eAlign_axis: default: { // XXX should instead use style data from the row of reference here ? - aReflowState.rendContext->SetFont(GetStyleFont()->mFont, - aPresContext->GetUserFontSet()); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); + aReflowState.rendContext->SetFont(fm); nscoord axisHeight; GetAxisHeight(*aReflowState.rendContext, aReflowState.rendContext->FontMetrics(), diff --git a/layout/mathml/nsMathMLmunderoverFrame.cpp b/layout/mathml/nsMathMLmunderoverFrame.cpp index a2dd4057497..bd9773d033c 100644 --- a/layout/mathml/nsMathMLmunderoverFrame.cpp +++ b/layout/mathml/nsMathMLmunderoverFrame.cpp @@ -425,9 +425,9 @@ nsMathMLmunderoverFrame::Place(nsRenderingContext& aRenderingContext, //////////////////// // Place Children - aRenderingContext.SetFont(GetStyleFont()->mFont, - PresContext()->GetUserFontSet()); - nsFontMetrics* fm = aRenderingContext.FontMetrics(); + nsRefPtr fm; + nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); + aRenderingContext.SetFont(fm); nscoord xHeight = fm->XHeight();