Bug 1533428 - patch 7 - Create a FontFamily type that wraps either a gfxFontFamily pointer or a mozilla::fontlist::Family pointer (to be used by the shared font list), and use this in various places where we need to pass families around. r=jwatt

Differential Revision: https://phabricator.services.mozilla.com/D22934

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jonathan Kew 2019-04-01 14:33:34 +00:00
Родитель 5f45afb7ec
Коммит d2a3361fa4
15 изменённых файлов: 115 добавлений и 69 удалений

Просмотреть файл

@ -837,12 +837,12 @@ gfxDWriteFontList::gfxDWriteFontList() : mForceGDIClassicMaxFontSize(0.0) {}
// I/O strain during cold startup due to dwrite caching bugs. Default to // I/O strain during cold startup due to dwrite caching bugs. Default to
// Arial to avoid this. // Arial to avoid this.
gfxFontFamily* gfxDWriteFontList::GetDefaultFontForPlatform( FontFamily gfxDWriteFontList::GetDefaultFontForPlatform(
const gfxFontStyle* aStyle) { const gfxFontStyle* aStyle) {
// try Arial first // try Arial first
gfxFontFamily* ff; gfxFontFamily* ff;
if ((ff = FindFamily(NS_LITERAL_CSTRING("Arial")))) { if ((ff = FindFamily(NS_LITERAL_CSTRING("Arial")))) {
return ff; return FontFamily(ff);
} }
// otherwise, use local default // otherwise, use local default
@ -854,11 +854,11 @@ gfxFontFamily* gfxDWriteFontList::GetDefaultFontForPlatform(
if (status) { if (status) {
ff = FindFamily(NS_ConvertUTF16toUTF8(ncm.lfMessageFont.lfFaceName)); ff = FindFamily(NS_ConvertUTF16toUTF8(ncm.lfMessageFont.lfFaceName));
if (ff) { if (ff) {
return ff; return FontFamily(ff);
} }
} }
return nullptr; return FontFamily();
} }
gfxFontEntry* gfxDWriteFontList::LookupLocalFont( gfxFontEntry* gfxDWriteFontList::LookupLocalFont(
@ -1417,7 +1417,7 @@ IFACEMETHODIMP DWriteFontFallbackRenderer::DrawGlyphRun(
gfxFontEntry* gfxDWriteFontList::PlatformGlobalFontFallback( gfxFontEntry* gfxDWriteFontList::PlatformGlobalFontFallback(
const uint32_t aCh, Script aRunScript, const gfxFontStyle* aMatchStyle, const uint32_t aCh, Script aRunScript, const gfxFontStyle* aMatchStyle,
gfxFontFamily** aMatchedFamily) { FontFamily* aMatchedFamily) {
HRESULT hr; HRESULT hr;
RefPtr<IDWriteFactory> dwFactory = Factory::GetDWriteFactory(); RefPtr<IDWriteFactory> dwFactory = Factory::GetDWriteFactory();
@ -1477,7 +1477,7 @@ gfxFontEntry* gfxDWriteFontList::PlatformGlobalFontFallback(
gfxFontEntry* fontEntry; gfxFontEntry* fontEntry;
fontEntry = family->FindFontForStyle(*aMatchStyle); fontEntry = family->FindFontForStyle(*aMatchStyle);
if (fontEntry && fontEntry->HasCharacter(aCh)) { if (fontEntry && fontEntry->HasCharacter(aCh)) {
*aMatchedFamily = family; *aMatchedFamily = FontFamily(family);
return fontEntry; return fontEntry;
} }
Telemetry::Accumulate(Telemetry::BAD_FALLBACK_FONT, true); Telemetry::Accumulate(Telemetry::BAD_FALLBACK_FONT, true);

Просмотреть файл

@ -404,14 +404,14 @@ class gfxDWriteFontList : public gfxPlatformFontList {
FontListSizes* aSizes) const; FontListSizes* aSizes) const;
protected: protected:
virtual gfxFontFamily* GetDefaultFontForPlatform( FontFamily GetDefaultFontForPlatform(const gfxFontStyle* aStyle) override;
const gfxFontStyle* aStyle) override;
// attempt to use platform-specific fallback for the given character, // attempt to use platform-specific fallback for the given character,
// return null if no usable result found // return null if no usable result found
gfxFontEntry* PlatformGlobalFontFallback( gfxFontEntry* PlatformGlobalFontFallback(const uint32_t aCh,
const uint32_t aCh, Script aRunScript, const gfxFontStyle* aMatchStyle, Script aRunScript,
gfxFontFamily** aMatchedFamily) override; const gfxFontStyle* aMatchStyle,
FontFamily* aMatchedFamily) override;
private: private:
friend class gfxDWriteFontFamily; friend class gfxDWriteFontFamily;

Просмотреть файл

@ -1505,7 +1505,7 @@ searchDone:
return fe; return fe;
} }
gfxFontFamily* gfxFT2FontList::GetDefaultFontForPlatform( FontFamily gfxFT2FontList::GetDefaultFontForPlatform(
const gfxFontStyle* aStyle) { const gfxFontStyle* aStyle) {
gfxFontFamily* ff = nullptr; gfxFontFamily* ff = nullptr;
#if defined(MOZ_WIDGET_ANDROID) #if defined(MOZ_WIDGET_ANDROID)
@ -1515,7 +1515,7 @@ gfxFontFamily* gfxFT2FontList::GetDefaultFontForPlatform(
} }
#endif #endif
/* TODO: what about Qt or other platforms that may use this? */ /* TODO: what about Qt or other platforms that may use this? */
return ff; return FontFamily(ff);
} }
gfxFontEntry* gfxFT2FontList::MakePlatformFont(const nsACString& aFontName, gfxFontEntry* gfxFT2FontList::MakePlatformFont(const nsACString& aFontName,

Просмотреть файл

@ -176,8 +176,7 @@ class gfxFT2FontList : public gfxPlatformFontList {
void FindFontsInDir(const nsCString& aDir, FontNameCache* aFNC); void FindFontsInDir(const nsCString& aDir, FontNameCache* aFNC);
virtual gfxFontFamily* GetDefaultFontForPlatform( FontFamily GetDefaultFontForPlatform(const gfxFontStyle* aStyle) override;
const gfxFontStyle* aStyle) override;
nsTHashtable<nsCStringHashKey> mSkipSpaceLookupCheckFamilies; nsTHashtable<nsCStringHashKey> mSkipSpaceLookupCheckFamilies;

Просмотреть файл

@ -1739,7 +1739,7 @@ void gfxFcPlatformFontList::GetFontList(nsAtom* aLangGroup,
if (serif) aListOfFonts.InsertElementAt(0, NS_LITERAL_STRING("serif")); if (serif) aListOfFonts.InsertElementAt(0, NS_LITERAL_STRING("serif"));
} }
gfxFontFamily* gfxFcPlatformFontList::GetDefaultFontForPlatform( FontFamily gfxFcPlatformFontList::GetDefaultFontForPlatform(
const gfxFontStyle* aStyle) { const gfxFontStyle* aStyle) {
// Get the default font by using a fake name to retrieve the first // Get the default font by using a fake name to retrieve the first
// scalable font that fontconfig suggests for the given language. // scalable font that fontconfig suggests for the given language.
@ -1749,7 +1749,7 @@ gfxFontFamily* gfxFcPlatformFontList::GetDefaultFontForPlatform(
if (prefFonts && !prefFonts->IsEmpty()) { if (prefFonts && !prefFonts->IsEmpty()) {
return (*prefFonts)[0]; return (*prefFonts)[0];
} }
return nullptr; return FontFamily();
} }
gfxFontEntry* gfxFcPlatformFontList::LookupLocalFont( gfxFontEntry* gfxFcPlatformFontList::LookupLocalFont(
@ -2030,7 +2030,7 @@ void gfxFcPlatformFontList::AddGenericFonts(
NS_ASSERTION(prefFonts, "null generic font list"); NS_ASSERTION(prefFonts, "null generic font list");
aFamilyList.SetCapacity(aFamilyList.Length() + prefFonts->Length()); aFamilyList.SetCapacity(aFamilyList.Length() + prefFonts->Length());
for (auto& f : *prefFonts) { for (auto& f : *prefFonts) {
aFamilyList.AppendElement(FamilyAndGeneric(f.get(), aGenericType)); aFamilyList.AppendElement(FamilyAndGeneric(f, aGenericType));
} }
} }

Просмотреть файл

@ -349,8 +349,7 @@ class gfxFcPlatformFontList : public gfxPlatformFontList {
static void CheckFontUpdates(nsITimer* aTimer, void* aThis); static void CheckFontUpdates(nsITimer* aTimer, void* aThis);
virtual gfxFontFamily* GetDefaultFontForPlatform( FontFamily GetDefaultFontForPlatform(const gfxFontStyle* aStyle) override;
const gfxFontStyle* aStyle) override;
gfxFontFamily* CreateFontFamily(const nsACString& aName) const override; gfxFontFamily* CreateFontFamily(const nsACString& aName) const override;

Просмотреть файл

@ -45,7 +45,11 @@ class nsAtom;
namespace mozilla { namespace mozilla {
class SVGContextPaint; class SVGContextPaint;
}; namespace fontlist {
struct Family;
struct Face;
} // namespace fontlist
} // namespace mozilla
#define NO_FONT_LANGUAGE_OVERRIDE 0 #define NO_FONT_LANGUAGE_OVERRIDE 0
@ -906,19 +910,61 @@ class gfxFontFamily {
}; };
}; };
// Wrapper for either a mozilla::fontlist::Family in the shared font list or an
// unshared gfxFontFamily that belongs just to the current process. This does
// not own a reference, it just wraps a raw pointer and records the type.
struct FontFamily {
FontFamily() : mUnshared(nullptr), mIsShared(false) {}
FontFamily(const FontFamily& aOther) = default;
explicit FontFamily(gfxFontFamily* aFamily)
: mUnshared(aFamily), mIsShared(false) {}
explicit FontFamily(mozilla::fontlist::Family* aFamily)
: mShared(aFamily), mIsShared(true) {}
bool operator==(const FontFamily& aOther) const {
return mIsShared == aOther.mIsShared &&
(mIsShared ? mShared == aOther.mShared
: mUnshared == aOther.mUnshared);
}
bool IsNull() const { return mIsShared ? !mShared : !mUnshared; }
union {
gfxFontFamily* mUnshared;
mozilla::fontlist::Family* mShared;
};
bool mIsShared;
};
// Struct used in the gfxFontGroup font list to keep track of a font family // Struct used in the gfxFontGroup font list to keep track of a font family
// together with the CSS generic (if any) that was mapped to it in this // together with the CSS generic (if any) that was mapped to it in this
// particular case (so it can be reported to the DevTools font inspector). // particular case (so it can be reported to the DevTools font inspector).
struct FamilyAndGeneric final { struct FamilyAndGeneric final {
FamilyAndGeneric() FamilyAndGeneric()
: mFamily(nullptr), mGeneric(mozilla::FontFamilyType::eFamily_none) {} : mFamily(), mGeneric(mozilla::FontFamilyType::eFamily_none) {}
FamilyAndGeneric(const FamilyAndGeneric& aOther) FamilyAndGeneric(const FamilyAndGeneric& aOther)
: mFamily(aOther.mFamily), mGeneric(aOther.mGeneric) {} : mFamily(aOther.mFamily), mGeneric(aOther.mGeneric) {}
explicit FamilyAndGeneric( explicit FamilyAndGeneric(
gfxFontFamily* aFamily, gfxFontFamily* aFamily,
mozilla::FontFamilyType aGeneric = mozilla::FontFamilyType::eFamily_none) mozilla::FontFamilyType aGeneric = mozilla::FontFamilyType::eFamily_none)
: mFamily(aFamily), mGeneric(aGeneric) {} : mFamily(aFamily), mGeneric(aGeneric) {}
gfxFontFamily* mFamily; explicit FamilyAndGeneric(
mozilla::fontlist::Family* aFamily,
mozilla::FontFamilyType aGeneric = mozilla::FontFamilyType::eFamily_none)
: mFamily(aFamily), mGeneric(aGeneric) {}
explicit FamilyAndGeneric(
const FontFamily& aFamily,
mozilla::FontFamilyType aGeneric = mozilla::FontFamilyType::eFamily_none)
: mFamily(aFamily), mGeneric(aGeneric) {}
bool operator==(const FamilyAndGeneric& aOther) const {
return (mFamily == aOther.mFamily && mGeneric == aOther.mGeneric);
}
FontFamily mFamily;
mozilla::FontFamilyType mGeneric; mozilla::FontFamilyType mGeneric;
}; };

Просмотреть файл

@ -843,7 +843,7 @@ bool gfxGDIFontList::FindAndAddFamilies(const nsACString& aFamily,
aStyle, aDevToCssSize); aStyle, aDevToCssSize);
} }
gfxFontFamily* gfxGDIFontList::GetDefaultFontForPlatform( FontFamily gfxGDIFontList::GetDefaultFontForPlatform(
const gfxFontStyle* aStyle) { const gfxFontStyle* aStyle) {
gfxFontFamily* ff = nullptr; gfxFontFamily* ff = nullptr;
@ -855,7 +855,7 @@ gfxFontFamily* gfxGDIFontList::GetDefaultFontForPlatform(
if (status) { if (status) {
ff = FindFamily(NS_ConvertUTF16toUTF8(ncm.lfMessageFont.lfFaceName)); ff = FindFamily(NS_ConvertUTF16toUTF8(ncm.lfMessageFont.lfFaceName));
if (ff) { if (ff) {
return ff; return FontFamily(ff);
} }
} }
@ -866,7 +866,7 @@ gfxFontFamily* gfxGDIFontList::GetDefaultFontForPlatform(
ff = FindFamily(NS_ConvertUTF16toUTF8(logFont.lfFaceName)); ff = FindFamily(NS_ConvertUTF16toUTF8(logFont.lfFaceName));
} }
return ff; return FontFamily(ff);
} }
void gfxGDIFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, void gfxGDIFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,

Просмотреть файл

@ -323,8 +323,7 @@ class gfxGDIFontList : public gfxPlatformFontList {
FontListSizes* aSizes) const; FontListSizes* aSizes) const;
protected: protected:
virtual gfxFontFamily* GetDefaultFontForPlatform( FontFamily GetDefaultFontForPlatform(const gfxFontStyle* aStyle) override;
const gfxFontStyle* aStyle) override;
private: private:
friend class gfxWindowsPlatform; friend class gfxWindowsPlatform;

Просмотреть файл

@ -178,7 +178,7 @@ class gfxMacPlatformFontList : public gfxPlatformFontList {
InfallibleTArray<mozilla::dom::SystemFontListEntry>* aList); InfallibleTArray<mozilla::dom::SystemFontListEntry>* aList);
protected: protected:
gfxFontFamily* GetDefaultFontForPlatform(const gfxFontStyle* aStyle) override; FontFamily GetDefaultFontForPlatform(const gfxFontStyle* aStyle) override;
private: private:
friend class gfxPlatformMac; friend class gfxPlatformMac;
@ -204,9 +204,10 @@ class gfxMacPlatformFontList : public gfxPlatformFontList {
// attempt to use platform-specific fallback for the given character // attempt to use platform-specific fallback for the given character
// return null if no usable result found // return null if no usable result found
gfxFontEntry* PlatformGlobalFontFallback( gfxFontEntry* PlatformGlobalFontFallback(const uint32_t aCh,
const uint32_t aCh, Script aRunScript, const gfxFontStyle* aMatchStyle, Script aRunScript,
gfxFontFamily** aMatchedFamily) override; const gfxFontStyle* aMatchStyle,
FontFamily* aMatchedFamily) override;
bool UsesSystemFallback() override { return true; } bool UsesSystemFallback() override { return true; }

Просмотреть файл

@ -1283,7 +1283,7 @@ void gfxMacPlatformFontList::RegisteredFontsChangedNotificationCallback(
gfxFontEntry* gfxMacPlatformFontList::PlatformGlobalFontFallback(const uint32_t aCh, gfxFontEntry* gfxMacPlatformFontList::PlatformGlobalFontFallback(const uint32_t aCh,
Script aRunScript, Script aRunScript,
const gfxFontStyle* aMatchStyle, const gfxFontStyle* aMatchStyle,
gfxFontFamily** aMatchedFamily) { FontFamily* aMatchedFamily) {
CFStringRef str; CFStringRef str;
UniChar ch[2]; UniChar ch[2];
CFIndex length = 1; CFIndex length = 1;
@ -1335,7 +1335,7 @@ gfxFontEntry* gfxMacPlatformFontList::PlatformGlobalFontFallback(const uint32_t
fontEntry = family->FindFontForStyle(*aMatchStyle); fontEntry = family->FindFontForStyle(*aMatchStyle);
if (fontEntry) { if (fontEntry) {
if (fontEntry->HasCharacter(aCh)) { if (fontEntry->HasCharacter(aCh)) {
*aMatchedFamily = family; *aMatchedFamily = FontFamily(family);
} else { } else {
fontEntry = nullptr; fontEntry = nullptr;
cantUseFallbackFont = true; cantUseFallbackFont = true;
@ -1358,14 +1358,14 @@ gfxFontEntry* gfxMacPlatformFontList::PlatformGlobalFontFallback(const uint32_t
return fontEntry; return fontEntry;
} }
gfxFontFamily* gfxMacPlatformFontList::GetDefaultFontForPlatform(const gfxFontStyle* aStyle) { FontFamily gfxMacPlatformFontList::GetDefaultFontForPlatform(const gfxFontStyle* aStyle) {
nsAutoreleasePool localPool; nsAutoreleasePool localPool;
NSString* defaultFamily = [[NSFont userFontOfSize:aStyle->size] familyName]; NSString* defaultFamily = [[NSFont userFontOfSize:aStyle->size] familyName];
nsAutoString familyName; nsAutoString familyName;
GetStringForNSString(defaultFamily, familyName); GetStringForNSString(defaultFamily, familyName);
return FindFamily(NS_ConvertUTF16toUTF8(familyName)); return FontFamily(FindFamily(NS_ConvertUTF16toUTF8(familyName)));
} }
int32_t gfxMacPlatformFontList::AppleWeightToCSSWeight(int32_t aAppleWeight) { int32_t gfxMacPlatformFontList::AppleWeightToCSSWeight(int32_t aAppleWeight) {

Просмотреть файл

@ -355,7 +355,6 @@ nsresult gfxPlatformFontList::InitFontList() {
} }
mFaceNameListsInitialized = false; mFaceNameListsInitialized = false;
ClearLangGroupPrefFonts(); ClearLangGroupPrefFonts();
mReplacementCharFallbackFamily = nullptr;
CancelLoader(); CancelLoader();
// initialize ranges of characters for which system-wide font search should be // initialize ranges of characters for which system-wide font search should be
@ -568,8 +567,12 @@ gfxFontEntry* gfxPlatformFontList::SystemFindFontForChar(
// encoding errors: just use cached family from last time U+FFFD was seen. // encoding errors: just use cached family from last time U+FFFD was seen.
// This helps speed up pages with lots of encoding errors, binary-as-text, // This helps speed up pages with lots of encoding errors, binary-as-text,
// etc. // etc.
if (aCh == 0xFFFD && mReplacementCharFallbackFamily) { if (aCh == 0xFFFD) {
fontEntry = mReplacementCharFallbackFamily->FindFontForStyle(*aStyle); if (!mReplacementCharFallbackFamily.mIsShared &&
mReplacementCharFallbackFamily.mUnshared) {
fontEntry =
mReplacementCharFallbackFamily.mUnshared->FindFontForStyle(*aStyle);
}
// this should never fail, as we must have found U+FFFD in order to set // this should never fail, as we must have found U+FFFD in order to set
// mReplacementCharFallbackFamily at all, but better play it safe // mReplacementCharFallbackFamily at all, but better play it safe
@ -582,7 +585,7 @@ gfxFontEntry* gfxPlatformFontList::SystemFindFontForChar(
// search commonly available fonts // search commonly available fonts
bool common = true; bool common = true;
gfxFontFamily* fallbackFamily = nullptr; FontFamily fallbackFamily;
fontEntry = fontEntry =
CommonFontFallback(aCh, aNextCh, aRunScript, aStyle, &fallbackFamily); CommonFontFallback(aCh, aNextCh, aRunScript, aStyle, &fallbackFamily);
@ -613,7 +616,7 @@ gfxFontEntry* gfxPlatformFontList::SystemFindFontForChar(
// no match? add to set of non-matching codepoints // no match? add to set of non-matching codepoints
if (!fontEntry) { if (!fontEntry) {
mCodepointsWithNoFonts.set(aCh); mCodepointsWithNoFonts.set(aCh);
} else if (aCh == 0xFFFD && fontEntry && fallbackFamily) { } else if (aCh == 0xFFFD && fontEntry) {
mReplacementCharFallbackFamily = fallbackFamily; mReplacementCharFallbackFamily = fallbackFamily;
} }
@ -638,7 +641,7 @@ gfxFontEntry* gfxPlatformFontList::SystemFindFontForChar(
gfxFontEntry* gfxPlatformFontList::CommonFontFallback( gfxFontEntry* gfxPlatformFontList::CommonFontFallback(
uint32_t aCh, uint32_t aNextCh, Script aRunScript, uint32_t aCh, uint32_t aNextCh, Script aRunScript,
const gfxFontStyle* aMatchStyle, gfxFontFamily** aMatchedFamily) { const gfxFontStyle* aMatchStyle, FontFamily* aMatchedFamily) {
AutoTArray<const char*, NUM_FALLBACK_FONTS> defaultFallbacks; AutoTArray<const char*, NUM_FALLBACK_FONTS> defaultFallbacks;
gfxPlatform::GetPlatform()->GetCommonFallbackFonts(aCh, aNextCh, aRunScript, gfxPlatform::GetPlatform()->GetCommonFallbackFonts(aCh, aNextCh, aRunScript,
defaultFallbacks); defaultFallbacks);
@ -649,7 +652,7 @@ gfxFontEntry* gfxPlatformFontList::CommonFontFallback(
if (fallback) { if (fallback) {
fallback->FindFontForChar(&data); fallback->FindFontForChar(&data);
if (data.mBestMatch) { if (data.mBestMatch) {
*aMatchedFamily = fallback; *aMatchedFamily = FontFamily(fallback);
return data.mBestMatch; return data.mBestMatch;
} }
} }
@ -659,7 +662,7 @@ gfxFontEntry* gfxPlatformFontList::CommonFontFallback(
gfxFontEntry* gfxPlatformFontList::GlobalFontFallback( gfxFontEntry* gfxPlatformFontList::GlobalFontFallback(
const uint32_t aCh, Script aRunScript, const gfxFontStyle* aMatchStyle, const uint32_t aCh, Script aRunScript, const gfxFontStyle* aMatchStyle,
uint32_t& aCmapCount, gfxFontFamily** aMatchedFamily) { uint32_t& aCmapCount, FontFamily* aMatchedFamily) {
bool useCmaps = IsFontFamilyWhitelistActive() || bool useCmaps = IsFontFamilyWhitelistActive() ||
gfxPlatform::GetPlatform()->UseCmapsDuringSystemFallback(); gfxPlatform::GetPlatform()->UseCmapsDuringSystemFallback();
if (!useCmaps) { if (!useCmaps) {
@ -686,7 +689,7 @@ gfxFontEntry* gfxPlatformFontList::GlobalFontFallback(
} }
aCmapCount = data.mCmapsTested; aCmapCount = data.mCmapsTested;
*aMatchedFamily = data.mMatchedFamily; *aMatchedFamily = FontFamily(data.mMatchedFamily);
return data.mBestMatch; return data.mBestMatch;
} }
@ -995,7 +998,7 @@ void gfxPlatformFontList::AddGenericFonts(
if (!prefFonts->IsEmpty()) { if (!prefFonts->IsEmpty()) {
aFamilyList.SetCapacity(aFamilyList.Length() + prefFonts->Length()); aFamilyList.SetCapacity(aFamilyList.Length() + prefFonts->Length());
for (auto& f : *prefFonts) { for (auto& f : *prefFonts) {
aFamilyList.AppendElement(FamilyAndGeneric(f.get(), aGenericType)); aFamilyList.AppendElement(FamilyAndGeneric(f, aGenericType));
} }
} }
} }
@ -1307,16 +1310,16 @@ mozilla::FontFamilyType gfxPlatformFontList::GetDefaultGeneric(
return eFamily_serif; return eFamily_serif;
} }
gfxFontFamily* gfxPlatformFontList::GetDefaultFont(const gfxFontStyle* aStyle) { FontFamily gfxPlatformFontList::GetDefaultFont(const gfxFontStyle* aStyle) {
gfxFontFamily* family = GetDefaultFontForPlatform(aStyle); FontFamily family = GetDefaultFontForPlatform(aStyle);
if (family) { if (!family.mIsShared && family.mUnshared) {
return family; return family;
} }
// Something has gone wrong and we were unable to retrieve a default font // Something has gone wrong and we were unable to retrieve a default font
// from the platform. (Likely the whitelist has blocked all potential // from the platform. (Likely the whitelist has blocked all potential
// default fonts.) As a last resort, we return the first font listed in // default fonts.) As a last resort, we return the first font listed in
// mFontFamilies. // mFontFamilies.
return mFontFamilies.Iter().Data(); return FontFamily(mFontFamilies.Iter().Data());
} }
void gfxPlatformFontList::GetFontFamilyNames( void gfxPlatformFontList::GetFontFamilyNames(

Просмотреть файл

@ -100,7 +100,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
// For font family lists loaded from user preferences (prefs such as // For font family lists loaded from user preferences (prefs such as
// font.name-list.<generic>.<langGroup>) that map CSS generics to // font.name-list.<generic>.<langGroup>) that map CSS generics to
// platform-specific font families. // platform-specific font families.
typedef nsTArray<RefPtr<gfxFontFamily>> PrefFontList; typedef nsTArray<FontFamily> PrefFontList;
static gfxPlatformFontList* PlatformFontList() { return sPlatformFontList; } static gfxPlatformFontList* PlatformFontList() { return sPlatformFontList; }
@ -184,7 +184,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
// pure virtual functions, to be provided by concrete subclasses // pure virtual functions, to be provided by concrete subclasses
// get the system default font family // get the system default font family
gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle); FontFamily GetDefaultFont(const gfxFontStyle* aStyle);
/** /**
* Look up a font by name on the host platform. * Look up a font by name on the host platform.
@ -396,7 +396,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
gfxFloat aDevToCssSize = 1.0) { gfxFloat aDevToCssSize = 1.0) {
AutoTArray<FamilyAndGeneric, 1> families; AutoTArray<FamilyAndGeneric, 1> families;
return FindAndAddFamilies(aFamily, &families, aFlags, aStyle, aDevToCssSize) return FindAndAddFamilies(aFamily, &families, aFlags, aStyle, aDevToCssSize)
? families[0].mFamily ? families[0].mFamily.mUnshared
: nullptr; : nullptr;
} }
@ -416,20 +416,20 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
gfxFontEntry* CommonFontFallback(uint32_t aCh, uint32_t aNextCh, gfxFontEntry* CommonFontFallback(uint32_t aCh, uint32_t aNextCh,
Script aRunScript, Script aRunScript,
const gfxFontStyle* aMatchStyle, const gfxFontStyle* aMatchStyle,
gfxFontFamily** aMatchedFamily); FontFamily* aMatchedFamily);
// Search fonts system-wide for a given character, null if not found. // Search fonts system-wide for a given character, null if not found.
gfxFontEntry* GlobalFontFallback(const uint32_t aCh, Script aRunScript, gfxFontEntry* GlobalFontFallback(const uint32_t aCh, Script aRunScript,
const gfxFontStyle* aMatchStyle, const gfxFontStyle* aMatchStyle,
uint32_t& aCmapCount, uint32_t& aCmapCount,
gfxFontFamily** aMatchedFamily); FontFamily* aMatchedFamily);
// Platform-specific implementation of global font fallback, if any; // Platform-specific implementation of global font fallback, if any;
// this may return nullptr in which case the default cmap-based fallback // this may return nullptr in which case the default cmap-based fallback
// will be performed. // will be performed.
virtual gfxFontEntry* PlatformGlobalFontFallback( virtual gfxFontEntry* PlatformGlobalFontFallback(
const uint32_t aCh, Script aRunScript, const gfxFontStyle* aMatchStyle, const uint32_t aCh, Script aRunScript, const gfxFontStyle* aMatchStyle,
gfxFontFamily** aMatchedFamily) { FontFamily* aMatchedFamily) {
return nullptr; return nullptr;
} }
@ -514,8 +514,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
const FontEntryTable& aTable, mozilla::MallocSizeOf aMallocSizeOf); const FontEntryTable& aTable, mozilla::MallocSizeOf aMallocSizeOf);
// Platform-specific helper for GetDefaultFont(...). // Platform-specific helper for GetDefaultFont(...).
virtual gfxFontFamily* GetDefaultFontForPlatform( virtual FontFamily GetDefaultFontForPlatform(const gfxFontStyle* aStyle) = 0;
const gfxFontStyle* aStyle) = 0;
// Protects mFontFamilies. // Protects mFontFamilies.
mozilla::Mutex mFontFamiliesMutex; mozilla::Mutex mFontFamiliesMutex;
@ -567,7 +566,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
// the family to use for U+FFFD fallback, to avoid expensive search every time // the family to use for U+FFFD fallback, to avoid expensive search every time
// on pages with lots of problems // on pages with lots of problems
RefPtr<gfxFontFamily> mReplacementCharFallbackFamily; FontFamily mReplacementCharFallbackFamily;
// Sorted array of lowercased family names; use ContainsSorted to test // Sorted array of lowercased family names; use ContainsSorted to test
nsTArray<nsCString> mBadUnderlineFamilyNames; nsTArray<nsCString> mBadUnderlineFamilyNames;

Просмотреть файл

@ -1734,7 +1734,7 @@ void gfxFontGroup::BuildFontList() {
// build the fontlist from the specified families // build the fontlist from the specified families
for (const auto& f : fonts) { for (const auto& f : fonts) {
AddFamilyToFontList(f.mFamily, f.mGeneric); AddFamilyToFontList(f.mFamily.mUnshared, f.mGeneric);
} }
} }
@ -1897,12 +1897,12 @@ gfxFont* gfxFontGroup::GetDefaultFont() {
} }
gfxPlatformFontList* pfl = gfxPlatformFontList::PlatformFontList(); gfxPlatformFontList* pfl = gfxPlatformFontList::PlatformFontList();
gfxFontFamily* defaultFamily = pfl->GetDefaultFont(&mStyle); FontFamily defaultFamily = pfl->GetDefaultFont(&mStyle);
NS_ASSERTION(defaultFamily, NS_ASSERTION(!defaultFamily.mIsShared && defaultFamily.mUnshared,
"invalid default font returned by GetDefaultFont"); "invalid default font returned by GetDefaultFont");
if (defaultFamily) { if (defaultFamily.mUnshared) {
gfxFontEntry* fe = defaultFamily->FindFontForStyle(mStyle, true); gfxFontEntry* fe = defaultFamily.mUnshared->FindFontForStyle(mStyle, true);
if (fe) { if (fe) {
mDefaultFont = fe->FindOrMakeFont(&mStyle); mDefaultFont = fe->FindOrMakeFont(&mStyle);
} }
@ -3186,8 +3186,8 @@ gfxFont* gfxFontGroup::WhichPrefFontSupportsChar(uint32_t aCh,
numPrefs = families->Length(); numPrefs = families->Length();
for (j = 0; j < numPrefs; j++) { for (j = 0; j < numPrefs; j++) {
// look up the appropriate face // look up the appropriate face
gfxFontFamily* family = (*families)[j]; FontFamily family = (*families)[j];
if (!family) { if (family.IsNull()) {
continue; continue;
} }
@ -3199,7 +3199,7 @@ gfxFont* gfxFontGroup::WhichPrefFontSupportsChar(uint32_t aCh,
return mLastPrefFont; return mLastPrefFont;
} }
gfxFontEntry* fe = family->FindFontForStyle(mStyle); gfxFontEntry* fe = family.mUnshared->FindFontForStyle(mStyle);
if (!fe) { if (!fe) {
continue; continue;
} }
@ -3219,7 +3219,7 @@ gfxFont* gfxFontGroup::WhichPrefFontSupportsChar(uint32_t aCh,
// If the char was not available, see if we can fall back to an // If the char was not available, see if we can fall back to an
// alternative face in the same family. // alternative face in the same family.
gfxFont* prefFont = FindFallbackFaceForChar(family, aCh); gfxFont* prefFont = FindFallbackFaceForChar(family.mUnshared, aCh);
if (prefFont) { if (prefFont) {
mLastPrefFamily = family; mLastPrefFamily = family;
mLastPrefFont = prefFont; mLastPrefFont = prefFont;

Просмотреть файл

@ -1186,7 +1186,7 @@ class gfxFontGroup final : public gfxTextRunFactory {
RefPtr<gfxTextRun> mCachedEllipsisTextRun; RefPtr<gfxTextRun> mCachedEllipsisTextRun;
// cache the most recent pref font to avoid general pref font lookup // cache the most recent pref font to avoid general pref font lookup
RefPtr<gfxFontFamily> mLastPrefFamily; FontFamily mLastPrefFamily;
RefPtr<gfxFont> mLastPrefFont; RefPtr<gfxFont> mLastPrefFont;
eFontPrefLang mLastPrefLang; // lang group for last pref font eFontPrefLang mLastPrefLang; // lang group for last pref font
eFontPrefLang mPageLang; eFontPrefLang mPageLang;