Switch lots of callers to using nsLayoutUtils::GetFontMetricsForFrame and nsLayoutUtils::GetFontMetricsForStyleContext. (Bug 678671, patch 1) r=roc

This changes a number of callers that were previously bypassing the use
of the correct language (with either no language or the charset-detected
language on the pres context via nsPresContext::GetMetricsFor) and/or
the correct user font set to pass the correct values, which should
improve the correctness of the behavior of whatever they were using the
fonts for, and also reduce the number of unique sets of font metrics
requested (which helps nsFontCache effectiveness).
This commit is contained in:
L. David Baron 2011-08-14 10:08:04 -07:00
Родитель a9aaf9d403
Коммит d2b6891283
18 изменённых файлов: 54 добавлений и 66 удалений

Просмотреть файл

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

Просмотреть файл

@ -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<nsFontMetrics> 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())

Просмотреть файл

@ -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<nsFontMetrics> fm = aTargetFrame->PresContext()->GetMetricsFor(f);
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(aTargetFrame, getter_AddRefs(fm));
NS_ASSERTION(fm, "FontMetrics is null!");
if (fm)
return fm->MaxHeight();

Просмотреть файл

@ -2203,9 +2203,8 @@ nsGfxScrollFrameInner::ScrollBy(nsIntPoint aDelta,
nsSize
nsGfxScrollFrameInner::GetLineScrollAmount() const
{
const nsStyleFont* font = mOuter->GetStyleFont();
const nsFont& f = font->mFont;
nsRefPtr<nsFontMetrics> fm = mOuter->PresContext()->GetMetricsFor(f);
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(mOuter, getter_AddRefs(fm));
NS_ASSERTION(fm, "FontMetrics is null, assuming fontHeight == 1 appunit");
nscoord fontHeight = 1;
if (fm) {

Просмотреть файл

@ -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<nsFontMetrics> fm = aPresContext->GetMetricsFor(font->mFont);
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForStyleContext(aStyleContext,
getter_AddRefs(fm));
nscoord xHeight = fm->XHeight();
return NSToCoordRound(aCSSValue.GetFloatValue() * (float)xHeight);
}

Просмотреть файл

@ -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<nsFontMetrics> fm = aChild->PresContext()->GetMetricsFor(
font->mFont);
nsRefPtr<nsFontMetrics> 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<nsFontMetrics> fm = aChild->PresContext()->GetMetricsFor(
font->mFont);
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(aChild, getter_AddRefs(fm));
GetSupDrop(fm, aSupDrop);
}

Просмотреть файл

@ -220,8 +220,8 @@ nsMathMLTokenFrame::Place(nsRenderingContext& aRenderingContext,
mBoundingMetrics += childSize.mBoundingMetrics;
}
nsRefPtr<nsFontMetrics> fm =
PresContext()->GetMetricsFor(GetStyleFont()->mFont);
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
nscoord ascent = fm->MaxAscent();
nscoord descent = fm->MaxDescent();

Просмотреть файл

@ -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<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
aRenderingContext.SetFont(fm);
GetRuleThickness(aRenderingContext, fm, mRuleThickness);
GetEmHeight(fm, mEmHeight);

Просмотреть файл

@ -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<nsFontMetrics> 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<nsFontMetrics> fm = presContext->GetMetricsFor(font->mFont);
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
nscoord em;
GetEmHeight(fm, em);

Просмотреть файл

@ -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<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
aRenderingContext.SetFont(fm);
nscoord defaultRuleThickness, axisHeight;
GetRuleThickness(aRenderingContext, fm, defaultRuleThickness);

Просмотреть файл

@ -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<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
aRenderingContext.SetFont(fm);
nscoord xHeight = fm->XHeight();

Просмотреть файл

@ -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<nsFontMetrics> fm =
presContext->GetMetricsFor(GetStyleFont()->mFont);
nsRefPtr<nsFontMetrics> 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<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
aRenderingContext.SetFont(fm);
nscoord axisHeight, height;
GetAxisHeight(aRenderingContext, fm, axisHeight);

Просмотреть файл

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

Просмотреть файл

@ -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<nsFontMetrics> fm =
aPresContext->GetMetricsFor(baseFrame->GetStyleFont()->mFont);
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(baseFrame, getter_AddRefs(fm));
xHeight = fm->XHeight();
nscoord minShiftFromXHeight = (nscoord)

Просмотреть файл

@ -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<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(baseFrame, getter_AddRefs(fm));
aRenderingContext.SetFont(fm);
// get x-height (an ex)
nscoord xHeight = fm->XHeight();

Просмотреть файл

@ -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<nsFontMetrics> fm =
aPresContext->GetMetricsFor(baseFrame->GetStyleFont()->mFont);
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(baseFrame, getter_AddRefs(fm));
xHeight = fm->XHeight();
nscoord minShiftFromXHeight = (nscoord)

Просмотреть файл

@ -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<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
aReflowState.rendContext->SetFont(fm);
nscoord axisHeight;
GetAxisHeight(*aReflowState.rendContext,
aReflowState.rendContext->FontMetrics(),

Просмотреть файл

@ -425,9 +425,9 @@ nsMathMLmunderoverFrame::Place(nsRenderingContext& aRenderingContext,
////////////////////
// Place Children
aRenderingContext.SetFont(GetStyleFont()->mFont,
PresContext()->GetUserFontSet());
nsFontMetrics* fm = aRenderingContext.FontMetrics();
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
aRenderingContext.SetFont(fm);
nscoord xHeight = fm->XHeight();