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(WIN) 27 #include "platform/fonts/win/FontPlatformDataWin.h" 28 #elif !OS(MACOSX) 29 #include "platform/fonts/harfbuzz/FontPlatformDataHarfBuzz.h" 30 31 #else 32 33 #ifndef FontPlatformData_h 34 #define FontPlatformData_h 35 36 #include "platform/PlatformExport.h" 37 #include "platform/fonts/FontOrientation.h" 38 #include "platform/fonts/FontWidthVariant.h" 39 40 #if OS(MACOSX) 41 OBJC_CLASS NSFont; 42 43 typedef struct CGFont* CGFontRef; 44 typedef const struct __CTFont* CTFontRef; 45 46 #include <CoreFoundation/CFBase.h> 47 #include <objc/objc-auto.h> 48 #endif 49 50 #include "wtf/Forward.h" 51 #include "wtf/HashTableDeletedValueType.h" 52 #include "wtf/PassRefPtr.h" 53 #include "wtf/RefCounted.h" 54 #include "wtf/RetainPtr.h" 55 #include "wtf/text/StringImpl.h" 56 57 #if OS(MACOSX) 58 #include "platform/fonts/mac/MemoryActivatedFont.h" 59 #endif 60 61 #if OS(MACOSX) 62 typedef struct CGFont* CGFontRef; 63 typedef const struct __CTFont* CTFontRef; 64 typedef UInt32 FMFont; 65 typedef FMFont ATSUFontID; 66 typedef UInt32 ATSFontRef; 67 #endif 68 69 namespace WebCore { 70 71 class FontDescription; 72 class SharedBuffer; 73 74 #if OS(MACOSX) 75 class HarfBuzzFace; 76 #endif 77 78 #if OS(MACOSX) 79 inline CTFontRef toCTFontRef(NSFont *nsFont) { return reinterpret_cast<CTFontRef>(nsFont); } 80 #endif 81 82 class PLATFORM_EXPORT FontPlatformData { 83 public: 84 FontPlatformData(WTF::HashTableDeletedValueType); 85 FontPlatformData(); 86 FontPlatformData(const FontPlatformData&); 87 FontPlatformData(const FontDescription&, const AtomicString& family); 88 FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation = Horizontal, FontWidthVariant = RegularWidth); 89 90 #if OS(MACOSX) 91 FontPlatformData(NSFont*, float size, bool isPrinterFont = false, bool syntheticBold = false, bool syntheticOblique = false, 92 FontOrientation = Horizontal, FontWidthVariant = RegularWidth); 93 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant); 94 #endif 95 96 ~FontPlatformData(); 97 98 #if OS(MACOSX) 99 NSFont* font() const { return m_font; } 100 void setFont(NSFont*); 101 #endif 102 103 #if OS(MACOSX) 104 CGFontRef cgFont() const { return m_cgFont.get(); } 105 CTFontRef ctFont() const; 106 107 bool roundsGlyphAdvances() const; 108 bool allowsLigatures() const; 109 #endif 110 111 String fontFamilyName() const; 112 bool isFixedPitch() const; 113 float size() const { return m_size; } 114 void setSize(float size) { m_size = size; } 115 bool syntheticBold() const { return m_syntheticBold; } 116 bool syntheticOblique() const { return m_syntheticOblique; } 117 bool isColorBitmapFont() const { return m_isColorBitmapFont; } 118 bool isCompositeFontReference() const { return m_isCompositeFontReference; } 119 #if OS(MACOSX) 120 bool isPrinterFont() const { return m_isPrinterFont; } 121 #endif 122 FontOrientation orientation() const { return m_orientation; } 123 FontWidthVariant widthVariant() const { return m_widthVariant; } 124 125 void setOrientation(FontOrientation orientation) { m_orientation = orientation; } 126 127 #if OS(MACOSX) 128 HarfBuzzFace* harfBuzzFace(); 129 #endif 130 131 unsigned hash() const 132 { 133 #if OS(MACOSX) 134 ASSERT(m_font || !m_cgFont); 135 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) }; 136 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); 137 #endif 138 } 139 140 const FontPlatformData& operator=(const FontPlatformData&); 141 142 bool operator==(const FontPlatformData& other) const 143 { 144 return platformIsEqual(other) 145 && m_size == other.m_size 146 && m_syntheticBold == other.m_syntheticBold 147 && m_syntheticOblique == other.m_syntheticOblique 148 && m_isColorBitmapFont == other.m_isColorBitmapFont 149 && m_isCompositeFontReference == other.m_isCompositeFontReference 150 #if OS(MACOSX) 151 && m_isPrinterFont == other.m_isPrinterFont 152 #endif 153 && m_orientation == other.m_orientation 154 && m_widthVariant == other.m_widthVariant; 155 } 156 157 bool isHashTableDeletedValue() const 158 { 159 #if OS(MACOSX) 160 return m_font == hashTableDeletedFontValue(); 161 #endif 162 } 163 164 #ifndef NDEBUG 165 String description() const; 166 #endif 167 168 private: 169 bool platformIsEqual(const FontPlatformData&) const; 170 void platformDataInit(const FontPlatformData&); 171 const FontPlatformData& platformDataAssign(const FontPlatformData&); 172 #if OS(MACOSX) 173 // Load various data about the font specified by |nsFont| with the size fontSize into the following output paramters: 174 // Note: Callers should always take into account that for the Chromium port, |outNSFont| isn't necessarily the same 175 // font as |nsFont|. This because the sandbox may block loading of the original font. 176 // * outNSFont - The font that was actually loaded, for the Chromium port this may be different than nsFont. 177 // The caller is responsible for calling CFRelease() on this parameter when done with it. 178 // * cgFont - CGFontRef representing the input font at the specified point size. 179 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&); 180 static NSFont* hashTableDeletedFontValue() { return reinterpret_cast<NSFont *>(-1); } 181 #endif 182 183 public: 184 bool m_syntheticBold; 185 bool m_syntheticOblique; 186 FontOrientation m_orientation; 187 float m_size; 188 FontWidthVariant m_widthVariant; 189 190 private: 191 #if OS(MACOSX) 192 NSFont* m_font; 193 #endif 194 195 #if OS(MACOSX) 196 RetainPtr<CGFontRef> m_cgFont; 197 mutable RetainPtr<CTFontRef> m_CTFont; 198 199 RefPtr<MemoryActivatedFont> m_inMemoryFont; 200 RefPtr<HarfBuzzFace> m_harfBuzzFace; 201 #endif 202 203 bool m_isColorBitmapFont; 204 bool m_isCompositeFontReference; 205 #if OS(MACOSX) 206 bool m_isPrinterFont; 207 #endif 208 }; 209 210 } // namespace WebCore 211 212 #endif // FontPlatformData_h 213 214 #endif 215