1 /* 2 * Copyright (C) 2006 Kevin Ollivier All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef FontPlatformData_H 30 #define FontPlatformData_H 31 32 #include "FontDescription.h" 33 #include "AtomicString.h" 34 #include "CString.h" 35 #include "StringImpl.h" 36 #include <wtf/RefPtr.h> 37 38 #include <wx/defs.h> 39 #include <wx/font.h> 40 41 namespace WebCore { 42 43 class String; 44 45 class FontHolder: public WTF::RefCounted<FontHolder> 46 { 47 public: 48 FontHolder() 49 : m_font(0) 50 {} 51 52 FontHolder(wxFont* font) 53 : m_font(font) 54 {} 55 56 wxFont* font() { return m_font; } 57 58 private: 59 wxFont* m_font; 60 }; 61 62 class FontPlatformData { 63 public: 64 enum FontState { UNINITIALIZED, DELETED, VALID }; 65 66 FontPlatformData(WTF::HashTableDeletedValueType) 67 : m_fontState(DELETED), 68 m_font(0) 69 { } 70 71 ~FontPlatformData(); 72 73 FontPlatformData(const FontDescription&, const AtomicString&); 74 FontPlatformData(float size, bool bold, bool italic) 75 : m_fontState(UNINITIALIZED) 76 , m_font(0) 77 { 78 } 79 80 FontPlatformData() 81 : m_fontState(UNINITIALIZED) 82 , m_font(0) 83 { 84 } 85 86 wxFont* font() const { 87 return m_font->font(); 88 } 89 90 unsigned hash() const { 91 switch (m_fontState) { 92 case DELETED: 93 return -1; 94 case UNINITIALIZED: 95 return 0; 96 case VALID: 97 return computeHash(); 98 } 99 } 100 101 unsigned computeHash() const; 102 103 bool operator==(const FontPlatformData& other) const 104 { 105 if (m_font && m_fontState == VALID && other.m_fontState == VALID && other.m_font) { 106 wxFont* thisFont = m_font->font(); 107 wxFont* otherFont = other.m_font->font(); 108 return thisFont->IsOk() && otherFont->IsOk() && thisFont->IsSameAs(*otherFont); 109 } 110 else 111 return m_fontState == other.m_fontState; 112 } 113 114 bool isHashTableDeletedValue() const { return m_fontState == DELETED; } 115 116 bool roundsGlyphAdvances() const { return false; } 117 118 #if OS(WINDOWS) 119 bool useGDI() const; 120 HFONT hfont() const; 121 #endif 122 123 #ifndef NDEBUG 124 String description() const; 125 #endif 126 127 private: 128 WTF::RefPtr<FontHolder> m_font; 129 FontState m_fontState; 130 }; 131 132 } 133 134 #endif 135