This source file includes following definitions.
- m_firstNonCssConnectedFace
- pruneTable
- isValid
- fontLoaded
- fontLoadWaitLimitExceeded
- addFontFace
- removeFontFace
- appendFontData
- getFontData
- isLoading
- isLoaded
- willUseFontData
- checkFont
- match
#include "config.h"
#include "core/css/CSSSegmentedFontFace.h"
#include "RuntimeEnabledFeatures.h"
#include "core/css/CSSFontFace.h"
#include "core/css/CSSFontSelector.h"
#include "platform/fonts/FontCache.h"
#include "platform/fonts/FontDescription.h"
#include "platform/fonts/SegmentedFontData.h"
#include "platform/fonts/SimpleFontData.h"
namespace WebCore {
CSSSegmentedFontFace::CSSSegmentedFontFace(CSSFontSelector* fontSelector, FontTraits traits)
: m_fontSelector(fontSelector)
, m_traits(traits)
, m_firstNonCssConnectedFace(m_fontFaces.end())
{
}
CSSSegmentedFontFace::~CSSSegmentedFontFace()
{
pruneTable();
for (FontFaceList::iterator it = m_fontFaces.begin(); it != m_fontFaces.end(); ++it)
(*it)->cssFontFace()->clearSegmentedFontFace();
}
void CSSSegmentedFontFace::pruneTable()
{
if (m_fontDataTable.isEmpty())
return;
m_fontDataTable.clear();
}
bool CSSSegmentedFontFace::isValid() const
{
for (FontFaceList::const_iterator it = m_fontFaces.begin(); it != m_fontFaces.end(); ++it) {
if ((*it)->cssFontFace()->isValid())
return true;
}
return false;
}
void CSSSegmentedFontFace::fontLoaded(CSSFontFace*)
{
pruneTable();
}
void CSSSegmentedFontFace::fontLoadWaitLimitExceeded(CSSFontFace*)
{
m_fontSelector->fontLoaded();
pruneTable();
}
void CSSSegmentedFontFace::addFontFace(PassRefPtr<FontFace> prpFontFace, bool cssConnected)
{
RefPtr<FontFace> fontFace = prpFontFace;
pruneTable();
fontFace->cssFontFace()->setSegmentedFontFace(this);
if (cssConnected) {
m_fontFaces.insertBefore(m_firstNonCssConnectedFace, fontFace);
} else {
FontFaceList::iterator iterator = m_fontFaces.addReturnIterator(fontFace);
if (m_firstNonCssConnectedFace == m_fontFaces.end())
m_firstNonCssConnectedFace = iterator;
}
}
void CSSSegmentedFontFace::removeFontFace(PassRefPtr<FontFace> prpFontFace)
{
RefPtr<FontFace> fontFace = prpFontFace;
FontFaceList::iterator it = m_fontFaces.find(fontFace);
if (it == m_fontFaces.end())
return;
if (it == m_firstNonCssConnectedFace)
++m_firstNonCssConnectedFace;
m_fontFaces.remove(it);
pruneTable();
fontFace->cssFontFace()->clearSegmentedFontFace();
}
static void appendFontData(SegmentedFontData* newFontData, PassRefPtr<SimpleFontData> prpFaceFontData, const CSSFontFace::UnicodeRangeSet& ranges)
{
RefPtr<SimpleFontData> faceFontData = prpFaceFontData;
unsigned numRanges = ranges.size();
if (!numRanges) {
newFontData->appendRange(FontDataRange(0, 0x7FFFFFFF, faceFontData));
return;
}
for (unsigned j = 0; j < numRanges; ++j)
newFontData->appendRange(FontDataRange(ranges.rangeAt(j).from(), ranges.rangeAt(j).to(), faceFontData));
}
PassRefPtr<FontData> CSSSegmentedFontFace::getFontData(const FontDescription& fontDescription)
{
if (!isValid())
return nullptr;
FontTraits desiredTraits = fontDescription.traits();
AtomicString emptyFontFamily = "";
FontCacheKey key = fontDescription.cacheKey(emptyFontFamily, desiredTraits);
RefPtr<SegmentedFontData>& fontData = m_fontDataTable.add(key.hash(), nullptr).storedValue->value;
if (fontData && fontData->numRanges())
return fontData;
if (!fontData)
fontData = SegmentedFontData::create();
FontDescription requestedFontDescription(fontDescription);
requestedFontDescription.setTraits(m_traits);
requestedFontDescription.setSyntheticBold(m_traits.weight() < FontWeight600 && desiredTraits.weight() >= FontWeight600);
requestedFontDescription.setSyntheticItalic(m_traits.style() == FontStyleNormal && desiredTraits.style() == FontStyleItalic);
for (FontFaceList::reverse_iterator it = m_fontFaces.rbegin(); it != m_fontFaces.rend(); ++it) {
if (!(*it)->cssFontFace()->isValid())
continue;
if (RefPtr<SimpleFontData> faceFontData = (*it)->cssFontFace()->getFontData(requestedFontDescription)) {
ASSERT(!faceFontData->isSegmented());
#if ENABLE(SVG_FONTS)
if (faceFontData->isSVGFont() && desiredTraits.variant() == FontVariantSmallCaps && m_traits.variant() == FontVariantNormal)
continue;
#endif
appendFontData(fontData.get(), faceFontData.release(), (*it)->cssFontFace()->ranges());
}
}
if (fontData->numRanges())
return fontData;
return nullptr;
}
bool CSSSegmentedFontFace::isLoading() const
{
for (FontFaceList::const_iterator it = m_fontFaces.begin(); it != m_fontFaces.end(); ++it) {
if ((*it)->loadStatus() == FontFace::Loading)
return true;
}
return false;
}
bool CSSSegmentedFontFace::isLoaded() const
{
for (FontFaceList::const_iterator it = m_fontFaces.begin(); it != m_fontFaces.end(); ++it) {
if ((*it)->loadStatus() != FontFace::Loaded)
return false;
}
return true;
}
void CSSSegmentedFontFace::willUseFontData(const FontDescription& fontDescription)
{
for (FontFaceList::iterator it = m_fontFaces.begin(); it != m_fontFaces.end(); ++it)
(*it)->cssFontFace()->willUseFontData(fontDescription);
}
bool CSSSegmentedFontFace::checkFont(const String& text) const
{
for (FontFaceList::const_iterator it = m_fontFaces.begin(); it != m_fontFaces.end(); ++it) {
if ((*it)->loadStatus() != FontFace::Loaded && (*it)->cssFontFace()->ranges().intersectsWith(text))
return false;
}
return true;
}
void CSSSegmentedFontFace::match(const String& text, Vector<RefPtr<FontFace> >& faces) const
{
for (FontFaceList::const_iterator it = m_fontFaces.begin(); it != m_fontFaces.end(); ++it) {
if ((*it)->cssFontFace()->ranges().intersectsWith(text))
faces.append(*it);
}
}
}