This source file includes following definitions.
- m_hasLoadingFallback
- invalidate
- releaseFontData
- determinePitch
- loadingCustomFonts
- shouldSkipDrawing
- primaryFontData
- getFontData
- fontDataAt
#include "config.h"
#include "platform/fonts/FontFallbackList.h"
#include "FontFamilyNames.h"
#include "platform/fonts/FontCache.h"
#include "platform/fonts/FontDescription.h"
#include "platform/fonts/FontFamily.h"
#include "platform/fonts/SegmentedFontData.h"
namespace WebCore {
FontFallbackList::FontFallbackList()
: m_pageZero(0)
, m_cachedPrimarySimpleFontData(0)
, m_fontSelector(nullptr)
, m_fontSelectorVersion(0)
, m_familyIndex(0)
, m_generation(FontCache::fontCache()->generation())
, m_pitch(UnknownPitch)
, m_hasLoadingFallback(false)
{
}
void FontFallbackList::invalidate(PassRefPtr<FontSelector> fontSelector)
{
releaseFontData();
m_fontList.clear();
m_pageZero = 0;
m_pages.clear();
m_cachedPrimarySimpleFontData = 0;
m_familyIndex = 0;
m_pitch = UnknownPitch;
m_hasLoadingFallback = false;
m_fontSelector = fontSelector;
m_fontSelectorVersion = m_fontSelector ? m_fontSelector->version() : 0;
m_generation = FontCache::fontCache()->generation();
m_widthCache.clear();
}
void FontFallbackList::releaseFontData()
{
unsigned numFonts = m_fontList.size();
for (unsigned i = 0; i < numFonts; ++i) {
if (!m_fontList[i]->isCustomFont()) {
ASSERT(!m_fontList[i]->isSegmented());
FontCache::fontCache()->releaseFontData(static_cast<const SimpleFontData*>(m_fontList[i].get()));
}
}
}
void FontFallbackList::determinePitch(const FontDescription& fontDescription) const
{
const FontData* fontData = primaryFontData(fontDescription);
if (!fontData->isSegmented())
m_pitch = static_cast<const SimpleFontData*>(fontData)->pitch();
else {
const SegmentedFontData* segmentedFontData = static_cast<const SegmentedFontData*>(fontData);
unsigned numRanges = segmentedFontData->numRanges();
if (numRanges == 1 && segmentedFontData->rangeAt(0).isEntireRange())
m_pitch = segmentedFontData->rangeAt(0).fontData()->pitch();
else
m_pitch = VariablePitch;
}
}
bool FontFallbackList::loadingCustomFonts() const
{
if (!m_hasLoadingFallback)
return false;
unsigned numFonts = m_fontList.size();
for (unsigned i = 0; i < numFonts; ++i) {
if (m_fontList[i]->isLoading())
return true;
}
return false;
}
bool FontFallbackList::shouldSkipDrawing() const
{
if (!m_hasLoadingFallback)
return false;
unsigned numFonts = m_fontList.size();
for (unsigned i = 0; i < numFonts; ++i) {
if (m_fontList[i]->shouldSkipDrawing())
return true;
}
return false;
}
const FontData* FontFallbackList::primaryFontData(const FontDescription& fontDescription) const
{
bool shouldLoadCustomFont = true;
for (unsigned fontIndex = 0; ; ++fontIndex) {
const FontData* fontData = fontDataAt(fontDescription, fontIndex);
if (!fontData) {
fontData = fontDataAt(fontDescription, 0);
if (!fontData)
fontData = FontCache::fontCache()->getLastResortFallbackFont(fontDescription).get();
ASSERT(fontData);
return fontData;
}
if (fontData->isSegmented() && !toSegmentedFontData(fontData)->containsCharacter(' '))
continue;
if (!fontData->isLoadingFallback())
return fontData;
if (shouldLoadCustomFont) {
shouldLoadCustomFont = false;
const SimpleFontData* simpleFontData = fontData->fontDataForCharacter(' ');
if (simpleFontData && simpleFontData->customFontData())
simpleFontData->customFontData()->beginLoadIfNeeded();
}
}
}
PassRefPtr<FontData> FontFallbackList::getFontData(const FontDescription& fontDescription, int& familyIndex) const
{
RefPtr<FontData> result;
int startIndex = familyIndex;
const FontFamily* startFamily = &fontDescription.family();
for (int i = 0; startFamily && i < startIndex; i++)
startFamily = startFamily->next();
const FontFamily* currFamily = startFamily;
while (currFamily && !result) {
familyIndex++;
if (currFamily->family().length()) {
if (m_fontSelector)
result = m_fontSelector->getFontData(fontDescription, currFamily->family());
if (!result)
result = FontCache::fontCache()->getFontData(fontDescription, currFamily->family());
}
currFamily = currFamily->next();
}
if (!currFamily)
familyIndex = cAllFamiliesScanned;
if (result || startIndex)
return result.release();
if (m_fontSelector) {
if (RefPtr<FontData> data = m_fontSelector->getFontData(fontDescription, FontFamilyNames::webkit_standard))
return data.release();
}
return FontCache::fontCache()->getLastResortFallbackFont(fontDescription);
}
const FontData* FontFallbackList::fontDataAt(const FontDescription& fontDescription, unsigned realizedFontIndex) const
{
if (realizedFontIndex < m_fontList.size())
return m_fontList[realizedFontIndex].get();
ASSERT(realizedFontIndex == m_fontList.size());
if (m_familyIndex == cAllFamiliesScanned)
return 0;
ASSERT(FontCache::fontCache()->generation() == m_generation);
RefPtr<FontData> result = getFontData(fontDescription, m_familyIndex);
if (result) {
m_fontList.append(result);
if (result->isLoadingFallback())
m_hasLoadingFallback = true;
}
return result.get();
}
}