~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/graphics/FontCache.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/PassRefPtr.h>
 
36
#include <wtf/RefPtr.h>
 
37
#include <wtf/Vector.h>
 
38
#include <wtf/text/WTFString.h>
 
39
#include <wtf/unicode/Unicode.h>
 
40
 
 
41
#if OS(WINDOWS)
 
42
#include <windows.h>
 
43
#include <objidl.h>
 
44
#include <mlang.h>
 
45
#endif
 
46
 
 
47
namespace WebCore {
 
48
 
 
49
class Font;
 
50
class FontPlatformData;
 
51
class FontData;
 
52
class FontDescription;
 
53
class FontSelector;
 
54
class OpenTypeVerticalData;
 
55
class SimpleFontData;
 
56
 
 
57
#if PLATFORM(WIN)
 
58
#if !OS(WINCE) || defined(IMLANG_FONT_LINK) && (IMLANG_FONT_LINK == 2)
 
59
typedef IMLangFontLink2 IMLangFontLinkType;
 
60
#else
 
61
typedef IMLangFontLink IMLangFontLinkType;
 
62
#endif
 
63
#endif
 
64
 
 
65
class FontCache {
 
66
    friend class FontCachePurgePreventer;
 
67
 
 
68
    WTF_MAKE_NONCOPYABLE(FontCache); WTF_MAKE_FAST_ALLOCATED;
 
69
public:
 
70
    friend FontCache* fontCache();
 
71
 
 
72
    enum ShouldRetain { Retain, DoNotRetain };
 
73
 
 
74
    PassRefPtr<FontData> getFontData(const Font&, int& familyIndex, FontSelector*);
 
75
    void releaseFontData(const SimpleFontData*);
 
76
 
 
77
    // This method is implemented by the platform.
 
78
    PassRefPtr<SimpleFontData> getFontDataForCharacters(const Font&, const UChar* characters, int length);
 
79
 
 
80
    // Also implemented by the platform.
 
81
    void platformInit();
 
82
 
 
83
#if PLATFORM(WIN)
 
84
    IMLangFontLinkType* getFontLinkInterface();
 
85
#if OS(WINCE)
 
86
    static void comInitialize();
 
87
    static void comUninitialize();
 
88
    static IMultiLanguage* getMultiLanguageInterface();
 
89
#endif
 
90
#endif
 
91
 
 
92
    void getTraitsInFamily(const AtomicString&, Vector<unsigned>&);
 
93
 
 
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&);
 
97
 
 
98
    void addClient(FontSelector*);
 
99
    void removeClient(FontSelector*);
 
100
 
 
101
    unsigned short generation();
 
102
    void invalidate();
 
103
 
 
104
    size_t fontDataCount();
 
105
    size_t inactiveFontDataCount();
 
106
    void purgeInactiveFontData(int count = INT_MAX);
 
107
 
 
108
#if PLATFORM(WIN)
 
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);
 
112
#endif
 
113
 
 
114
#if ENABLE(OPENTYPE_VERTICAL)
 
115
#if USE(SKIA)
 
116
    typedef uint32_t FontFileKey;
 
117
#else
 
118
    typedef AtomicString FontFileKey;
 
119
#endif
 
120
    PassRefPtr<OpenTypeVerticalData> getVerticalData(const FontFileKey&, const FontPlatformData&);
 
121
#endif
 
122
 
 
123
    struct SimpleFontFamily {
 
124
        String name;
 
125
        bool isBold;
 
126
        bool isItalic;
 
127
    };
 
128
    static void getFontFamilyForCharacters(const UChar* characters, size_t numCharacters, const char* preferredLocale, SimpleFontFamily*);
 
129
 
 
130
private:
 
131
    FontCache();
 
132
    ~FontCache();
 
133
 
 
134
    void disablePurging() { m_purgePreventCount++; }
 
135
    void enablePurging()
 
136
    {
 
137
        ASSERT(m_purgePreventCount);
 
138
        if (!--m_purgePreventCount)
 
139
            purgeInactiveFontDataIfNeeded();
 
140
    }
 
141
 
 
142
    void purgeInactiveFontDataIfNeeded();
 
143
 
 
144
    // FIXME: This method should eventually be removed.
 
145
    FontPlatformData* getCachedFontPlatformData(const FontDescription&, const AtomicString& family, bool checkingAlternateName = false);
 
146
 
 
147
    // These methods are implemented by each platform.
 
148
    PassRefPtr<SimpleFontData> getSimilarFontPlatformData(const Font&);
 
149
    FontPlatformData* createFontPlatformData(const FontDescription&, const AtomicString& family);
 
150
 
 
151
    PassRefPtr<SimpleFontData> getCachedFontData(const FontPlatformData*, ShouldRetain = Retain);
 
152
 
 
153
    // Don't purge if this count is > 0;
 
154
    int m_purgePreventCount;
 
155
 
 
156
#if PLATFORM(MAC) || (PLATFORM(CHROMIUM) && OS(DARWIN)) || OS(ANDROID)
 
157
    friend class ComplexTextController;
 
158
#endif
 
159
    friend class SimpleFontData; // For getCachedFontData(const FontPlatformData*)
 
160
    friend class FontFallbackList;
 
161
};
 
162
 
 
163
// Get the global fontCache.
 
164
FontCache* fontCache();
 
165
 
 
166
class FontCachePurgePreventer {
 
167
public:
 
168
    FontCachePurgePreventer() { fontCache()->disablePurging(); }
 
169
    ~FontCachePurgePreventer() { fontCache()->enablePurging(); }
 
170
};
 
171
 
 
172
}
 
173
 
 
174
#endif