Bug 998869 part 2 - switch to GetFontAt(0) to GetFirstValidFont(). r=jfkthame

This commit is contained in:
John Daggett 2014-09-25 12:16:53 +09:00
parent 7e4f2550ee
commit 309315cc14
9 changed files with 30 additions and 23 deletions

View File

@ -460,7 +460,7 @@ TextAttrsMgr::FontFamilyTextAttr::
nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm));
gfxFontGroup* fontGroup = fm->GetThebesFontGroup();
gfxFont* font = fontGroup->GetFontAt(0);
gfxFont* font = fontGroup->GetFirstValidFont();
gfxFontEntry* fontEntry = font->GetFontEntry();
aFamily = fontEntry->FamilyName();
return true;
@ -618,7 +618,7 @@ TextAttrsMgr::FontWeightTextAttr::
nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm));
gfxFontGroup *fontGroup = fm->GetThebesFontGroup();
gfxFont *font = fontGroup->GetFontAt(0);
gfxFont *font = fontGroup->GetFirstValidFont();
// When there doesn't exist a bold font in the family and so the rendering of
// a non-bold font face is changed so that the user sees what looks like a

View File

@ -182,7 +182,8 @@ sdnTextAccessible::get_fontFamily(BSTR __RPC_FAR* aFontFamily)
nsRefPtr<nsFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForFrame(frame, getter_AddRefs(fm));
const nsString& name = fm->GetThebesFontGroup()->GetFontAt(0)->GetName();
const nsString& name =
fm->GetThebesFontGroup()->GetFirstValidFont()->GetName();
if (name.IsEmpty())
return S_FALSE;

View File

@ -3457,7 +3457,8 @@ CanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText,
// offset pt.y based on text baseline
processor.mFontgrp->UpdateFontList(); // ensure user font generation is current
NS_ASSERTION(processor.mFontgrp->FontListLength()>0, "font group contains no fonts");
const gfxFont::Metrics& fontMetrics = processor.mFontgrp->GetFontAt(0)->GetMetrics();
const gfxFont::Metrics& fontMetrics =
processor.mFontgrp->GetFirstValidFont()->GetMetrics();
gfxFloat anchorY;

View File

@ -150,7 +150,7 @@ nsFontMetrics::Destroy()
const gfxFont::Metrics& nsFontMetrics::GetMetrics() const
{
return mFontGroup->GetFontAt(0)->GetMetrics();
return mFontGroup->GetFirstValidFont()->GetMetrics();
}
nscoord

View File

