Remove TIZEN_FONTCACHE_DEPRECATED which is not used anymore
[framework/web/webkit-efl.git] / Source / WebCore / platform / graphics / FontCache.h
1 /*
2  * Copyright (C) 2006, 2008 Apple Computer, Inc.  All rights reserved.
3  * Copyright (C) 2007-2008 Torch Mobile, Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
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. 
17  *
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.
28  */
29
30 #ifndef FontCache_h
31 #define FontCache_h
32
33 #include <limits.h>
34 #include <wtf/Forward.h>
35 #include <wtf/Vector.h>
36 #include <wtf/unicode/Unicode.h>
37
38 #if OS(WINDOWS)
39 #include <windows.h>
40 #include <objidl.h>
41 #include <mlang.h>
42 #endif
43
44 namespace WebCore
45 {
46
47 class Font;
48 class FontPlatformData;
49 class FontData;
50 class FontDescription;
51 class FontSelector;
52 class SimpleFontData;
53
54 class FontCache {
55     friend class FontCachePurgePreventer;
56
57     WTF_MAKE_NONCOPYABLE(FontCache); WTF_MAKE_FAST_ALLOCATED;
58 public:
59     friend FontCache* fontCache();
60
61     enum ShouldRetain { Retain, DoNotRetain };
62
63     const FontData* getFontData(const Font&, int& familyIndex, FontSelector*);
64     void releaseFontData(const SimpleFontData*);
65
66     // This method is implemented by the platform.
67     const SimpleFontData* getFontDataForCharacters(const Font&, const UChar* characters, int length);
68
69     // Also implemented by the platform.
70     void platformInit();
71
72 #if OS(WINCE) && !PLATFORM(QT)
73 #if defined(IMLANG_FONT_LINK) && (IMLANG_FONT_LINK == 2)
74     IMLangFontLink2* getFontLinkInterface();
75 #else
76     IMLangFontLink* getFontLinkInterface();
77 #endif
78     static void comInitialize();
79     static void comUninitialize();
80     static IMultiLanguage* getMultiLanguageInterface();
81 #elif PLATFORM(WIN)
82     IMLangFontLink2* getFontLinkInterface();
83 #endif
84
85     void getTraitsInFamily(const AtomicString&, Vector<unsigned>&);
86
87     SimpleFontData* getCachedFontData(const FontDescription&, const AtomicString&, bool checkingAlternateName = false, ShouldRetain = Retain);
88     SimpleFontData* getLastResortFallbackFont(const FontDescription&, ShouldRetain = Retain);
89     SimpleFontData* getNonRetainedLastResortFallbackFont(const FontDescription&);
90
91     void addClient(FontSelector*);
92     void removeClient(FontSelector*);
93
94     unsigned short generation();
95     void invalidate();
96
97     size_t fontDataCount();
98     size_t inactiveFontDataCount();
99     void purgeInactiveFontData(int count = INT_MAX);
100
101 #if PLATFORM(WIN)
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);
105 #endif
106
107 private:
108     FontCache();
109     ~FontCache();
110
111     void disablePurging() { m_purgePreventCount++; }
112     void enablePurging()
113     {
114         ASSERT(m_purgePreventCount);
115         if (!--m_purgePreventCount)
116             purgeInactiveFontDataIfNeeded();
117     }
118
119     void purgeInactiveFontDataIfNeeded();
120
121     // FIXME: This method should eventually be removed.
122     FontPlatformData* getCachedFontPlatformData(const FontDescription&, const AtomicString& family, bool checkingAlternateName = false);
123
124     // These methods are implemented by each platform.
125     SimpleFontData* getSimilarFontPlatformData(const Font&);
126     FontPlatformData* createFontPlatformData(const FontDescription&, const AtomicString& family);
127
128     SimpleFontData* getCachedFontData(const FontPlatformData*, ShouldRetain = Retain);
129
130     // Don't purge if this count is > 0;
131     int m_purgePreventCount;
132
133 #if PLATFORM(MAC) || (PLATFORM(CHROMIUM) && OS(DARWIN)) || OS(ANDROID)
134     friend class ComplexTextController;
135 #endif
136     friend class SimpleFontData; // For getCachedFontData(const FontPlatformData*)
137     friend class FontFallbackList;
138 };
139
140 // Get the global fontCache.
141 FontCache* fontCache();
142
143 class FontCachePurgePreventer {
144 public:
145     FontCachePurgePreventer() {
146         fontCache()->disablePurging();
147     }
148     ~FontCachePurgePreventer() {
149         fontCache()->enablePurging();
150     }
151 };
152
153 }
154
155 #endif