2009-08-16 17:52:12 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2011-01-21 19:44:33 +03:00
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#define FORCE_PR_LOG /* Allow logging in the release build */
|
|
|
|
#endif
|
|
|
|
#include "prlog.h"
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
#include "gfxPlatformFontList.h"
|
|
|
|
|
|
|
|
#include "nsUnicharUtils.h"
|
2011-01-21 19:44:33 +03:00
|
|
|
#include "nsUnicodeRange.h"
|
2012-02-24 14:15:46 +04:00
|
|
|
#include "nsUnicodeProperties.h"
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/Likely.h"
|
2011-06-12 06:30:16 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-07-27 10:42:53 +04:00
|
|
|
#include "mozilla/Telemetry.h"
|
2011-11-30 05:55:11 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2011-06-12 06:30:16 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
// font info loader constants
|
2012-08-22 19:56:38 +04:00
|
|
|
static const uint32_t kDelayBeforeLoadingCmaps = 8 * 1000; // 8secs
|
|
|
|
static const uint32_t kIntervalBetweenLoadingCmaps = 150; // 150ms
|
|
|
|
static const uint32_t kNumFontsPerSlice = 10; // read in info 10 fonts at a time
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2011-01-21 19:44:33 +03:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
|
|
|
|
#define LOG_FONTLIST(args) PR_LOG(gfxPlatform::GetLog(eGfxLog_fontlist), \
|
|
|
|
PR_LOG_DEBUG, args)
|
|
|
|
#define LOG_FONTLIST_ENABLED() PR_LOG_TEST( \
|
|
|
|
gfxPlatform::GetLog(eGfxLog_fontlist), \
|
|
|
|
PR_LOG_DEBUG)
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2011-01-21 19:44:33 +03:00
|
|
|
#endif // PR_LOGGING
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
gfxPlatformFontList *gfxPlatformFontList::sPlatformFontList = nullptr;
|
2009-08-16 17:52:12 +04:00
|
|
|
|
|
|
|
|
2011-06-12 06:30:16 +04:00
|
|
|
static const char* kObservedPrefs[] = {
|
|
|
|
"font.",
|
|
|
|
"font.name-list.",
|
|
|
|
"intl.accept_languages", // hmmmm...
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr
|
2011-06-12 06:30:16 +04:00
|
|
|
};
|
|
|
|
|
2012-06-13 08:14:28 +04:00
|
|
|
class gfxFontListPrefObserver MOZ_FINAL : public nsIObserver {
|
2009-08-16 17:52:12 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
};
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
static gfxFontListPrefObserver* gFontListPrefObserver = nullptr;
|
2011-06-12 06:30:16 +04:00
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(gfxFontListPrefObserver, nsIObserver)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
gfxFontListPrefObserver::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
|
|
|
const PRUnichar *aData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID), "invalid topic");
|
|
|
|
// XXX this could be made to only clear out the cache for the prefs that were changed
|
|
|
|
// but it probably isn't that big a deal.
|
|
|
|
gfxPlatformFontList::PlatformFontList()->ClearPrefFonts();
|
2009-10-07 21:16:52 +04:00
|
|
|
gfxFontCache::GetCache()->AgeAllGenerations();
|
2009-08-16 17:52:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-28 01:38:39 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(gfxPlatformFontList::MemoryReporter, nsIMemoryMultiReporter)
|
|
|
|
|
2012-12-24 04:59:51 +04:00
|
|
|
NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(FontListMallocSizeOf)
|
2012-03-28 01:38:39 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
gfxPlatformFontList::MemoryReporter::GetName(nsACString &aName)
|
|
|
|
{
|
|
|
|
aName.AssignLiteral("font-list");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
gfxPlatformFontList::MemoryReporter::CollectReports
|
|
|
|
(nsIMemoryMultiReporterCallback* aCb,
|
|
|
|
nsISupports* aClosure)
|
|
|
|
{
|
|
|
|
FontListSizes sizes;
|
|
|
|
sizes.mFontListSize = 0;
|
|
|
|
sizes.mFontTableCacheSize = 0;
|
|
|
|
sizes.mCharMapsSize = 0;
|
|
|
|
|
|
|
|
gfxPlatformFontList::PlatformFontList()->SizeOfIncludingThis(&FontListMallocSizeOf,
|
|
|
|
&sizes);
|
|
|
|
|
|
|
|
aCb->Callback(EmptyCString(),
|
|
|
|
NS_LITERAL_CSTRING("explicit/gfx/font-list"),
|
|
|
|
nsIMemoryReporter::KIND_HEAP, nsIMemoryReporter::UNITS_BYTES,
|
|
|
|
sizes.mFontListSize,
|
|
|
|
NS_LITERAL_CSTRING("Memory used to manage the list of font families and faces."),
|
|
|
|
aClosure);
|
|
|
|
|
|
|
|
aCb->Callback(EmptyCString(),
|
|
|
|
NS_LITERAL_CSTRING("explicit/gfx/font-charmaps"),
|
|
|
|
nsIMemoryReporter::KIND_HEAP, nsIMemoryReporter::UNITS_BYTES,
|
|
|
|
sizes.mCharMapsSize,
|
|
|
|
NS_LITERAL_CSTRING("Memory used to record the character coverage of individual fonts."),
|
|
|
|
aClosure);
|
|
|
|
|
|
|
|
if (sizes.mFontTableCacheSize) {
|
|
|
|
aCb->Callback(EmptyCString(),
|
|
|
|
NS_LITERAL_CSTRING("explicit/gfx/font-tables"),
|
|
|
|
nsIMemoryReporter::KIND_HEAP, nsIMemoryReporter::UNITS_BYTES,
|
|
|
|
sizes.mFontTableCacheSize,
|
|
|
|
NS_LITERAL_CSTRING("Memory used for cached font metrics and layout tables."),
|
|
|
|
aClosure);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxPlatformFontList::MemoryReporter::GetExplicitNonHeap(int64_t* aAmount)
|
2012-03-28 01:38:39 +04:00
|
|
|
{
|
|
|
|
// This reporter only measures heap memory.
|
|
|
|
*aAmount = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
gfxPlatformFontList::gfxPlatformFontList(bool aNeedFullnamePostscriptNames)
|
2010-01-29 04:41:25 +03:00
|
|
|
: mNeedFullnamePostscriptNames(aNeedFullnamePostscriptNames),
|
|
|
|
mStartIndex(0), mIncrement(kNumFontsPerSlice), mNumFamilies(0)
|
2009-08-16 17:52:12 +04:00
|
|
|
{
|
|
|
|
mFontFamilies.Init(100);
|
|
|
|
mOtherFamilyNames.Init(30);
|
2011-10-17 18:59:28 +04:00
|
|
|
mOtherFamilyNamesInitialized = false;
|
2010-01-29 04:41:25 +03:00
|
|
|
|
|
|
|
if (mNeedFullnamePostscriptNames) {
|
|
|
|
mFullnames.Init(100);
|
|
|
|
mPostscriptNames.Init(100);
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mFaceNamesInitialized = false;
|
2010-01-29 04:41:25 +03:00
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
mPrefFonts.Init(10);
|
|
|
|
|
2010-01-28 09:56:16 +03:00
|
|
|
mBadUnderlineFamilyNames.Init(10);
|
|
|
|
LoadBadUnderlineList();
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
// pref changes notification setup
|
2011-06-12 06:30:16 +04:00
|
|
|
NS_ASSERTION(!gFontListPrefObserver,
|
|
|
|
"There has been font list pref observer already");
|
|
|
|
gFontListPrefObserver = new gfxFontListPrefObserver();
|
|
|
|
NS_ADDREF(gFontListPrefObserver);
|
|
|
|
Preferences::AddStrongObservers(gFontListPrefObserver, kObservedPrefs);
|
2012-04-19 03:59:43 +04:00
|
|
|
|
|
|
|
mSharedCmaps.Init(16);
|
2012-12-19 13:42:25 +04:00
|
|
|
|
|
|
|
NS_RegisterMemoryMultiReporter(new MemoryReporter);
|
2011-06-12 06:30:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxPlatformFontList::~gfxPlatformFontList()
|
|
|
|
{
|
2012-04-19 03:59:43 +04:00
|
|
|
mSharedCmaps.Clear();
|
2011-06-12 06:30:16 +04:00
|
|
|
NS_ASSERTION(gFontListPrefObserver, "There is no font list pref observer");
|
|
|
|
Preferences::RemoveObservers(gFontListPrefObserver, kObservedPrefs);
|
|
|
|
NS_RELEASE(gFontListPrefObserver);
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 14:02:27 +03:00
|
|
|
nsresult
|
2010-01-29 04:41:25 +03:00
|
|
|
gfxPlatformFontList::InitFontList()
|
|
|
|
{
|
|
|
|
mFontFamilies.Clear();
|
|
|
|
mOtherFamilyNames.Clear();
|
2011-10-17 18:59:28 +04:00
|
|
|
mOtherFamilyNamesInitialized = false;
|
2010-01-29 04:41:25 +03:00
|
|
|
if (mNeedFullnamePostscriptNames) {
|
|
|
|
mFullnames.Clear();
|
|
|
|
mPostscriptNames.Clear();
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mFaceNamesInitialized = false;
|
2010-01-29 04:41:25 +03:00
|
|
|
mPrefFonts.Clear();
|
2012-12-19 13:42:25 +04:00
|
|
|
mReplacementCharFallbackFamily = nullptr;
|
2010-01-29 04:41:25 +03:00
|
|
|
CancelLoader();
|
|
|
|
|
|
|
|
// initialize ranges of characters for which system-wide font search should be skipped
|
|
|
|
mCodepointsWithNoFonts.reset();
|
|
|
|
mCodepointsWithNoFonts.SetRange(0,0x1f); // C0 controls
|
|
|
|
mCodepointsWithNoFonts.SetRange(0x7f,0x9f); // C1 controls
|
2010-11-08 14:02:27 +03:00
|
|
|
|
|
|
|
sPlatformFontList = this;
|
|
|
|
|
|
|
|
return NS_OK;
|
2010-01-29 04:41:25 +03:00
|
|
|
}
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
void
|
|
|
|
gfxPlatformFontList::GenerateFontListKey(const nsAString& aKeyName, nsAString& aResult)
|
|
|
|
{
|
|
|
|
aResult = aKeyName;
|
|
|
|
ToLowerCase(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatformFontList::InitOtherFamilyNames()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mOtherFamilyNamesInitialized = true;
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2011-07-27 10:42:53 +04:00
|
|
|
Telemetry::AutoTimer<Telemetry::FONTLIST_INITOTHERFAMILYNAMES> timer;
|
2009-08-16 17:52:12 +04:00
|
|
|
// iterate over all font families and read in other family names
|
|
|
|
mFontFamilies.Enumerate(gfxPlatformFontList::InitOtherFamilyNamesProc, this);
|
|
|
|
}
|
|
|
|
|
2012-09-25 20:18:38 +04:00
|
|
|
PLDHashOperator
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxPlatformFontList::InitOtherFamilyNamesProc(nsStringHashKey::KeyType aKey,
|
|
|
|
nsRefPtr<gfxFontFamily>& aFamilyEntry,
|
|
|
|
void* userArg)
|
|
|
|
{
|
|
|
|
gfxPlatformFontList *fc = static_cast<gfxPlatformFontList*>(userArg);
|
2010-01-29 04:41:25 +03:00
|
|
|
aFamilyEntry->ReadOtherFamilyNames(fc);
|
2009-08-16 17:52:12 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-29 04:41:25 +03:00
|
|
|
gfxPlatformFontList::InitFaceNameLists()
|
2009-08-16 17:52:12 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mFaceNamesInitialized = true;
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2010-01-29 04:41:25 +03:00
|
|
|
// iterate over all font families and read in other family names
|
2011-07-27 10:42:53 +04:00
|
|
|
Telemetry::AutoTimer<Telemetry::FONTLIST_INITFACENAMELISTS> timer;
|
2010-01-29 04:41:25 +03:00
|
|
|
mFontFamilies.Enumerate(gfxPlatformFontList::InitFaceNameListsProc, this);
|
|
|
|
}
|
|
|
|
|
2012-09-25 20:18:38 +04:00
|
|
|
PLDHashOperator
|
2010-01-29 04:41:25 +03:00
|
|
|
gfxPlatformFontList::InitFaceNameListsProc(nsStringHashKey::KeyType aKey,
|
|
|
|
nsRefPtr<gfxFontFamily>& aFamilyEntry,
|
|
|
|
void* userArg)
|
|
|
|
{
|
|
|
|
gfxPlatformFontList *fc = static_cast<gfxPlatformFontList*>(userArg);
|
|
|
|
aFamilyEntry->ReadFaceNames(fc, fc->NeedFullnamePostscriptNames());
|
|
|
|
return PL_DHASH_NEXT;
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatformFontList::PreloadNamesList()
|
|
|
|
{
|
|
|
|
nsAutoTArray<nsString, 10> preloadFonts;
|
|
|
|
gfxFontUtils::GetPrefsFontList("font.preload-names-list", preloadFonts);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numFonts = preloadFonts.Length();
|
|
|
|
for (uint32_t i = 0; i < numFonts; i++) {
|
2009-08-16 17:52:12 +04:00
|
|
|
nsAutoString key;
|
|
|
|
GenerateFontListKey(preloadFonts[i], key);
|
|
|
|
|
|
|
|
// only search canonical names!
|
2012-03-28 01:38:39 +04:00
|
|
|
gfxFontFamily *familyEntry = mFontFamilies.GetWeak(key);
|
2009-08-16 17:52:12 +04:00
|
|
|
if (familyEntry) {
|
2010-01-29 04:41:25 +03:00
|
|
|
familyEntry->ReadOtherFamilyNames(this);
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatformFontList::SetFixedPitch(const nsAString& aFamilyName)
|
|
|
|
{
|
|
|
|
gfxFontFamily *family = FindFamily(aFamilyName);
|
|
|
|
if (!family) return;
|
|
|
|
|
2009-10-13 03:43:43 +04:00
|
|
|
family->FindStyleVariations();
|
2009-08-16 17:52:12 +04:00
|
|
|
nsTArray<nsRefPtr<gfxFontEntry> >& fontlist = family->GetFontList();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i, numFonts = fontlist.Length();
|
2009-08-16 17:52:12 +04:00
|
|
|
|
|
|
|
for (i = 0; i < numFonts; i++) {
|
|
|
|
fontlist[i]->mFixedPitch = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-28 09:56:16 +03:00
|
|
|
gfxPlatformFontList::LoadBadUnderlineList()
|
2009-08-16 17:52:12 +04:00
|
|
|
{
|
|
|
|
nsAutoTArray<nsString, 10> blacklist;
|
|
|
|
gfxFontUtils::GetPrefsFontList("font.blacklist.underline_offset", blacklist);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numFonts = blacklist.Length();
|
|
|
|
for (uint32_t i = 0; i < numFonts; i++) {
|
2009-08-16 17:52:12 +04:00
|
|
|
nsAutoString key;
|
|
|
|
GenerateFontListKey(blacklist[i], key);
|
2011-11-09 00:22:04 +04:00
|
|
|
mBadUnderlineFamilyNames.PutEntry(key);
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxPlatformFontList::ResolveFontName(const nsAString& aFontName, nsAString& aResolvedFontName)
|
|
|
|
{
|
|
|
|
gfxFontFamily *family = FindFamily(aFontName);
|
|
|
|
if (family) {
|
|
|
|
aResolvedFontName = family->Name();
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct FontListData {
|
2010-02-24 20:57:57 +03:00
|
|
|
FontListData(nsIAtom *aLangGroup,
|
2009-08-16 17:52:12 +04:00
|
|
|
const nsACString& aGenericFamily,
|
|
|
|
nsTArray<nsString>& aListOfFonts) :
|
|
|
|
mLangGroup(aLangGroup), mGenericFamily(aGenericFamily),
|
|
|
|
mListOfFonts(aListOfFonts) {}
|
2010-02-24 20:57:57 +03:00
|
|
|
nsIAtom *mLangGroup;
|
2009-08-16 17:52:12 +04:00
|
|
|
const nsACString& mGenericFamily;
|
|
|
|
nsTArray<nsString>& mListOfFonts;
|
|
|
|
};
|
|
|
|
|
2012-09-25 20:18:38 +04:00
|
|
|
PLDHashOperator
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxPlatformFontList::HashEnumFuncForFamilies(nsStringHashKey::KeyType aKey,
|
|
|
|
nsRefPtr<gfxFontFamily>& aFamilyEntry,
|
|
|
|
void *aUserArg)
|
|
|
|
{
|
|
|
|
FontListData *data = static_cast<FontListData*>(aUserArg);
|
|
|
|
|
2009-10-07 18:13:40 +04:00
|
|
|
// use the first variation for now. This data should be the same
|
|
|
|
// for all the variations and should probably be moved up to
|
|
|
|
// the Family
|
|
|
|
gfxFontStyle style;
|
2010-02-24 20:57:44 +03:00
|
|
|
style.language = data->mLangGroup;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool needsBold;
|
2009-10-07 18:13:40 +04:00
|
|
|
nsRefPtr<gfxFontEntry> aFontEntry = aFamilyEntry->FindFontForStyle(style, needsBold);
|
|
|
|
NS_ASSERTION(aFontEntry, "couldn't find any font entry in family");
|
|
|
|
if (!aFontEntry)
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
|
|
|
|
/* skip symbol fonts */
|
|
|
|
if (aFontEntry->IsSymbolFont())
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
|
|
|
|
if (aFontEntry->SupportsLangGroup(data->mLangGroup) &&
|
|
|
|
aFontEntry->MatchesGenericFamily(data->mGenericFamily)) {
|
|
|
|
nsAutoString localizedFamilyName;
|
|
|
|
aFamilyEntry->LocalizedName(localizedFamilyName);
|
|
|
|
data->mListOfFonts.AppendElement(localizedFamilyName);
|
|
|
|
}
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-02-24 20:57:57 +03:00
|
|
|
gfxPlatformFontList::GetFontList(nsIAtom *aLangGroup,
|
2009-08-16 17:52:12 +04:00
|
|
|
const nsACString& aGenericFamily,
|
|
|
|
nsTArray<nsString>& aListOfFonts)
|
|
|
|
{
|
|
|
|
FontListData data(aLangGroup, aGenericFamily, aListOfFonts);
|
|
|
|
|
|
|
|
mFontFamilies.Enumerate(gfxPlatformFontList::HashEnumFuncForFamilies, &data);
|
|
|
|
|
|
|
|
aListOfFonts.Sort();
|
|
|
|
aListOfFonts.Compact();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct FontFamilyListData {
|
|
|
|
FontFamilyListData(nsTArray<nsRefPtr<gfxFontFamily> >& aFamilyArray)
|
|
|
|
: mFamilyArray(aFamilyArray)
|
|
|
|
{}
|
|
|
|
|
2012-09-25 20:18:38 +04:00
|
|
|
static PLDHashOperator AppendFamily(nsStringHashKey::KeyType aKey,
|
|
|
|
nsRefPtr<gfxFontFamily>& aFamilyEntry,
|
|
|
|
void *aUserArg)
|
2009-08-16 17:52:12 +04:00
|
|
|
{
|
|
|
|
FontFamilyListData *data = static_cast<FontFamilyListData*>(aUserArg);
|
|
|
|
data->mFamilyArray.AppendElement(aFamilyEntry);
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsRefPtr<gfxFontFamily> >& mFamilyArray;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatformFontList::GetFontFamilyList(nsTArray<nsRefPtr<gfxFontFamily> >& aFamilyArray)
|
|
|
|
{
|
|
|
|
FontFamilyListData data(aFamilyArray);
|
|
|
|
mFontFamilies.Enumerate(FontFamilyListData::AppendFamily, &data);
|
|
|
|
}
|
|
|
|
|
2012-03-09 06:05:24 +04:00
|
|
|
gfxFontEntry*
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxPlatformFontList::SystemFindFontForChar(const uint32_t aCh,
|
|
|
|
int32_t aRunScript,
|
2012-03-09 06:05:24 +04:00
|
|
|
const gfxFontStyle* aStyle)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
gfxFontEntry* fontEntry = nullptr;
|
2012-03-09 06:05:24 +04:00
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
// is codepoint with no matching font? return null immediately
|
|
|
|
if (mCodepointsWithNoFonts.test(aCh)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
2012-12-19 13:42:25 +04:00
|
|
|
// Try to short-circuit font fallback for U+FFFD, used to represent
|
|
|
|
// 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,
|
|
|
|
// etc.
|
|
|
|
if (aCh == 0xFFFD && mReplacementCharFallbackFamily) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool needsBold; // ignored in the system fallback case
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2012-12-19 13:42:25 +04:00
|
|
|
fontEntry =
|
|
|
|
mReplacementCharFallbackFamily->FindFontForStyle(*aStyle,
|
|
|
|
needsBold);
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2012-12-19 13:42:25 +04:00
|
|
|
// this should never fail, as we must have found U+FFFD in order to set
|
|
|
|
// mReplacementCharFallbackFamily at all, but better play it safe
|
|
|
|
if (fontEntry && fontEntry->TestCharacterMap(aCh)) {
|
2009-08-16 17:52:12 +04:00
|
|
|
return fontEntry;
|
2012-12-19 13:42:25 +04:00
|
|
|
}
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
2011-11-30 05:55:11 +04:00
|
|
|
TimeStamp start = TimeStamp::Now();
|
|
|
|
|
2012-03-09 06:05:24 +04:00
|
|
|
// search commonly available fonts
|
|
|
|
bool common = true;
|
2012-12-19 13:42:25 +04:00
|
|
|
gfxFontFamily *fallbackFamily = nullptr;
|
|
|
|
fontEntry = CommonFontFallback(aCh, aRunScript, aStyle, &fallbackFamily);
|
2012-03-09 06:05:24 +04:00
|
|
|
|
|
|
|
// if didn't find a font, do system-wide fallback (except for specials)
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t cmapCount = 0;
|
2012-03-09 06:05:24 +04:00
|
|
|
if (!fontEntry) {
|
|
|
|
common = false;
|
2012-12-19 13:42:25 +04:00
|
|
|
fontEntry = GlobalFontFallback(aCh, aRunScript, aStyle, cmapCount,
|
|
|
|
&fallbackFamily);
|
2012-03-09 06:05:24 +04:00
|
|
|
}
|
2011-11-30 05:55:11 +04:00
|
|
|
TimeDuration elapsed = TimeStamp::Now() - start;
|
|
|
|
|
2011-01-21 19:44:33 +03:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
PRLogModuleInfo *log = gfxPlatform::GetLog(eGfxLog_textrun);
|
|
|
|
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(log)) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t charRange = gfxFontUtils::CharRangeBit(aCh);
|
|
|
|
uint32_t unicodeRange = FindCharUnicodeRange(aCh);
|
|
|
|
int32_t script = mozilla::unicode::GetScriptCode(aCh);
|
2012-03-09 06:05:24 +04:00
|
|
|
PR_LOG(log, PR_LOG_WARNING,\
|
|
|
|
("(textrun-systemfallback-%s) char: u+%6.6x "
|
|
|
|
"char-range: %d unicode-range: %d script: %d match: [%s]"
|
|
|
|
" time: %dus cmaps: %d\n",
|
|
|
|
(common ? "common" : "global"), aCh,
|
|
|
|
charRange, unicodeRange, script,
|
|
|
|
(fontEntry ? NS_ConvertUTF16toUTF8(fontEntry->Name()).get() :
|
|
|
|
"<none>"),
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t(elapsed.ToMicroseconds()),
|
2012-03-09 06:05:24 +04:00
|
|
|
cmapCount));
|
2011-01-21 19:44:33 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
// no match? add to set of non-matching codepoints
|
2012-03-09 06:05:24 +04:00
|
|
|
if (!fontEntry) {
|
2012-12-19 13:42:25 +04:00
|
|
|
mCodepointsWithNoFonts.set(aCh);
|
|
|
|
} else if (aCh == 0xFFFD && fontEntry && fallbackFamily) {
|
|
|
|
mReplacementCharFallbackFamily = fallbackFamily;
|
|
|
|
}
|
2012-03-09 06:05:24 +04:00
|
|
|
|
|
|
|
// track system fallback time
|
|
|
|
static bool first = true;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t intElapsed = int32_t(first ? elapsed.ToMilliseconds() :
|
2011-11-30 05:55:11 +04:00
|
|
|
elapsed.ToMicroseconds());
|
|
|
|
Telemetry::Accumulate((first ? Telemetry::SYSTEM_FONT_FALLBACK_FIRST :
|
|
|
|
Telemetry::SYSTEM_FONT_FALLBACK),
|
|
|
|
intElapsed);
|
|
|
|
first = false;
|
|
|
|
|
2012-03-09 06:06:06 +04:00
|
|
|
// track the script for which fallback occurred (incremented one make it
|
|
|
|
// 1-based)
|
|
|
|
Telemetry::Accumulate(Telemetry::SYSTEM_FONT_FALLBACK_SCRIPT, aRunScript + 1);
|
|
|
|
|
2012-03-09 06:05:24 +04:00
|
|
|
return fontEntry;
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
2012-09-25 20:18:38 +04:00
|
|
|
PLDHashOperator
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxPlatformFontList::FindFontForCharProc(nsStringHashKey::KeyType aKey, nsRefPtr<gfxFontFamily>& aFamilyEntry,
|
|
|
|
void *userArg)
|
|
|
|
{
|
2012-03-09 06:05:24 +04:00
|
|
|
GlobalFontMatch *data = static_cast<GlobalFontMatch*>(userArg);
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2012-12-19 13:42:25 +04:00
|
|
|
// evaluate all fonts in this family for a match
|
|
|
|
aFamilyEntry->FindFontForChar(data);
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
2012-03-09 06:05:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NUM_FALLBACK_FONTS 8
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxPlatformFontList::CommonFontFallback(const uint32_t aCh,
|
|
|
|
int32_t aRunScript,
|
2012-12-19 13:42:25 +04:00
|
|
|
const gfxFontStyle* aMatchStyle,
|
|
|
|
gfxFontFamily** aMatchedFamily)
|
2012-03-09 06:05:24 +04:00
|
|
|
{
|
|
|
|
nsAutoTArray<const char*,NUM_FALLBACK_FONTS> defaultFallbacks;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i, numFallbacks;
|
2012-03-09 06:05:24 +04:00
|
|
|
|
|
|
|
gfxPlatform::GetPlatform()->GetCommonFallbackFonts(aCh, aRunScript,
|
|
|
|
defaultFallbacks);
|
|
|
|
numFallbacks = defaultFallbacks.Length();
|
|
|
|
for (i = 0; i < numFallbacks; i++) {
|
|
|
|
nsAutoString familyName;
|
|
|
|
const char *fallbackFamily = defaultFallbacks[i];
|
|
|
|
|
|
|
|
familyName.AppendASCII(fallbackFamily);
|
|
|
|
gfxFontFamily *fallback =
|
|
|
|
gfxPlatformFontList::PlatformFontList()->FindFamily(familyName);
|
|
|
|
if (!fallback)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gfxFontEntry *fontEntry;
|
|
|
|
bool needsBold; // ignored in the system fallback case
|
|
|
|
|
|
|
|
// use first font in list that supports a given character
|
|
|
|
fontEntry = fallback->FindFontForStyle(*aMatchStyle, needsBold);
|
|
|
|
if (fontEntry && fontEntry->TestCharacterMap(aCh)) {
|
2012-12-19 13:42:25 +04:00
|
|
|
*aMatchedFamily = fallback;
|
2012-03-09 06:05:24 +04:00
|
|
|
return fontEntry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-03-09 06:05:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxPlatformFontList::GlobalFontFallback(const uint32_t aCh,
|
|
|
|
int32_t aRunScript,
|
2012-03-09 06:05:24 +04:00
|
|
|
const gfxFontStyle* aMatchStyle,
|
2012-12-19 13:42:25 +04:00
|
|
|
uint32_t& aCmapCount,
|
|
|
|
gfxFontFamily** aMatchedFamily)
|
2012-03-09 06:05:24 +04:00
|
|
|
{
|
|
|
|
// otherwise, try to find it among local fonts
|
|
|
|
GlobalFontMatch data(aCh, aRunScript, aMatchStyle);
|
|
|
|
|
|
|
|
// iterate over all font families to find a font that support the character
|
|
|
|
mFontFamilies.Enumerate(gfxPlatformFontList::FindFontForCharProc, &data);
|
|
|
|
|
|
|
|
aCmapCount = data.mCmapsTested;
|
2012-12-19 13:42:25 +04:00
|
|
|
*aMatchedFamily = data.mMatchedFamily;
|
2012-03-09 06:05:24 +04:00
|
|
|
|
|
|
|
return data.mBestMatch;
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
2011-01-21 19:44:33 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
// crude hack for using when monitoring process
|
|
|
|
static void LogRegistryEvent(const wchar_t *msg)
|
|
|
|
{
|
|
|
|
HKEY dummyKey;
|
|
|
|
HRESULT hr;
|
|
|
|
wchar_t buf[512];
|
|
|
|
|
|
|
|
wsprintfW(buf, L" log %s", msg);
|
|
|
|
hr = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buf, 0, KEY_READ, &dummyKey);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
RegCloseKey(dummyKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxFontFamily*
|
|
|
|
gfxPlatformFontList::FindFamily(const nsAString& aFamily)
|
|
|
|
{
|
|
|
|
nsAutoString key;
|
|
|
|
gfxFontFamily *familyEntry;
|
|
|
|
GenerateFontListKey(aFamily, key);
|
|
|
|
|
2011-01-28 03:40:06 +03:00
|
|
|
NS_ASSERTION(mFontFamilies.Count() != 0, "system font list was not initialized correctly");
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
// lookup in canonical (i.e. English) family name list
|
2012-03-28 01:38:39 +04:00
|
|
|
if ((familyEntry = mFontFamilies.GetWeak(key))) {
|
2009-08-16 17:52:12 +04:00
|
|
|
return familyEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
// lookup in other family names list (mostly localized names)
|
2012-07-30 18:20:58 +04:00
|
|
|
if ((familyEntry = mOtherFamilyNames.GetWeak(key)) != nullptr) {
|
2009-08-16 17:52:12 +04:00
|
|
|
return familyEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
// name not found and other family names not yet fully initialized so
|
|
|
|
// initialize the rest of the list and try again. this is done lazily
|
2011-01-07 15:29:49 +03:00
|
|
|
// since reading name table entries is expensive.
|
|
|
|
// although ASCII localized family names are possible they don't occur
|
|
|
|
// in practice so avoid pulling in names at startup
|
|
|
|
if (!mOtherFamilyNamesInitialized && !IsASCII(aFamily)) {
|
2009-08-16 17:52:12 +04:00
|
|
|
InitOtherFamilyNames();
|
2012-07-30 18:20:58 +04:00
|
|
|
if ((familyEntry = mOtherFamilyNames.GetWeak(key)) != nullptr) {
|
2009-08-16 17:52:12 +04:00
|
|
|
return familyEntry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2011-09-29 10:19:26 +04:00
|
|
|
gfxPlatformFontList::FindFontForFamily(const nsAString& aFamily, const gfxFontStyle* aStyle, bool& aNeedsBold)
|
2009-08-16 17:52:12 +04:00
|
|
|
{
|
|
|
|
gfxFontFamily *familyEntry = FindFamily(aFamily);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
aNeedsBold = false;
|
2009-08-16 17:52:12 +04:00
|
|
|
|
|
|
|
if (familyEntry)
|
|
|
|
return familyEntry->FindFontForStyle(*aStyle, aNeedsBold);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxPlatformFontList::GetPrefFontFamilyEntries(eFontPrefLang aLangGroup, nsTArray<nsRefPtr<gfxFontFamily> > *array)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
return mPrefFonts.Get(uint32_t(aLangGroup), array);
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatformFontList::SetPrefFontFamilyEntries(eFontPrefLang aLangGroup, nsTArray<nsRefPtr<gfxFontFamily> >& array)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
mPrefFonts.Put(uint32_t(aLangGroup), array);
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatformFontList::AddOtherFamilyName(gfxFontFamily *aFamilyEntry, nsAString& aOtherFamilyName)
|
|
|
|
{
|
|
|
|
nsAutoString key;
|
|
|
|
GenerateFontListKey(aOtherFamilyName, key);
|
|
|
|
|
2012-03-28 01:38:39 +04:00
|
|
|
if (!mOtherFamilyNames.GetWeak(key)) {
|
2009-08-16 17:52:12 +04:00
|
|
|
mOtherFamilyNames.Put(key, aFamilyEntry);
|
2011-01-21 19:44:33 +03:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
LOG_FONTLIST(("(fontlist-otherfamily) canonical family: %s, "
|
|
|
|
"other family: %s\n",
|
|
|
|
NS_ConvertUTF16toUTF8(aFamilyEntry->Name()).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(aOtherFamilyName).get()));
|
|
|
|
#endif
|
2010-02-11 15:00:07 +03:00
|
|
|
if (mBadUnderlineFamilyNames.Contains(key))
|
2010-01-28 09:56:16 +03:00
|
|
|
aFamilyEntry->SetBadUnderlineFamily();
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-29 04:41:25 +03:00
|
|
|
void
|
|
|
|
gfxPlatformFontList::AddFullname(gfxFontEntry *aFontEntry, nsAString& aFullname)
|
|
|
|
{
|
2012-03-28 01:38:39 +04:00
|
|
|
if (!mFullnames.GetWeak(aFullname)) {
|
2010-01-29 04:41:25 +03:00
|
|
|
mFullnames.Put(aFullname, aFontEntry);
|
2011-01-21 19:44:33 +03:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
LOG_FONTLIST(("(fontlist-fullname) name: %s, fullname: %s\n",
|
|
|
|
NS_ConvertUTF16toUTF8(aFontEntry->Name()).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(aFullname).get()));
|
|
|
|
#endif
|
2010-01-29 04:41:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatformFontList::AddPostscriptName(gfxFontEntry *aFontEntry, nsAString& aPostscriptName)
|
|
|
|
{
|
2012-03-28 01:38:39 +04:00
|
|
|
if (!mPostscriptNames.GetWeak(aPostscriptName)) {
|
2010-01-29 04:41:25 +03:00
|
|
|
mPostscriptNames.Put(aPostscriptName, aFontEntry);
|
2011-01-21 19:44:33 +03:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
LOG_FONTLIST(("(fontlist-postscript) name: %s, psname: %s\n",
|
|
|
|
NS_ConvertUTF16toUTF8(aFontEntry->Name()).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(aPostscriptName).get()));
|
|
|
|
#endif
|
2010-01-29 04:41:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-10-07 18:13:40 +04:00
|
|
|
gfxPlatformFontList::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
|
|
|
{
|
|
|
|
aFamilyName.Truncate();
|
|
|
|
ResolveFontName(aFontName, aFamilyName);
|
|
|
|
return !aFamilyName.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2012-04-19 03:59:43 +04:00
|
|
|
gfxCharacterMap*
|
|
|
|
gfxPlatformFontList::FindCharMap(gfxCharacterMap *aCmap)
|
|
|
|
{
|
|
|
|
aCmap->CalcHash();
|
|
|
|
gfxCharacterMap *cmap = AddCmap(aCmap);
|
|
|
|
cmap->mShared = true;
|
|
|
|
return cmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add a cmap to the shared cmap set
|
|
|
|
gfxCharacterMap*
|
|
|
|
gfxPlatformFontList::AddCmap(const gfxCharacterMap* aCharMap)
|
|
|
|
{
|
|
|
|
CharMapHashKey *found =
|
|
|
|
mSharedCmaps.PutEntry(const_cast<gfxCharacterMap*>(aCharMap));
|
|
|
|
return found->GetKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove the cmap from the shared cmap set
|
|
|
|
void
|
|
|
|
gfxPlatformFontList::RemoveCmap(const gfxCharacterMap* aCharMap)
|
|
|
|
{
|
|
|
|
// skip lookups during teardown
|
|
|
|
if (mSharedCmaps.Count() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// cmap needs to match the entry *and* be the same ptr before removing
|
|
|
|
CharMapHashKey *found =
|
|
|
|
mSharedCmaps.GetEntry(const_cast<gfxCharacterMap*>(aCharMap));
|
|
|
|
if (found && found->GetKey() == aCharMap) {
|
|
|
|
mSharedCmaps.RemoveEntry(const_cast<gfxCharacterMap*>(aCharMap));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
void
|
|
|
|
gfxPlatformFontList::InitLoader()
|
|
|
|
{
|
|
|
|
GetFontFamilyList(mFontFamiliesToLoad);
|
|
|
|
mStartIndex = 0;
|
|
|
|
mNumFamilies = mFontFamiliesToLoad.Length();
|
|
|
|
}
|
|
|
|
|
2012-03-09 06:05:40 +04:00
|
|
|
bool
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxPlatformFontList::RunLoader()
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i, endIndex = (mStartIndex + mIncrement < mNumFamilies ? mStartIndex + mIncrement : mNumFamilies);
|
2012-03-09 06:05:40 +04:00
|
|
|
bool loadCmaps = !UsesSystemFallback() ||
|
|
|
|
gfxPlatform::GetPlatform()->UseCmapsDuringSystemFallback();
|
2009-08-16 17:52:12 +04:00
|
|
|
|
|
|
|
// for each font family, load in various font info
|
|
|
|
for (i = mStartIndex; i < endIndex; i++) {
|
2009-10-13 03:43:43 +04:00
|
|
|
gfxFontFamily* familyEntry = mFontFamiliesToLoad[i];
|
|
|
|
|
|
|
|
// find all faces that are members of this family
|
|
|
|
familyEntry->FindStyleVariations();
|
2010-02-11 14:59:47 +03:00
|
|
|
if (familyEntry->GetFontList().Length() == 0) {
|
|
|
|
// failed to load any faces for this family, so discard it
|
|
|
|
nsAutoString key;
|
|
|
|
GenerateFontListKey(familyEntry->Name(), key);
|
|
|
|
mFontFamilies.Remove(key);
|
|
|
|
continue;
|
|
|
|
}
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2012-03-09 06:05:40 +04:00
|
|
|
// load the cmaps if needed
|
|
|
|
if (loadCmaps) {
|
|
|
|
familyEntry->ReadAllCMAPs();
|
|
|
|
}
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2010-01-29 04:41:25 +03:00
|
|
|
// read in face names
|
|
|
|
familyEntry->ReadFaceNames(this, mNeedFullnamePostscriptNames);
|
2009-08-16 17:52:12 +04:00
|
|
|
|
|
|
|
// check whether the family can be considered "simple" for style matching
|
2009-10-13 03:43:43 +04:00
|
|
|
familyEntry->CheckForSimpleFamily();
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
2010-02-11 14:59:47 +03:00
|
|
|
mStartIndex = endIndex;
|
|
|
|
|
|
|
|
return (mStartIndex >= mNumFamilies);
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatformFontList::FinishLoader()
|
|
|
|
{
|
|
|
|
mFontFamiliesToLoad.Clear();
|
|
|
|
mNumFamilies = 0;
|
|
|
|
}
|
2012-03-28 01:38:39 +04:00
|
|
|
|
|
|
|
// Support for memory reporting
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
SizeOfFamilyEntryExcludingThis(const nsAString& aKey,
|
|
|
|
const nsRefPtr<gfxFontFamily>& aFamily,
|
|
|
|
nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
FontListSizes *sizes = static_cast<FontListSizes*>(aUserArg);
|
|
|
|
aFamily->SizeOfExcludingThis(aMallocSizeOf, sizes);
|
|
|
|
|
|
|
|
sizes->mFontListSize += aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
|
|
|
|
// we return zero here because the measurements have been added directly
|
|
|
|
// to the relevant fields of the FontListSizes record
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is also used by subclasses that hold additional hashes of family names
|
|
|
|
/*static*/ size_t
|
|
|
|
gfxPlatformFontList::SizeOfFamilyNameEntryExcludingThis
|
|
|
|
(const nsAString& aKey,
|
|
|
|
const nsRefPtr<gfxFontFamily>& aFamily,
|
|
|
|
nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
// we don't count the size of the family here, because this is an *extra*
|
|
|
|
// reference to a family that will have already been counted in the main list
|
|
|
|
return aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
SizeOfFontNameEntryExcludingThis(const nsAString& aKey,
|
|
|
|
const nsRefPtr<gfxFontEntry>& aFont,
|
|
|
|
nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
// the font itself is counted by its owning family; here we only care about
|
|
|
|
// the name stored in the hashtable key
|
|
|
|
return aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
SizeOfPrefFontEntryExcludingThis
|
2012-08-22 19:56:38 +04:00
|
|
|
(const uint32_t& aKey,
|
2012-03-28 01:38:39 +04:00
|
|
|
const nsTArray<nsRefPtr<gfxFontFamily> >& aList,
|
|
|
|
nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
// again, we only care about the size of the array itself; we don't follow
|
|
|
|
// the refPtrs stored in it, because they point to entries already owned
|
|
|
|
// and accounted-for by the main font list
|
|
|
|
return aList.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
SizeOfStringEntryExcludingThis(nsStringHashKey* aHashEntry,
|
|
|
|
nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
return aHashEntry->GetKey().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2012-04-19 03:59:43 +04:00
|
|
|
static size_t
|
|
|
|
SizeOfSharedCmapExcludingThis(CharMapHashKey* aHashEntry,
|
|
|
|
nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
FontListSizes *sizes = static_cast<FontListSizes*>(aUserArg);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t size = aHashEntry->GetKey()->SizeOfIncludingThis(aMallocSizeOf);
|
2012-04-19 03:59:43 +04:00
|
|
|
sizes->mCharMapsSize += size;
|
|
|
|
|
|
|
|
// we return zero here because the measurements have been added directly
|
|
|
|
// to the relevant fields of the FontListSizes record
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-28 01:38:39 +04:00
|
|
|
void
|
|
|
|
gfxPlatformFontList::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
FontListSizes* aSizes) const
|
|
|
|
{
|
|
|
|
aSizes->mFontListSize +=
|
|
|
|
mFontFamilies.SizeOfExcludingThis(SizeOfFamilyEntryExcludingThis,
|
|
|
|
aMallocSizeOf, aSizes);
|
|
|
|
|
|
|
|
aSizes->mFontListSize +=
|
|
|
|
mOtherFamilyNames.SizeOfExcludingThis(SizeOfFamilyNameEntryExcludingThis,
|
|
|
|
aMallocSizeOf);
|
|
|
|
|
|
|
|
if (mNeedFullnamePostscriptNames) {
|
|
|
|
aSizes->mFontListSize +=
|
|
|
|
mFullnames.SizeOfExcludingThis(SizeOfFontNameEntryExcludingThis,
|
|
|
|
aMallocSizeOf);
|
|
|
|
aSizes->mFontListSize +=
|
|
|
|
mPostscriptNames.SizeOfExcludingThis(SizeOfFontNameEntryExcludingThis,
|
|
|
|
aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
aSizes->mFontListSize +=
|
|
|
|
mCodepointsWithNoFonts.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
aSizes->mFontListSize +=
|
|
|
|
mFontFamiliesToLoad.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
aSizes->mFontListSize +=
|
|
|
|
mPrefFonts.SizeOfExcludingThis(SizeOfPrefFontEntryExcludingThis,
|
|
|
|
aMallocSizeOf);
|
|
|
|
|
|
|
|
aSizes->mFontListSize +=
|
|
|
|
mBadUnderlineFamilyNames.SizeOfExcludingThis(SizeOfStringEntryExcludingThis,
|
|
|
|
aMallocSizeOf);
|
2012-04-19 03:59:43 +04:00
|
|
|
|
|
|
|
aSizes->mFontListSize +=
|
|
|
|
mSharedCmaps.SizeOfExcludingThis(SizeOfSharedCmapExcludingThis,
|
|
|
|
aMallocSizeOf, aSizes);
|
2012-03-28 01:38:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatformFontList::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
FontListSizes* aSizes) const
|
|
|
|
{
|
|
|
|
aSizes->mFontListSize += aMallocSizeOf(this);
|
|
|
|
SizeOfExcludingThis(aMallocSizeOf, aSizes);
|
|
|
|
}
|