#ifndef FontCache_h
#define FontCache_h
#include <limits.h>
#include <wtf/Forward.h>
#include <wtf/Vector.h>
#include <wtf/unicode/Unicode.h>
#if PLATFORM(WIN)
#include <objidl.h>
#include <mlang.h>
#endif
namespace WebCore
{
class Font;
class FontPlatformData;
class FontData;
class FontDescription;
class FontSelector;
class SimpleFontData;
class FontCache {
friend class FontCachePurgePreventer;
enum ShouldRetain { Retain, DoNotRetain };
WTF_MAKE_NONCOPYABLE(FontCache); WTF_MAKE_FAST_ALLOCATED;
public:
friend FontCache* fontCache();
const FontData* getFontData(const Font&, int& familyIndex, FontSelector*);
void releaseFontData(const SimpleFontData*);
const SimpleFontData* getFontDataForCharacters(const Font&, const UChar* characters, int length);
void platformInit();
#if OS(WINCE) && !PLATFORM(QT)
#if defined(IMLANG_FONT_LINK) && (IMLANG_FONT_LINK == 2)
IMLangFontLink2* getFontLinkInterface();
#else
IMLangFontLink* getFontLinkInterface();
#endif
static void comInitialize();
static void comUninitialize();
static IMultiLanguage* getMultiLanguageInterface();
#elif PLATFORM(WIN)
IMLangFontLink2* getFontLinkInterface();
#endif
void getTraitsInFamily(const AtomicString&, Vector<unsigned>&);
SimpleFontData* getCachedFontData(const FontDescription&, const AtomicString&, bool checkingAlternateName = false, ShouldRetain = Retain);
SimpleFontData* getLastResortFallbackFont(const FontDescription&);
void addClient(FontSelector*);
void removeClient(FontSelector*);
unsigned generation();
void invalidate();
size_t fontDataCount();
size_t inactiveFontDataCount();
void purgeInactiveFontData(int count = INT_MAX);
private:
FontCache();
~FontCache();
void disablePurging() { m_purgePreventCount++; }
void enablePurging()
{
ASSERT(m_purgePreventCount);
if (!--m_purgePreventCount)
purgeInactiveFontDataIfNeeded();
}
void purgeInactiveFontDataIfNeeded();
FontPlatformData* getCachedFontPlatformData(const FontDescription&, const AtomicString& family, bool checkingAlternateName = false);
SimpleFontData* getSimilarFontPlatformData(const Font&);
FontPlatformData* createFontPlatformData(const FontDescription&, const AtomicString& family);
SimpleFontData* getCachedFontData(const FontPlatformData*, ShouldRetain = Retain);
int m_purgePreventCount;
friend class SimpleFontData; friend class FontFallbackList;
};
FontCache* fontCache();
class FontCachePurgePreventer {
public:
FontCachePurgePreventer() { fontCache()->disablePurging(); }
~FontCachePurgePreventer() { fontCache()->enablePurging(); }
};
}
#endif