2 * Copyright (C) 2006, 2010 Apple Inc. All rights reserved.
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.
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.
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.
21 #ifndef FontFallbackList_h
22 #define FontFallbackList_h
24 #include "platform/fonts/FontSelector.h"
25 #include "platform/fonts/SimpleFontData.h"
26 #include "platform/fonts/WidthCache.h"
27 #include "wtf/Forward.h"
28 #include "wtf/MainThread.h"
32 class GlyphPageTreeNode;
33 class FontDescription;
35 const int cAllFamiliesScanned = -1;
37 class PLATFORM_EXPORT FontFallbackList : public RefCounted<FontFallbackList> {
38 WTF_MAKE_NONCOPYABLE(FontFallbackList);
40 typedef HashMap<int, GlyphPageTreeNode*, DefaultHash<int>::Hash> GlyphPages;
42 class GlyphPagesStateSaver {
44 GlyphPagesStateSaver(FontFallbackList& fallbackList)
45 : m_fallbackList(fallbackList)
46 , m_pages(fallbackList.m_pages)
47 , m_pageZero(fallbackList.m_pageZero)
51 ~GlyphPagesStateSaver()
53 m_fallbackList.m_pages = m_pages;
54 m_fallbackList.m_pageZero = m_pageZero;
58 FontFallbackList& m_fallbackList;
60 GlyphPageTreeNode* m_pageZero;
63 static PassRefPtr<FontFallbackList> create() { return adoptRef(new FontFallbackList()); }
65 ~FontFallbackList() { releaseFontData(); }
66 void invalidate(PassRefPtrWillBeRawPtr<FontSelector>);
68 bool isFixedPitch(const FontDescription& fontDescription) const
70 if (m_pitch == UnknownPitch)
71 determinePitch(fontDescription);
72 return m_pitch == FixedPitch;
74 void determinePitch(const FontDescription&) const;
76 bool loadingCustomFonts() const;
77 bool shouldSkipDrawing() const;
79 FontSelector* fontSelector() const { return m_fontSelector.get(); }
80 // FIXME: It should be possible to combine fontSelectorVersion and generation.
81 unsigned fontSelectorVersion() const { return m_fontSelectorVersion; }
82 unsigned generation() const { return m_generation; }
84 WidthCache& widthCache() const { return m_widthCache; }
86 const SimpleFontData* primarySimpleFontData(const FontDescription& fontDescription)
88 ASSERT(isMainThread());
89 if (!m_cachedPrimarySimpleFontData)
90 m_cachedPrimarySimpleFontData = determinePrimarySimpleFontData(fontDescription);
91 return m_cachedPrimarySimpleFontData;
93 const FontData* fontDataAt(const FontDescription&, unsigned index) const;
95 GlyphPageTreeNode* getPageNode(unsigned pageNumber) const
97 return pageNumber ? m_pages.get(pageNumber) : m_pageZero;
100 void setPageNode(unsigned pageNumber, GlyphPageTreeNode* node)
103 m_pages.set(pageNumber, node);
111 PassRefPtr<FontData> getFontData(const FontDescription&, int& familyIndex) const;
113 const SimpleFontData* determinePrimarySimpleFontData(const FontDescription&) const;
115 void releaseFontData();
117 mutable Vector<RefPtr<FontData>, 1> m_fontList;
119 GlyphPageTreeNode* m_pageZero;
120 mutable const SimpleFontData* m_cachedPrimarySimpleFontData;
121 RefPtrWillBePersistent<FontSelector> m_fontSelector;
122 mutable WidthCache m_widthCache;
123 unsigned m_fontSelectorVersion;
124 mutable int m_familyIndex;
125 unsigned short m_generation;
126 mutable unsigned m_pitch : 3; // Pitch
127 mutable bool m_hasLoadingFallback : 1;