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 Apple Computer, Inc. 6 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com 7 * Copyright (C) 2007 Holger Hans Peter Freyther 8 * Copyright (C) 2007 Pioneer Research Center USA, Inc. 9 * All rights reserved. 10 * 11 * This library is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Library General Public 13 * License as published by the Free Software Foundation; either 14 * version 2 of the License, or (at your option) any later version. 15 * 16 * This library is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Library General Public License for more details. 20 * 21 * You should have received a copy of the GNU Library General Public License 22 * along with this library; see the file COPYING.LIB. If not, write to 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 24 * Boston, MA 02110-1301, USA. 25 * 26 */ 27 28 #ifndef FontPlatformData_h 29 #define FontPlatformData_h 30 31 #include "GlyphBuffer.h" 32 #include "FontDescription.h" 33 #include <cairo.h> 34 #if defined(USE_FREETYPE) 35 #include <cairo-ft.h> 36 #include <fontconfig/fcfreetype.h> 37 #elif defined(USE_PANGO) 38 #include <pango/pangocairo.h> 39 #else 40 #error "Must defined a font backend" 41 #endif 42 43 namespace WebCore { 44 45 class String; 46 47 class FontPlatformData { 48 public: FontPlatformData(WTF::HashTableDeletedValueType)49 FontPlatformData(WTF::HashTableDeletedValueType) 50 #if defined(USE_FREETYPE) 51 : m_pattern(hashTableDeletedFontValue()) 52 , m_fallbacks(0) 53 #elif defined(USE_PANGO) 54 : m_context(0) 55 , m_font(hashTableDeletedFontValue()) 56 #else 57 #error "Must defined a font backend" 58 #endif 59 , m_scaledFont(0) 60 { } 61 FontPlatformData()62 FontPlatformData() 63 #if defined(USE_FREETYPE) 64 : m_pattern(0) 65 , m_fallbacks(0) 66 #elif defined(USE_PANGO) 67 : m_context(0) 68 , m_font(0) 69 #else 70 #error "Must defined a font backend" 71 #endif 72 , m_scaledFont(0) 73 { } 74 75 FontPlatformData(const FontDescription&, const AtomicString& family); 76 77 FontPlatformData(float size, bool bold, bool italic); 78 FontPlatformData(cairo_font_face_t* fontFace, int size, bool bold, bool italic); 79 FontPlatformData(const FontPlatformData&); 80 81 ~FontPlatformData(); 82 83 static bool init(); 84 85 bool isFixedPitch(); size()86 float size() const { return m_size; } syntheticBold()87 bool syntheticBold() const { return m_syntheticBold; } syntheticOblique()88 bool syntheticOblique() const { return m_syntheticOblique; } 89 90 void setFont(cairo_t*) const; 91 hash()92 unsigned hash() const 93 { 94 #if defined(USE_FREETYPE) 95 if (m_pattern) 96 return FcPatternHash(m_pattern); 97 #endif 98 uintptr_t hashCodes[1] = { reinterpret_cast<uintptr_t>(m_scaledFont) }; 99 return StringImpl::computeHash(reinterpret_cast<UChar*>(hashCodes), sizeof(hashCodes) / sizeof(UChar)); 100 } 101 102 bool operator==(const FontPlatformData&) const; 103 FontPlatformData& operator=(const FontPlatformData&); isHashTableDeletedValue()104 bool isHashTableDeletedValue() const { 105 #if defined(USE_FREETYPE) 106 return m_pattern == hashTableDeletedFontValue(); 107 #elif defined(USE_PANGO) 108 return m_font == hashTableDeletedFontValue(); 109 #endif 110 }; 111 112 #ifndef NDEBUG 113 String description() const; 114 #endif 115 116 #if defined(USE_FREETYPE) 117 FcPattern* m_pattern; 118 FcFontSet* m_fallbacks; 119 #elif defined(USE_PANGO) 120 static PangoFontMap* m_fontMap; 121 static GHashTable* m_hashTable; 122 123 PangoContext* m_context; 124 PangoFont* m_font; 125 #else 126 #error "Must defined a font backend" 127 #endif 128 float m_size; 129 bool m_syntheticBold; 130 bool m_syntheticOblique; 131 cairo_scaled_font_t* m_scaledFont; 132 private: 133 #if defined(USE_FREETYPE) hashTableDeletedFontValue()134 static FcPattern *hashTableDeletedFontValue() { return reinterpret_cast<FcPattern*>(-1); } 135 #elif defined(USE_PANGO) 136 static PangoFont *hashTableDeletedFontValue() { return reinterpret_cast<PangoFont*>(-1); } 137 #endif 138 }; 139 140 } 141 142 #endif 143