Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit 85c78c0

Browse files
committed
Remove the multiple-parameter versions of nsRenderingContext::SetFont. (Bug 678671, patch 5) r=roc
This changes the only remaining callers (in nsMathMLChar) to pass the correct language, which they were not previously doing, which should improve the correctness of font selection and also reduce the number of unique font metrics objects requested (which helps nsFontCache effectiveness). Those callers, however, remain the odd font users within all of layout.
1 parent 0013e9c commit 85c78c0

File tree

3 files changed

+29
-34
lines changed

3 files changed

+29
-34
lines changed

gfx/src/nsRenderingContext.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -454,22 +454,6 @@ nsRenderingContext::SetTextRunRTL(PRBool aIsRTL)
454454
mFontMetrics->SetTextRunRTL(aIsRTL);
455455
}
456456

457-
void
458-
nsRenderingContext::SetFont(const nsFont& aFont, nsIAtom* aLanguage,
459-
gfxUserFontSet *aUserFontSet)
460-
{
461-
mDeviceContext->GetMetricsFor(aFont, aLanguage, aUserFontSet,
462-
*getter_AddRefs(mFontMetrics));
463-
}
464-
465-
void
466-
nsRenderingContext::SetFont(const nsFont& aFont,
467-
gfxUserFontSet *aUserFontSet)
468-
{
469-
mDeviceContext->GetMetricsFor(aFont, nsnull, aUserFontSet,
470-
*getter_AddRefs(mFontMetrics));
471-
}
472-
473457
void
474458
nsRenderingContext::SetFont(nsFontMetrics *aFontMetrics)
475459
{

gfx/src/nsRenderingContext.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ class nsRenderingContext
117117

118118
// Text
119119

120-
void SetFont(const nsFont& aFont, nsIAtom* aLanguage,
121-
gfxUserFontSet *aUserFontSet);
122-
void SetFont(const nsFont& aFont, gfxUserFontSet *aUserFontSet);
123120
void SetFont(nsFontMetrics *aFontMetrics);
124121
nsFontMetrics *FontMetrics() { return mFontMetrics; } // may be null
125122

layout/mathml/nsMathMLChar.cpp

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,8 @@ AddFallbackFonts(nsAString& aFontName, const nsAString& aFallbackFamilies)
10421042

10431043
// Update the font and rendering context if there is a family change
10441044
static void
1045-
SetFontFamily(nsPresContext* aPresContext,
1046-
nsRenderingContext& aRenderingContext,
1045+
SetFontFamily(nsStyleContext* aStyleContext,
1046+
nsRenderingContext& aRenderingContext,
10471047
nsFont& aFont,
10481048
const nsGlyphTable* aGlyphTable,
10491049
const nsGlyphCode& aGlyphCode,
@@ -1053,7 +1053,12 @@ SetFontFamily(nsPresContext* aPresContext,
10531053
aGlyphCode.font ? aGlyphTable->FontNameFor(aGlyphCode) : aDefaultFamily;
10541054
if (! family.Equals(aFont.name)) {
10551055
aFont.name = family;
1056-
aRenderingContext.SetFont(aFont, aPresContext->GetUserFontSet());
1056+
nsRefPtr fm;
1057+
aRenderingContext.DeviceContext()->GetMetricsFor(aFont,
1058+
aStyleContext->GetStyleVisibility()->mLanguage,
1059+
aStyleContext->PresContext()->GetUserFontSet(),
1060+
*getter_AddRefs(fm));
1061+
aRenderingContext.SetFont(fm);
10571062
}
10581063
}
10591064

@@ -1119,7 +1124,8 @@ nsMathMLChar::StretchEnumContext::TryVariants(nsGlyphTable* aGlyphTable,
11191124
const nsAString& aFamily)
11201125
{
11211126
// Use our stretchy style context now that stretching is in progress
1122-
nsFont font = mChar->mStyleContext->GetStyleFont()->mFont;
1127+
nsStyleContext *sc = mChar->mStyleContext;
1128+
nsFont font = sc->GetStyleFont()->mFont;
11231129
// Ensure mRenderingContext.SetFont will be called:
11241130
font.name.Truncate();
11251131

@@ -1144,8 +1150,7 @@ nsMathMLChar::StretchEnumContext::TryVariants(nsGlyphTable* aGlyphTable,
11441150
nsGlyphCode ch;
11451151
while ((ch = aGlyphTable->BigOf(mPresContext, mChar, size)).Exists()) {
11461152

1147-
SetFontFamily(mChar->mStyleContext->PresContext(), mRenderingContext,
1148-
font, aGlyphTable, ch, aFamily);
1153+
SetFontFamily(sc, mRenderingContext, font, aGlyphTable, ch, aFamily);
11491154

11501155
NS_ASSERTION(maxWidth || ch.code[0] != mChar->mGlyph.code[0] ||
11511156
ch.code[1] != mChar->mGlyph.code[1] ||
@@ -1269,7 +1274,7 @@ nsMathMLChar::StretchEnumContext::TryParts(nsGlyphTable* aGlyphTable,
12691274
sizedata[i] = mTargetSize;
12701275
}
12711276
else {
1272-
SetFontFamily(mChar->mStyleContext->PresContext(), mRenderingContext,
1277+
SetFontFamily(mChar->mStyleContext, mRenderingContext,
12731278
font, aGlyphTable, ch, aFamily);
12741279
nsBoundingMetrics bm = mRenderingContext.GetBoundingMetrics(ch.code,
12751280
ch.Length());
@@ -1460,7 +1465,11 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
14601465
mFamily = families;
14611466
}
14621467

1463-
aRenderingContext.SetFont(font, aPresContext->GetUserFontSet());
1468+
nsRefPtr fm;
1469+
aRenderingContext.DeviceContext()->GetMetricsFor(font,
1470+
mStyleContext->GetStyleVisibility()->mLanguage,
1471+
aPresContext->GetUserFontSet(), *getter_AddRefs(fm));
1472+
aRenderingContext.SetFont(fm);
14641473
aDesiredStretchSize =
14651474
aRenderingContext.GetBoundingMetrics(mData.get(), PRUint32(mData.Length()));
14661475

@@ -2056,7 +2065,12 @@ nsMathMLChar::PaintForeground(nsPresContext* aPresContext,
20562065
if (! mFamily.IsEmpty()) {
20572066
theFont.name = mFamily;
20582067
}
2059-
aRenderingContext.SetFont(theFont, aPresContext->GetUserFontSet());
2068+
nsRefPtr fm;
2069+
aRenderingContext.DeviceContext()->GetMetricsFor(theFont,
2070+
styleContext->GetStyleVisibility()->mLanguage,
2071+
aPresContext->GetUserFontSet(),
2072+
*getter_AddRefs(fm));
2073+
aRenderingContext.SetFont(fm);
20602074

20612075
aRenderingContext.PushState();
20622076
nsRect r = mRect + aPt;
@@ -2165,7 +2179,7 @@ nsMathMLChar::PaintVertically(nsPresContext* aPresContext,
21652179
if (!ch.Exists()) ch = chGlue;
21662180
// if (!ch.Exists()) glue is null, leave bounding metrics at 0
21672181
if (ch.Exists()) {
2168-
SetFontFamily(aPresContext, aRenderingContext,
2182+
SetFontFamily(aStyleContext, aRenderingContext,
21692183
aFont, aGlyphTable, ch, mFamily);
21702184
bmdata[i] = aRenderingContext.GetBoundingMetrics(ch.code, ch.Length());
21712185
}
@@ -2250,7 +2264,7 @@ nsMathMLChar::PaintVertically(nsPresContext* aPresContext,
22502264
}
22512265
if (!clipRect.IsEmpty()) {
22522266
AutoPushClipRect clip(aRenderingContext, clipRect);
2253-
SetFontFamily(aPresContext, aRenderingContext,
2267+
SetFontFamily(aStyleContext, aRenderingContext,
22542268
aFont, aGlyphTable, ch, mFamily);
22552269
aRenderingContext.DrawString(ch.code, ch.Length(), dx, dy);
22562270
}
@@ -2307,7 +2321,7 @@ nsMathMLChar::PaintVertically(nsPresContext* aPresContext,
23072321
bm.descent -= oneDevPixel;
23082322
}
23092323

2310-
SetFontFamily(aPresContext, aRenderingContext,
2324+
SetFontFamily(aStyleContext, aRenderingContext,
23112325
aFont, aGlyphTable, chGlue, mFamily);
23122326
nsRect clipRect = unionRect;
23132327

@@ -2393,7 +2407,7 @@ nsMathMLChar::PaintHorizontally(nsPresContext* aPresContext,
23932407
if (!ch.Exists()) ch = chGlue;
23942408
// if (!ch.Exists()) glue is null, leave bounding metrics at 0.
23952409
if (ch.Exists()) {
2396-
SetFontFamily(aPresContext, aRenderingContext,
2410+
SetFontFamily(aStyleContext, aRenderingContext,
23972411
aFont, aGlyphTable, ch, mFamily);
23982412
bmdata[i] = aRenderingContext.GetBoundingMetrics(ch.code, ch.Length());
23992413
}
@@ -2473,7 +2487,7 @@ nsMathMLChar::PaintHorizontally(nsPresContext* aPresContext,
24732487
}
24742488
if (!clipRect.IsEmpty()) {
24752489
AutoPushClipRect clip(aRenderingContext, clipRect);
2476-
SetFontFamily(aPresContext, aRenderingContext,
2490+
SetFontFamily(aStyleContext, aRenderingContext,
24772491
aFont, aGlyphTable, ch, mFamily);
24782492
aRenderingContext.DrawString(ch.code, ch.Length(), dx, dy);
24792493
}
@@ -2529,7 +2543,7 @@ nsMathMLChar::PaintHorizontally(nsPresContext* aPresContext,
25292543
bm.rightBearing -= oneDevPixel;
25302544
}
25312545

2532-
SetFontFamily(aPresContext, aRenderingContext,
2546+
SetFontFamily(aStyleContext, aRenderingContext,
25332547
aFont, aGlyphTable, chGlue, mFamily);
25342548
nsRect clipRect = unionRect;
25352549

0 commit comments

Comments
 (0)