Bug 476724. Recomputed underline offset after we rebuild our font set. r+sr=roc

This commit is contained in:
Boris Zbarsky 2009-02-03 21:58:21 -05:00
parent 749a81258a
commit 586e118dfb
2 changed files with 50 additions and 38 deletions

View File

@ -193,6 +193,12 @@ protected:
const PRUnichar *aString, PRUint32 aLength,
PRUint32 aLayoutStart, PRUint32 aLayoutLength,
PRUint32 aOffsetInTextRun, PRUint32 aLengthInTextRun);
/**
* Function to reinitialize our mFonts array and any other data
* that depends on mFonts.
*/
void InitFontList();
// cache the most recent pref font to avoid general pref font lookup
nsRefPtr<MacOSFamilyEntry> mLastPrefFamily;

View File

@ -522,45 +522,9 @@ gfxAtsuiFontGroup::gfxAtsuiFontGroup(const nsAString& families,
gfxUserFontSet *aUserFontSet)
: gfxFontGroup(families, aStyle, aUserFontSet)
{
ForEachFont(FindATSUFont, this);
if (mFonts.Length() == 0) {
// XXX this will generate a list of the lang groups for which we have no
// default fonts for on the mac; we should fix this!
// Known:
// ja x-beng x-devanagari x-tamil x-geor x-ethi x-gujr x-mlym x-armn
// x-orya x-telu x-knda x-sinh
//fprintf (stderr, "gfxAtsuiFontGroup: %s [%s] -> %d fonts found\n", NS_ConvertUTF16toUTF8(families).get(), aStyle->langGroup.get(), mFonts.Length());
// If we get here, we most likely didn't have a default font for
// a specific langGroup. Let's just pick the default OSX
// user font.
PRBool needsBold;
MacOSFontEntry *defaultFont = gfxQuartzFontCache::SharedFontCache()->GetDefaultFont(aStyle, needsBold);
NS_ASSERTION(defaultFont, "invalid default font returned by GetDefaultFont");
nsRefPtr<gfxAtsuiFont> font = GetOrMakeFont(defaultFont, aStyle, needsBold);
if (font) {
mFonts.AppendElement(font);
}
}
mPageLang = gfxPlatform::GetFontPrefLangFor(mStyle.langGroup.get());
if (!mStyle.systemFont) {
for (PRUint32 i = 0; i < mFonts.Length(); ++i) {
gfxAtsuiFont* font = static_cast<gfxAtsuiFont*>(mFonts[i].get());
if (font->GetFontEntry()->mIsBadUnderlineFont) {
gfxFloat first = mFonts[0]->GetMetrics().underlineOffset;
gfxFloat bad = font->GetMetrics().underlineOffset;
mUnderlineOffset = PR_MIN(first, bad);
break;
}
}
}
InitFontList();
}
PRBool
@ -970,7 +934,8 @@ gfxAtsuiFontGroup::UpdateFontList()
if (mUserFontSet && mCurrGeneration != GetGeneration()) {
// xxx - can probably improve this to detect when all fonts were found, so no need to update list
mFonts.Clear();
ForEachFont(FindATSUFont, this);
mUnderlineOffset = UNDERLINE_OFFSET_NOT_SET;
InitFontList();
mCurrGeneration = GetGeneration();
}
}
@ -1605,3 +1570,44 @@ gfxAtsuiFontGroup::InitTextRun(gfxTextRun *aRun,
return !closure.mOverrunningGlyphs;
}
void
gfxAtsuiFontGroup::InitFontList()
{
ForEachFont(FindATSUFont, this);
if (mFonts.Length() == 0) {
// XXX this will generate a list of the lang groups for which we have no
// default fonts for on the mac; we should fix this!
// Known:
// ja x-beng x-devanagari x-tamil x-geor x-ethi x-gujr x-mlym x-armn
// x-orya x-telu x-knda x-sinh
//fprintf (stderr, "gfxAtsuiFontGroup: %s [%s] -> %d fonts found\n", NS_ConvertUTF16toUTF8(families).get(), mStyle.langGroup.get(), mFonts.Length());
// If we get here, we most likely didn't have a default font for
// a specific langGroup. Let's just pick the default OSX
// user font.
PRBool needsBold;
MacOSFontEntry *defaultFont = gfxQuartzFontCache::SharedFontCache()->GetDefaultFont(&mStyle, needsBold);
NS_ASSERTION(defaultFont, "invalid default font returned by GetDefaultFont");
nsRefPtr<gfxAtsuiFont> font = GetOrMakeFont(defaultFont, &mStyle, needsBold);
if (font) {
mFonts.AppendElement(font);
}
}
if (!mStyle.systemFont) {
for (PRUint32 i = 0; i < mFonts.Length(); ++i) {
gfxAtsuiFont* font = static_cast<gfxAtsuiFont*>(mFonts[i].get());
if (font->GetFontEntry()->mIsBadUnderlineFont) {
gfxFloat first = mFonts[0]->GetMetrics().underlineOffset;
gfxFloat bad = font->GetMetrics().underlineOffset;
mUnderlineOffset = PR_MIN(first, bad);
break;
}
}
}
}