@ -1808,7 +1808,7 @@ gfxFontGroup::MakeSpaceTextRun(const Parameters *aParams, uint32_t aFlags)
orientation = TEXT_ORIENT_VERTICAL_UPRIGHT;
}
gfxFont *font = GetFontAt(0);
gfxFont *font = GetFirstValidFont();
if (MOZ_UNLIKELY(GetStyle()->size == 0)) {
// Short-circuit for size-0 fonts, as Windows and ATSUI can't handle
// them, and always create at least size 1 fonts, i.e. they still
@ -1854,7 +1854,7 @@ gfxFontGroup::MakeBlankTextRun(uint32_t aLength,
if (orientation == TEXT_ORIENT_VERTICAL_MIXED) {
orientation = TEXT_ORIENT_VERTICAL_UPRIGHT;
}
textRun->AddGlyphRun(GetFontAt(0), gfxTextRange::kFontGroup, 0, false,
textRun->AddGlyphRun(GetFirstValidFont(), gfxTextRange::kFontGroup, 0, false,
orientation);
return textRun;
}
@ -1866,8 +1866,8 @@ gfxFontGroup::MakeHyphenTextRun(gfxContext *aCtx, uint32_t aAppUnitsPerDevUnit)
// it's better to use ASCII '-' from the primary font than to fall back to
// U+2010 from some other, possibly poorly-matching face
static const char16_t hyphen = 0x2010;
gfxFont *font = GetFontAt(0);
if (font && font->HasCharacter(hyphen)) {
gfxFont *font = GetFirstValidFont();
if (font->HasCharacter(hyphen)) {
return MakeTextRun(&hyphen, 1, aCtx, aAppUnitsPerDevUnit,
gfxFontGroup::TEXT_IS_PERSISTENT);
}
@ -2137,7 +2137,7 @@ gfxFontGroup::InitScriptRun(gfxContext *aContext,
NS_ASSERTION(aTextRun->GetShapingState() != gfxTextRun::eShapingState_Aborted,
"don't call InitScriptRun with aborted shaping state");
gfxFont *mainFont = GetFontAt(0);
gfxFont *mainFont = GetFirstValidFont();
uint32_t runStart = 0;
nsAutoTArray<gfxTextRange,3> fontRanges;
@ -2343,7 +2343,7 @@ gfxFontGroup::GetEllipsisTextRun(int32_t aAppUnitsPerDevPixel,
// Use a Unicode ellipsis if the font supports it,
// otherwise use three ASCII periods as fallback.
gfxFont* firstFont = GetFontAt(0);
gfxFont* firstFont = GetFirstValidFont();
nsString ellipsis = firstFont->HasCharacter(kEllipsisChar[0])
? nsDependentString(kEllipsisChar,
ArrayLength(kEllipsisChar) - 1)
@ -2403,7 +2403,7 @@ gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
bool isVarSelector = gfxFontUtils::IsVarSelector(aCh);
if (!isJoinControl && !wasJoinCauser && !isVarSelector) {
nsRefPtr<gfxFont> firstFont = GetFontAt(0);
nsRefPtr<gfxFont> firstFont = GetFirstValidFont();
if (firstFont->HasCharacter(aCh)) {
*aMatchType = gfxTextRange::kFontGroup;
return firstFont.forget();
@ -2515,7 +2515,7 @@ gfxFontGroup::FindFontForChar(uint32_t aCh, uint32_t aPrevCh,
// we'll synthesize appropriate-width spaces instead of missing-glyph boxes
if (GetGeneralCategory(aCh) ==
HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR &&
GetFontAt(0)->SynthesizeSpaceWidth(aCh) >= 0.0)
GetFirstValidFont()->SynthesizeSpaceWidth(aCh) >= 0.0)
{
return nullptr;
}
@ -2540,7 +2540,7 @@ void gfxFontGroup::ComputeRanges(nsTArray<gfxTextRange>& aRanges,
// initialize prevFont to the group's primary font, so that this will be
// used for string-initial control chars, etc rather than risk hitting font
// fallback for these (bug 716229)
gfxFont *prevFont = GetFontAt(0);
gfxFont *prevFont = GetFirstValidFont();
// if we use the initial value of prevFont, we treat this as a match from
// the font group; fixes bug 978313

View File

@ -731,6 +731,10 @@ public:
virtual ~gfxFontGroup();
virtual gfxFont* GetFirstValidFont() {
return GetFontAt(0);
}
virtual gfxFont *GetFontAt(int32_t i) {
// If it turns out to be hard for all clients that cache font
// groups to call UpdateFontList at appropriate times, we could
@ -837,7 +841,7 @@ public:
enum { UNDERLINE_OFFSET_NOT_SET = INT16_MAX };
virtual gfxFloat GetUnderlineOffset() {
if (mUnderlineOffset == UNDERLINE_OFFSET_NOT_SET)
mUnderlineOffset = GetFontAt(0)->GetMetrics().underlineOffset;
mUnderlineOffset = GetFirstValidFont()->GetMetrics().underlineOffset;
return mUnderlineOffset;
}

View File

@ -1795,7 +1795,7 @@ GetFirstFontMetrics(gfxFontGroup* aFontGroup)
{
if (!aFontGroup)
return gfxFont::Metrics();
gfxFont* font = aFontGroup->GetFontAt(0);
gfxFont* font = aFontGroup->GetFirstValidFont();
if (!font)
return gfxFont::Metrics();
return font->GetMetrics();
@ -5660,7 +5660,7 @@ nsTextFrame::PaintTextSelectionDecorations(gfxContext* aCtx,
sdptr = sdptr->mNext;
}
gfxFont* firstFont = aProvider.GetFontGroup()->GetFontAt(0);
gfxFont* firstFont = aProvider.GetFontGroup()->GetFirstValidFont();
if (!firstFont)
return; // OOM
gfxFont::Metrics decorationMetrics(firstFont->GetMetrics());
@ -6341,7 +6341,7 @@ nsTextFrame::CombineSelectionUnderlineRect(nsPresContext* aPresContext,
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm),
GetFontSizeInflation());
gfxFontGroup* fontGroup = fm->GetThebesFontGroup();
gfxFont* firstFont = fontGroup->GetFontAt(0);
gfxFont* firstFont = fontGroup->GetFirstValidFont();
if (!firstFont)
return false; // OOM
const gfxFont::Metrics& metrics = firstFont->GetMetrics();

View File

@ -555,7 +555,8 @@ nsOpenTypeTable::MakeTextRun(gfxContext* aThebesContext,
aThebesContext, nullptr, nullptr, nullptr, 0, aAppUnitsPerDevPixel
};
gfxTextRun* textRun = gfxTextRun::Create(&params, 1, aFontGroup, 0);
textRun->AddGlyphRun(aFontGroup->GetFontAt(0), gfxTextRange::kFontGroup, 0,
textRun->AddGlyphRun(aFontGroup->GetFirstValidFont(),
gfxTextRange::kFontGroup, 0,
false, gfxTextRunFactory::TEXT_ORIENT_HORIZONTAL);
// We don't care about CSS writing mode here;
// math runs are assumed to be horizontal.
@ -563,7 +564,7 @@ nsOpenTypeTable::MakeTextRun(gfxContext* aThebesContext,
detailedGlyph.mGlyphID = aGlyph.glyphID;
detailedGlyph.mAdvance =
NSToCoordRound(aAppUnitsPerDevPixel *
aFontGroup->GetFontAt(0)->
aFontGroup->GetFirstValidFont()->
GetGlyphHAdvance(aThebesContext, aGlyph.glyphID));
detailedGlyph.mXOffset = detailedGlyph.mYOffset = 0;
gfxShapedText::CompressedGlyph g;
@ -993,7 +994,7 @@ nsMathMLChar::SetFontFamily(nsPresContext* aPresContext,
*getter_AddRefs(fm));
// Set the font if it is an unicode table
// or if the same family name has been found
gfxFont *firstFont = fm->GetThebesFontGroup()->GetFontAt(0);
gfxFont *firstFont = fm->GetThebesFontGroup()->GetFirstValidFont();
FontFamilyList firstFontList;
if (firstFont) {
firstFontList.Append(
@ -1439,7 +1440,7 @@ nsMathMLChar::StretchEnumContext::EnumCallback(const FontFamilyName& aFamily,
glyphTable = &gGlyphTableList->mUnicodeTable;
} else {
// If the font contains an Open Type MATH table, use it.
openTypeTable = nsOpenTypeTable::Create(fontGroup->GetFontAt(0));
openTypeTable = nsOpenTypeTable::Create(fontGroup->GetFirstValidFont());
if (openTypeTable) {
glyphTable = openTypeTable;
} else {

View File

@ -500,7 +500,7 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue,
nsRefPtr<nsFontMetrics> fm =
GetMetricsFor(aPresContext, aStyleContext, styleFont,
aFontSize, aUseUserFontSet);
gfxFloat zeroWidth = (fm->GetThebesFontGroup()->GetFontAt(0)
gfxFloat zeroWidth = (fm->GetThebesFontGroup()->GetFirstValidFont()
->GetMetrics().zeroOrAveCharWidth);
return ScaleCoordRound(aValue, ceil(aPresContext->AppUnitsPerDevPixel() *