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 GraphicsContext;
35 class FontDescription;
36 class FontPlatformData;
39 const int cAllFamiliesScanned = -1;
41 class PLATFORM_EXPORT FontFallbackList : public RefCounted<FontFallbackList> {
42 WTF_MAKE_NONCOPYABLE(FontFallbackList);
44 typedef HashMap<int, GlyphPageTreeNode*, DefaultHash<int>::Hash> GlyphPages;
46 class GlyphPagesStateSaver {
48 GlyphPagesStateSaver(FontFallbackList& fallbackList)
49 : m_fallbackList(fallbackList)
50 , m_pages(fallbackList.m_pages)
51 , m_pageZero(fallbackList.m_pageZero)
55 ~GlyphPagesStateSaver()
57 m_fallbackList.m_pages = m_pages;
58 m_fallbackList.m_pageZero = m_pageZero;
62 FontFallbackList& m_fallbackList;
64 GlyphPageTreeNode* m_pageZero;
67 static PassRefPtr<FontFallbackList> create() { return adoptRef(new FontFallbackList()); }
69 ~FontFallbackList() { releaseFontData(); }
70 void invalidate(PassRefPtrWillBeRawPtr<FontSelector>);
72 bool isFixedPitch(const FontDescription& fontDescription) const
74 if (m_pitch == UnknownPitch)
75 determinePitch(fontDescription);
76 return m_pitch == FixedPitch;
78 void determinePitch(const FontDescription&) const;
80 bool loadingCustomFonts() const;
81 bool shouldSkipDrawing() const;
83 FontSelector* fontSelector() const { return m_fontSelector.get(); }
84 // FIXME: It should be possible to combine fontSelectorVersion and generation.
85 unsigned fontSelectorVersion() const { return m_fontSelectorVersion; }
86 unsigned generation() const { return m_generation; }
88 WidthCache& widthCache() const { return m_widthCache; }
93 const SimpleFontData* primarySimpleFontData(const FontDescription& fontDescription)
95 ASSERT(isMainThread());
96 if (!m_cachedPrimarySimpleFontData)
97 m_cachedPrimarySimpleFontData = primaryFontData(fontDescription)->fontDataForCharacter(' ');
98 return m_cachedPrimarySimpleFontData;
101 PassRefPtr<FontData> getFontData(const FontDescription&, int& familyIndex) const;
103 const FontData* primaryFontData(const FontDescription&) const;
104 const FontData* fontDataAt(const FontDescription&, unsigned index) const;
106 void releaseFontData();
108 mutable Vector<RefPtr<FontData>, 1> m_fontList;
109 mutable GlyphPages m_pages;
110 mutable GlyphPageTreeNode* m_pageZero;
111 mutable const SimpleFontData* m_cachedPrimarySimpleFontData;
112 RefPtrWillBePersistent<FontSelector> m_fontSelector;
113 mutable WidthCache m_widthCache;
114 unsigned m_fontSelectorVersion;
115 mutable int m_familyIndex;
116 unsigned short m_generation;
117 mutable unsigned m_pitch : 3; // Pitch
118 mutable bool m_hasLoadingFallback : 1;