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
parent 0e183d4c4d
commit 16051fe356
5 changed files with 78 additions and 1 deletions

View File

@ -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 ||

View File

@ -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<nsRefPtr<gfxFontFamily> >& aFamiliesArray)
: mPrefFamilies(aFamiliesArray)

View File

@ -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<gfxFontFamily> mFamily;
// either a font or a font entry exists

View File

@ -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)
{

View File

@ -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; }