| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. | |
| 3 * Copyright (C) 2006 Michael Emmel mike.emmel@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@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 "core/platform/graphics/win/FontPlatformDataWin.h" | |
| 28 #elif !OS(MACOSX) | |
| 29 #include "core/platform/graphics/harfbuzz/FontPlatformDataHarfBuzz.h" | |
| 30 | |
| 31 #else | |
| 32 | |
| 33 #ifndef FontPlatformData_h | |
| 34 #define FontPlatformData_h | |
| 35 | |
| 36 #include "platform/fonts/FontOrientation.h" | |
| 37 #include "platform/fonts/FontWidthVariant.h" | |
| 38 | |
| 39 #if OS(MACOSX) | |
| 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(MACOSX) | |
| 57 #include "core/platform/graphics/mac/MemoryActivatedFont.h" | |
| 58 #endif | |
| 59 | |
| 60 #if OS(MACOSX) | |
| 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(MACOSX) | |
| 74 class HarfBuzzFace; | |
| 75 #endif | |
| 76 | |
| 77 #if OS(MACOSX) | |
| 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, Font
Orientation = Horizontal, FontWidthVariant = RegularWidth); | |
| 88 | |
| 89 #if OS(MACOSX) | |
| 90 FontPlatformData(NSFont*, float size, bool isPrinterFont = false, bool synth
eticBold = false, bool syntheticOblique = false, | |
| 91 FontOrientation = Horizontal, FontWidthVariant = RegularWid
th); | |
| 92 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOb
lique, FontOrientation, FontWidthVariant); | |
| 93 #endif | |
| 94 | |
| 95 ~FontPlatformData(); | |
| 96 | |
| 97 #if OS(MACOSX) | |
| 98 NSFont* font() const { return m_font; } | |
| 99 void setFont(NSFont*); | |
| 100 #endif | |
| 101 | |
| 102 #if OS(MACOSX) | |
| 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 String fontFamilyName() const; | |
| 111 bool isFixedPitch() const; | |
| 112 float size() const { return m_size; } | |
| 113 void setSize(float size) { m_size = size; } | |
| 114 bool syntheticBold() const { return m_syntheticBold; } | |
| 115 bool syntheticOblique() const { return m_syntheticOblique; } | |
| 116 bool isColorBitmapFont() const { return m_isColorBitmapFont; } | |
| 117 bool isCompositeFontReference() const { return m_isCompositeFontReference; } | |
| 118 #if OS(MACOSX) | |
| 119 bool isPrinterFont() const { return m_isPrinterFont; } | |
| 120 #endif | |
| 121 FontOrientation orientation() const { return m_orientation; } | |
| 122 FontWidthVariant widthVariant() const { return m_widthVariant; } | |
| 123 | |
| 124 void setOrientation(FontOrientation orientation) { m_orientation = orientati
on; } | |
| 125 | |
| 126 #if OS(MACOSX) | |
| 127 HarfBuzzFace* harfBuzzFace(); | |
| 128 #endif | |
| 129 | |
| 130 unsigned hash() const | |
| 131 { | |
| 132 #if OS(MACOSX) | |
| 133 ASSERT(m_font || !m_cgFont); | |
| 134 uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, static_cas
t<uintptr_t>(m_isPrinterFont << 3 | m_orientation << 2 | m_syntheticBold << 1 |
m_syntheticOblique) }; | |
| 135 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); | |
| 136 #endif | |
| 137 } | |
| 138 | |
| 139 const FontPlatformData& operator=(const FontPlatformData&); | |
| 140 | |
| 141 bool operator==(const FontPlatformData& other) const | |
| 142 { | |
| 143 return platformIsEqual(other) | |
| 144 && m_size == other.m_size | |
| 145 && m_syntheticBold == other.m_syntheticBold | |
| 146 && m_syntheticOblique == other.m_syntheticOblique | |
| 147 && m_isColorBitmapFont == other.m_isColorBitmapFont | |
| 148 && m_isCompositeFontReference == other.m_isCompositeFontReference | |
| 149 #if OS(MACOSX) | |
| 150 && m_isPrinterFont == other.m_isPrinterFont | |
| 151 #endif | |
| 152 && m_orientation == other.m_orientation | |
| 153 && m_widthVariant == other.m_widthVariant; | |
| 154 } | |
| 155 | |
| 156 bool isHashTableDeletedValue() const | |
| 157 { | |
| 158 #if OS(MACOSX) | |
| 159 return m_font == hashTableDeletedFontValue(); | |
| 160 #endif | |
| 161 } | |
| 162 | |
| 163 #ifndef NDEBUG | |
| 164 String description() const; | |
| 165 #endif | |
| 166 | |
| 167 private: | |
| 168 bool platformIsEqual(const FontPlatformData&) const; | |
| 169 void platformDataInit(const FontPlatformData&); | |
| 170 const FontPlatformData& platformDataAssign(const FontPlatformData&); | |
| 171 #if OS(MACOSX) | |
| 172 // Load various data about the font specified by |nsFont| with the size font
Size into the following output paramters: | |
| 173 // Note: Callers should always take into account that for the Chromium port,
|outNSFont| isn't necessarily the same | |
| 174 // font as |nsFont|. This because the sandbox may block loading of the origi
nal font. | |
| 175 // * outNSFont - The font that was actually loaded, for the Chromium port th
is may be different than nsFont. | |
| 176 // The caller is responsible for calling CFRelease() on this parameter when
done with it. | |
| 177 // * cgFont - CGFontRef representing the input font at the specified point s
ize. | |
| 178 void loadFont(NSFont*, float fontSize, NSFont*& outNSFont, CGFontRef&); | |
| 179 static NSFont* hashTableDeletedFontValue() { return reinterpret_cast<NSFont
*>(-1); } | |
| 180 #endif | |
| 181 | |
| 182 public: | |
| 183 bool m_syntheticBold; | |
| 184 bool m_syntheticOblique; | |
| 185 FontOrientation m_orientation; | |
| 186 float m_size; | |
| 187 FontWidthVariant m_widthVariant; | |
| 188 | |
| 189 private: | |
| 190 #if OS(MACOSX) | |
| 191 NSFont* m_font; | |
| 192 #endif | |
| 193 | |
| 194 #if OS(MACOSX) | |
| 195 RetainPtr<CGFontRef> m_cgFont; | |
| 196 mutable RetainPtr<CTFontRef> m_CTFont; | |
| 197 | |
| 198 RefPtr<MemoryActivatedFont> m_inMemoryFont; | |
| 199 RefPtr<HarfBuzzFace> m_harfBuzzFace; | |
| 200 #endif | |
| 201 | |
| 202 bool m_isColorBitmapFont; | |
| 203 bool m_isCompositeFontReference; | |
| 204 #if OS(MACOSX) | |
| 205 bool m_isPrinterFont; | |
| 206 #endif | |
| 207 }; | |
| 208 | |
| 209 } // namespace WebCore | |
| 210 | |
| 211 #endif // FontPlatformData_h | |
| 212 | |
| 213 #endif | |
| OLD | NEW |