• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/Vector.h>
35 #include <wtf/unicode/Unicode.h>
36 
37 #if PLATFORM(WIN)
38 #include <objidl.h>
39 #include <mlang.h>
40 #endif
41 
42 namespace WebCore
43 {
44 
45 class AtomicString;
46 class Font;
47 class FontPlatformData;
48 class FontData;
49 class FontDescription;
50 class FontSelector;
51 class SimpleFontData;
52 
53 class FontCache : public Noncopyable {
54 public:
55     friend FontCache* fontCache();
56 
57     const FontData* getFontData(const Font&, int& familyIndex, FontSelector*);
58     void releaseFontData(const SimpleFontData*);
59 
60     // This method is implemented by the platform.
61     // FIXME: Font data returned by this method never go inactive because callers don't track and release them.
62     const SimpleFontData* getFontDataForCharacters(const Font&, const UChar* characters, int length);
63 
64     // Also implemented by the platform.
65     void platformInit();
66 
67 #if OS(WINCE) && !PLATFORM(QT)
68 #if defined(IMLANG_FONT_LINK) && (IMLANG_FONT_LINK == 2)
69     IMLangFontLink2* getFontLinkInterface();
70 #else
71     IMLangFontLink* getFontLinkInterface();
72 #endif
73     static void comInitialize();
74     static void comUninitialize();
75 #elif PLATFORM(WIN)
76     IMLangFontLink2* getFontLinkInterface();
77 #endif
78 
79     void getTraitsInFamily(const AtomicString&, Vector<unsigned>&);
80 
81     SimpleFontData* getCachedFontData(const FontDescription& fontDescription, const AtomicString& family, bool checkingAlternateName = false);
82     SimpleFontData* getLastResortFallbackFont(const FontDescription&);
83 
84     void addClient(FontSelector*);
85     void removeClient(FontSelector*);
86 
87     unsigned generation();
88     void invalidate();
89 
90     size_t fontDataCount();
91     size_t inactiveFontDataCount();
92     void purgeInactiveFontData(int count = INT_MAX);
93 
94 private:
95     FontCache();
96     ~FontCache();
97 
98     // FIXME: This method should eventually be removed.
99     FontPlatformData* getCachedFontPlatformData(const FontDescription&, const AtomicString& family, bool checkingAlternateName = false);
100 
101     // These methods are implemented by each platform.
102     SimpleFontData* getSimilarFontPlatformData(const Font&);
103     FontPlatformData* createFontPlatformData(const FontDescription&, const AtomicString& family);
104 
105     SimpleFontData* getCachedFontData(const FontPlatformData*);
106 
107     friend class SimpleFontData; // For getCachedFontData(const FontPlatformData*)
108     friend class FontFallbackList;
109 };
110 
111 // Get the global fontCache.
112 FontCache* fontCache();
113 
114 }
115 
116 #endif
117