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/Vector.h>
36 #include <wtf/unicode/Unicode.h>
48 class FontPlatformData;
50 class FontDescription;
55 friend class FontCachePurgePreventer;
57 WTF_MAKE_NONCOPYABLE(FontCache); WTF_MAKE_FAST_ALLOCATED;
59 friend FontCache* fontCache();
61 enum ShouldRetain { Retain, DoNotRetain };
63 const FontData* getFontData(const Font&, int& familyIndex, FontSelector*);
64 void releaseFontData(const SimpleFontData*);
66 // This method is implemented by the platform.
67 const SimpleFontData* getFontDataForCharacters(const Font&, const UChar* characters, int length);
69 // Also implemented by the platform.
72 #if OS(WINCE) && !PLATFORM(QT)
73 #if defined(IMLANG_FONT_LINK) && (IMLANG_FONT_LINK == 2)
74 IMLangFontLink2* getFontLinkInterface();
76 IMLangFontLink* getFontLinkInterface();
78 static void comInitialize();
79 static void comUninitialize();
80 static IMultiLanguage* getMultiLanguageInterface();
82 IMLangFontLink2* getFontLinkInterface();
85 void getTraitsInFamily(const AtomicString&, Vector<unsigned>&);
87 SimpleFontData* getCachedFontData(const FontDescription&, const AtomicString&, bool checkingAlternateName = false, ShouldRetain = Retain);
88 SimpleFontData* getLastResortFallbackFont(const FontDescription&, ShouldRetain = Retain);
89 SimpleFontData* getNonRetainedLastResortFallbackFont(const FontDescription&);
91 void addClient(FontSelector*);
92 void removeClient(FontSelector*);
94 unsigned short generation();
97 size_t fontDataCount();
98 size_t inactiveFontDataCount();
99 void purgeInactiveFontData(int count = INT_MAX);
102 SimpleFontData* fontDataFromDescriptionAndLogFont(const FontDescription&, ShouldRetain, const LOGFONT& font, AtomicString& outFontFamilyName);
103 #elif PLATFORM(CHROMIUM) && OS(WINDOWS)
104 SimpleFontData* fontDataFromDescriptionAndLogFont(const FontDescription&, ShouldRetain, const LOGFONT& font, wchar_t* outFontFamilyName);
111 void disablePurging() { m_purgePreventCount++; }
114 ASSERT(m_purgePreventCount);
115 if (!--m_purgePreventCount)
116 purgeInactiveFontDataIfNeeded();
119 void purgeInactiveFontDataIfNeeded();
121 // FIXME: This method should eventually be removed.
122 FontPlatformData* getCachedFontPlatformData(const FontDescription&, const AtomicString& family, bool checkingAlternateName = false);
124 // These methods are implemented by each platform.
125 SimpleFontData* getSimilarFontPlatformData(const Font&);
126 FontPlatformData* createFontPlatformData(const FontDescription&, const AtomicString& family);
128 SimpleFontData* getCachedFontData(const FontPlatformData*, ShouldRetain = Retain);
130 // Don't purge if this count is > 0;
131 int m_purgePreventCount;
133 #if PLATFORM(MAC) || (PLATFORM(CHROMIUM) && OS(DARWIN)) || OS(ANDROID)
134 friend class ComplexTextController;
136 friend class SimpleFontData; // For getCachedFontData(const FontPlatformData*)
137 friend class FontFallbackList;
140 // Get the global fontCache.
141 FontCache* fontCache();
143 class FontCachePurgePreventer {
145 FontCachePurgePreventer() {
146 fontCache()->disablePurging();
148 ~FontCachePurgePreventer() {
149 fontCache()->enablePurging();