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 "FontSelector.h"
25 #include "SimpleFontData.h"
26 #include <wtf/Forward.h>
27 #include <wtf/MainThread.h>
32 class GlyphPageTreeNode;
33 class GraphicsContext;
35 class FontDescription;
36 class FontPlatformData;
39 const int cAllFamiliesScanned = -1;
41 class FontFallbackList : public RefCounted<FontFallbackList> {
43 static PassRefPtr<FontFallbackList> create() { return adoptRef(new FontFallbackList()); }
45 ~FontFallbackList() { releaseFontData(); }
46 void invalidate(PassRefPtr<FontSelector>);
48 bool isFixedPitch(const Font* f) const { if (m_pitch == UnknownPitch) determinePitch(f); return m_pitch == FixedPitch; };
49 void determinePitch(const Font*) const;
51 bool loadingCustomFonts() const { return m_loadingCustomFonts; }
53 FontSelector* fontSelector() const { return m_fontSelector.get(); }
54 // FIXME: It should be possible to combine fontSelectorVersion and generation.
55 unsigned fontSelectorVersion() const { return m_fontSelectorVersion; }
56 unsigned generation() const { return m_generation; }
58 struct GlyphPagesHashTraits : HashTraits<int> {
59 static const int minimumTableSize = 16;
61 typedef HashMap<int, GlyphPageTreeNode*, DefaultHash<int>::Hash, GlyphPagesHashTraits> GlyphPages;
62 GlyphPageTreeNode* glyphPageZero() const { return m_pageZero; }
63 const GlyphPages& glyphPages() const { return m_pages; }
66 friend class SVGTextRunRenderingContext;
67 void setGlyphPageZero(GlyphPageTreeNode* pageZero) { m_pageZero = pageZero; }
68 void setGlyphPages(const GlyphPages& pages) { m_pages = pages; }
72 const SimpleFontData* primarySimpleFontData(const Font* f)
74 ASSERT(isMainThread());
75 if (!m_cachedPrimarySimpleFontData)
76 m_cachedPrimarySimpleFontData = primaryFontData(f)->fontDataForCharacter(' ');
77 return m_cachedPrimarySimpleFontData;
80 const FontData* primaryFontData(const Font* f) const { return fontDataAt(f, 0); }
81 const FontData* fontDataAt(const Font*, unsigned index) const;
83 void setPlatformFont(const FontPlatformData&);
85 void releaseFontData();
87 mutable Vector<pair<const FontData*, bool>, 1> m_fontList;
88 mutable GlyphPages m_pages;
89 mutable GlyphPageTreeNode* m_pageZero;
90 mutable const SimpleFontData* m_cachedPrimarySimpleFontData;
91 RefPtr<FontSelector> m_fontSelector;
92 unsigned m_fontSelectorVersion;
93 mutable int m_familyIndex;
94 unsigned short m_generation;
95 mutable unsigned m_pitch : 3; // Pitch
96 mutable bool m_loadingCustomFonts : 1;