From 124e75ff80039a636a5e88f3ca1bab5d4ec9c31d Mon Sep 17 00:00:00 2001 From: "jdaggett@mozilla.com" Date: Wed, 9 Jan 2008 00:51:44 -0800 Subject: [PATCH] Bug 410954. Don't add fallback fonts to the font group list. Add better weight matching. r+sr=pavlov --- gfx/thebes/public/gfxAtsuiFonts.h | 2 +- gfx/thebes/src/gfxAtsuiFonts.cpp | 39 ++++++++++++++++++++++-------------- gfx/thebes/src/gfxQuartzFontCache.mm | 10 +++++++-- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/gfx/thebes/public/gfxAtsuiFonts.h b/gfx/thebes/public/gfxAtsuiFonts.h index dc17fd963..2800b98e2 100644 --- a/gfx/thebes/public/gfxAtsuiFonts.h +++ b/gfx/thebes/public/gfxAtsuiFonts.h @@ -131,7 +131,7 @@ public: return static_cast(static_cast(mFonts[aFontIndex])); } - gfxAtsuiFont* FindFontFor(ATSUFontID fid); + already_AddRefed FindFontFor(ATSUFontID fid); PRBool HasFont(ATSUFontID fid); diff --git a/gfx/thebes/src/gfxAtsuiFonts.cpp b/gfx/thebes/src/gfxAtsuiFonts.cpp index dbbc2f439..32478489d 100644 --- a/gfx/thebes/src/gfxAtsuiFonts.cpp +++ b/gfx/thebes/src/gfxAtsuiFonts.cpp @@ -449,12 +449,11 @@ PRBool gfxAtsuiFont::TestCharacterMap(PRUint32 aCh) { /** * Look up the font in the gfxFont cache. If we don't find it, create one. - * In either case, add a ref, append it to the aFonts array, and return it --- + * In either case, add a ref and return it --- * except for OOM in which case we do nothing and return null. */ -static gfxAtsuiFont * -GetOrMakeFont(ATSUFontID aFontID, const gfxFontStyle *aStyle, - nsTArray > *aFonts) +static already_AddRefed +GetOrMakeFont(ATSUFontID aFontID, const gfxFontStyle *aStyle) { const nsAString& name = gfxQuartzFontCache::SharedFontCache()->GetPostscriptNameForFontID(aFontID); @@ -465,12 +464,8 @@ GetOrMakeFont(ATSUFontID aFontID, const gfxFontStyle *aStyle, return nsnull; gfxFontCache::GetCache()->AddNew(font); } - // Add it to aFonts without unncessary refcount adjustment - nsRefPtr *destination = aFonts->AppendElement(); - if (!destination) - return nsnull; - destination->swap(font); - gfxFont *f = *destination; + gfxFont *f = nsnull; + font.swap(f); return static_cast(f); } @@ -493,7 +488,11 @@ gfxAtsuiFontGroup::gfxAtsuiFontGroup(const nsAString& families, // user font. ATSUFontID fontID = gfxQuartzFontCache::SharedFontCache()->GetDefaultATSUFontID (aStyle); NS_ASSERTION(fontID != kATSUInvalidFontID, "invalid default font returned by GetDefaultATSUFontID"); - GetOrMakeFont(fontID, aStyle, &mFonts); + + nsRefPtr font = GetOrMakeFont(fontID, aStyle); + if (font) { + mFonts.AppendElement(font); + } } } @@ -510,7 +509,10 @@ gfxAtsuiFontGroup::FindATSUFont(const nsAString& aName, if (fontID != kATSUInvalidFontID && !fontGroup->HasFont(fontID)) { //fprintf (stderr, "..FindATSUFont: %s\n", NS_ConvertUTF16toUTF8(aName).get()); - GetOrMakeFont(fontID, fontStyle, &fontGroup->mFonts); + nsRefPtr font = GetOrMakeFont(fontID, fontStyle); + if (font) { + fontGroup->mFonts.AppendElement(font); + } } return PR_TRUE; @@ -719,7 +721,7 @@ gfxAtsuiFontGroup::MakeTextRun(const PRUint8 *aString, PRUint32 aLength, return textRun; } -gfxAtsuiFont* +already_AddRefed gfxAtsuiFontGroup::FindFontFor(ATSUFontID fid) { gfxAtsuiFont *font; @@ -733,7 +735,9 @@ gfxAtsuiFontGroup::FindFontFor(ATSUFontID fid) return font; } - return GetOrMakeFont(fid, GetStyle(), &mFonts); + // font is *not* appended to the font group, so fallback fonts don't get added + nsRefPtr f = GetOrMakeFont(fid, GetStyle()); + return f.forget(); } PRBool @@ -1207,6 +1211,8 @@ struct AFLClosure { nsTArray > *fontArray; }; +// xxx - this is almost identical to the static method FindATSUFont, +// except for the closure struct used, we should merge these PRBool AppendFontToList(const nsAString& aName, const nsACString& aGenericName, @@ -1219,7 +1225,10 @@ AppendFontToList(const nsAString& aName, if (fontID != kATSUInvalidFontID) { //fprintf (stderr, "..AppendFontToList: %s\n", NS_ConvertUTF16toUTF8(aName).get()); - GetOrMakeFont(fontID, afl->style, afl->fontArray); + nsRefPtr font = GetOrMakeFont(fontID, afl->style); + if (font) { + afl->fontArray->AppendElement(font); + } } return PR_TRUE; diff --git a/gfx/thebes/src/gfxQuartzFontCache.mm b/gfx/thebes/src/gfxQuartzFontCache.mm index 6f0bb133d..aada31919 100644 --- a/gfx/thebes/src/gfxQuartzFontCache.mm +++ b/gfx/thebes/src/gfxQuartzFontCache.mm @@ -897,9 +897,15 @@ gfxQuartzFontCache::FindFontForCharProc(nsUint32HashKey::KeyType aKey, nsRefPtr< // weight PRInt8 baseWeight, weightDistance; style->ComputeWeightAndOffset(&baseWeight, &weightDistance); - PRUint16 targetWeight = (baseWeight * 100) + (weightDistance * 100); - if (aFontEntry->Weight() == targetWeight) + PRUint32 targetWeight = (baseWeight * 100) + (weightDistance * 100); + PRUint32 entryWeight = aFontEntry->Weight() * 100; + if (entryWeight == targetWeight) { rank += 5; + } else { + PRUint32 diffWeight = abs(entryWeight - targetWeight); + if (diffWeight <= 100) // favor faces close in weight + rank += 2; + } } else { // if no font to match, prefer non-bold, non-italic fonts if (!aFontEntry->IsItalicStyle() && !aFontEntry->IsBold()) -- 2.11.4.GIT