diff --git a/gfx/thebes/gfxFont.cpp b/gfx/thebes/gfxFont.cpp index d80b65a1ff8a..b2b2b6a9dba6 100644 --- a/gfx/thebes/gfxFont.cpp +++ b/gfx/thebes/gfxFont.cpp @@ -3641,6 +3641,29 @@ gfxFontGroup::InitScriptRun(gfxContext *aContext, } } +already_AddRefed +gfxFontGroup::TryOtherFamilyMembers(gfxFont* aFont, PRUint32 aCh) +{ + gfxFontFamily *family = aFont->GetFontEntry()->Family(); + if (family && !aFont->GetFontEntry()->mIsProxy && + family->TestCharacterMap(aCh)) { + // Note that we don't need the actual runScript in matchData for + // gfxFontFamily::SearchAllFontsForChar, it's only used for the + // system-fallback case. So we can just set it to 0 here. + GlobalFontMatch matchData(aCh, 0, &mStyle); + family->SearchAllFontsForChar(&matchData); + gfxFontEntry *fe = matchData.mBestMatch; + if (fe) { + bool needsBold = aFont->GetStyle()->weight >= 600 && !fe->IsBold(); + nsRefPtr font = fe->FindOrMakeFont(&mStyle, needsBold); + if (font) { + return font.forget(); + } + } + } + return nsnull; +} + already_AddRefed gfxFontGroup::FindFontForChar(PRUint32 aCh, PRUint32 aPrevCh, PRInt32 aRunScript, gfxFont *aPrevMatchedFont, @@ -3660,6 +3683,13 @@ gfxFontGroup::FindFontForChar(PRUint32 aCh, PRUint32 aPrevCh, firstFont->AddRef(); return firstFont; } + // It's possible that another font in the family (e.g. regular face, + // where the requested style was italic) will support the character + nsRefPtr font = TryOtherFamilyMembers(firstFont, aCh); + if (font) { + *aMatchType = gfxTextRange::kFontGroup; + return font.forget(); + } // we don't need to check the first font again below ++nextIndex; } @@ -3705,22 +3735,10 @@ gfxFontGroup::FindFontForChar(PRUint32 aCh, PRUint32 aPrevCh, return font.forget(); } - // check other faces of the family - gfxFontFamily *family = font->GetFontEntry()->Family(); - if (family && !font->GetFontEntry()->mIsProxy && - family->TestCharacterMap(aCh)) - { - GlobalFontMatch matchData(aCh, aRunScript, &mStyle); - family->SearchAllFontsForChar(&matchData); - gfxFontEntry *fe = matchData.mBestMatch; - if (fe) { - bool needsBold = - font->GetStyle()->weight >= 600 && !fe->IsBold(); - font = fe->FindOrMakeFont(font->GetStyle(), needsBold); - if (font) { - return font.forget(); - } - } + font = TryOtherFamilyMembers(font, aCh); + if (font) { + *aMatchType = gfxTextRange::kFontGroup; + return font.forget(); } } diff --git a/gfx/thebes/gfxFont.h b/gfx/thebes/gfxFont.h index 106358de729c..ac8e23768795 100644 --- a/gfx/thebes/gfxFont.h +++ b/gfx/thebes/gfxFont.h @@ -3181,6 +3181,12 @@ protected: FontCreationCallback fc, void *closure); + // Helper for font-matching: + // see if aCh is supported in any of the other faces from aFont's family; + // if so return the best style match, else return null. + already_AddRefed TryOtherFamilyMembers(gfxFont* aFont, + PRUint32 aCh); + static bool FontResolverProc(const nsAString& aName, void *aClosure); static bool FindPlatformFont(const nsAString& aName,