Bug 935862 p2 - add various userfont lookup methods. r=heycam

This commit is contained in:
John Daggett 2015-03-06 17:44:18 +09:00
Родитель 0e183d4c4d
Коммит 16051fe356
5 изменённых файлов: 78 добавлений и 1 удалений

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

@ -9,6 +9,7 @@
#include "nsDebug.h" #include "nsDebug.h"
#include "nsISupportsImpl.h" #include "nsISupportsImpl.h"
#include "nsString.h" #include "nsString.h"
#include "nsUnicharUtils.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "mozilla/MemoryReporting.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; } FontFamilyType GetDefaultFontType() const { return mDefaultFontType; }
void SetDefaultFontType(FontFamilyType aType) { void SetDefaultFontType(FontFamilyType aType) {
NS_ASSERTION(aType == eFamily_none || aType == eFamily_serif || NS_ASSERTION(aType == eFamily_none || aType == eFamily_serif ||

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

@ -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 bool
gfxFontGroup::FontLoadingForFamily(gfxFontFamily* aFamily, uint32_t aCh) const 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 { struct PrefFontCallbackData {
explicit PrefFontCallbackData(nsTArray<nsRefPtr<gfxFontFamily> >& aFamiliesArray) explicit PrefFontCallbackData(nsTArray<nsRefPtr<gfxFontFamily> >& aFamiliesArray)
: mPrefFamilies(aFamiliesArray) : mPrefFamilies(aFamiliesArray)

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

@ -24,6 +24,7 @@
class gfxContext; class gfxContext;
class gfxFontGroup; class gfxFontGroup;
class gfxUserFontEntry;
class gfxUserFontSet; class gfxUserFontSet;
class gfxTextContextPaint; class gfxTextContextPaint;
class nsIAtom; class nsIAtom;
@ -864,6 +865,9 @@ public:
// caches need updating. // caches need updating.
virtual void UpdateUserFonts(); virtual void UpdateUserFonts();
// search for a specific userfont in the list of fonts
bool ContainsUserFont(const gfxUserFontEntry* aUserFont);
bool ShouldSkipDrawing() const { bool ShouldSkipDrawing() const {
return mSkipDrawing; return mSkipDrawing;
} }
@ -1002,6 +1006,8 @@ protected:
mLoading = false; mLoading = false;
} }
bool EqualsUserFont(const gfxUserFontEntry* aUserFont) const;
private: private:
nsRefPtr<gfxFontFamily> mFamily; nsRefPtr<gfxFontFamily> mFamily;
// either a font or a font entry exists // either a font or a font entry exists

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

@ -920,6 +920,21 @@ gfxUserFontSet::LookupFamily(const nsAString& aFamilyName) const
return mFontFamilies.GetWeak(key); 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* gfxUserFontFamily*
gfxUserFontSet::GetFamily(const nsAString& aFamilyName) gfxUserFontSet::GetFamily(const nsAString& aFamilyName)
{ {

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

@ -7,6 +7,7 @@
#define GFX_USER_FONT_SET_H #define GFX_USER_FONT_SET_H
#include "gfxFont.h" #include "gfxFont.h"
#include "gfxFontFamilyList.h"
#include "nsRefPtrHashtable.h" #include "nsRefPtrHashtable.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -238,6 +239,9 @@ public:
// the given name // the given name
gfxUserFontFamily* LookupFamily(const nsAString& aName) const; 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. // Lookup a font entry for a given style, returns null if not loaded.
// aFamily must be a family returned by our LookupFamily method. // aFamily must be a family returned by our LookupFamily method.
// (only used by gfxPangoFontGroup for now) // (only used by gfxPangoFontGroup for now)
@ -553,7 +557,7 @@ public:
virtual gfxFont* CreateFontInstance(const gfxFontStyle* aFontStyle, virtual gfxFont* CreateFontInstance(const gfxFontStyle* aFontStyle,
bool aNeedsBold); bool aNeedsBold);
gfxFontEntry* GetPlatformFontEntry() { return mPlatformFontEntry; } gfxFontEntry* GetPlatformFontEntry() const { return mPlatformFontEntry; }
// is the font loading or loaded, or did it fail? // is the font loading or loaded, or did it fail?
UserFontLoadState LoadState() const { return mUserFontLoadState; } UserFontLoadState LoadState() const { return mUserFontLoadState; }