2
* Copyright (C) 2006, 2008 Apple Computer, Inc. All rights reserved.
3
* Copyright (C) 2007-2008 Torch Mobile, Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
#include <wtf/Forward.h>
35
#include <wtf/PassRefPtr.h>
36
#include <wtf/RefPtr.h>
37
#include <wtf/Vector.h>
38
#include <wtf/text/WTFString.h>
39
#include <wtf/unicode/Unicode.h>
50
class FontPlatformData;
52
class FontDescription;
54
class OpenTypeVerticalData;
58
#if !OS(WINCE) || defined(IMLANG_FONT_LINK) && (IMLANG_FONT_LINK == 2)
59
typedef IMLangFontLink2 IMLangFontLinkType;
61
typedef IMLangFontLink IMLangFontLinkType;
66
friend class FontCachePurgePreventer;
68
WTF_MAKE_NONCOPYABLE(FontCache); WTF_MAKE_FAST_ALLOCATED;
70
friend FontCache* fontCache();
72
enum ShouldRetain { Retain, DoNotRetain };
74
PassRefPtr<FontData> getFontData(const Font&, int& familyIndex, FontSelector*);
75
void releaseFontData(const SimpleFontData*);
77
// This method is implemented by the platform.
78
PassRefPtr<SimpleFontData> getFontDataForCharacters(const Font&, const UChar* characters, int length);
80
// Also implemented by the platform.
84
IMLangFontLinkType* getFontLinkInterface();
86
static void comInitialize();
87
static void comUninitialize();
88
static IMultiLanguage* getMultiLanguageInterface();
92
void getTraitsInFamily(const AtomicString&, Vector<unsigned>&);
94
PassRefPtr<SimpleFontData> getCachedFontData(const FontDescription&, const AtomicString&, bool checkingAlternateName = false, ShouldRetain = Retain);
95
PassRefPtr<SimpleFontData> getLastResortFallbackFont(const FontDescription&, ShouldRetain = Retain);
96
SimpleFontData* getNonRetainedLastResortFallbackFont(const FontDescription&);
98
void addClient(FontSelector*);
99
void removeClient(FontSelector*);
101
unsigned short generation();
104
size_t fontDataCount();
105
size_t inactiveFontDataCount();
106
void purgeInactiveFontData(int count = INT_MAX);
109
PassRefPtr<SimpleFontData> fontDataFromDescriptionAndLogFont(const FontDescription&, ShouldRetain, const LOGFONT&, AtomicString& outFontFamilyName);
110
#elif PLATFORM(CHROMIUM) && OS(WINDOWS)
111
PassRefPtr<SimpleFontData> fontDataFromDescriptionAndLogFont(const FontDescription&, ShouldRetain, const LOGFONT&, wchar_t* outFontFamilyName);
114
#if ENABLE(OPENTYPE_VERTICAL)
116
typedef uint32_t FontFileKey;
118
typedef AtomicString FontFileKey;
120
PassRefPtr<OpenTypeVerticalData> getVerticalData(const FontFileKey&, const FontPlatformData&);
123
struct SimpleFontFamily {
128
static void getFontFamilyForCharacters(const UChar* characters, size_t numCharacters, const char* preferredLocale, SimpleFontFamily*);
134
void disablePurging() { m_purgePreventCount++; }
137
ASSERT(m_purgePreventCount);
138
if (!--m_purgePreventCount)
139
purgeInactiveFontDataIfNeeded();
142
void purgeInactiveFontDataIfNeeded();
144
// FIXME: This method should eventually be removed.
145
FontPlatformData* getCachedFontPlatformData(const FontDescription&, const AtomicString& family, bool checkingAlternateName = false);
147
// These methods are implemented by each platform.
148
PassRefPtr<SimpleFontData> getSimilarFontPlatformData(const Font&);
149
FontPlatformData* createFontPlatformData(const FontDescription&, const AtomicString& family);
151
PassRefPtr<SimpleFontData> getCachedFontData(const FontPlatformData*, ShouldRetain = Retain);
153
// Don't purge if this count is > 0;
154
int m_purgePreventCount;
156
#if PLATFORM(MAC) || (PLATFORM(CHROMIUM) && OS(DARWIN)) || OS(ANDROID)
157
friend class ComplexTextController;
159
friend class SimpleFontData; // For getCachedFontData(const FontPlatformData*)
160
friend class FontFallbackList;
163
// Get the global fontCache.
164
FontCache* fontCache();
166
class FontCachePurgePreventer {
168
FontCachePurgePreventer() { fontCache()->disablePurging(); }
169
~FontCachePurgePreventer() { fontCache()->enablePurging(); }