1 /* 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. 3 * Copyright (C) 2006 Michael Emmel mike.emmel (at) gmail.com 4 * Copyright (C) 2007 Holger Hans Peter Freyther 5 * Copyright (C) 2007 Pioneer Research Center USA, Inc. 6 * Copyright (C) 2010, 2011 Brent Fulgham <bfulgham (at) webkit.org> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public License 19 * along with this library; see the file COPYING.LIB. If not, write to 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301, USA. 22 * 23 */ 24 25 // FIXME: This is temporary until all ports switch to using this file. 26 #if OS(WINDOWS) 27 #include "core/platform/graphics/chromium/FontPlatformDataChromiumWin.h" 28 #elif OS(UNIX) && !OS(DARWIN) 29 #include "core/platform/graphics/harfbuzz/FontPlatformDataHarfBuzz.h" 30 31 #else 32 33 #ifndef FontPlatformData_h 34 #define FontPlatformData_h 35 36 #include "core/platform/graphics/FontOrientation.h" 37 #include "core/platform/graphics/FontWidthVariant.h" 38 39 #if OS(DARWIN) 40 OBJC_CLASS NSFont; 41 42 typedef struct CGFont* CGFontRef; 43 typedef const struct __CTFont* CTFontRef; 44 45 #include <CoreFoundation/CFBase.h> 46 #include <objc/objc-auto.h> 47 #endif 48 49 #include "wtf/Forward.h" 50 #include "wtf/HashTableDeletedValueType.h" 51 #include "wtf/PassRefPtr.h" 52 #include "wtf/RefCounted.h" 53 #include "wtf/RetainPtr.h" 54 #include "wtf/text/StringImpl.h" 55 56 #if OS(DARWIN) 57 #include "core/platform/graphics/chromium/CrossProcessFontLoading.h" 58 #endif 59 60 #if OS(DARWIN) 61 typedef struct CGFont* CGFontRef; 62 typedef const struct __CTFont* CTFontRef; 63 typedef UInt32 FMFont; 64 typedef FMFont ATSUFontID; 65 typedef UInt32 ATSFontRef; 66 #endif 67 68 namespace WebCore { 69 70 class FontDescription; 71 class SharedBuffer; 72 73 #if OS(DARWIN) 74 class HarfBuzzFace; 75 #endif 76 77 #if OS(DARWIN) 78 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); } 79 #endif 80 81 class FontPlatformData { 82 public: 83 FontPlatformData(WTF::HashTableDeletedValueType); 84 FontPlatformData(); 85 FontPlatformData(const FontPlatformData&); 86 FontPlatformData(const FontDescription&, const AtomicString& family); 87 FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation = Horizontal, FontWidthVariant = RegularWidth); 88 89 #if OS(DARWIN) 90 FontPlatformData(NSFont*, float size, bool isPrinterFont = false, bool syntheticBold = false, bool syntheticOblique = false, 91 FontOrientation = Horizontal, FontWidthVariant = RegularWidth); 92 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant); 93 #endif 94 95 ~FontPlatformData(); 96 97 #if OS(DARWIN) 98 NSFont* font() const { return m_font; } 99 void setFont(NSFont*); 100 #endif 101 102 #if OS(DARWIN) 103 CGFontRef cgFont() const { return m_cgFont.get(); } 104 CTFontRef ctFont() const; 105 106 bool roundsGlyphAdvances() const; 107 bool allowsLigatures() const; 108 #endif 109 110 bool isFixedPitch() const; 111 float size() const { return m_size; } 112 void setSize(float size) { m_size = size; } 113 bool syntheticBold() const { return m_syntheticBold; } 114 bool syntheticOblique() const { return m_syntheticOblique; } 115 bool isColorBitmapFont() const { return m_isColorBitmapFont; } 116 bool isCompositeFontReference() const { return m_isCompositeFontReference; } 117 #if OS(DARWIN) 118 bool isPrinterFont() const { return m_isPrinterFont; } 119 #endif 120 FontOrientation orientation() const { return m_orientation; } 121 FontWidthVariant widthVariant() const { return m_widthVariant; } 122 123 void setOrientation(FontOrientation orientation) { m_orientation = orientation; } 124 125 #if OS(DARWIN) 126 HarfBuzzFace* harfBuzzFace(); 127 #endif 128 129 unsigned hash() const 130 { 131 #if OS(DARWIN) 132 ASSERT(m_font || !m_cgFont); 133 uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, static_cast<uintptr_t>(m_isPrinterFont << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique) }; 134 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); 135 #endif 136 } 137 138 const FontPlatformData& operator=(const FontPlatformData&); 139 140 bool operator==(const FontPlatformData& other) const 141 { 142 return platformIsEqual(other) 143 && m_size == other.m_size 144 && m_syntheticBold == other.m_syntheticBold 145 && m_syntheticOblique == other.m_syntheticOblique 146 && m_isColorBitmapFont == other.m_isColorBitmapFont 147 && m_isCompositeFontReference == other.m_isCompositeFontReference 148 #if OS(DARWIN) 149 && m_isPrinterFont == other.m_isPrinterFont 150 #endif 151 && m_orientation == other.m_orientation 152 && m_widthVariant == other.m_widthVariant; 153 } 154 155 bool isHashTableDeletedValue() const 156 { 157 #if OS(DARWIN) 158 return m_font == hashTableDeletedFontValue(); 159 #endif 160 } 161 162 #ifndef NDEBUG 163 String description() const; 164 #endif 165 166 private: 167 bool platformIsEqual(const FontPlatformData&) const; 168 void platformDataInit(const FontPlatformData&); 169 const FontPlatformData& platformDataAssign(const FontPlatformData&); 170 #if OS(DARWIN) 171 // Load various data about the font specified by |nsFont| with the size fontSize into the following output paramters: 172 // Note: Callers should always take into account that for the Chromium port, |outNSFont| isn't necessarily the same 173 // font as |nsFont|. This because the sandbox may block loading of the original font. 174 // * outNSFont - The font that was actually loaded, for the Chromium port this may be different than nsFont. 175 // The caller is responsible for calling CFRelease() on this parameter when done with it. 176 // * cgFont - CGFontRef representing the input font at the specified point size. 177 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&); 178 static NSFont* hashTableDeletedFontValue() { return reinterpret_cast<NSFont *>(-1); } 179 #endif 180 181 public: 182 bool m_syntheticBold; 183 bool m_syntheticOblique; 184 FontOrientation m_orientation; 185 float m_size; 186 FontWidthVariant m_widthVariant; 187 188 private: 189 #if OS(DARWIN) 190 NSFont* m_font; 191 #endif 192 193 #if OS(DARWIN) 194 RetainPtr<CGFontRef> m_cgFont; 195 mutable RetainPtr<CTFontRef> m_CTFont; 196 197 RefPtr<MemoryActivatedFont> m_inMemoryFont; 198 RefPtr<HarfBuzzFace> m_harfBuzzFace; 199 #endif 200 201 bool m_isColorBitmapFont; 202 bool m_isCompositeFontReference; 203 #if OS(DARWIN) 204 bool m_isPrinterFont; 205 #endif 206 }; 207 208 } // namespace WebCore 209 210 #endif // FontPlatformData_h 211 212 #endif 213