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 "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" 29 30 namespace WebCore { 31 32 class GlyphPageTreeNode; 33 class GraphicsContext; 34 class IntRect; 35 class FontDescription; 36 class FontPlatformData; 37 class FontSelector; 38 39 const int cAllFamiliesScanned = -1; 40 41 class PLATFORM_EXPORT FontFallbackList : public RefCounted<FontFallbackList> { 42 WTF_MAKE_NONCOPYABLE(FontFallbackList); 43 public: 44 typedef HashMap<int, GlyphPageTreeNode*, DefaultHash<int>::Hash> GlyphPages; 45 46 class GlyphPagesStateSaver { 47 public: 48 GlyphPagesStateSaver(FontFallbackList& fallbackList) 49 : m_fallbackList(fallbackList) 50 , m_pages(fallbackList.m_pages) 51 , m_pageZero(fallbackList.m_pageZero) 52 { 53 } 54 55 ~GlyphPagesStateSaver() 56 { 57 m_fallbackList.m_pages = m_pages; 58 m_fallbackList.m_pageZero = m_pageZero; 59 } 60 61 private: 62 FontFallbackList& m_fallbackList; 63 GlyphPages& m_pages; 64 GlyphPageTreeNode* m_pageZero; 65 }; 66 67 static PassRefPtr<FontFallbackList> create() { return adoptRef(new FontFallbackList()); } 68 69 ~FontFallbackList() { releaseFontData(); } 70 void invalidate(PassRefPtr<FontSelector>); 71 72 bool isFixedPitch(const FontDescription& fontDescription) const 73 { 74 if (m_pitch == UnknownPitch) 75 determinePitch(fontDescription); 76 return m_pitch == FixedPitch; 77 } 78 void determinePitch(const FontDescription&) const; 79 80 bool loadingCustomFonts() const; 81 82 FontSelector* fontSelector() const { return m_fontSelector.get(); } 83 // FIXME: It should be possible to combine fontSelectorVersion and generation. 84 unsigned fontSelectorVersion() const { return m_fontSelectorVersion; } 85 unsigned generation() const { return m_generation; } 86 87 WidthCache& widthCache() const { return m_widthCache; } 88 89 private: 90 FontFallbackList(); 91 92 const SimpleFontData* primarySimpleFontData(const FontDescription& fontDescription) 93 { 94 ASSERT(isMainThread()); 95 if (!m_cachedPrimarySimpleFontData) 96 m_cachedPrimarySimpleFontData = primaryFontData(fontDescription)->fontDataForCharacter(' '); 97 return m_cachedPrimarySimpleFontData; 98 } 99 100 PassRefPtr<FontData> getFontData(const FontDescription&, int& familyIndex) const; 101 102 const FontData* primaryFontData(const FontDescription&) const; 103 const FontData* fontDataAt(const FontDescription&, unsigned index) const; 104 105 void setPlatformFont(const FontPlatformData&); 106 107 void releaseFontData(); 108 109 mutable Vector<RefPtr<FontData>, 1> m_fontList; 110 mutable GlyphPages m_pages; 111 mutable GlyphPageTreeNode* m_pageZero; 112 mutable const SimpleFontData* m_cachedPrimarySimpleFontData; 113 RefPtr<FontSelector> m_fontSelector; 114 mutable WidthCache m_widthCache; 115 unsigned m_fontSelectorVersion; 116 mutable int m_familyIndex; 117 unsigned short m_generation; 118 mutable unsigned m_pitch : 3; // Pitch 119 mutable bool m_loadingCustomFonts : 1; 120 121 friend class Font; 122 }; 123 124 } 125 126 #endif 127