1/* 2 * Copyright (C) 2011 Brent Fulgham 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 * 19 */ 20 21#include "config.h" 22#include "FontPlatformData.h" 23 24#include <wtf/HashMap.h> 25#include <wtf/RetainPtr.h> 26#include <wtf/Vector.h> 27#include <wtf/text/StringHash.h> 28#include <wtf/text/WTFString.h> 29 30#if OS(DARWIN) && USE(CG) 31#include "SharedBuffer.h" 32#include <CoreGraphics/CGFont.h> 33#endif 34 35namespace WebCore { 36 37FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType) 38 : m_syntheticBold(false) 39 , m_syntheticOblique(false) 40 , m_orientation(Horizontal) 41#if PLATFORM(IOS) 42 , m_isEmoji(false) 43#endif 44 , m_size(0) 45 , m_widthVariant(RegularWidth) 46#if PLATFORM(WIN) 47 , m_font(WTF::HashTableDeletedValue) 48#elif OS(DARWIN) 49 , m_font(hashTableDeletedFontValue()) 50#endif 51#if USE(CG) && PLATFORM(WIN) 52 , m_cgFont(0) 53#elif USE(CAIRO) 54 , m_scaledFont(hashTableDeletedFontValue()) 55#endif 56 , m_isColorBitmapFont(false) 57 , m_isCompositeFontReference(false) 58#if OS(DARWIN) 59 , m_isPrinterFont(false) 60#endif 61#if PLATFORM(WIN) 62 , m_useGDI(false) 63#endif 64{ 65} 66 67FontPlatformData::FontPlatformData() 68 : m_syntheticBold(false) 69 , m_syntheticOblique(false) 70 , m_orientation(Horizontal) 71#if PLATFORM(IOS) 72 , m_isEmoji(false) 73#endif 74 , m_size(0) 75 , m_widthVariant(RegularWidth) 76#if OS(DARWIN) 77 , m_font(0) 78#endif 79#if USE(CG) && PLATFORM(WIN) 80 , m_cgFont(0) 81#elif USE(CAIRO) 82 , m_scaledFont(0) 83#endif 84 , m_isColorBitmapFont(false) 85 , m_isCompositeFontReference(false) 86#if OS(DARWIN) 87 , m_isPrinterFont(false) 88#endif 89#if PLATFORM(WIN) 90 , m_useGDI(false) 91#endif 92{ 93} 94 95FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant) 96 : m_syntheticBold(syntheticBold) 97 , m_syntheticOblique(syntheticOblique) 98 , m_orientation(orientation) 99#if PLATFORM(IOS) 100 , m_isEmoji(false) 101#endif 102 , m_size(size) 103 , m_widthVariant(widthVariant) 104#if OS(DARWIN) 105 , m_font(0) 106#endif 107#if USE(CG) && PLATFORM(WIN) 108 , m_cgFont(0) 109#elif USE(CAIRO) 110 , m_scaledFont(0) 111#endif 112 , m_isColorBitmapFont(false) 113 , m_isCompositeFontReference(false) 114#if OS(DARWIN) 115 , m_isPrinterFont(false) 116#endif 117#if PLATFORM(WIN) 118 , m_useGDI(false) 119#endif 120{ 121} 122 123#if OS(DARWIN) && USE(CG) 124FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant) 125 : m_syntheticBold(syntheticBold) 126 , m_syntheticOblique(syntheticOblique) 127 , m_orientation(orientation) 128#if PLATFORM(IOS) 129 , m_isEmoji(false) 130#endif 131 , m_size(size) 132 , m_widthVariant(widthVariant) 133 , m_font(0) 134 , m_cgFont(cgFont) 135 , m_isColorBitmapFont(false) 136 , m_isCompositeFontReference(false) 137 , m_isPrinterFont(false) 138{ 139} 140#endif 141 142FontPlatformData::FontPlatformData(const FontPlatformData& source) 143 : m_syntheticBold(source.m_syntheticBold) 144 , m_syntheticOblique(source.m_syntheticOblique) 145 , m_orientation(source.m_orientation) 146 , m_size(source.m_size) 147 , m_widthVariant(source.m_widthVariant) 148 , m_isColorBitmapFont(source.m_isColorBitmapFont) 149 , m_isCompositeFontReference(source.m_isCompositeFontReference) 150#if OS(DARWIN) 151 , m_isPrinterFont(source.m_isPrinterFont) 152#endif 153{ 154 platformDataInit(source); 155} 156 157const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& other) 158{ 159 // Check for self-assignment. 160 if (this == &other) 161 return *this; 162 163 m_syntheticBold = other.m_syntheticBold; 164 m_syntheticOblique = other.m_syntheticOblique; 165 m_orientation = other.m_orientation; 166 m_size = other.m_size; 167 m_widthVariant = other.m_widthVariant; 168 m_isColorBitmapFont = other.m_isColorBitmapFont; 169 m_isCompositeFontReference = other.m_isCompositeFontReference; 170#if OS(DARWIN) 171 m_isPrinterFont = other.m_isPrinterFont; 172#endif 173 174 return platformDataAssign(other); 175} 176 177#if OS(DARWIN) && USE(CG) 178PassRefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const 179{ 180 if (RetainPtr<CFDataRef> data = adoptCF(CGFontCopyTableForTag(cgFont(), table))) 181 return SharedBuffer::wrapCFData(data.get()); 182 183 return nullptr; 184} 185#endif 186 187} 188