1 /* 2 * Copyright (C) 2006, 2007 Apple Computer, Inc. 3 * Copyright (c) 2006, 2007, 2008, 2009, Google Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * * Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following disclaimer 13 * in the documentation and/or other materials provided with the 14 * distribution. 15 * * Neither the name of Google Inc. nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef FontPlatformDataChromiumWin_h 33 #define FontPlatformDataChromiumWin_h 34 35 #include "config.h" 36 37 #include "FontOrientation.h" 38 #include <wtf/Forward.h> 39 #include <wtf/PassRefPtr.h> 40 #include <wtf/RefCounted.h> 41 #include <wtf/text/StringImpl.h> 42 43 #include <usp10.h> 44 45 typedef struct HFONT__ *HFONT; 46 47 namespace WebCore { 48 49 class FontDescription; 50 51 class FontPlatformData { 52 public: 53 // Used for deleted values in the font cache's hash tables. The hash table 54 // will create us with this structure, and it will compare other values 55 // to this "Deleted" one. It expects the Deleted one to be differentiable 56 // from the NULL one (created with the empty constructor), so we can't just 57 // set everything to NULL. 58 FontPlatformData(WTF::HashTableDeletedValueType); 59 FontPlatformData(); 60 FontPlatformData(HFONT, float size); 61 FontPlatformData(float size, bool bold, bool oblique); 62 FontPlatformData(const FontPlatformData&); 63 64 FontPlatformData& operator=(const FontPlatformData&); 65 isHashTableDeletedValue()66 bool isHashTableDeletedValue() const { return m_font == hashTableDeletedFontValue(); } 67 68 ~FontPlatformData(); 69 hfont()70 HFONT hfont() const { return m_font ? m_font->hfont() : 0; } size()71 float size() const { return m_size; } 72 orientation()73 FontOrientation orientation() const { return Horizontal; } // FIXME: Implement. setOrientation(FontOrientation)74 void setOrientation(FontOrientation) { } // FIXME: Implement. 75 hash()76 unsigned hash() const 77 { 78 return m_font ? m_font->hash() : NULL; 79 } 80 81 bool operator==(const FontPlatformData& other) const 82 { 83 return m_font == other.m_font && m_size == other.m_size; 84 } 85 86 #ifndef NDEBUG 87 String description() const; 88 #endif 89 90 SCRIPT_FONTPROPERTIES* scriptFontProperties() const; scriptCache()91 SCRIPT_CACHE* scriptCache() const { return &m_scriptCache; } 92 93 private: 94 // We refcount the internal HFONT so that FontPlatformData can be 95 // efficiently copied. WebKit depends on being able to copy it, and we 96 // don't really want to re-create the HFONT. 97 class RefCountedHFONT : public RefCounted<RefCountedHFONT> { 98 public: create(HFONT hfont)99 static PassRefPtr<RefCountedHFONT> create(HFONT hfont) 100 { 101 return adoptRef(new RefCountedHFONT(hfont)); 102 } 103 104 ~RefCountedHFONT(); 105 hfont()106 HFONT hfont() const { return m_hfont; } hash()107 unsigned hash() const 108 { 109 return StringHasher::hashMemory<sizeof(HFONT)>(&m_hfont); 110 } 111 112 bool operator==(const RefCountedHFONT& other) const 113 { 114 return m_hfont == other.m_hfont; 115 } 116 117 private: 118 // The create() function assumes there is already a refcount of one 119 // so it can do adoptRef. RefCountedHFONT(HFONT hfont)120 RefCountedHFONT(HFONT hfont) : m_hfont(hfont) 121 { 122 } 123 124 HFONT m_hfont; 125 }; 126 127 static RefCountedHFONT* hashTableDeletedFontValue(); 128 129 RefPtr<RefCountedHFONT> m_font; 130 float m_size; // Point size of the font in pixels. 131 132 mutable SCRIPT_CACHE m_scriptCache; 133 mutable SCRIPT_FONTPROPERTIES* m_scriptFontProperties; 134 }; 135 136 } // WebCore 137 138 #endif // FontPlatformDataChromiumWin_h 139