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 
28 namespace WebCore {
29 
30 class Font;
31 class GlyphPageTreeNode;
32 class GraphicsContext;
33 class IntRect;
34 class FontDescription;
35 class FontPlatformData;
36 class FontSelector;
37 
38 const int cAllFamiliesScanned = -1;
39 
40 class FontFallbackList : public RefCounted<FontFallbackList> {
41 public:
create()42     static PassRefPtr<FontFallbackList> create() { return adoptRef(new FontFallbackList()); }
43 
~FontFallbackList()44     ~FontFallbackList() { releaseFontData(); }
45     void invalidate(PassRefPtr<FontSelector>);
46 
isFixedPitch(const Font * f)47     bool isFixedPitch(const Font* f) const { if (m_pitch == UnknownPitch) determinePitch(f); return m_pitch == FixedPitch; };
48     void determinePitch(const Font*) const;
49 
loadingCustomFonts()50     bool loadingCustomFonts() const { return m_loadingCustomFonts; }
51 
fontSelector()52     FontSelector* fontSelector() const { return m_fontSelector.get(); }
generation()53     unsigned generation() const { return m_generation; }
54 
55 private:
56     FontFallbackList();
57 
primarySimpleFontData(const Font * f)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 
primaryFontData(const Font * f)66     const FontData* primaryFontData(const Font* f) const { return fontDataAt(f, 0); }
67     const FontData* fontDataAt(const Font*, unsigned index) const;
68 
69     void setPlatformFont(const FontPlatformData&);
70 
71     void releaseFontData();
72 
73     mutable Vector<pair<const FontData*, bool>, 1> m_fontList;
74     mutable HashMap<int, GlyphPageTreeNode*> m_pages;
75     mutable GlyphPageTreeNode* m_pageZero;
76     mutable const SimpleFontData* m_cachedPrimarySimpleFontData;
77     RefPtr<FontSelector> m_fontSelector;
78     mutable int m_familyIndex;
79     mutable Pitch m_pitch;
80     mutable bool m_loadingCustomFonts;
81     unsigned m_generation;
82 
83     friend class Font;
84 };
85 
86 }
87 
88 #endif
89