FontFallbackList.h revision cad810f21b803229eb11403f9209855525a25d57
1/*
2 * Copyright (C) 2006, 2010 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB.  If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#ifndef FontFallbackList_h
22#define FontFallbackList_h
23
24#include "FontSelector.h"
25#include "SimpleFontData.h"
26#include <wtf/Forward.h>
27
28namespace WebCore {
29
30class Font;
31class GlyphPageTreeNode;
32class GraphicsContext;
33class IntRect;
34class FontDescription;
35class FontPlatformData;
36class FontSelector;
37
38const int cAllFamiliesScanned = -1;
39
40class FontFallbackList : public RefCounted<FontFallbackList> {
41public:
42    static PassRefPtr<FontFallbackList> create() { return adoptRef(new FontFallbackList()); }
43
44    ~FontFallbackList() { releaseFontData(); }
45    void invalidate(PassRefPtr<FontSelector>);
46
47    bool isFixedPitch(const Font* f) const { if (m_pitch == UnknownPitch) determinePitch(f); return m_pitch == FixedPitch; };
48    void determinePitch(const Font*) const;
49
50    bool loadingCustomFonts() const { return m_loadingCustomFonts; }
51
52    FontSelector* fontSelector() const { return m_fontSelector.get(); }
53    unsigned generation() const { return m_generation; }
54
55private:
56    FontFallbackList();
57
58    const SimpleFontData* primarySimpleFontData(const Font* f)
59    {
60        ASSERT(isMainThread());
61        if (!m_cachedPrimarySimpleFontData)
62            m_cachedPrimarySimpleFontData = primaryFontData(f)->fontDataForCharacter(' ');
63        return m_cachedPrimarySimpleFontData;
64    }
65
66    const FontData* primaryFontData(const Font* f) const { return fontDataAt(f, 0); }
67    const FontData* fontDataAt(const Font*, unsigned index) const;
68    const FontData* fontDataForCharacters(const Font*, const UChar*, int length) const;
69
70    void setPlatformFont(const FontPlatformData&);
71
72    void releaseFontData();
73
74    mutable Vector<pair<const FontData*, bool>, 1> m_fontList;
75    mutable HashMap<int, GlyphPageTreeNode*> m_pages;
76    mutable GlyphPageTreeNode* m_pageZero;
77    mutable const SimpleFontData* m_cachedPrimarySimpleFontData;
78    RefPtr<FontSelector> m_fontSelector;
79    mutable int m_familyIndex;
80    mutable Pitch m_pitch;
81    mutable bool m_loadingCustomFonts;
82    unsigned m_generation;
83
84    friend class Font;
85};
86
87}
88
89#endif
90