1 /* 2 * This file is part of the internal font implementation. It should not be included by anyone other than 3 * FontMac.cpp, FontWin.cpp and Font.cpp. 4 * 5 * Copyright (C) 2006, 2007, 2008 Apple Inc. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Library General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Library General Public License for more details. 16 * 17 * You should have received a copy of the GNU Library General Public License 18 * along with this library; see the file COPYING.LIB. If not, write to 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * Boston, MA 02110-1301, USA. 21 * 22 */ 23 24 #ifndef FontPlatformData_H 25 #define FontPlatformData_H 26 27 #include "StringImpl.h" 28 #include <wtf/PassRefPtr.h> 29 #include <wtf/RetainPtr.h> 30 #include <wtf/RefCounted.h> 31 32 #if PLATFORM(CAIRO) 33 #include <cairo-win32.h> 34 #endif 35 36 typedef struct HFONT__* HFONT; 37 typedef struct CGFont* CGFontRef; 38 39 namespace WebCore { 40 41 class FontDescription; 42 class String; 43 44 class FontPlatformData { 45 public: FontPlatformData()46 FontPlatformData() 47 #if PLATFORM(CAIRO) 48 : m_fontFace(0) 49 , m_scaledFont(0) 50 , 51 #else 52 : 53 #endif 54 m_size(0) 55 , m_syntheticBold(false) 56 , m_syntheticOblique(false) 57 , m_useGDI(false) 58 { 59 } 60 61 FontPlatformData(HFONT, float size, bool bold, bool oblique, bool useGDI); 62 FontPlatformData(float size, bool bold, bool oblique); 63 64 #if PLATFORM(CG) 65 FontPlatformData(HFONT, CGFontRef, float size, bool bold, bool oblique, bool useGDI); 66 #elif PLATFORM(CAIRO) 67 FontPlatformData(cairo_font_face_t*, float size, bool bold, bool oblique); 68 FontPlatformData(const FontPlatformData&); 69 70 FontPlatformData& operator=(const FontPlatformData&); 71 #endif 72 ~FontPlatformData(); 73 FontPlatformData(WTF::HashTableDeletedValueType)74 FontPlatformData(WTF::HashTableDeletedValueType) : m_font(WTF::HashTableDeletedValue) { } isHashTableDeletedValue()75 bool isHashTableDeletedValue() const { return m_font.isHashTableDeletedValue(); } 76 hfont()77 HFONT hfont() const { return m_font->hfont(); } 78 #if PLATFORM(CG) cgFont()79 CGFontRef cgFont() const { return m_cgFont.get(); } 80 #elif PLATFORM(CAIRO) fontFace()81 cairo_font_face_t* fontFace() const { return m_fontFace; } scaledFont()82 cairo_scaled_font_t* scaledFont() const { return m_scaledFont; } 83 #endif 84 size()85 float size() const { return m_size; } setSize(float size)86 void setSize(float size) { m_size = size; } syntheticBold()87 bool syntheticBold() const { return m_syntheticBold; } syntheticOblique()88 bool syntheticOblique() const { return m_syntheticOblique; } useGDI()89 bool useGDI() const { return m_useGDI; } 90 hash()91 unsigned hash() const 92 { 93 return m_font->hash(); 94 } 95 96 bool operator==(const FontPlatformData& other) const 97 { 98 return m_font == other.m_font && 99 #if PLATFORM(CG) 100 m_cgFont == other.m_cgFont && 101 #elif PLATFORM(CAIRO) 102 m_fontFace == other.m_fontFace && 103 m_scaledFont == other.m_scaledFont && 104 #endif 105 m_size == other.m_size && 106 m_syntheticBold == other.m_syntheticBold && m_syntheticOblique == other.m_syntheticOblique && 107 m_useGDI == other.m_useGDI; 108 } 109 110 #ifndef NDEBUG 111 String description() const; 112 #endif 113 114 private: 115 class RefCountedHFONT : public RefCounted<RefCountedHFONT> { 116 public: create(HFONT hfont)117 static PassRefPtr<RefCountedHFONT> create(HFONT hfont) { return adoptRef(new RefCountedHFONT(hfont)); } createDeleted()118 static PassRefPtr<RefCountedHFONT> createDeleted() { return adoptRef(new RefCountedHFONT(reinterpret_cast<HFONT>(-1))); } 119 ~RefCountedHFONT()120 ~RefCountedHFONT() { if (m_hfont != reinterpret_cast<HFONT>(-1)) DeleteObject(m_hfont); } 121 hfont()122 HFONT hfont() const { return m_hfont; } hash()123 unsigned hash() const 124 { 125 return StringImpl::computeHash(reinterpret_cast<const UChar*>(&m_hfont), sizeof(HFONT) / sizeof(UChar)); 126 } 127 128 private: RefCountedHFONT(HFONT hfont)129 RefCountedHFONT(HFONT hfont) 130 : m_hfont(hfont) 131 { 132 } 133 134 HFONT m_hfont; 135 }; 136 137 void platformDataInit(HFONT font, float size, HDC hdc, WCHAR* faceName); 138 139 RefPtr<RefCountedHFONT> m_font; 140 #if PLATFORM(CG) 141 RetainPtr<CGFontRef> m_cgFont; 142 #elif PLATFORM(CAIRO) 143 cairo_font_face_t* m_fontFace; 144 cairo_scaled_font_t* m_scaledFont; 145 #endif 146 147 float m_size; 148 bool m_syntheticBold; 149 bool m_syntheticOblique; 150 bool m_useGDI; 151 }; 152 153 } 154 155 #endif 156