From 16051fe356d93169bfd6ea11f0e5e7dc299cb7dc Mon Sep 17 00:00:00 2001 From: John Daggett Date: Fri, 6 Mar 2015 17:44:18 +0900 Subject: [PATCH] Bug 935862 p2 - add various userfont lookup methods. r=heycam --- gfx/thebes/gfxFontFamilyList.h | 21 +++++++++++++++++++++ gfx/thebes/gfxTextRun.cpp | 31 +++++++++++++++++++++++++++++++ gfx/thebes/gfxTextRun.h | 6 ++++++ gfx/thebes/gfxUserFontSet.cpp | 15 +++++++++++++++ gfx/thebes/gfxUserFontSet.h | 6 +++++- 5 files changed, 78 insertions(+), 1 deletion(-) diff --git a/gfx/thebes/gfxFontFamilyList.h b/gfx/thebes/gfxFontFamilyList.h index 1906fba828bd..c1d189d92cc3 100644 --- a/gfx/thebes/gfxFontFamilyList.h +++ b/gfx/thebes/gfxFontFamilyList.h @@ -9,6 +9,7 @@ #include "nsDebug.h" #include "nsISupportsImpl.h" #include "nsString.h" +#include "nsUnicharUtils.h" #include "nsTArray.h" #include "mozilla/MemoryReporting.h" @@ -280,6 +281,26 @@ public: } } + // searches for a specific non-generic name, lowercase comparison + bool Contains(const nsAString& aFamilyName) const { + uint32_t len = mFontlist.Length(); + nsAutoString fam(aFamilyName); + ToLowerCase(fam); + for (uint32_t i = 0; i < len; i++) { + const FontFamilyName& name = mFontlist[i]; + if (name.mType != eFamily_named && + name.mType != eFamily_named_quoted) { + continue; + } + nsAutoString listname(name.mName); + ToLowerCase(listname); + if (listname.Equals(fam)) { + return true; + } + } + return false; + } + FontFamilyType GetDefaultFontType() const { return mDefaultFontType; } void SetDefaultFontType(FontFamilyType aType) { NS_ASSERTION(aType == eFamily_none || aType == eFamily_serif || diff --git a/gfx/thebes/gfxTextRun.cpp b/gfx/thebes/gfxTextRun.cpp index f5ba248bd24e..e068b8c37947 100644 --- a/gfx/thebes/gfxTextRun.cpp +++ b/gfx/thebes/gfxTextRun.cpp @@ -1802,6 +1802,22 @@ gfxFontGroup::FamilyFace::CheckState(bool& aSkipDrawing) } } +bool +gfxFontGroup::FamilyFace::EqualsUserFont(const gfxUserFontEntry* aUserFont) const +{ + gfxFontEntry* fe = FontEntry(); + // if there's a font, the entry is the underlying platform font + if (mFontCreated) { + gfxFontEntry* pfe = aUserFont->GetPlatformFontEntry(); + if (pfe == fe) { + return true; + } + } else if (fe == aUserFont) { + return true; + } + return false; +} + bool gfxFontGroup::FontLoadingForFamily(gfxFontFamily* aFamily, uint32_t aCh) const { @@ -3030,6 +3046,21 @@ gfxFontGroup::UpdateUserFonts() } } +bool +gfxFontGroup::ContainsUserFont(const gfxUserFontEntry* aUserFont) +{ + UpdateUserFonts(); + // search through the fonts list for a specific user font + uint32_t len = mFonts.Length(); + for (uint32_t i = 0; i < len; i++) { + FamilyFace& ff = mFonts[i]; + if (ff.EqualsUserFont(aUserFont)) { + return true; + } + } + return false; +} + struct PrefFontCallbackData { explicit PrefFontCallbackData(nsTArray >& aFamiliesArray) : mPrefFamilies(aFamiliesArray) diff --git a/gfx/thebes/gfxTextRun.h b/gfx/thebes/gfxTextRun.h index f9c8d83679ab..08bf8a200105 100644 --- a/gfx/thebes/gfxTextRun.h +++ b/gfx/thebes/gfxTextRun.h @@ -24,6 +24,7 @@ class gfxContext; class gfxFontGroup; +class gfxUserFontEntry; class gfxUserFontSet; class gfxTextContextPaint; class nsIAtom; @@ -864,6 +865,9 @@ public: // caches need updating. virtual void UpdateUserFonts(); + // search for a specific userfont in the list of fonts + bool ContainsUserFont(const gfxUserFontEntry* aUserFont); + bool ShouldSkipDrawing() const { return mSkipDrawing; } @@ -1002,6 +1006,8 @@ protected: mLoading = false; } + bool EqualsUserFont(const gfxUserFontEntry* aUserFont) const; + private: nsRefPtr mFamily; // either a font or a font entry exists diff --git a/gfx/thebes/gfxUserFontSet.cpp b/gfx/thebes/gfxUserFontSet.cpp index f1dd9f94e4b4..21a65f3cfa9e 100644 --- a/gfx/thebes/gfxUserFontSet.cpp +++ b/gfx/thebes/gfxUserFontSet.cpp @@ -920,6 +920,21 @@ gfxUserFontSet::LookupFamily(const nsAString& aFamilyName) const return mFontFamilies.GetWeak(key); } +bool +gfxUserFontSet::ContainsUserFontSetFonts(const FontFamilyList& aFontList) const +{ + for (const FontFamilyName& name : aFontList.GetFontlist()) { + if (name.mType != eFamily_named && + name.mType != eFamily_named_quoted) { + continue; + } + if (LookupFamily(name.mName)) { + return true; + } + } + return false; +} + gfxUserFontFamily* gfxUserFontSet::GetFamily(const nsAString& aFamilyName) { diff --git a/gfx/thebes/gfxUserFontSet.h b/gfx/thebes/gfxUserFontSet.h index 20fce3d6ec0c..422b4c10c77f 100644 --- a/gfx/thebes/gfxUserFontSet.h +++ b/gfx/thebes/gfxUserFontSet.h @@ -7,6 +7,7 @@ #define GFX_USER_FONT_SET_H #include "gfxFont.h" +#include "gfxFontFamilyList.h" #include "nsRefPtrHashtable.h" #include "nsAutoPtr.h" #include "nsCOMPtr.h" @@ -238,6 +239,9 @@ public: // the given name gfxUserFontFamily* LookupFamily(const nsAString& aName) const; + // Look up names in a fontlist and return true if any are in the set + bool ContainsUserFontSetFonts(const mozilla::FontFamilyList& aFontList) const; + // Lookup a font entry for a given style, returns null if not loaded. // aFamily must be a family returned by our LookupFamily method. // (only used by gfxPangoFontGroup for now) @@ -553,7 +557,7 @@ public: virtual gfxFont* CreateFontInstance(const gfxFontStyle* aFontStyle, bool aNeedsBold); - gfxFontEntry* GetPlatformFontEntry() { return mPlatformFontEntry; } + gfxFontEntry* GetPlatformFontEntry() const { return mPlatformFontEntry; } // is the font loading or loaded, or did it fail? UserFontLoadState LoadState() const { return mUserFontLoadState; }