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