| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2006, 2008 Apple Computer, Inc. All rights reserved. | |
| 3 * Copyright (C) 2007-2008 Torch Mobile, Inc. | |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions | |
| 7 * are met: | |
| 8 * | |
| 9 * 1. Redistributions of source code must retain the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer. | |
| 11 * 2. Redistributions in binary form must reproduce the above copyright | |
| 12 * notice, this list of conditions and the following disclaimer in the | |
| 13 * documentation and/or other materials provided with the distribution. | |
| 14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
| 15 * its contributors may be used to endorse or promote products derived | |
| 16 * from this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
| 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
| 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 28 */ | |
| 29 | |
| 30 #ifndef FontCache_h | |
| 31 #define FontCache_h | |
| 32 | |
| 33 #include <limits.h> | |
| 34 #include "wtf/Forward.h" | |
| 35 #include "wtf/PassRefPtr.h" | |
| 36 #include "wtf/RefPtr.h" | |
| 37 #include "wtf/Vector.h" | |
| 38 #include "wtf/text/CString.h" | |
| 39 #include "wtf/text/WTFString.h" | |
| 40 #include "wtf/unicode/Unicode.h" | |
| 41 | |
| 42 #if OS(WIN) | |
| 43 #include <windows.h> | |
| 44 #include <objidl.h> | |
| 45 #include <mlang.h> | |
| 46 #endif | |
| 47 | |
| 48 #if OS(WIN) && !ENABLE(GDI_FONTS_ON_WINDOWS) | |
| 49 #include "SkFontMgr.h" | |
| 50 #endif | |
| 51 | |
| 52 class SkTypeface; | |
| 53 | |
| 54 namespace WebCore { | |
| 55 | |
| 56 class FontPlatformData; | |
| 57 class FontData; | |
| 58 class FontDescription; | |
| 59 class FontSelector; | |
| 60 class OpenTypeVerticalData; | |
| 61 class SimpleFontData; | |
| 62 | |
| 63 enum ShouldRetain { Retain, DoNotRetain }; | |
| 64 enum PurgeSeverity { PurgeIfNeeded, ForcePurge }; | |
| 65 | |
| 66 class FontCache { | |
| 67 friend class FontCachePurgePreventer; | |
| 68 | |
| 69 WTF_MAKE_NONCOPYABLE(FontCache); WTF_MAKE_FAST_ALLOCATED; | |
| 70 public: | |
| 71 friend FontCache* fontCache(); | |
| 72 | |
| 73 void releaseFontData(const SimpleFontData*); | |
| 74 | |
| 75 // This method is implemented by the plaform and used by | |
| 76 // FontFastPath to lookup the font for a given character. | |
| 77 PassRefPtr<SimpleFontData> platformFallbackForCharacter(const FontDescriptio
n&, UChar32, const SimpleFontData* fontDataToSubstitute, bool disallowSynthetics
); | |
| 78 | |
| 79 // Also implemented by the platform. | |
| 80 void platformInit(); | |
| 81 | |
| 82 PassRefPtr<SimpleFontData> getFontData(const FontDescription&, const AtomicS
tring&, bool checkingAlternateName = false, ShouldRetain = Retain); | |
| 83 PassRefPtr<SimpleFontData> getLastResortFallbackFont(const FontDescription&,
ShouldRetain = Retain); | |
| 84 SimpleFontData* getNonRetainedLastResortFallbackFont(const FontDescription&)
; | |
| 85 bool isPlatformFontAvailable(const FontDescription&, const AtomicString&); | |
| 86 | |
| 87 void addClient(FontSelector*); | |
| 88 void removeClient(FontSelector*); | |
| 89 | |
| 90 unsigned short generation(); | |
| 91 void invalidate(); | |
| 92 | |
| 93 #if OS(WIN) | |
| 94 PassRefPtr<SimpleFontData> fontDataFromDescriptionAndLogFont(const FontDescr
iption&, ShouldRetain, const LOGFONT&, wchar_t* outFontFamilyName); | |
| 95 #endif | |
| 96 | |
| 97 #if ENABLE(OPENTYPE_VERTICAL) | |
| 98 typedef uint32_t FontFileKey; | |
| 99 PassRefPtr<OpenTypeVerticalData> getVerticalData(const FontFileKey&, const F
ontPlatformData&); | |
| 100 #endif | |
| 101 | |
| 102 #if OS(ANDROID) | |
| 103 static AtomicString getGenericFamilyNameForScript(const AtomicString& family
Name, UScriptCode); | |
| 104 #else | |
| 105 struct SimpleFontFamily { | |
| 106 String name; | |
| 107 bool isBold; | |
| 108 bool isItalic; | |
| 109 }; | |
| 110 static void getFontFamilyForCharacter(UChar32, const char* preferredLocale,
SimpleFontFamily*); | |
| 111 #endif | |
| 112 | |
| 113 private: | |
| 114 FontCache(); | |
| 115 ~FontCache(); | |
| 116 | |
| 117 void purge(PurgeSeverity = PurgeIfNeeded); | |
| 118 | |
| 119 void disablePurging() { m_purgePreventCount++; } | |
| 120 void enablePurging() | |
| 121 { | |
| 122 ASSERT(m_purgePreventCount); | |
| 123 if (!--m_purgePreventCount) | |
| 124 purge(PurgeIfNeeded); | |
| 125 } | |
| 126 | |
| 127 // FIXME: This method should eventually be removed. | |
| 128 FontPlatformData* getFontPlatformData(const FontDescription&, const AtomicSt
ring& family, bool checkingAlternateName = false); | |
| 129 | |
| 130 // These methods are implemented by each platform. | |
| 131 FontPlatformData* createFontPlatformData(const FontDescription&, const Atomi
cString& family, float fontSize); | |
| 132 | |
| 133 // Implemented on skia platforms. | |
| 134 PassRefPtr<SkTypeface> createTypeface(const FontDescription&, const AtomicSt
ring& family, CString& name); | |
| 135 | |
| 136 PassRefPtr<SimpleFontData> fontDataFromFontPlatformData(const FontPlatformDa
ta*, ShouldRetain = Retain); | |
| 137 | |
| 138 // Don't purge if this count is > 0; | |
| 139 int m_purgePreventCount; | |
| 140 | |
| 141 #if OS(WIN) && !ENABLE(GDI_FONTS_ON_WINDOWS) | |
| 142 OwnPtr<SkFontMgr> m_fontManager; | |
| 143 bool m_useSubpixelPositioning; | |
| 144 #endif | |
| 145 | |
| 146 #if OS(MACOSX) || OS(ANDROID) | |
| 147 friend class ComplexTextController; | |
| 148 #endif | |
| 149 friend class SimpleFontData; // For fontDataFromFontPlatformData | |
| 150 friend class FontFallbackList; | |
| 151 }; | |
| 152 | |
| 153 // Get the global fontCache. | |
| 154 FontCache* fontCache(); | |
| 155 | |
| 156 class FontCachePurgePreventer { | |
| 157 public: | |
| 158 FontCachePurgePreventer() { fontCache()->disablePurging(); } | |
| 159 ~FontCachePurgePreventer() { fontCache()->enablePurging(); } | |
| 160 }; | |
| 161 | |
| 162 } | |
| 163 | |
| 164 #endif | |
| OLD | NEW |