1 /* 2 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 Copyright (C) 2008 Holger Hans Peter Freyther 4 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Library General Public 8 License as published by the Free Software Foundation; either 9 version 2 of the License, or (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Library General Public License for more details. 15 16 You should have received a copy of the GNU Library General Public License 17 along with this library; see the file COPYING.LIB. If not, write to 18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 Boston, MA 02110-1301, USA. 20 21 This class provides all functionality needed for loading images, style sheets and html 22 pages from the web. It has a memory cache for these objects. 23 */ 24 #ifndef FontPlatformData_h 25 #define FontPlatformData_h 26 27 #include "FontDescription.h" 28 #include <QFont> 29 #include <QHash> 30 31 namespace WebCore { 32 33 class String; 34 class FontPlatformDataPrivate : public Noncopyable { 35 public: 36 FontPlatformDataPrivate() 37 : refCount(1) 38 , size(font.pointSizeF()) 39 , bold(font.bold()) 40 , oblique(false) 41 {} 42 FontPlatformDataPrivate(const float size, const bool bold, const bool oblique) 43 : refCount(1) 44 , size(size) 45 , bold(bold) 46 , oblique(oblique) 47 {} 48 FontPlatformDataPrivate(const QFont& font) 49 : refCount(1) 50 , font(font) 51 , size(font.pointSizeF()) 52 , bold(font.bold()) 53 , oblique(false) 54 {} 55 unsigned refCount; 56 QFont font; 57 float size; 58 bool bold : 1; 59 bool oblique : 1; 60 }; 61 62 63 64 class FontPlatformData : public FastAllocBase { 65 public: 66 FontPlatformData(float size, bool bold, bool oblique); 67 FontPlatformData(const FontPlatformData &); 68 FontPlatformData(const FontDescription&, const AtomicString& familyName, int wordSpacing = 0, int letterSpacing = 0); 69 FontPlatformData(const QFont& font) 70 : m_data(new FontPlatformDataPrivate(font)) 71 {} 72 FontPlatformData(WTF::HashTableDeletedValueType) 73 : m_data(reinterpret_cast<FontPlatformDataPrivate*>(-1)) 74 {} 75 76 ~FontPlatformData(); 77 78 FontPlatformData& operator=(const FontPlatformData&); 79 bool operator==(const FontPlatformData&) const; 80 81 bool isHashTableDeletedValue() const 82 { 83 return m_data == reinterpret_cast<FontPlatformDataPrivate*>(-1); 84 } 85 86 static inline QFont::Weight toQFontWeight(FontWeight fontWeight) 87 { 88 switch (fontWeight) { 89 case FontWeight100: 90 case FontWeight200: 91 return QFont::Light; // QFont::Light == Weight of 25 92 case FontWeight600: 93 return QFont::DemiBold; // QFont::DemiBold == Weight of 63 94 case FontWeight700: 95 case FontWeight800: 96 return QFont::Bold; // QFont::Bold == Weight of 75 97 case FontWeight900: 98 return QFont::Black; // QFont::Black == Weight of 87 99 case FontWeight300: 100 case FontWeight400: 101 case FontWeight500: 102 default: 103 return QFont::Normal; // QFont::Normal == Weight of 50 104 } 105 } 106 107 QFont font() const 108 { 109 Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1)); 110 if (m_data) 111 return m_data->font; 112 return QFont(); 113 } 114 float size() const 115 { 116 Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1)); 117 if (m_data) 118 return m_data->size; 119 return 0.0f; 120 } 121 QString family() const 122 { 123 Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1)); 124 if (m_data) 125 return m_data->font.family(); 126 return QString(); 127 } 128 bool bold() const 129 { 130 Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1)); 131 if (m_data) 132 return m_data->bold; 133 return false; 134 } 135 bool italic() const 136 { 137 Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1)); 138 if (m_data) 139 return m_data->font.italic(); 140 return false; 141 } 142 bool smallCaps() const 143 { 144 Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1)); 145 if (m_data) 146 return m_data->font.capitalization() == QFont::SmallCaps; 147 return false; 148 } 149 int pixelSize() const 150 { 151 Q_ASSERT(m_data != reinterpret_cast<FontPlatformDataPrivate*>(-1)); 152 if (m_data) 153 return m_data->font.pixelSize(); 154 return 0; 155 } 156 unsigned hash() const; 157 158 #ifndef NDEBUG 159 String description() const; 160 #endif 161 private: 162 FontPlatformDataPrivate* m_data; 163 }; 164 165 } // namespace WebCore 166 167 #endif // FontPlatformData_h 168